@c4a/context-cli 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +51 -3
  2. package/README.zh-CN.md +43 -3
  3. package/cli.js +32849 -28177
  4. package/docs/context-debug-event-v1.schema.json +31 -0
  5. package/docs/context-debug-replay-v1.schema.json +33 -0
  6. package/docs/debug-tracing.md +94 -0
  7. package/docs/quickstart.md +1 -1
  8. package/package.json +6 -3
  9. package/plugins/VERSION +1 -1
  10. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  11. package/plugins/claude/commands/continue.md +19 -14
  12. package/plugins/claude/commands/init.md +3 -1
  13. package/plugins/codex/.codex-plugin/plugin.json +2 -2
  14. package/plugins/codex/skills/continue/SKILL.md +19 -14
  15. package/plugins/codex/skills/init/SKILL.md +2 -0
  16. package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
  17. package/plugins/cursor/commands/context-continue.md +19 -14
  18. package/plugins/cursor/commands/context-init.md +3 -1
  19. package/plugins/skills/context-continue/SKILL.md +19 -14
  20. package/plugins/skills/context-init/SKILL.md +2 -0
  21. package/providers/context/actions/inspect-code-extraction.yaml +5 -0
  22. package/providers/context/actions/inspect-repository-recovery.yaml +6 -0
  23. package/providers/context/actions/reconcile-review-identities.yaml +5 -0
  24. package/providers/context/actions/repair-verification.yaml +3 -3
  25. package/providers/context/actions/restore-repository-sources.yaml +7 -0
  26. package/providers/context/codes.yaml +2 -1
  27. package/providers/context/graphs/workspace.yaml +51 -8
  28. package/providers/context/manifest.json +126 -45
  29. package/providers/context/provider.yaml +1 -1
  30. package/providers/context/resources/dialogue/code-extraction.md +11 -0
  31. package/providers/context/resources/dialogue/package-output.md +9 -0
  32. package/providers/context/resources/dialogue/repository-source-recovery.md +23 -0
  33. package/providers/context/resources/manuals/guides/lark-resources.md +121 -0
  34. package/providers/context/resources/manuals/guides/package-outputs.md +22 -0
  35. package/providers/context/resources/manuals/reference/code-extractors.md +94 -0
  36. package/providers/context/resources/manuals/reference/package-templates.md +52 -0
  37. package/providers/context/resources/manuals/reference/project-api.md +78 -7
  38. package/providers/context/resources/procedures/close-and-build.md +5 -3
  39. package/providers/context/resources/procedures/code-extraction.md +23 -0
  40. package/providers/context/resources/procedures/document-capture.md +5 -1
  41. package/providers/context/resources/procedures/knowledge-review.md +10 -0
  42. package/providers/context/resources/procedures/package-output.md +21 -0
  43. package/providers/context/resources/procedures/repository-source-recovery.md +43 -0
  44. package/providers/context/resources/procedures/source-capture-detailed.md +13 -0
  45. package/providers/context/resources/procedures/verify-and-repair.md +12 -0
  46. package/providers/context/resources/semantic/align/gates.md +2 -2
  47. package/providers/context/resources/semantic/align/structure-planning.md +8 -3
  48. package/providers/context/resources/views/source-boundary.yaml +6 -0
  49. package/providers/context/schemas/repository-source-recovery.schema.json +40 -0
  50. package/providers/context/actions/ensure-repository-sources.yaml +0 -5
