Skip to content

ZAP CLI - #1725

Open
paulr34 wants to merge 8 commits into
project-chip:masterfrom
paulr34:cursor/zap-edit-cli-b5b9
Open

ZAP CLI#1725
paulr34 wants to merge 8 commits into
project-chip:masterfrom
paulr34:cursor/zap-edit-cli-b5b9

Conversation

@paulr34

@paulr34 paulr34 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive command-line interface (zap edit) that allows users to perform configuration edits—such as managing endpoints, device types, clusters, attributes, commands, events, and features—directly from the terminal or via batch scripts. The review feedback highlights a critical bug in cli-operations.js where using e.parentRef instead of e.parentEndpointRef bypasses the safety check when deleting parent endpoints. Additionally, improvements were suggested to allow global options to precede the edit command in the argument parser and to make the package category matching case-insensitive.

let endpoint = await resolver.resolveEndpoint(ctx, params.endpoint)
let all = await queryEndpoint.selectAllEndpoints(ctx.db, ctx.sessionId)

let children = all.filter((e) => e.parentRef === endpoint.id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The endpoint object e returned by selectAllEndpoints has its parent endpoint reference mapped to parentEndpointRef (corresponding to the database column PARENT_ENDPOINT_REF), not parentRef. Using e.parentRef will evaluate to undefined, causing the children check to always be empty and allowing deletion of parent endpoints without --force (which silently orphans children).

Please update this to use e.parentEndpointRef instead.

Suggested change
let children = all.filter((e) => e.parentRef === endpoint.id)
let children = all.filter((e) => e.parentEndpointRef === endpoint.id)

Comment thread src-electron/cli/cli-commands.js Outdated
for (let i = 0; i < argv.length; i++) {
let arg = argv[i]
if (typeof arg !== 'string') continue
if (arg.startsWith('-')) return -1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Returning -1 immediately when an argument starting with - is encountered prevents users from placing global options (such as --logToStdout or --stateDirectory) before the edit command.

Consider skipping option flags and their values or using a more flexible detection mechanism to allow global options to precede the edit subcommand.

Comment thread src-electron/cli/cli-resolver.js Outdated
Comment on lines +165 to +168
let filtered = pkgs.filter(
(p) =>
p.category === wanted || p.type === dbEnum.packageType.zclXmlStandalone
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The category comparison p.category === wanted is case-sensitive. Since users might pass mixed-case category names (e.g., --category Zigbee or --category Matter), it is more robust to perform a case-insensitive comparison and guard against null/undefined categories.

    let wantedLower = wanted.toLowerCase()
    let filtered = pkgs.filter(
      (p) =>
        (p.category && p.category.toLowerCase() === wantedLower) ||
        p.type === dbEnum.packageType.zclXmlStandalone
    )

@cursor
cursor Bot force-pushed the cursor/zap-edit-cli-b5b9 branch 4 times, most recently from 830a5fd to da463ff Compare August 1, 2026 13:22
@paulr34
paulr34 force-pushed the cursor/zap-edit-cli-b5b9 branch from 80d143c to 9b25dff Compare August 1, 2026 14:53
@cursor
cursor Bot force-pushed the cursor/zap-edit-cli-b5b9 branch from dec864f to 23c8cb2 Compare August 1, 2026 16:02
@paulr34
paulr34 force-pushed the cursor/zap-edit-cli-b5b9 branch 2 times, most recently from 139bb55 to dc5bed3 Compare August 1, 2026 16:16
@codecov-commenter

codecov-commenter commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.40073% with 101 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.12%. Comparing base (27f4885) to head (54f162f).
⚠️ Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
src-electron/cli/cli-operations.js 94.21% 57 Missing ⚠️
src-electron/cli/cli-resolver.js 95.85% 8 Missing ⚠️
src-electron/util/args.js 82.22% 8 Missing ⚠️
src-electron/main-process/startup.js 63.15% 7 Missing ⚠️
src-electron/util/env.js 87.50% 6 Missing ⚠️
src-electron/cli/cli-script.js 89.18% 4 Missing ⚠️
src-electron/cli/cli-error.js 93.18% 3 Missing ⚠️
src-electron/cli/cli-commands.js 99.01% 2 Missing ⚠️
src-electron/rest/user-data.js 50.00% 2 Missing ⚠️
src-electron/cli/cli-help.js 99.10% 1 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1725      +/-   ##
==========================================
+ Coverage   75.07%   77.12%   +2.04%     
==========================================
  Files         204      219      +15     
  Lines       23892    26552    +2660     
  Branches     5469     6243     +774     
==========================================
+ Hits        17938    20477    +2539     
- Misses       5954     6075     +121     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@paulr34
paulr34 force-pushed the cursor/zap-edit-cli-b5b9 branch 3 times, most recently from 311d66e to aa06ef3 Compare August 3, 2026 15:27
Comment thread docs/make-zap-edit-architecture-pdf
Comment thread docs/zap-edit-architecture.md
Comment thread docs/zap-edit-architecture.md
Comment thread docs/zap-edit-architecture.md
Comment thread docs/zap-edit-architecture.md
@paulr34
paulr34 force-pushed the cursor/zap-edit-cli-b5b9 branch 2 times, most recently from 99d9de1 to cd4755f Compare August 3, 2026 20:11
@paulr34
paulr34 force-pushed the cursor/zap-edit-cli-b5b9 branch 4 times, most recently from 6daea04 to 54f162f Compare August 6, 2026 20:09
@CLAassistant

CLAassistant commented Aug 28, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@paulr34
paulr34 force-pushed the cursor/zap-edit-cli-b5b9 branch 3 times, most recently from 491525a to fac54ab Compare September 9, 2026 17:59
Provides a discoverable CLI to create and edit .zap files: endpoints,
clusters, attributes, commands, events, and Matter features, with ranked
lookup suggestions, multiprotocol support, GUI-aligned guardrails, and
generation/check coverage.

Shares Zigbee cluster state across endpoints the same way the UI does
(via util/shared-cluster-state.js), with protocol rules driven by the
data model rather than protocol name checks.

Ships zap-cli with bundled edit modules and test generation defaults,
short --zcl/--gen names, release smoke coverage, and a QA quick-start.

When --studioHttpPort and --ideProjectPath are both given, cluster
enable/disable and endpoint create ask Studio to install or remove the
matching UC components, matching the GUI path.

Includes a SKILL.md so agents use zap-cli (with SDK-provided --zcl) instead
of rewriting .zap JSON by hand.

Includes architecture docs, layering tests, and the step-by-step edit guide.
Adds what an agent could not work out from the command surface alone: where
zap-cli and the .zap files live, that clusters need their UC component
installed and the project regenerated afterwards, that batching through
apply avoids paying the metadata load per command, and that concurrent
jobs need their own state directory.

Corrects two things. --strict also applies to edits, where it refuses to
save when that edit introduced errors, and --gen is not only for code
generation: the cluster-to-component mapping is a gen-templates package
extension, so component integration needs it too.
Configuring a cluster is half of what the GUI checkbox does; installing the
component that implements it is the other half, and only Studio can write the
project file. Two ways of getting that wrong were silent.

Asking for Studio integration when nothing is answering saved the edit,
installed nothing and looked like success, because failures were reported one
404 per component after the fact. The port is now checked once, up front,
against the same endpoint isProjectActive uses, and a request that cannot be
served is refused.

Without Studio the cluster-to-component mapping is still known locally, since
it is a package extension the generation templates carry. It was being thrown
away. An enable now names the components it could not install, so a headless
caller can hand them to slc instead of discovering later that nothing
implements the cluster it configured.

Also guards isProjectActive against a missing response, which threw a
TypeError rather than returning false when nothing was listening.
The test copied a resource .zap and passed the generation templates that
carry the cluster-to-component mapping. A resource names its own templates,
and fuzzy package matching prefers those, so the session only used the
templates the test asked for when the state database happened to resolve the
file's reference to them by file name. It did on a machine that had run the
suite before, and did not on a fresh one, which is every build agent.

Starting from an empty configuration means the file names the templates the
test loaded, so what is under test no longer depends on what the database has
already seen.
Omitting them can rewrite Matter .zap packages to Zigbee test templates
and leave slc generate without Matter zap-generated output.
Strict package matching stops new rewrites but does not fix a .zap that
already points at Zigbee test gen-templates.
So a bare zap-cli edit against an SLC project uses the same SDK packages
Studio and generate already inject from apack properties, instead of the
bundled test templates that corrupt Matter .zap files on save.
Studio 6's Jetty 12 rejects %2F in a path segment, so encodeURIComponent of a filesystem .slcp never reaches the UC servlets. Match the GUI's %→_ mangling and document the Studio-vs-slc component install routes in the skill.
@paulr34
paulr34 force-pushed the cursor/zap-edit-cli-b5b9 branch from fac54ab to 31a8f57 Compare September 17, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants