@c4a/context-cli 0.6.13 → 0.6.17

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 (52) hide show
  1. package/README.md +6 -0
  2. package/README.zh-CN.md +5 -0
  3. package/cli.js +6114 -3390
  4. package/docs/document-optimization.md +58 -0
  5. package/docs/document-optimization.zh-CN.md +50 -0
  6. package/package.json +3 -2
  7. package/plugins/VERSION +1 -1
  8. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  9. package/plugins/claude/commands/context.md +43 -2
  10. package/plugins/codex/.codex-plugin/plugin.json +2 -2
  11. package/plugins/codex/skills/context/SKILL.md +43 -2
  12. package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
  13. package/plugins/cursor/commands/c4a-context.md +43 -2
  14. package/plugins/skills/c4a-context/SKILL.md +43 -2
  15. package/providers/context/actions/optimize-documents.yaml +6 -0
  16. package/providers/context/actions/preview-extraction-batch.yaml +5 -0
  17. package/providers/context/actions/revise-document.yaml +5 -0
  18. package/providers/context/codes.yaml +6 -0
  19. package/providers/context/graphs/workspace.yaml +118 -3
  20. package/providers/context/manifest.json +242 -26
  21. package/providers/context/provider.yaml +1 -1
  22. package/providers/context/resources/dialogue/code-extraction.md +39 -9
  23. package/providers/context/resources/dialogue/package-output.md +5 -8
  24. package/providers/context/resources/manuals/guides/package-outputs.md +14 -20
  25. package/providers/context/resources/manuals/reference/code-extractors.md +75 -18
  26. package/providers/context/resources/manuals/reference/package-templates.md +26 -33
  27. package/providers/context/resources/manuals/reference/project-api.md +156 -14
  28. package/providers/context/resources/manuals/reference/template-variables.md +4 -3
  29. package/providers/context/resources/procedures/close-and-build.md +5 -0
  30. package/providers/context/resources/procedures/code-extraction.md +86 -13
  31. package/providers/context/resources/procedures/document-optimization.md +43 -0
  32. package/providers/context/resources/procedures/document-revision.md +31 -0
  33. package/providers/context/resources/procedures/package-output.md +10 -34
  34. package/providers/context/resources/semantic/code-index/classification.md +267 -0
  35. package/providers/context/resources/semantic/code-index/templates/adapter.md +109 -0
  36. package/providers/context/resources/semantic/code-index/templates/api-service.md +116 -0
  37. package/providers/context/resources/semantic/code-index/templates/background-runtime.md +109 -0
  38. package/providers/context/resources/semantic/code-index/templates/cli-tool.md +129 -0
  39. package/providers/context/resources/semantic/code-index/templates/contract-source.md +73 -0
  40. package/providers/context/resources/semantic/code-index/templates/cross-module-chain.md +78 -0
  41. package/providers/context/resources/semantic/code-index/templates/derived-source.md +116 -0
  42. package/providers/context/resources/semantic/code-index/templates/domain-service.md +109 -0
  43. package/providers/context/resources/semantic/code-index/templates/event-flow.md +62 -0
  44. package/providers/context/resources/semantic/code-index/templates/monorepo-container.md +124 -0
  45. package/providers/context/resources/semantic/code-index/templates/persistence-boundary.md +56 -0
  46. package/providers/context/resources/semantic/code-index/templates/plugin-extension.md +52 -0
  47. package/providers/context/resources/semantic/code-index/templates/protocol-boundary.md +88 -0
  48. package/providers/context/resources/semantic/code-index/templates/sdk-library.md +132 -0
  49. package/providers/context/resources/semantic/code-index/templates/web-application.md +145 -0
  50. package/providers/context/resources/views/document-optimization-current.yaml +6 -0
  51. package/providers/context/resources/views/extraction-preview.yaml +6 -0
  52. package/providers/context/schemas/document-optimization-decisions.schema.json +34 -0