@@ -0,0 +1,121 @@
1
+ ---
2
+ id: context.sdk.lark-resources
3
+ kind: procedure
4
+ mediaType: text/markdown
5
+ ---
6
+
7
+ # Lark Resource Materialization
8
+
9
+ Lark documents can contain evidence that is not present in the readable text
10
+ body. Context handles these resources mechanically during `captureLark`; the
11
+ Agent does not download, summarize, or reconstruct them itself.
12
+
13
+ ## Resource policy
14
+
15
+ | Resource | Default capture behavior |
16
+ |---|---|
17
+ | Image and attachment | Download the original file and link it from the Markdown projection. |
18
+ | Sheet | Read the complete selected sheet, render a Markdown table, and retain a CSV snapshot. |
19
+ | Base | Read the selected table/view with pagination, render a Markdown table, and retain a canonical JSON snapshot. |
20
+ | Whiteboard and diagram | Retain a readable preview plus the raw structured export. |
21
+ | Synced block | Resolve the exact source block, project its body, and retain a Markdown evidence snapshot. |
22
+ | Poll | Preserve exported options and metadata as non-interactive Markdown; warn when the export omits them. |
23
+ | Bookmark, citation, sub-document, chat, and generic embed | Preserve a stable navigation reference and provenance. |
24
+ | Video | Preserve a stable reference by default; download only when `resources.videos` is `bundle`. |
25
+
26
+ Required inline resources fail closed when their stable identity, bytes, or
27
+ complete structured data cannot be obtained. When the remote API explicitly
28
+ confirms that a referenced whiteboard or diagram no longer exists, Context
29
+ preserves an unavailable-resource notice with the reason code
30
+ `document.resource.source-missing`, reports a warning, and continues capture;
31
+ it does not pretend that the deleted content was materialized. When the current
32
+ identity can read the document body but the API explicitly returns
33
+ `authorization/permission_denied` for an embedded resource, Context records
34
+ `document.resource.permission-denied`, keeps the stable resource identity in
35
+ the audit layer, renders the same unavailable-resource notice, and continues
36
+ with a warning. Missing scopes, transient network errors, malformed payloads,
37
+ and unclassified authorization failures still block capture. Reference-only
38
+ resources remain explicit in the capture report. Unknown non-empty XML blocks
39
+ stay auditable in the raw XML and receive a warning; the CLI does not infer
40
+ their meaning.
41
+
42
+ ## Storage lifecycle
43
+
44
+ Resources have three distinct locations:
45
+
46
+ ```text
47
+ sources/lark/<date>/
48
+ ├── <module>.md
49
+ ├── manifest.json
50
+ └── assets/<module>/
51
+ ├── source.xml
52
+ ├── capture-report.json
53
+ └── materialized/**
54
+ knowledge/assets/<resource-kind>/<content-sha256>.<ext>
55
+ dist/<package>/others/assets/<resource-kind>/<content-sha256>.<ext>
56
+ ```
57
+
58
+ - `sources/` is the captured source and audit layer. `source.xml` preserves the
59
+ structured source, one `capture-report.json` closes fidelity and resource
60
+ handling for the document, and `materialized/` contains downloaded files and
61
+ structured exports. Resource descriptors are consolidated in the report;
62
+ capture does not create one metadata file per embedded resource.
63
+ - The date-level `manifest.json` is a compact inventory. It records hashes,
64
+ asset roles, the report path, and status summaries without duplicating the
65
+ complete report.
66
+ - `knowledge/assets/` contains only resources referenced by approved pages.
67
+ Paths are content-addressed, so identical bytes are reused and changed bytes
68
+ produce a new identity. Review apply rewrites page links mechanically;
69
+ verification compares the underlying content identity, so this deterministic
70
+ path projection does not count as a change to a verbatim section.
71
+ Markdown files below `knowledge/assets/` remain evidence resources and are
72
+ never interpreted as approved knowledge pages or structure views.
73
+ - `others/assets/` is the portable package projection. Build copies only
74
+ resources referenced by selected package pages and rewrites their relative
75
+ links. Audit-only source files are not distributed.
76
+
77
+ Deleting an approved page allows unreferenced `knowledge/assets` files to be
78
+ cleaned. A missing approved or packaged resource is a verification error rather
79
+ than a silent broken link.
80
+
81
+ Source assets are part of the reproducible evidence snapshot and should not be
82
+ ignored when the workspace is versioned. Repositories with many binary source
83
+ assets can use Git LFS for `materialized/` while keeping Markdown, XML, JSON, and
84
+ CSV directly reviewable in Git. The workspace must remain private when the
85
+ captured source or screenshots are access-controlled.
86
+
87
+ ## SDK configuration
88
+
89
+ Defaults are suitable for ordinary documents:
90
+
91
+ ```ts
92
+ captureLark({ source: handbook });
93
+ ```
94
+
95
+ Projects can opt into bundled video and adjust deterministic byte limits:
96
+
97
+ ```ts
98
+ captureLark({
99
+ source: handbook,
100
+ resources: {
101
+ videos: "bundle",
102
+ maxBytesPerResource: 20 * 1024 * 1024,
103
+ maxTotalBytes: 200 * 1024 * 1024,
104
+ },
105
+ });
106
+ ```
107
+
108
+ The limits are capture constraints, not semantic filters. Context does not
109
+ decide which resources are important from their business content.
110
+
111
+ ## Agent behavior
112
+
113
+ Use the capture command returned by the current Route. Inspect the structured
114
+ resource summary and fidelity diagnostics; do not manually edit `sources/`,
115
+ `knowledge/assets/`, or package links. Required materialization failures other
116
+ than a confirmed source-side deletion or an explicit resource-level permission
117
+ denial must be resolved by recapturing after access or source problems are
118
+ fixed. Accepted failures remain visible as warnings and unavailable-resource
119
+ notices; they are never represented as downloaded evidence. Review shows
120
+ available previews, references, and warnings so the human or managed policy can
121
+ assess the page with its non-text evidence.
@@ -67,6 +67,7 @@ wikis/index.md
67
67
  guides/...
68
68
  rules/...
69
69
  feats/...
