Repository navigation
feat(import): import cli defaults and instruction documents - #316
Merged
Merged
Conversation
nixuuu
force-pushed
the
feat/cli-import-6
branch
from
November 7, 2026 09:02
a8be7ce to
c7612a7
Compare
nixuuu
force-pushed
the
feat/cli-import-6
branch
4 times, most recently
from
November 7, 2026 10:26
be8b721 to
b044c19
Compare
Settings → Import lists the settings and instruction files of each CLI home next to Canopy's own: the default model per agent CLI, the permission mode of new threads (never Full access), and CLAUDE.md / AGENTS.md as instruction documents for the source worker's Canopy homes. What stays out is listed with its reason; Undo restores only what nobody changed since. See docs/import.md.
nixuuu
force-pushed
the
feat/cli-import-6
branch
from
November 7, 2026 10:56
b044c19 to
eb51d28
Compare
nixuuu
marked this pull request as ready for review
November 7, 2026 11:13
nixuuu
added a commit
that referenced
this pull request
Nov 7, 2026
Stage 7 of the CLI import (stack B). Design: `docs/import.md` ("Skille i
pluginy").
## What
- **Skills:** `skills/<name>/` in the Claude, Codex and Grok homes, and
the device's `~/.agents/skills/`.
- They are read through the confined reader (regular files only, no
links) and text files are masked.
- They are validated by the library rules (`SKILL.md` with name and
description; limits of 1000 files, 1 MiB per file, 25 MiB in total), so
the scan's digest is the checksum the library will store.
- The same skill in several CLIs is one item. Two versions with one name
are both shown, and the gateway accepts one.
- **Commands and prompts as skills:** Claude `commands/**.md` and Codex
`prompts/*.md` get a generated `SKILL.md`. They are unticked by default.
- **Saving:** through `SaveLibrarySkill` (same validation, limits and
audit as an upload), assigned to the source worker's Canopy platform
homes only. Replace adds a new version. Undo removes the skill or
restores the previous full definition, including repository provenance,
unless the definition changed since.
- **Marketplaces:**
- Claude `known_marketplaces.json` and Codex `[marketplaces.*]` (git
over HTTPS) are added as on manual add.
- Local-directory marketplaces are listed with the reason.
- Undo keeps a marketplace a plugin was approved from.
- **Plugins** are listed with their version and "Plugins run code.
Approve each one in Agent environment." An import never activates code.
## Why
Skills and commands are the reusable part of a CLI setup. Bringing them
into the Agent environment library makes them available in Canopy
threads with the library's review and audit. Plugins stay a deliberate,
per-file approval.
## Verification
- `tests/integration/import-library-skills.test.ts` (gRPC):
- a skill shared across CLIs becomes one item;
- masked file contents;
- a link or a file outside the home reads nothing;
- Replace and Undo with versions;
- marketplace add and Undo;
- plugins never activated;
- command → skill.
- Worker tests: skill validation, sorting, version conflicts,
`~/.agents` lock origin.
- Gates on this stage: typecheck, lint, format check, import unit tests
(67 pass), integration file above.
- Current validation is recorded in “Re-check fixes” below and on the
top stage (#318).
- Original implementation browser check: light and dark, desktop and
phone, long skill names and descriptions.
## Copy audit (docs/copy.md §8)
- **New strings:**
- section description: "Defaults for new threads, instructions, skills
and marketplaces. Undo puts back what was there, unless you changed it
since." (extended again in #318);
- outcomes: "New skill for {CLIs}", "New version {version} in Agent
environment", "New version of the library skill", "New marketplace in
Agent environment", "Added to Agent environment as {name}";
- badge: "Marketplace";
- reasons: "A marketplace on this computer. Add it in Agent
environment.", "Plugins run code. Approve each one in Agent
environment.", "Canopy can't read this kind of marketplace source.",
"Its name can't be a skill name.", "Another version has this name.
Choose one.", "A skill with this name is in Agent environment.", "Canopy
masks {n} possible secret(s) in this skill.";
- errors: "Choose one version of {name}.", "A skill named {name} is in
Agent environment. Scan again.";
- generated description: "Imported {command|prompt} /{name}".
- **Checks:** reasons name the next action; glossary terms ("skill",
"marketplace", "plugin", "Agent environment") are used throughout; no
banned synonyms; long names truncate.
## Security review fixes
- **Non-UTF-8 skill files (P1):** fail closed. A skill with any file
that isn't UTF-8 text (another encoding or binary) isn't imported, and
its reason names the file. Nothing of it leaves the worker (reading it
by key is refused).
- **Marketplace URL credentials (P1):** a source with user info or a
credential-like parameter is listed masked and marked "Its URL holds a
credential…". The gateway independently refuses any marketplace whose
source still shows user info or masking, before any plan is stored.
- **Skill undo (P2):** the receipt stores a fingerprint of the whole
skill definition: version, harnesses, selector and per-machine
overrides, homes, source. Undo keeps the skill if any of it changed, not
only the version.
- **Receipts:** skill and marketplace saves and removals take the same
in-transaction receipt as #316.
- **Tests:**
- `library.test.ts`: a Latin-1 `config.env` with a known credential
blocks the skill and its read; marketplace URLs with `?token=` and user
info are masked and unavailable.
- `import-library-skills.test.ts`: an assignment change at the same
version keeps the skill on Undo.
## Re-check fixes
- Marketplace URLs use the shared WHATWG credential check. The gateway
independently checks decoded parameter names and canonical userinfo,
including unusual HTTPS spellings and long userinfo, before plan
insertion. Gateway responses also redact credential URLs independently
of worker masking. Worker fixtures and the gateway integration
regression cover `%74oken`, each authority variant, masked responses and
absent plan rows.
- Skills containing NULs or binary controls are refused as a whole,
including BOM-less UTF-16 ASCII. The reason names the file; read-by-key
also refuses it. Worker fixtures cover UTF-16 and binary controls; the
integration test confirms no artifact is saved.
- Replace receipts save the previous full skill definition. An internal
owner-scoped restore path restores repository/ref/path/commit,
credential association and update policy with the Undo receipt in one
transaction. The fingerprint covers every source field, including
`autoUpdate` and `credentialAccountId`. Regressions verify the restored
source/artifact, receipt-failure rollback, all source fields and the
existing assignment-change guard.
- Validation: install, generation, typecheck, lint and format check
passed. Worker/gateway import tests and both stage integration files: 98
passed, 3 live tests skipped, 0 failed.
- Copy audit (§8): the unavailable marketplace reason is reused; the
plan boundary error says to add the marketplace in Agent environment.
Binary-file reasons name the file and the same action. No controls or
layouts changed; browser checks were not rerun.
### Round 3
- Marketplace checks inherit #316's shared bounded decoder: `%2574oken`,
deeper encoding and malformed escapes are unavailable and redacted.
Worker fixtures verify masked scan metadata; the gateway regression
independently verifies masked lists, rejected StartImport and no
persisted credential plan.
- A benign repository URL with `?design=compact#authentication` stays
readable and available in both worker metadata and gateway lists.
Classification uses actual `name=value` pairs and whole credential-name
tokens.
- Gates: install, generation, typecheck, lint and format check passed.
Worker/gateway import tests plus both stage integrations: 98 passed, 3
live tests skipped, 0 failed. Copy audit: existing reasons are reused;
no UI text, controls or layout changed.
### Final targeted fixes
- Inherits #316's conservative authority/value boundaries and
unconditional OAuth `code` classification. Multiline/quoted userinfo,
spaced/quoted query values and code values containing dots are masked
and unavailable.
- The same synthetic matrix is exercised in actual worker marketplace
scan metadata and independently forged gateway metadata.
ListImportLibrary stays redacted, StartImport rejects every case, and
SQL confirms that none of the supplied URLs enters a persisted plan. The
benign documentation query/anchor remains readable and available.
- Final stack gate on #318: `bun run check:tmp` passed (1,695 passed,
161 skipped, 0 failed; nothing left in its temp directory), and the web
production build passed.
nixuuu
added a commit
that referenced
this pull request
Nov 7, 2026
Stage 8 of the CLI import (stack B, top). Design: `docs/import.md`
("Serwery MCP").
## What
- **Remote MCP servers** (Claude `~/.claude.json`, user and per-project;
Codex `[mcp_servers.*]`) become custom **connected accounts** in
Connectors. Each keeps its URL and transport and has **no access**
(workers, bots) until the owner grants it.
- The scan carries the URL, the transport and the secret *slots* (header
name, and whether it is literal or from an env var), **never values**.
Env-var values are never read.
- **A secret moves only on confirmation.** For a literal header the
owner ticks "Bring the value of {header} from the CLI file" (off by
default). Then:
- the gateway stores the sha256 of a one-time token on the item;
- it asks the worker (`ReadImportSecret`, not journaled or replayed);
- the worker checks the key, the MCP place, the scan digest and the slot
kind;
- the gateway accepts the value only if the token comes back and the
stored hash matches. It reads and clears that hash in one transaction,
with the run locked.
- The value goes straight into the account's encrypted credentials
(`CANOPY_SECRETS_KEY`). It never reaches a row, a log, the UI, a worker
or a model.
- **Stays out, listed with the reason:**
- stdio servers: the gateway is the only MCP client and runs no
processes;
- URLs with user, password or query;
- model providers (pointed to Proxies).
- **Undo** removes the account unless it changed since (e.g. access was
granted), in which case it is `kept`.
## Why
Users' MCP servers are part of their working setup. Making them
connected accounts keeps every credential in the gateway, encrypted,
with explicit grants, as the security rules require.
## Verification
- `tests/integration/import-library-connectors.test.ts` (gRPC, real
worker):
- a chosen secret goes from the worker into the encrypted account only,
and the account works against a fake MCP server;
- no value appears in rows, responses or logs;
- an unticked secret never leaves the worker;
- a forged or replayed token is refused;
- only headers with a value can be chosen;
- stdio servers stay listed only;
- Undo.
- Worker tests: MCP parsing for both CLIs, literal vs env slots, the
digest check in `readImportSecret`.
- Gates on this top of the stack:
- `bun install`, `gen:check`, typecheck, lint and format check: clean;
- current full-suite results are recorded in “Re-check fixes” below;
- web build passes;
- all import integration files green.
- Original implementation browser check of the MCP rows and the secret
checkbox: light and dark, desktop and iPhone SE width.
## Copy audit (docs/copy.md §8)
- **New strings:**
- badge "MCP server";
- outcomes: "New connected account, with no access yet", "Added to
Connectors, no access yet." / "… Enter {headers} there.";
- slot hint: "Authorization: enter the value of {VAR} in Connectors.";
- checkbox: "Bring the value of {header} from the CLI file. Canopy keeps
it encrypted.";
- reasons: "Runs a command on this computer. Canopy calls MCP servers
over the network, from the gateway only.", "Canopy calls MCP servers
over HTTP(S) only.", "Its URL may hold a secret (user, password or
query). Add it in Connectors.", "The URL is not valid.";
- errors: "Choose only headers of {name} that have a value in the CLI
file.", "The import of this server is not valid. Scan again.", "The
worker's answer for {header} did not match this import.";
- the section description now ends "…skills, marketplaces and MCP
servers."
- **Changed during the audit:**
- "Choose secrets of {name} from its headers with a value." → "Choose
only headers of {name} that have a value in the CLI file.";
- "reaches MCP servers" → "calls MCP servers" (one verb in both
reasons).
- **Checks:** "connected account" and "Connectors" match the glossary;
the secret checkbox is off by default and says where the value goes; no
error contains a value.
## Security review fixes
- **MCP URL credentials (P1):** a server URL with user info or a
credential-like query is unavailable, as before, and now also masked in
`detail`/`value` (the single item constructor masks every field). The
gateway also refuses such a URL independently.
- **Connector undo race (P2):** `connectors.remove` takes an expected
revision. It checks it on the account row locked in the owner-scoped
delete transaction and records the item as `undone` in that same
transaction; a changed account stays (`kept`). Account creation and the
item's receipt are also one transaction.
- **Tests (`import-library-connectors.test.ts`):** URLs with user info
or `?api_key=` are unavailable, and `ListImportLibrary` carries no part
of them. A remove with a stale revision returns `changed` and the
account stays; Undo then marks it kept.
- `connectorWrites` header checks moved into a helper (size limit).
## Re-check fixes
- MCP metadata uses the shared WHATWG URL validator, including decoded
query/fragment names, unusual HTTPS spellings, long userinfo and
malformed credential-bearing URLs. Both gateway candidate and plan
boundaries reject unsafe URLs; gateway responses independently redact
them. Synthetic worker-to-gateway fixtures cover masked unavailable
metadata and the absence of persisted credential URLs.
- Nested slot names, kinds and environment-variable names now pass
through the same masking builder as all other library text. Worker and
integration regressions cover known credentials in slot names and
variables, including unavailable servers.
- A changed account's `kept` receipt now runs inside the owner-scoped
transaction that checks its locked revision. A simulated failure after
writing that receipt rolls it back; retry records `kept` while
preserving the account. Successful deletion still records `undone`
atomically.
- Validation: install, generation, typecheck, lint and format check
passed. Focused import tests: 107 passed, 3 live tests skipped, 0
failed. The web production build passed. Tests used synthetic HOME/CLI
fixtures; Git discovery was capped at the temporary root so
uninitialized fixtures could not inherit the worktree's origin. No
repository workaround was added.
- Copy audit (§8): existing unavailable reasons are reused. The
additional plan-boundary error says to add the server in Connectors; no
values appear in errors. No UI controls or layouts changed; browser
checks were not rerun.
### Round 3
- MCP metadata and gateway validation inherit #316's single strict
parameter classifier. Double/deeper encoded names in query and fragment,
malformed encodings, and space/quote userinfo remain masked and
unavailable.
- Synthetic WorkerLink regressions verify masked lists and independently
forge worker metadata to check gateway redaction, rejected StartImport
and no persisted credential plan. A plain `#authentication` fragment
stays readable and available.
- Gates: install, generation, typecheck, lint and format check passed.
Focused worker/gateway import tests plus all three library integrations:
107 passed, 3 live tests skipped, 0 failed. Tests used synthetic homes
with Git discovery capped at the temporary root; no real CLI homes or
credentials were read.
- Copy audit: existing reasons are reused; no UI text, controls or
layout changed.
### Final targeted fixes
- Inherits #316's conservative authority/value boundaries and
unconditional OAuth `code` classification. The shared matrix is
installed as actual MCP configuration and also supplied independently as
forged worker metadata.
- Every case stays masked/unavailable in ListImportLibrary, StartImport
rejects it, and SQL verifies no supplied URL enters a persisted plan.
Bare documentation fragments stay readable and available. The inherited
instruction integration covers scan metadata, instruction_documents,
environment API and actual WorkerLink sync for every case, including the
valid-host prose sentence.
- Final `bun run check:tmp`: **1,695 passed, 161 skipped, 0 failed**,
nothing left in its temp directory. The web production build passed. All
local gates completed in the foreground; only synthetic CLI homes were
used.
nixuuu
added a commit
that referenced
this pull request
Nov 7, 2026
Instruction imports from workers with long names exceeded the document store's 120-character limit and failed on every retry. Bound generated names in UTF-16 units, truncating the worker name at a grapheme boundary with an ellipsis and stable SHA-256 suffix while preserving the CLI and filename. Keep both reserves room for its counter and checks the owner's occupied names. Retry also handles oversized labels saved by older failed imports. Existing documents retain their names, and receipt-based Replace and Undo behavior is preserved. Apply bounded names and collision checks to imported connected accounts, and stable suffixes to truncated command-derived skill names. Manifest-defined skills and marketplaces retain their existing name validation. Document the naming rules in `docs/import.md`. Verification: - Gateway/worker integration coverage: 190-character worker names with shared prefixes, combining marks and emoji, uniqueness, Keep both, Replace, Undo, and legacy failed-import retry. - Connected account integration coverage and command-to-skill adapter coverage. - Full test gate: 1,727 passed, 161 skipped, 0 failed across 309 files; temporary-directory cleanup passed. Tests used worktree-local temporary data with Git discovery isolated from the parent repository. - `bun install`, `bun run gen:check`, `bun run typecheck`, `bun run lint`, `bun run format:check`, `bun run check:tmp`, and `bun run --filter @canopy/web build`. no UI text changed Fixes: #316
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stage 6 of the CLI import (stack B, settings and library; stack A #309–#313 is in
dev). Design:docs/import.md("Ustawienia i biblioteka").What
cli_import_library_v1, the scan also lists each CLI home's settings and library: names, places and digests, with no contents and no secrets.ListImportLibrarycompares them with Canopy's state,StartImport.librarypicks items, and the run applies them before threads.CLAUDE.md, andAGENTS.override.mdorAGENTS.md, become an instruction document in Agent environment.@imports are not expanded (warning). The limit is 24 KiB.env, permission rules, logins, CLI memory, model providers ("Add it in Proxies, with its key.").kept). Migration0094_cli_import_libraryaddsimport_library_items(unique live source).importTransaction, with its run locked first (locks.ts). Multi-step changes are single transactions.Why
New threads in Canopy should start with the defaults and instructions the user already relies on in their CLIs, without copying secrets or anything that runs code.
Verification
tests/integration/import-library.test.ts(gateway ↔ worker over gRPC):@warnings, size limits, confined reads.Copy audit (docs/copy.md §8)
Security review fixes
scheme://user:pass@) and values of credential-named parameters (token,key,secret,auth,sig,code, …). The rest of the URL stays readable. It applies to threads and to every library item: all text fields (name, value, detail, reason, warnings) go through the single masking entry point, including items shown as not importable.untrustedand structured policies are unavailable because Canopy has no mode preserving their approval gates.workspace-write+on-request/on-failure→ Accept edits, +never→ Full auto; unknown values import nothing; Full access never.receipt. It records the item's state and undo receipt throughimportTransactionas the last step of the store's own transaction (lock order: store row, then run). Worker sync stays after commit. A receipt with no item to land on rolls the change back. Undo's restore and the item's new state commit the same way.undone. A library item whose restore fails staysdonewith the reason, and a later Undo (the button shows again) retries only those items.Bearer/tokenprefixes, and forBasicthe decodeduser:passwordand the password.import-library.test.ts: an undo whose receipt can't land is rolled back; a failed undo keeps its item and the next Undo finishes it.library.test.ts: the Codex mapping table.masking.test.ts: bare forms ofBearer/Basic/quoted credentials; URL credentials.Re-check fixes
masking.test.tsexercises unknown synthetic credentials as well as encoded known values.untrustedand structured approval policies are unavailable, including active-profile overrides. Worker regressions cover the mapping;import-library.test.tsconfirms these candidates cannot enter a gateway plan.masking.test.ts.bun install,gen:check,typecheck,lint,format:checkpassed. Worker/gateway import tests plusimport-library.test.ts: 84 passed, 3 live tests skipped, 0 failed. Malformed URLs fail closed and safe git shorthand stays readable.Round 3
@masks from the scheme through the next@in the field, across any number of lines; without an@, it masks through the line's end. Valid hostnames and numeric ports establish a safe boundary, preserving prose containing a later contact address. Percent-encoded spaces remain covered. Tests exercise prose, Markdown links/code, JSON and malformed authorities.name=valuepairs count; credential names match whole_,-,., camelCase tokens. Everycodevalue is a credential, including short values, words and dots. Known secret values are checked at every decoded layer. Ordinary documentation/repository URLs, bare anchors and noncredential parameters stay unchanged.Final targeted fixes
@characters. An invalid host token without@masks to the end of its line. The valid-host sentenceSee https://docs.example.test (contact [email protected]).stays readable.&/#. Spaces, quotes and backticks mask through the end of the line; line breaks fail closed through the field. Every OAuthcodevalue is sensitive, including readable words, short numbers and dots; the entropy heuristic is removed.bun run check:tmppassed (1,695 passed, 161 skipped, 0 failed; nothing left in its temp directory), and the web production build passed.