@@ -10,13 +10,33 @@ 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.
13
+ Before declaring a phase, run the Route-selected batch inspection once for all
14
+ confirmed modules. Read their manifests, module documentation, stable entries,
15
+ and dependency/protocol locators. First record an evidence-backed classification
16
+ for every module without reading an archetype template. A module has one primary
17
+ `moduleType`, may declare additional `moduleTypes`, and may combine relevant
18
+ `facets`. Only after classification, read every matching file from the Route's
19
+ recommended `resources/semantic/code-index/templates/` directory and merge them
20
+ into one deduplicated plan per user-visible module or aggregate.
21
+
22
+ The target is a stable module map, public contract, protocol boundary, or
23
+ runtime map—not a page for every function, variable, constant, or internal type.
24
+ Use the Code Extractor Selection manual to choose `extractTs`, an optional
25
+ structural package inside `extractCustom`, or a project-owned adapter. Read the
26
+ selected package's public SDK/README before editing `src/index.ts`; never infer
27
+ its API from bundled output. `moduleTypeEvidence` must identify the inspected
28
+ paths that support the classification. An `unknown` unit or a unit with no
29
+ classification evidence is an incomplete index plan.
30
+
31
+ For every custom extraction preview, Context probes source paths for known
32
+ community structural capabilities: TypeScript symbols, React Router routes, Go
33
+ symbols, Rush workspace structure, and source-owned protocol schemas. Every
34
+ probe applicable to an index unit's output profile must be represented by the
35
+ candidate evidence for that unit. A project adapter may aggregate and explain
36
+ those facts in one high-value page, but it cannot replace a matched structural
37
+ probe with a static template or a manually listed filename. Missing probe
38
+ coverage is a `material-required` capability gap and uses the same
39
+ non-delegatable capability Gate in ordinary and fully managed conversations.
20
40
 
21
41
  `include` filters files inside a selected source; it is not a package/module
22
42
  selector. Use source declarations to select repository modules. Use configured
@@ -24,14 +44,58 @@ entry patterns when entry-led traversal is meaningful, or scan mode when the
24
44
  selected module intentionally has no package entry. Do not require source-code
25
45
  rewrites merely to create an extraction entry.
26
46
 
27
- Use a dry-run when the current route requests scope inspection. Report
47
+ Exports-only single-package TypeScript extraction has a compatible stable
48
+ public-contract plan. Scan mode, repository collections, and custom extraction
49
+ must declare their index units explicitly; an inferred plan is diagnostic only
50
+ and cannot write candidates.
51
+
52
+ Extractor output shape must match the semantic plan. `extractTs()` projects one
53
+ candidate page per selected symbol and assigns each source to one index unit;
54
+ it is suitable for a deliberately granular public reference. Aggregated module
55
+ maps, registries, protocol indexes, cross-module flows, or multiple units over
56
+ one source require `extractCustom()` with explicit candidate ownership. For a
57
+ monorepo, register independently visible children as separate sources before
58
+ giving them separate `extractTs()` units.
59
+
60
+ The Route runs one cache-writing batch preview after classification, template
61
+ selection, and configuration, but before any candidate write. Report
28
62
  discovered files, AST-analyzed files, skipped files, symbols, and relations
29
- separately. Use resolved entry files, exported/internal counts, and symbol-kind
30
- counts as structural scope evidence only. Resolve TypeScript/JavaScript
63
+ separately, together with each index unit's output owner, output profile,
64
+ projected Markdown count, total bytes, largest sampled page, and risk flags.
65
+ For custom phases, also report detected structural probes, covered and uncovered
66
+ probe counts, representative evidence paths, and the affected output profile.
67
+ Use resolved entry files, exported/internal counts, and symbol-kind counts as
68
+ structural scope evidence only. Resolve TypeScript/JavaScript
31
69
  configuration and aliases through the extractor rather than guessing paths
32
- from imports. Explain the scope without treating filenames or symbol kinds as
33
- semantic knowledge. After confirmation, process exactly one pending extraction
34
- target and evaluate again.
70
+ from imports.
71
+
72
+ Template examples never determine the expected page count. Scale policy is
73
+ applied only to the measured batch preview and is fixed per index unit: at most
74
+ 100 pages continues normally,
75
+ 101–300 pages continues with a warning, and more than 300 pages stops at the
76
+ non-delegatable extraction-scale Gate. Fully managed authority cannot bypass
77
+ that Gate. Ambiguous output ownership and `material-required` capability gaps
78
+ also stop before candidate writes. Ambiguous ownership returns to project
79
+ configuration without creating another human Gate. Revise all affected units
80
+ together, re-check whether their classification or selected templates changed,
81
+ rerun the batch preview, then process exactly one pending extraction target and
82
+ evaluate again. Do not add a second classification Gate after the page-count
83
+ Gate; a plan revision returns through the same configuration step.
84
+
85
+ A batch-total page warning and quality risks such as a thin aggregate are
86
+ advisory only. They remain visible for cost and content-shape review but do not
87
+ become a new Gate. Legal scale recovery includes narrowing `include`, excluding
88
+ generated or mirrored directories, enabling `exportedOnly`, moving from a
89
+ symbol catalog to an aggregated `extractCustom()` plan, or registering real
90
+ child sources. Splitting one `extractTs()` source into overlapping units is not
91
+ a valid workaround.
92
+
93
+ Current previews are cached below `.tmp/context-runtime/extract/previews/` and
94
+ formal extraction reuses their validated structural result. Cache identity is
95
+ bound to source scope, phase/adapter declarations, project `src/`, dependency
96
+ locks, and the preview protocol. Deleting
97
+ `.tmp` only causes a fresh preview. Existing approved knowledge is not
98
+ retroactively rejected solely because it is large.
35
99
 