70
+ others/assets/...
70
71
  ```
71
72
 
72
73
  Do not ask for another distribution namespace. Older workspaces may still
@@ -94,6 +95,27 @@ package needs project-specific terminology, entry points, known limits, or
94
95
  task workflows. Authors may explicitly accept the generic default when it is
95
96
  intentionally sufficient.
96
97
 
98
+ When approved pages reference materialized document resources, Context keeps
99
+ their production copies in content-addressed `knowledge/assets/` paths. New KB
100
+ setup should offer Git raw delivery first. It rewrites package links to either
101
+ an automatically derived raw prefix or an explicit author-provided prefix.
102
+ Context does not check whether resource files are committed, pushed, or
103
+ remotely readable; that is the package author's responsibility. With no
104
+ explicit prefix, supported remotes use an immutable commit URL. An explicit
105
+ prefix can contain `{commit}` when the Context workspace is in Git, or name a
106
+ mutable branch when that lifecycle is intentional; a literal prefix also works
107
+ when resources are published from a separate repository.
108
+
109
+ Workspaces without usable Git or an explicit raw prefix can choose bundled
110
+ delivery, which copies only selected resources to `others/assets/`, or explicit
111
+ omission, which does not copy resources and reports that links remain
112
+ unresolved. Bundled output may
113
+ optionally install `sharp` in the workspace and configure
114
+ `assets.optimize`; Context itself has no image dependency. Optimization changes
115
+ only `dist/`, content-addresses smaller WebP output, and leaves `sources/` and
116
+ `knowledge/assets/` unchanged. Source audit XML and capture reports are never
117
+ distributed as reader assets. See [Lark Resource Materialization](./lark-resources.md).
118
+
97
119
  The same inventory exposes `structure.relationship_coverage`. It records
98
120
  whether selected codegraph pages have current source-backed AST relationship
99
121
  metadata, how many codegraph views were selected, and how many package-visible
@@ -0,0 +1,94 @@
1
+ ---
2
+ id: manual.reference.code-extractors
3
+ kind: procedure
4
+ mediaType: text/markdown
5
+ ---
6
+
7
+ # Code Extractor Selection
8
+
9
+ Use this manual only when the current code-extraction Route asks the Agent to
10
+ choose or declare an extractor. The CLI reports repository facts; the Agent
11
+ chooses how those facts become source-backed code knowledge.
12
+
13
+ ## Inspect Before Declaring
14
+
15
+ Run every read-only inspection command returned by the extraction-scope Gate.
16
+ The result identifies each confirmed module and its recognized `manifests`.
17
+ Treat these as deterministic technology signals, not as product semantics:
18
+
19
+ | Signal | Technology candidate |
20
+ |---|---|
21
+ | `package.json` | TypeScript, TSX, JavaScript, or JSX |
22
+ | `go.mod` | Go |
23
+ | `Cargo.toml` | Rust |
24
+ | `pyproject.toml` or `setup.py` | Python |
25
+ | `pom.xml` or `build.gradle` | Java or JVM |
26
+ | multiple manifests | a mixed module that may need more than one extractor |
27
+
28
+ Do not select `extractTs()` merely because a repository contains some
29
+ TypeScript. Decide against the exact confirmed module and include boundary. A
30
+ mixed module may compose multiple structural passes; parser selection is not an
31
+ exclusive repository-wide switch.
32
+
33
+ ## Selection Order
34
+
35
+ Use the narrowest reusable capability that covers the confirmed source:
36
+
37
+ 1. Use a Context-owned phase when its contract matches the source.
38
+ 2. Otherwise use a reusable structural package inside `extractCustom()`.
39
+ 3. If no reusable package covers the syntax or repository protocol, implement a
40
+ project-owned adapter and keep it in the Context workspace.
41
+
42
+ Current reusable capabilities are:
43
+
44
+ | Source fact | Preferred capability | Lifecycle integration |
45
+ |---|---|---|
46
+ | TypeScript/TSX package or file scope | `extractTs()` | Context-owned phase |
47
+ | Go declarations, imports, calls, and common HTTP routes | `@c4a/extract-go` | call from `extractCustom()` |
48
+ | Rush workspace packages, tags, dependencies, entries, and owners | `@c4a/extract-rush` | call from `extractCustom()`; may complement a language extractor |
49
+ | React Router route declarations | `extractReactRouterRoutes()` from `@c4a/extract-ts` | call from `extractCustom()`; complements TypeScript symbols |
50
+ | Rust, Python, Java/JVM, or an unsupported framework/protocol | no assumed built-in parser | project-owned `extractCustom()` adapter |
51
+
52
+ An optional package does not create a new CLI phase. Add it as an explicit
53
+ workspace dependency, then map its structural facts to candidates in the
54
+ project callback. Do not add a parser package when its documented coverage does
55
+ not match the inspected source.
56
+
57
+ ## Read The Contract Before Extending
58
+
59
+ Before editing `src/index.ts`, read the relevant installed public manual or
60
+ package README. Do not infer APIs from bundled JavaScript.
61
+
62
+ - Context lifecycle and `extractCustom()`:
63
+ `node_modules/@c4a/context/docs/reference/project-api.md`
64
+ - Generic plugin protocol:
65
+ `node_modules/@c4a/extract/README.md`
66
+ - TypeScript:
67
+ `node_modules/@c4a/extract-ts/README.md`
68
+ - Go:
69
+ `node_modules/@c4a/extract-go/README.md`
70
+ - Rush:
71
+ `node_modules/@c4a/extract-rush/README.md`
72
+
73
+ If an optional package is not installed, use this capability matrix to decide
74
+ whether it is relevant, add only that dependency, and then read its shipped
75
+ README before implementing the callback.
76
+
77
+ A project-owned adapter may use an existing parser, compiler API, or command
78
+ whose output is deterministic. It must return source-backed candidates through
79
+ `extractCustom()`; it must not write lifecycle, knowledge, or Review files.
80
+ Framework-specific classification and rendering remain in the project. The CLI
81
+ and structural parser must not infer product meaning.
82
+
83
+ ## Decision To Report
84
+
85
+ Before the first extraction preview, state briefly:
86
+
87
+ - the inspected module and manifest signals;
88
+ - the selected Context phase or structural package;
89
+ - whether coverage is complete or which facts remain project-owned; and
90
+ - why another available extractor is not needed.
91
+
92
+ If no current capability can parse the source reliably, stop at configuration
93
+ and report the missing generic capability. Do not silently emit an empty
94
+ codegraph or reuse an unrelated parser.
@@ -37,6 +37,10 @@ kbPackage({
37
37
  foldDirectoryIndexes: true,
38
38
  maxInlineEntries: 50,
39
39
  },
40
+ assets: {
41
+ delivery: "git-raw",
42
+ urlPrefix: "https://code.example.com/team/knowledge/raw/{commit}",
43
+ },
40
44
  });
41
45
  ```
42
46
 
@@ -58,8 +62,56 @@ llmsPackage({
58
62
  | `template` | yes | Project-relative template directory or `{ path, vars }`. |
59
63
  | `select` | no | Approved knowledge selector. Omit to include all approved knowledge. Supports internal `collections`, OKF `okfRoots`, and `include` / `exclude` path patterns relative to `knowledge/`. |
60
64
  | `navigation` | no | KB directory-index policy. Defaults to `{ foldDirectoryIndexes: true, maxInlineEntries: 50 }`. |
65
+ | `assets` | no | Resource delivery: Git raw links, bundled files, or explicit omission. New KB setup should offer Git raw first. Omit for legacy byte-for-byte bundling. |
61
66
  | `distribution` | no | Legacy input accepted from older workspaces. It no longer changes package paths and should not be added to new declarations. |
62
67
 
68
+ Use Git raw delivery when resources are published from a Git repository.
69
+ Without `urlPrefix`, the Context workspace must be inside Git; GitHub remotes
70
+ are derived automatically and pinned to the current commit. Other hosts and
71
+ workspaces outside Git accept an explicit HTTPS prefix; Context appends the
72
+ project-relative `knowledge/assets/...` path. Context does not check whether
73
+ the resources are committed, pushed, or remotely readable; publishing them is
74
+ the package author's responsibility.
75
+ `{commit}` is replaced when present. A literal branch in the prefix is allowed
76
+ but intentionally follows that mutable branch. The configured raw host must be
77
+ reachable by the eventual package consumers.
78
+
79
+ ```ts
80
+ assets: {
81
+ delivery: "git-raw",
82
+ urlPrefix: "https://code.example.com/team/knowledge/raw/{commit}",
83
+ }
84
+ ```
85
+
86
+ When the workspace is not in Git and has no explicit raw prefix, choose bundled
87
+ delivery or explicit omission:
88
+
89
+ ```ts
90
+ assets: { delivery: "bundle" }
91
+ assets: { delivery: "omit" } // keeps unresolved links and reports them
92
+ ```
93
+
94
+ Bundled resources are copied byte-for-byte unless image optimization is
95
+ configured. When optimizable PNG/JPEG resources exceed 20 MiB, build and status
96
+ return `package.assets.optimization-recommended`. To optimize bundled output:
97
+
98
+ ```bash
99
+ bun add -D sharp
100
+ ```
101
+
102
+ ```ts
103
+ assets: {
104
+ delivery: "bundle",
105
+ optimize: { processor: "sharp", mode: "lossless-webp" },
106
+ }
107
+ ```
108
+
109
+ `optimize.mode: "webp"` additionally accepts `quality` from 1 to 100. Both modes accept
110
+ an optional positive `maxDimension`; images are never enlarged. Context adopts
111
+ a generated image only when it is smaller, uses a digest-derived `.webp` path,
112
+ and rewrites package links. A configured but missing processor blocks before
113
+ the previous `dist/` package is replaced.
114
+
63
115
  `template` is required. Do not call `kbPackage({ name })` or
64
116
  `llmsPackage({ name })`.
65
117
 
@@ -215,6 +215,13 @@ extraction phases, review gates, close/build, and packages explicitly. The CLI
215
215
  then routes work through `context status`, `context run <phase-id>`, `context
216
216
  review html/apply`, `context close`, `context verify`, and `context build`.
217
217
 
218
+ For Agent and automation output, use `context verify --format json --compact`.
219
+ It returns deterministic groups, counts, affected-scope totals, and a few
220
+ representative samples instead of repeating every issue. Read the complete,
221
+ auditable issue set only when needed with `context verify --view diagnostics
222
+ --page-size 25 --format json`; follow its executable pagination command without
223
+ inventing overlapping file ranges.
224
+
218
225
  ### Status declaration coverage
219
226
 
220
227
  `context status --format json --view full` includes a `declarationGraph` and
@@ -327,6 +334,21 @@ Markdown snapshot:
327
334
  captureLark({ source: handbook });
328
335
  ```
329
336
 
337
+ Embedded resources are materialized with deterministic defaults. Video remains
338
+ reference-only unless a project opts into bundling, and byte limits prevent an
339
+ unexpected document from expanding the workspace without bound:
340
+
341
+ ```ts
342
+ captureLark({
343
+ source: handbook,
344
+ resources: {
345
+ videos: "bundle",
346
+ maxBytesPerResource: 20 * 1024 * 1024,
347
+ maxTotalBytes: 200 * 1024 * 1024,
348
+ },
349
+ });
350
+ ```
351
+
330
352
  Phase id:
331
353
 
332
354
  ```text
@@ -340,19 +362,33 @@ one date batch; when `--module` is omitted, the CLI derives an opaque,
340
362
  credential-safe module id. Capture reads the
341
363
  remote document through the CLI runner as structured Docx XML. Context keeps a
342
364
  redacted XML audit asset, projects supported blocks deterministically into
343
- readable Markdown, and registers external resources such as document citations,
344
- images, video, whiteboards, and Base references in the snapshot manifest even
345
- when their binary content is not downloaded. The projection does not infer or
346
- summarize document meaning. Its fidelity report closes discovered blocks
365
+ readable Markdown, and materializes required inline resources such as images,
366
+ attachments, Sheets, Bases, whiteboards, diagrams, and synced blocks. Navigation
367
+ resources and default video capture remain explicit references. The projection
368
+ does not infer or summarize document meaning. Its fidelity and resource reports close discovered blocks
347
369
  against converted and intentionally skipped blocks and reports evidence
348
370
  completeness separately from Markdown projection quality. Unknown non-empty XML
349
371
  blocks receive a generic, auditable, non-interactive projection and do not block
350
- downstream work. Missing source content or unresolved external-resource identity
351
- remains an evidence error and prevents downstream Review.
372
+ downstream work. A remote whiteboard or diagram explicitly confirmed as deleted
373
+ is preserved as an unavailable-resource notice with
374
+ `document.resource.source-missing` and a warning. An embedded resource whose
375
+ export is explicitly rejected as `authorization/permission_denied` is retained
376
+ the same way with `document.resource.permission-denied`. Missing scopes,
377
+ unresolved external-resource identity, retryable failures, and unclassified
378
+ authorization errors remain evidence errors and prevent downstream Review.
352
379
  Snapshot files live under `sources/lark/<date>/` as sibling document files
353
- tracked by one date-level `manifest.json`. Access credentials and transient
380
+ tracked by one compact date-level `manifest.json`. Each module keeps one raw
381
+ `source.xml`, one consolidated `capture-report.json`, and its actual downloaded
382
+ or structured resources under `assets/<module>/materialized/`; it does not emit
383
+ one descriptor file per embedded resource. Access credentials and transient
354
384
  signed media URLs are not written into the workspace.
355
385
 
386
+ Approved resource bytes are projected to content-addressed
387
+ `knowledge/assets/<kind>/` paths. KB build copies selected resources to
388
+ `others/assets/<kind>/` inside the package and rewrites page links. See
389
+ [Lark Resource Materialization](../guides/lark-resources.md) for the complete
390
+ resource table and storage lifecycle.
391
+
356
392
  Use a typed document reference in project declarations:
357
393
 
358
394
  ```ts
@@ -709,6 +745,41 @@ Review summary and source-backed evidence). It must not write `knowledge/`,
709
745
  Review snapshots directly. Context owns those files and preserves rejected and
710
746
  unchanged-approved decisions across reruns.
711
747
 
748
+ #### Optional structural extractors
749
+
750
+ For the manifest-to-capability decision and unsupported-language extension
751
+ boundary, read [Code Extractor Selection](./code-extractors.md) before declaring
752
+ the phase.
753
+
754
+ `extractCustom()` may consume optional community packages without making them
755
+ Context CLI dependencies:
756
+
757
+ ```ts
758
+ import { indexGoRepository } from "@c4a/extract-go";
759
+ import { extractCustom } from "@c4a/context";
760
+
761
+ extractCustom({
762
+ id: "extract:service:codegraph",
763
+ sources: [service],
764
+ collection: "codegraph",
765
+ extract: async ({ projectRoot }) => {
766
+ const facts = await indexGoRepository(resolveServiceCheckout(projectRoot));
767
+ return { candidates: buildServiceCandidates(facts) };
768
+ },
769
+ });
770
+ ```
771
+
772
+ Available structural libraries include:
773
+
774
+ - `@c4a/extract-go`: Go declarations, imports, calls, and common HTTP routes;
775
+ - `@c4a/extract-rush`: Rush projects, tags, entries, dependencies, and owners;
776
+ - `@c4a/extract-ts`: TypeScript extraction and `extractReactRouterRoutes()`.
777
+
778
+ The packages return syntax and repository facts only. They do not classify
779
+ product meaning, choose candidate identities, or write lifecycle state. The
780
+ knowledge project owns that mapping. Context CLI does not auto-install these
781
+ packages and does not expose a built-in Go or Rush phase.
782
+
712
783
  ### `reviewValidity`
713
784
 
714
785
  Declare the review step for a collection:
@@ -8,9 +8,11 @@ mediaType: text/markdown
8
8
 
9
9
  Close deterministically derives `knowledge/structure.yaml` from approved
10
10
  Markdown and the confirmed structure snapshots. It validates the rebuilt
11
- projection; it does not rewrite approved page bodies. Before removing the
12
- transient snapshots, it retains only each closed prose target's source,
13
- collection, and consumed snapshot hash under `source_inputs`.
11
+ projection. When an approved page still points at a captured source asset,
12
+ close may mechanically replace that target with its content-addressed
13
+ `knowledge/assets` path; it does not rewrite reader-visible prose. Before
14
+ removing the transient snapshots, it retains only each closed prose target's
15
+ source, collection, and consumed snapshot hash under `source_inputs`.
14
16
 
15
17
  Build runs only after close and verification are current. It writes declared
16
18
  packages under `dist/` and records an inventory receipt with added, updated,
@@ -10,6 +10,14 @@ Code extraction operates on user-confirmed repository modules and source
10
10
  patterns. A source registration identifies the repository or module; the
11
11
  extraction declaration defines the code scope inside it.
12
12
 
13
+ Before declaring a phase, run the extraction-scope Gate's inspection Action for
14
+ every confirmed module. Read all reported `manifests`, including mixed-module
15
+ signals, then use the route-selected Code Extractor Selection manual to choose
16
+ `extractTs`, an optional structural package inside `extractCustom`, or a
17
+ project-owned adapter. Read the selected package's public SDK/README before
18
+ editing `src/index.ts`; never infer its API from bundled output. Do not silently
19
+ substitute the TypeScript extractor for Go, Rust, or another unsupported source.
20
+
13
21
  `include` filters files inside a selected source; it is not a package/module
14
22
  selector. Use source declarations to select repository modules. Use configured
15
23
  entry patterns when entry-led traversal is meaningful, or scan mode when the
@@ -48,3 +56,18 @@ declared `extractCustom` phase. The project-owned callback returns candidate
48
56
  semantics plus structured source evidence; Context owns canonical refs,
49
57
  fingerprints, candidate storage, Review snapshots, freshness, and rerun cleanup.
50
58
  Do not use a generic `customPhase` callback to write lifecycle files directly.
59
+
60
+ Prefer a reusable structural library over a project-local parser when one
61
+ matches the confirmed source: `@c4a/extract-go` for Go facts,
62
+ `@c4a/extract-rush` for Rush workspace facts, and
63
+ `extractReactRouterRoutes()` from `@c4a/extract-ts` for React Router facts.
64
+ These are optional project dependencies consumed inside `extractCustom()`;
65
+ they are not built-in CLI phases. Keep product-specific classification and
66
+ candidate rendering in the project, and do not ask the CLI or parser to infer
67
+ business meaning.
68
+
69
+ For Rust, Python, Java/JVM, or another source without a matching reusable
70
+ extractor, keep the lifecycle in `extractCustom()` and implement only the
71
+ missing project adapter. If reliable syntax facts cannot be produced, stop at
72
+ configuration and report the generic capability gap rather than emitting an
73
+ empty or guessed graph.
@@ -39,7 +39,11 @@ and continue until the graph reports the batch complete. Never treat one
39
39
  successful module as completion of the whole batch.
40
40
 
41
41
  The CLI owns normalization, snapshot identity, hashes, manifests, and
42
- idempotency. Never hand-write or repair captured snapshots. If a selected local
42
+ idempotency. For Lark sources it also owns embedded-resource download,
43
+ structured export, completeness reporting, and link projection. Required
44
+ resource failures block the next phase; reference-only resources remain
45
+ explicit in the report. Never hand-write or repair captured snapshots or their
46
+ asset links. If a selected local
43
47
  boundary is a documentation site rather than plain Markdown, use the
44
48
  Context-provided processor/configuration diagnostic; do not invent rendered
45
49
  text or scan outside the confirmed boundary.
@@ -10,6 +10,16 @@ Review is the authority boundary between candidates and approved knowledge.
10
10
  Open one report for the complete current candidate set and apply only a payload
11
11
  that matches its collection scope and candidate-set digest.
12
12
 
13
+ Before Review, Context checks both sides of approved page identity: whether a
14
+ candidate path is already owned by another `view_ref` / `node_ref`, and whether
15
+ the candidate `view_ref` is already approved at another path. Either conflict
16
+ blocks Review. Follow the returned identity-coordination route: the default
17
+ mechanical repair preserves the approved identity and approved path, then
18
+ recompiles only the affected source. It keeps the candidate batch intact while
19
+ replacing affected candidates in place. Changing an approved identity or moving
20
+ an approved path is a migration and must never run without a separate, explicit
21
+ authorization.
22
+
13
23
  Without explicit session-managed authority:
14
24
 
15
25
  - open the report returned by the route;
@@ -35,3 +35,24 @@ maintain the complete final Skill directory name in the template, such as
35
35
 
36
36
  Package output is incremental: a built package is current only for the approved
37
37
  knowledge and template digests recorded by its receipt.
38
+
39
+ When declaring a new KB package, make resource delivery an explicit author
40
+ choice. Offer Git raw when the workspace is in Git or the author supplies a
41
+ raw `urlPrefix`; it keeps package payloads small and uses either the derived
42
+ commit-pinned URL or that explicit prefix. Context does not check whether those
43
+ files are committed, pushed, or remotely readable; that remains the package
44
+ author's responsibility. If neither Git nor an explicit prefix is available,
45
+ offer bundled resources or explicit omission; omission keeps unresolved links
46
+ and must be described as such. Do not infer repository identity or invent a raw
47
+ host URL.
48
+
49
+ Large image optimization applies only to bundled delivery. Without an `assets`
50
+ declaration, existing workspaces continue to copy selected resources
51
+ byte-for-byte. If build or status reports
52
+ `package.assets.optimization-recommended`, explain that the current package is
53
+ valid but contains more than 20 MiB of eligible PNG/JPEG resources. Do not
54
+ install a dependency or edit project configuration automatically. If the user
55
+ chooses to optimize the package, use the exact reported setup command and add
56
+ the reported `kbPackage().assets.optimize` value. The processor is installed in the
57
+ Context workspace, not bundled into Context itself. Optimization changes only
58
+ `dist/`; source snapshots and approved resources remain unchanged.
@@ -0,0 +1,43 @@
1
+ ---
2
+ id: procedure.repository-source-recovery
3
+ kind: procedure
4
+ mediaType: text/markdown
5
+ ---
6
+
7
+ # Repository source recovery
8
+
9
+ Repository checkout contents and materialized module links are local runtime
10
+ inputs. Git stores their recovery recipe in `sources/repo/index.yaml`; it does
11
+ not store the checkout, local aliases, or `sources/repo/<date>/<module>` links.
12
+
13
+ Run the route's inspection action first. It groups logical modules by registered
14
+ remote and pinned commit, so one physical checkout can restore every module in
15
+ that group. Do not create one clone per module. Groups already marked `ready`
16
+ need no decision; when every group is ready, the plan has no recovery action.
17
+
18
+ For each missing physical checkout, ask the user to choose one option:
19
+
20
+ 1. provide an existing local Git checkout;
21
+ 2. name a bounded directory that the Agent may scan, then choose one of the
22
+ matching checkouts shown by the Agent; or
23
+ 3. explicitly allow Context to clone the registered repository into the
24
+ suggested `.tmp/repo/` target.
25
+
26
+ Scanning and clone access are separate external authorities. Never scan an
27
+ unspecified disk root. Never infer or substitute another remote, branch, tag,
28
+ or nearby repository. A recovery clone uses the registered pinned commit so
29
+ the existing knowledge state is reproducible. Updating knowledge to a newer
30
+ upstream version is a later, explicit source update decision.
31
+
32
+ After the user decides, submit one payload matching the route-selected recovery
33
+ schema to the exact resolution command. Local mode validates origin, the pinned
34
+ commit, and every required subpath without changing the supplied checkout.
35
+ Clone mode performs a shallow partial checkout where supported, falls back to a
36
+ shallow checkout, and uses sparse checkout only when every registered source is
37
+ bounded to a subpath. Context then restores declared local aliases and
38
+ materializes module links.
39
+
40
+ Repository sources are ready only when every selected module resolves to the
41
+ registered remote and pinned commit, every registered subpath exists, no local
42
+ path was overwritten, Context materialization succeeds, and the current route
43
+ no longer reports `route.source.repository-not-ready`.
@@ -54,6 +54,19 @@ contract, so any manual edit breaks idempotency.
54
54
  Lark capture obtains the structured XML representation and produces two
55
55
  separate artifacts: XML audit evidence and a deterministic readable Markdown
56
56
  projection. Do not treat raw XML as Markdown and do not rewrite it yourself.
57
+ The CLI also materializes supported embedded resources and returns a closed
58
+ `resource_materialization` report. Required images, attachments, Sheets, Bases,
59
+ whiteboards, diagrams, and synced blocks must be materialized before downstream
60
+ Review. Polls and navigation references remain explicit non-interactive
61
+ projections; video is reference-only unless the project SDK opts into bundling.
62
+ If the remote API explicitly confirms that a referenced whiteboard or diagram
63
+ no longer exists, preserve the unresolved placeholder and the structured
64
+ `document.resource.source-missing` warning, then continue through the Route.
65
+ This is an audited source-side deletion, not successful materialization. Access,
66
+ network, parameter, and unknown resource failures still block downstream work.
67
+ Do not manually download resources or patch links. Approved resources move to
68
+ `knowledge/assets/`, and package build projects selected resources to
69
+ `others/assets/`.
57
70
  Inspect `evidence_status` and `projection_status` separately. An evidence error
58
71
  means the source body, external content, or a stable resource locator could not
59
72
  be preserved, so the workflow must not proceed to Align, Compile, or Review.
@@ -14,6 +14,18 @@ is stale, the legal repair is `context close --format json`. Otherwise, repair
14
14
  the source-bound candidate or project declaration named by the root diagnostic,
15
15
  then run verification again.
16
16
 
17
+ When every blocking finding is an approved document `source_ref` drift or an
18
+ unresolved required-resource placeholder, and each affected source already has
19
+ a declared pending structure target, the current prose align/compile round is
20
+ the repair path. Continue that Route before running verification again. This
21
+ exception does not apply to missing sources, malformed approved knowledge,
22
+ unrelated verification errors, or findings without a matching pending target.
23
+
24
+ When a complete replacement candidate batch is ready for Review, stable prose
25
+ candidate ids may intentionally match their currently approved pages. Review
26
+ that batch before deterministic close and final verification; the pending
27
+ replacement is not an approved-identity conflict.
28
+
17
29
  Do not delete candidates, approved pages, snapshots, or structure slots to make
18
30
  verification pass. Derived diagnostics should not be handled as independent
19
31
  root failures.
@@ -249,7 +249,7 @@ Each source must include `rationale` when inferred and at least one of `source_r
249
249
  ## Final Reflection
250
250
 
251
251
  - Entity cannot pick a legal tag, or depends on its upstream title to make sense -> write it as a Section under the upstream Node or change type before submit.
252
- - Action only supports one Section -> write it as a Section instead of an Action, or add source-backed structure that reaches at least two distinct Section kinds / one child Action. The CLI does not use source prose keywords to grant an exception.
252
+ - Action only supports one Section -> confirm its standalone retrieval value, write it as a Section under its owner, or add another source-backed Section / child Action. Multiple source-backed Sections may use the same kind; the CLI does not manufacture semantic variety to validate an Action.
253
253
  - Action "steps" are parallel options/configs -> route to Entity `comparison` / `spec` / `description`.
254
254
  - Domain has no children -> delete it or merge it into a larger Domain.
255
255
 
@@ -267,7 +267,7 @@ checks as deterministic diagnostics:
267
267
  | `node.thin_concrete_entity` | A concrete Entity has one Section and no child Nodes. | Keep it only when it has stable standalone retrieval value; otherwise merge it into the owning Node. |
268
268
  | `node.children_should_be_sections` | One parent contains many same-source, single-section child Entities with no stable shape tag. | Merge those children into parent Sections unless the user confirms each child has standalone lookup value. |
269
269
  | `node.term_expanded_beyond_definition` | A `term` Entity has grown past a compact definition or owns children. | Move rules, procedures, designs, and examples to the owning Node; keep the term entry narrow. |
270
- | `node.action_too_thin` | An Action has fewer than two distinct planned Section kinds and no child Action. | Downgrade it to a Section under the owning Node, add a distinct Section kind, or add a child Action; the CLI does not infer a single-section exception from source text. |
270
+ | `node.action_too_thin` | An Action has one planned Section and no child Action. | Confirm its standalone retrieval value, keep it as a Section under the owning Node, add another source-backed Section, or add a child Action. This warning does not require artificial Section-kind diversity. |
271
271
  | `node.domain_without_children` | A Domain has no source-backed `contains` child edge. | Add supported children, keep an explicitly confirmed no-write placeholder, or reclassify the Node. |
272
272
  | `tags.child_inherits_system` | A child Entity repeats its parent `system` / `application` scope tag. | Retag by the child’s own shape/scope, or keep the child as a Section if it is only a local aspect. |
273
273
  | `edge.confidence_invalid` | An edge declares a confidence value outside the current schema. | Use only `possible` or `hypothesis`, or omit the field for source-certain relations. |