36
100
  Do not open Review while another extraction target in the same batch remains.
37
101
  Unchanged approved or rejected symbols do not need another decision; new or
@@ -45,6 +109,10 @@ receipt reports `relationships.detected`, `emitted`, and omission counts.
45
109
  Review materializes those source-backed relations with the approved symbol,
46
110
  and deterministic close refreshes the typed edge projection.
47
111
 
112
+ Project-owned custom edges use `source-backed-explicit` rather than claiming
113
+ AST derivation. They remain subject to the same evidence, endpoint, Review, and
114
+ close projection checks.
115
+
48
116
  Zero edges remain a valid result. Read `close.relationshipCoverage` or the
49
117
  package inventory's `structure.relationship_coverage` to distinguish a current
50
118
  source-backed extraction that found no approved edges from an older or
@@ -56,6 +124,11 @@ declared `extractCustom` phase. The project-owned callback returns candidate
56
124
  semantics plus structured source evidence; Context owns canonical refs,
57
125
  fingerprints, candidate storage, Review snapshots, freshness, and rerun cleanup.
58
126
  Do not use a generic `customPhase` callback to write lifecycle files directly.
127
+ Large custom adapters may return candidates as an `AsyncIterable`; Context
128
+ retains at most the proof boundary for an over-limit unit instead of collecting
129
+ thousands of full Markdown candidates. A project-owned `inspect` adapter may
130
+ report generic module/protocol findings and capability gaps without putting
131
+ framework-specific rules in the community CLI.
59
132
 
60
133
  Prefer a reusable structural library over a project-local parser when one
61
134
  matches the confirmed source: `@c4a/extract-go` for Go facts,
@@ -0,0 +1,43 @@
1
+ ---
2
+ id: procedure.document-optimization
3
+ kind: procedure
4
+ mediaType: text/markdown
5
+ ---
6
+
7
+ # Document revisions
8
+
9
+ This optional phase improves the presentation of approved file and document
10
+ prose without mutating the approved page. It runs only when
11
+ `package.json.context.documentOptimization` is true.
12
+
13
+ Run the Route-selected plan command. Read every returned fragment in the
14
+ current batch and write one decision for each fragment to the returned
15
+ `payload_target`, using the Route input schema. Use `keep` when no safe local
16
+ repair is needed. Use `replace` only for Markdown structure, spacing, obvious
17
+ typographical errors, or link syntax. Preserve meaning, paragraph order,
18
+ technical identifiers, URLs, code, and numbers. Do not summarize, expand,
19
+ reorder, or invent facts.
20
+
21
+ After the complete payload is ready, execute the exact `next_action.command`
22
+ returned by the plan. Context rejects stale, incomplete, duplicate, or
23
+ semantically broad decisions. Unchanged fragments reuse their previous
24
+ decision; changed fragments alone return to this phase.
25
+
26
+ Only pages with reader-visible changes are stored. A revision is a full
27
+ Markdown sidecar beside its approved page: `knowledge/guides/setup.md` becomes
28
+ `knowledge/guides/setup__revision.md`. Default knowledge discovery excludes the
29
+ reserved suffix. The filename derives the base page; the revision stores only
30
+ the base digest that cannot be derived. Unchanged fragments inside a revision
31
+ are inferred. A page with no changes stores one derived negative cache key
32
+ below `.tmp/context-runtime/document-optimization/`; replacement prose and
33
+ fragment metadata are never duplicated there.
34
+
35
+ For a later user-requested correction, use `context revise "<title or approved
36
+ path>" --format json`. The resulting `route.document-revision.requested` owns
37
+ target selection, revision editing, and validation; it also works when broad
38
+ document optimization was not previously enabled. The compatibility entry
39
+ `context optimize-docs revise` accepts the same selectors. Validation rejects
40
+ lifecycle metadata changes, stale page baselines, unsafe token changes, broad
41
+ rewrites, and invalid Markdown structure. A source change makes the revision a
42
+ blocking conflict instead of silently applying it. Do not create fragment JSON
43
+ files or another revision namespace.
@@ -0,0 +1,31 @@
1
+ ---
2
+ id: procedure.document-revision
3
+ kind: procedure
4
+ mediaType: text/markdown
5
+ ---
6
+
7
+ # Conversational document correction
8
+
9
+ Use this procedure only for a correction explicitly requested by the user after
10
+ an approved knowledge page already exists. The request selects one page; it
11
+ does not authorize a broad rewrite or a change to source facts.
12
+
13
+ 1. Run the Route command `context optimize-docs revise-current --format json`.
14
+ 2. Read the complete approved page and its sibling `__revision.md` page named
15
+ by the returned plan. Check the cited source when the requested correction
16
+ could change a fact rather than formatting or wording.
17
+ 3. Edit only the returned revision page. Preserve its frontmatter identity,
18
+ `context_revision` baseline, Context section boundaries, evidence markers,
19
+ links, code, numbers, and unsupported details. Make the smallest change that
20
+ satisfies the user's request. Never edit the approved base page for this
21
+ operation.
22
+ 4. Run `context optimize-docs validate --format json`. If validation reports a
23
+ stale baseline, unsafe replacement, or missing evidence, stop and report the
24
+ exact finding instead of weakening the correction.
25
+ 5. Continue from the returned `context status --format json` Route. A valid
26
+ correction makes the package stale, so the normal build Route will offer
27
+ compilation without requiring a second correction decision.
28
+
29
+ If the entry returned more than one target candidate, select a candidate only
30
+ when the user's wording or current conversation identifies it uniquely;
31
+ otherwise ask the user which approved page to correct. Do not guess.
@@ -36,37 +36,13 @@ maintain the complete final Skill directory name in the template, such as
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
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.
47
-
48
- Before falling back to bundled delivery for a non-GitHub remote, inspect the
49
- confirmed repository web URL or a known raw-file URL. When the Git service uses
50
- the GitHub-compatible same-host shape
51
- `https://<host>/<namespace>/<repository>/raw/<ref>/<path>`, prefer an explicit
52
- `urlPrefix` such as
53
- `https://git.example.com/team/knowledge/raw/{commit}`. Include the
54
- repository-relative workspace directory in that prefix when the Context
55
- workspace is nested below the repository root; Context appends the
56
- project-relative `knowledge/assets/...` path. Lack of built-in automatic
57
- derivation alone is not a reason to bundle. Prefer `{commit}` for immutable
58
- links; use a literal published ref only when the author intentionally wants it.
59
- If the service's raw convention or repository identity cannot be established,
60
- do not guess or probe an invented endpoint: ask the author for `urlPrefix`, or
61
- offer bundled delivery.
62
-
63
- Large image optimization applies only to bundled delivery. Without an `assets`
64
- declaration, existing workspaces continue to copy selected resources
65
- byte-for-byte. If build or status reports
66
- `package.assets.optimization-recommended`, explain that the current package is
67
- valid but contains more than 20 MiB of eligible PNG/JPEG resources. Do not
68
- install a dependency or edit project configuration automatically. If the user
69
- chooses to optimize the package, use the exact reported setup command and add
70
- the reported `kbPackage().assets.optimize` value. The processor is installed in the
71
- Context workspace, not bundled into Context itself. Optimization changes only
72
- `dist/`; source snapshots and approved resources remain unchanged.
39
+ KB packages bundle referenced resources by default. Images are copied to
40
+ `others/assets/`; when necessary, Context compresses supported images so each
41
+ output image is at most 1 MiB and their combined package size is at most 40
42
+ MiB. This changes only `dist/`, never captured or approved source resources.
43
+
44
+ Configure `assets.delivery="git-raw"` only when the author explicitly wants
45
+ external links and accepts responsibility for publishing and access. Use a
46
+ confirmed immutable HTTPS prefix where possible; do not infer or probe an
47
+ unknown host convention. Explicit omission keeps unresolved links and must be
48
+ described as such.
@@ -0,0 +1,267 @@
1
+ ---
2
+ id: semantic.code-index.classification
3
+ kind: procedure
4
+ media-type: text/markdown
5
+ ---
6
+
7
+ # Classify code modules before choosing a template
8
+
9
+ This procedure is the first semantic step for code extraction. Start from the
10
+ Route-selected batch inspection. Do not open an archetype template and then fit
11
+ the module to it. First classify every confirmed module from inspected evidence,
12
+ then read only the matching templates.
13
+
14
+ Classification determines which reader questions the index must answer. It
15
+ does not grant access to undeclared sources, prove a relationship, or override
16
+ the measured extraction preview.
17
+
18
+ ## 1. Use one batch evidence pass
19
+
20
+ Use the inspection result for every confirmed module before opening more files.
21
+ It already reports manifests, maintained documentation, entry candidates,
22
+ protocol locators, lifecycle signals, and generic structural capabilities.
23
+ Open source files only for unresolved facts, and follow stable registration or
24
+ executable wiring rather than scanning the whole tree.
25
+
26
+ Confirm, where applicable:
27
+
28
+ - the module manifest or workspace registration;
29
+ - its README or nearest maintained operating documentation;
30
+ - build, executable, application, service, or library entrypoints;
31
+ - route, command, service, event, job, plugin, or export registries;
32
+ - authoritative protocol/schema locations and concrete consumer call sites;
33
+ - generated, mirrored, vendored, legacy, test, fixture, and mock boundaries;
34
+ - development, configuration, deployment, and release entrypoints owned by the
35
+ module.
36
+
37
+ A language, framework dependency, exported symbol, or folder name does not by
38
+ itself prove a module type.
39
+
40
+ ## 2. Record classification before reading templates
41
+
42
+ Produce one batch table first:
43
+
44
+ | module | primary type | additional types | facets | evidence paths | gaps |
45
+ | --- | --- | --- | --- | --- | --- |
46
+ | `customer-portal` | `web-application` | — | `page-routing`, `protocol-consumer` | `package.json`, `src/routes.ts` | upstream schema is external |
47
+ | `edge-gateway` | `api-service` | `adapter` | `protocol-provider`, `protocol-consumer` | `cmd/server.go`, `api/openapi.yaml` | — |
48
+
49
+ Each module must have:
50
+
51
+ - one primary `moduleType` for concise reports;
52
+ - every additional applicable type in `moduleTypes`;
53
+ - relevant behavior and boundary `facets`;
54
+ - concrete inspected paths in `moduleTypeEvidence`;
55
+ - an explicit gap when available source cannot support a reliable claim.
56
+
57
+ Choose the primary type from the boundary through which a reader most often
58
+ enters the module. A gateway is normally `api-service`, a plugin-hosting command
59
+ application is normally `cli-tool`, and a generated client is normally
60
+ `sdk-library`; their translation or provenance roles remain additional types.
61
+
62
+ Supported types are:
63
+
64
+ - `web-application`: browser, native mobile, desktop, embedded, or cross-platform
65
+ interactive applications with routes, pages, screens, or host integration;
66
+ - `api-service`: an HTTP, RPC, GraphQL, message-request, or similar inbound
67
+ protocol surface with dispatch to handlers;
68
+ - `service`: a stable domain/use-case or reusable service boundary whose public
69
+ operations coordinate implementation or persistence;
70
+ - `background-runtime`: workers, consumers, schedulers, pipelines, functions,
71
+ or long-running processes driven by triggers rather than interactive calls;
72
+ - `sdk-library`: a reusable package with a deliberately supported consumer API;
73
+ - `cli-tool`: an executable tool organized around commands, flags,
74
+ configuration, outputs, and exit behavior;
75
+ - `adapter`: a bridge that translates protocols, identities, models, lifecycle,
76
+ or host capabilities between boundaries;
77
+ - `monorepo-container`: a workspace whose stable value is its child-module,
78
+ ownership, dependency, build, or release topology;
79
+ - `derived-source`: generated, mirrored, vendored, or legacy source whose
80
+ authority lives elsewhere;
81
+ - `contract-source`: an authoritative IDL, API description, schema, or contract
82
+ registry used by providers, consumers, generators, or validators;
83
+ - `unknown`: the source is insufficient to classify without guessing.
84
+
85
+ `unknown` cannot be combined with a known type. A hybrid module may combine
86
+ several known types. Independent infrastructure definitions, migration sets,
87
+ or data-model projects that do not fit a supported type remain `unknown` and
88
+ use a project-owned inspection/extraction adapter; do not force them into an
89
+ unrelated application type.
90
+
91
+ ## 3. Add composable facets
92
+
93
+ Facets identify behavior that may cross the primary type:
94
+
95
+ - `page-routing`: concrete route, page, screen, or navigation registration;
96
+ - `public-api`: a deliberately supported programmatic consumer surface;
97
+ - `protocol-provider` / `protocol-consumer`: inbound or outbound operation
98
+ boundaries with authoritative locators;
99
+ - `event-producer` / `event-consumer`: asynchronous trigger and delivery flow;
100
+ - `persistence`: repository, datastore, cache, or durable-state boundary;
101
+ - `plugin-extension`: discovery, activation, contribution, or host extension;
102
+ - `configuration-runtime`: configuration or runtime selection that changes
103
+ observable behavior;
104
+ - `build-release`: module-owned build, packaging, deployment, or release entry;
105
+ - `cross-module-chain`: an evidenced flow joins two or more registered modules;
106
+ - `generated-contract`: generated code represents or locates an upstream
107
+ schema but is not automatically authoritative.
108
+
109
+ Require a registration, call site, schema locator, or runtime entry. A matching
110
+ dependency alone is not evidence.
111
+
112
+ ## 4. Read matching templates
113
+
114
+ After the batch table is complete, read every applicable type template and only
115
+ the applicable facet template:
116
+
117
+ | Type or facet | Template path |
118
+ | --- | --- |
119
+ | `web-application` | `resources/semantic/code-index/templates/web-application.md` |
120
+ | `api-service` | `resources/semantic/code-index/templates/api-service.md` |
121
+ | `service` | `resources/semantic/code-index/templates/domain-service.md` |
122
+ | `background-runtime` | `resources/semantic/code-index/templates/background-runtime.md` |
123
+ | `sdk-library` | `resources/semantic/code-index/templates/sdk-library.md` |
124
+ | `cli-tool` | `resources/semantic/code-index/templates/cli-tool.md` |
125
+ | `adapter` | `resources/semantic/code-index/templates/adapter.md` |
126
+ | `monorepo-container` | `resources/semantic/code-index/templates/monorepo-container.md` |
127
+ | `derived-source` | `resources/semantic/code-index/templates/derived-source.md` |
128
+ | `contract-source` | `resources/semantic/code-index/templates/contract-source.md` |
129
+ | `protocol-provider`, `protocol-consumer`, `generated-contract` | `resources/semantic/code-index/templates/protocol-boundary.md` |
130
+ | `event-producer`, `event-consumer` | `resources/semantic/code-index/templates/event-flow.md` |
131
+ | `persistence` | `resources/semantic/code-index/templates/persistence-boundary.md` |
132
+ | `plugin-extension` | `resources/semantic/code-index/templates/plugin-extension.md` |
133
+ | `cross-module-chain` | `resources/semantic/code-index/templates/cross-module-chain.md` |
134
+
135
+ `page-routing` and `public-api` refine their matching application or library
136
+ template. `configuration-runtime` and `build-release` add chapter expectations
137
+ to the selected type template. They do not require duplicate pages.
138
+
139
+ Templates are question sets and chapter blueprints. Omit unsupported sections,
140
+ merge overlapping output, and retain concrete identifiers and source locators
141
+ for every kept claim.
142
+
143
+ ## 5. Match the plan to the extractor
144
+
145
+ Extractor shape is part of the plan, not an implementation detail:
146
+
147
+ - `extractTs()` projects each selected symbol to its own candidate page. It is
148
+ suitable for a deliberately granular public reference, but it does not
149
+ produce an aggregated module map, registry, protocol index, or chain page.
150
+ - `extractTs()` assigns ownership by source. A source can belong to only one
151
+ index unit in a phase. Splitting one source into several units or adding an
152
+ overlapping cross-source unit causes `ownership-ambiguous`.
153
+ - Use `extractCustom()` for aggregate pages or multiple units over one source.
154
+ Every candidate must declare its owning `module`, and its evidence must cover
155
+ the Route-reported structural probes. Use evidence-scoped `sections` rather
156
+ than one undifferentiated `markdown` body: each section declares a coverage
157
+ kind and the exact source evidence supporting that part of the page. Resolve
158
+ source roots from the extractor context's `sources[].absolutePath`; never
159
+ embed a machine-specific checkout path.
160
+ - Register independently visible monorepo children as separate sources before
161
+ giving them separate `extractTs()` units. An `include` pattern filters files;
162
+ it does not create a source boundary.
163
+
164
+ Do not wait for an expensive preview to discover that the chosen extractor
165
+ cannot produce the planned page shape.
166
+
167
+ ## 6. Produce one deduplicated plan
168
+
169
+ Create one `CodeIndexUnitPlan` per user-visible module or independently useful
170
+ custom cross-module flow. A minimal plan has this shape:
171
+
172
+ ```ts
173
+ {
174
+ module: "customer-portal",
175
+ moduleType: "web-application",
176
+ moduleTypes: ["web-application"],
177
+ facets: ["page-routing", "protocol-consumer"],
178
+ moduleTypeEvidence: ["package.json", "src/routes.ts"],
179
+ outputOwner: "customer-portal",
180
+ outputProfile: "application-map",
181
+ inputSources: ["repo:customer-portal"],
182
+ entries: ["src/bootstrap.ts", "src/routes.ts"],
183
+ protocols: ["api/openapi.yaml"],
184
+ excludes: ["dist/**", "**/*.test.ts"],
185
+ lifecycle: "source",
186
+ pageKinds: ["application-map", "route-registry", "protocol-boundary"],
187
+ capability: "complete"
188
+ }
189
+ ```
190
+
191
+ `outputProfile` is a closed value and selects structural coverage expectations:
192
+
193
+ | Profile | Intended output |
194
+ | --- | --- |
195
+ | `module-map` | stable module responsibility and entry map |
196
+ | `application-map` | application entry, route, state, and boundary map |
197
+ | `protocol-index` | provider/consumer operations anchored to contracts |
198
+ | `service-boundary` | service operations, orchestration, and dependencies |
199
+ | `runtime-map` | triggers, processing, state, effects, and recovery |
200
+ | `public-api-reference` | deliberately supported consumer API |
201
+ | `command-map` | commands, options, effects, outputs, and recovery |
202
+ | `adapter-contract` | inbound-to-outbound translation contract |
203
+ | `module-registry` | workspace child modules, ownership, and topology |
204
+ | `cross-module-flow` | evidenced handoffs across registered modules |
205
+ | `provenance-only` | source identity, derivation, consumers, and authority |
206
+
207
+ The preview also requires these evidence-scoped section kinds:
208
+
209
+ | Profile | Required section coverage |
210
+ | --- | --- |
211
+ | `module-map` | `responsibility`, `entrypoint` |
212
+ | `application-map` | `entrypoint`, `operation`, `handoff` |
213
+ | `protocol-index` | `contract`, `operation`, `handoff` |
214
+ | `service-boundary` | `operation`, `handoff` |
215
+ | `runtime-map` | `entrypoint`, `operation`, `failure-recovery` |
216
+ | `public-api-reference` | `contract` |
217
+ | `adapter-contract` | `contract`, `handoff` |
218
+ | `command-map` | `entrypoint`, `operation`, `failure-recovery` |
219
+ | `module-registry` | `responsibility`, `source-authority` |
220
+ | `cross-module-flow` | `operation`, `handoff`, plus at least one structured edge |
221
+ | `provenance-only` | `source-authority` |
222
+
223
+ The `build-release`, `persistence`, `configuration-runtime`, and
224
+ `generated-contract` facets additionally require `delivery`, `state-boundary`,
225
+ `state-boundary`, and `source-authority` respectively. A heading without an
226
+ evidence-scoped section does not satisfy coverage.
227
+
228
+ The profile affects structural probes and advisory risks. `pageKinds` remains
229
+ free-form so projects can name useful page families, but use stable kebab-case
230
+ tokens consistently within a project. Type templates provide recommended
231
+ tokens.
232
+
233
+ For a multi-module round, finish all classifications first, read the union of
234
+ matching templates once, and revise affected plans together. Do not create a
235
+ copy of the same operation or plugin record for each selected template.
236
+
237
+ ## 7. Capability gaps and preview
238
+
239
+ Use `capability: "material-required"` when an unsupported parser, missing
240
+ project adapter, absent evidence, or unresolved source boundary prevents the
241
+ promised output. This typed capability is valid in ordinary and fully managed
242
+ flows and stops both at the same Route Gate.
243
+
244
+ Missing authority does not always block all output. For generated or mirrored
245
+ source whose upstream schema cannot be located, a `provenance-only` unit may
246
+ still record source identity, known derivation facts, and evidenced consumers.
247
+ Keep field semantics and compatibility claims material-required. Stop the
248
+ whole unit only when those semantics are the confirmed knowledge goal.
249
+
250
+ Run the Route-selected batch preview after every plan is evidence-backed. Its
251
+ projected Markdown count is authoritative per index unit:
252
+
253
+ - up to 100 pages: continue;
254
+ - 101–300 pages: report an advisory and continue;
255
+ - more than 300 pages: block and revise, including in fully managed mode.
256
+
257
+ A large batch also reports a batch-total advisory even when each unit remains
258
+ within its limit. Advisory risks describe quality or cost; they do not become a
259
+ new human Gate. `scale-limit-exceeded`, `ownership-ambiguous`, and
260
+ `material-required` capability gaps remain blocking.
261
+
262
+ Legal recovery includes narrowing `include`, excluding generated or mirrored
263
+ areas, using `exportedOnly`, changing a symbol catalog into an aggregated
264
+ `extractCustom()` output, or registering real child sources. Splitting one
265
+ `extractTs()` source into overlapping units is not a valid workaround. Group all
266
+ affected modules into one plan revision instead of creating one Gate per
267
+ module.
@@ -0,0 +1,109 @@
1
+ ---
2
+ id: semantic.code-index.template.adapter
3
+ kind: procedure
4
+ media-type: text/markdown
5
+ ---
6
+
7
+ # Adapter, bridge, and integration template
8
+
9
+ Use for `adapter`: BFFs, protocol bridges, host integrations, plugin adapters,
10
+ compatibility layers, gateways, and translators whose stable responsibility is
11
+ to connect two boundaries. An ordinary internal helper that converts one object
12
+ is not automatically an adapter module.
13
+
14
+ Recommended `outputProfile`: `adapter-contract`. For an inbound gateway whose
15
+ reader goal is the provided operation surface, use `protocol-index` instead.
16
+
17
+ ## Evidence pass
18
+
19
+ Locate both sides of the boundary and the code that joins them:
20
+
21
+ - inbound operation, event, command, host hook, or extension registration;
22
+ - outbound operation, client, plugin contribution, or runtime capability;
23
+ - authoritative input and output contract locations;
24
+ - identity, field, enum, version, and lifecycle mappings;
25
+ - authentication, authorization, credential, and context propagation;
26
+ - validation, normalization, batching, caching, fallback, and compatibility;
27
+ - timeout, retry, partial failure, and error/status translation;
28
+ - configuration, feature selection, ownership, and release entrypoints;
29
+ - generated DTOs/clients and converter helpers that should remain evidence.
30
+
31
+ Sample representative paths from each mapping family. Do not claim a mapping
32
+ from matching field names alone.
33
+
34
+ ## Questions the knowledge must answer
35
+
36
+ 1. Which two boundaries does the adapter connect, and who owns each one?
37
+ 2. What triggers the mapping and where is it registered?
38
+ 3. Which fields, identities, versions, or lifecycle states are transformed?
39
+ 4. Which values pass through unchanged, default, or intentionally disappear?
40
+ 5. How are credentials, context, errors, retries, and fallbacks translated?
41
+ 6. Which contracts are authoritative and which artifacts are generated?
42
+ 7. What compatibility obligation makes the adapter stable knowledge?
43
+
44
+ ## Suggested knowledge units
45
+
46
+ - **Adapter contract**: responsibility, inbound/outbound boundaries,
47
+ registration, ownership, and authoritative contracts.
48
+ - **Operation mapping registry**: use the canonical operation record from
49
+ `protocol-boundary.md` and add only adapter-specific transformation fields.
50
+ - **Data or identity mapping**: only stable, non-trivial mappings that readers
51
+ must understand; summarize generated field copies.
52
+ - **Lifecycle and failure translation**: when activation, cancellation,
53
+ retries, partial failure, or compatibility behavior is material.
54
+ - **Cross-module execution path**: when both connected modules are registered
55
+ sources and the chain is source-backed.
56
+
57
+ ## Chapter blueprints
58
+
59
+ ```markdown
60
+ # <Adapter> contract
61
+ ## Responsibility and connected boundaries
62
+ ## Activation or registration
63
+ ## Inbound contracts
64
+ ## Outbound contracts
65
+ ## Data, identity, and lifecycle mapping
66
+ ## Authentication and context propagation
67
+ ## Error, retry, fallback, and compatibility behavior
68
+ ## Configuration, ownership, and release
69
+ ## Evidence and exclusions
70
+ ```
71
+
72
+ For adapter-specific detail attached to a canonical operation record:
73
+
74
+ ```markdown
75
+ ## Adapter transformation
76
+ - Mapper/handler entry:
77
+ - Field/identity/default transformations:
78
+ - Context and credential propagation:
79
+ - Error and fallback mapping:
80
+ ```
81
+
82
+ ## Granularity and relationships
83
+
84
+ Group mappings that share the same boundary pair and transformation policy.
85
+ Split when protocol authority, ownership, lifecycle, or failure semantics
86
+ differ. Do not publish every DTO, converter, generated client, or transport
87
+ helper separately.
88
+
89
+ Add structured edges only for concrete registration and call paths. Keep a
90
+ narrative locator when dynamic dispatch prevents an unambiguous edge.
91
+
92
+ ## Template composition examples
93
+
94
+ - An HTTP endpoint backed by an RPC client is `api-service` + `adapter`; combine
95
+ one operation registry with one mapping contract rather than duplicating the
96
+ route facts.
97
+ - A host plugin bridge reads `plugin-extension.md` and may also be `sdk-library`
98
+ when consumers import
99
+ a supported extension API.
100
+ - A compatibility wrapper over generated clients also reads
101
+ `derived-source.md` and identifies the authoritative schemas.
102
+
103
+ ## Revise or stop when
104
+
105
+ - either side of the adapter cannot be identified;
106
+ - mappings are inferred only from same-named types or fields;
107
+ - credential, identity, or error behavior would be guessed;
108
+ - generated DTOs are replacing authoritative contracts in the plan;
109
+ - the adapter page would merely say that one module “calls” another.