@c4a/context 0.6.0-beta.3 → 0.6.0-beta.5

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.
@@ -209,12 +209,19 @@ This means files outside `src/` and non-exported/internal helpers are skipped.
209
209
  If you want docs, tests, examples, or internal APIs included, say that before
210
210
  extraction.
211
211
 
212
+ If the selected package has no standard package entry, do not ask the user to
213
+ change its source or `package.json`. Explain two Context-owned choices: provide
214
+ the source-relative API roots as configured entries, or scan every file matched
215
+ by the confirmed file scope. Entry-based extraction preserves public API
216
+ reachability; scan mode includes internal declarations by default.
217
+
212
218
  I will first generate a preview without writing candidates. The preview will
213
219
  show the file count, symbol count, candidate count, and planned `knowledge/`
214
220
  tree. I will only run extraction after that preview matches your expectation.
215
221
  ```
216
222
 
217
- Mention `extractTs`, `include`, `exportedOnly`, or `reviewValidity` only if the
223
+ Mention `extractTs`, `include`, `entries`, `mode`, `exportedOnly`, or
224
+ `reviewValidity` only if the
218
225
  user asks for implementation details, or when editing `src/index.ts` in a code
219
226
  summary.
220
227
 
@@ -241,6 +248,22 @@ You do not need to save a payload file; I will write a temporary file and run
241
248
  the apply command.
242
249
  ```
243
250
 
251
+ For a repeated codegraph run with no Review delta, say instead:
252
+
253
+ ```text
254
+ The source was checked and no added, changed, or removed code symbols need a
255
+ decision. Existing approved symbols were preserved, so there is no human gate
256
+ for this run and I can continue.
257
+ ```
258
+
259
+ For an explicitly requested CI/CD path, say:
260
+
261
+ ```text
262
+ I will run the codegraph phase with --auto-promote. It will apply only
263
+ deterministic code add/update/remove deltas, run verification, and fail the
264
+ pipeline if verification fails. Semantic knowledge still requires Review.
265
+ ```
266
+
244
267
  ## Package Gate
245
268
 
246
269
  Bad:
@@ -142,6 +142,13 @@ subdirectory as its own source and write
142
142
  `include: ["packages/button/src/**"]` to choose a package from a larger source;
143
143
  `include` only filters files inside the selected source.
144
144
 
145
+ For a non-standard package, configure source-relative `entries` on `extractTs`;
146
+ every entry must match `include`. If the user wants all declarations in the
147
+ selected files instead of public API reachability, use `mode: "scan"`, which
148
+ needs no entries and defaults to including internal symbols. Never add an entry
149
+ file or package manifest field to the source repository solely to make Context
150
+ run.
151
+
145
152
  Follow the source inspection pattern when scope is unclear: run
146
153
  `context source inspect <source-name> --format json`, show the candidate package
147
154
  paths from that CLI output, wait for the user to choose the package path(s), then
@@ -155,11 +162,31 @@ context source inspect <source-name> --format json
155
162
  context run <extract-phase-id> --dry-run --format json
156
163
  ```
157
164
 
158
- Use the `preview.sources[].modules[]`, `candidateEstimate`, and `agent_hints`
165
+ After the preview, run codegraph extraction normally unless the user explicitly
166
+ asked for CI/CD automation. The first normal run requires Review for all code
167
+ candidates. Subsequent normal runs require Review only for added, changed, or
168
+ removed symbols; unchanged approved symbols stay approved. Always inspect
169
+ `next_action.human_gate`: open Review only when it is `true`, and continue when
170
+ it is `false`.
171
+
172
+ For a non-interactive pipeline, use `context run <extract-phase-id>
173
+ --auto-promote --format json`. This flag applies only to codegraph, applies its
174
+ deterministic deltas, runs verify, and fails the command if verify fails. Never
175
+ use it for semantic knowledge collections.
176
+
177
+ Use the preview `mode`, optional `entries`, `preview.sources[].modules[]`,
178
+ `candidateEstimate`, and `agent_hints`
159
179
  fields as the authoritative scope check. To the user, call it a preview without
160
180
  writing candidates; avoid the internal CLI term. Also show `knowledgeTree` and
161
- `knowledgePathExamples` before first extraction. Explain that approved pages
162
- will be written under paths derived from collection, containment, and slug:
181
+ `knowledgePathExamples` before first extraction.
182
+
183
+ Treat `NO_ENTRY_DETECTED` as a configuration failure: choose explicit
184
+ `entries`, or use `mode: "scan"` when the intended scope is all matched files;
185
+ never report an empty extraction as success. Report discovered, AST-analyzed,
186
+ skipped, symbol, and relation counts separately. The extractor follows
187
+ tsconfig/jsconfig `baseUrl` and `paths`, so do not ask users to rewrite `@/`
188
+ imports solely for Context. Explain that approved pages will be written under
189
+ paths derived from collection, containment, and slug:
163
190
 
164
191
  ```text
165
192
  knowledge/<collection>/<containment>/<slug>.md
@@ -259,9 +259,40 @@ Options:
259
259
  | `source` | `source("name")` |
260
260
  | `collection` | Code extraction uses `"codegraph"` |
261
261
  | `include` | Optional glob list inside the selected source; default is `["src/**/*.{ts,tsx}"]` |
262
- | `exportedOnly` | Default `true` |
262
+ | `mode` | `"exports"` (default) traces public exports from automatic or configured entries; `"scan"` uses every file matched by `include` as an entry root |
263
+ | `entries` | Optional source-relative entry files for `"exports"` mode. They override `package.json` entry detection and live only in the Context project configuration |
264
+ | `exportedOnly` | Defaults to `true` in `"exports"` mode and `false` in `"scan"` mode |
263
265
  | `transform` | Optional markdown transform function or functions |
264
266
 
267
+ `source` is the only package/module boundary. `include` narrows files inside
268
+ that source; it does not select a second module. Standard packages can omit
269
+ `entries` and use `package.json` `exports`, `main`, or `bin` detection. For a
270
+ non-standard package, configure `entries` in the Context project instead of
271
+ editing the source repository:
272
+
273
+ ```ts
274
+ extractTs({
275
+ source: componentLib,
276
+ collection: "codegraph",
277
+ include: ["src/**/*.ts"],
278
+ entries: ["src/api.ts"],
279
+ });
280
+ ```
281
+
282
+ When the intended knowledge scope is every declaration in the selected files
283
+ rather than a public export graph, use `mode: "scan"`. Scan mode does not accept
284
+ `entries`; `include` supplies its file roots.
285
+
286
+ Entry failures use the stable machine code `NO_ENTRY_DETECTED`. This includes
287
+ `entries: []`, exports mode with no detected/configured entry, and scan mode
288
+ with no files matched by `include`; these cases never succeed silently.
289
+
290
+ TypeScript extraction reads the selected module's `tsconfig.json` or
291
+ `jsconfig.json`. JSONC comments/trailing commas, local or installed `extends`,
292
+ `compilerOptions.baseUrl`, and `compilerOptions.paths` are used for export
293
+ tracing and internal dependency relations, so aliases such as `@/*` resolve to
294
+ their source files.
295
+
265
296
  In monorepos, make the package/subdirectory the source boundary. Register the
266
297
  chosen package path with `context source add repo --local <package-dir>` and
267
298
  reference the CLI-returned date source name with `source("<source-name>")`.
@@ -274,6 +305,9 @@ boundaries before choosing the source. Use `context run <phase-id> --dry-run
274
305
  candidate estimate before writing `unapproved/entities.jsonl`. The dry-run
275
306
  preview also includes `knowledgeTree` and `knowledgePathExamples`, which show
276
307
  where approved Markdown will land after review apply.
308
+ Its module and total summaries distinguish `discoveredFiles`, `analyzedFiles`,
309
+ `skippedFiles`, `symbols`, and `relations`; modules with skipped files include
310
+ the reason, such as files not reachable from exports-mode entries.
277
311
 
278
312
  Phase id shape:
279
313
 
@@ -281,6 +315,21 @@ Phase id shape:
281
315
  extract:<source-name-or-repo>:codegraph
282
316
  ```
283
317
 
318
+ Codegraph extraction has two execution policies:
319
+
320
+ - `context run <phase-id>` is the Agent/user default. The first run sends every
321
+ code symbol to Review. Later runs preserve unchanged approved symbols and send
322
+ only `add`, `update`, and `remove` deltas to Review. If there is no delta, the
323
+ result returns `next_action.human_gate=false` and the Agent continues.
324
+ - `context run <phase-id> --auto-promote` is the explicit CI/CD path. It is valid
325
+ only for `phase.extract.ts` codegraph phases, applies deterministic code deltas
326
+ without Review, then runs project verification. Verification errors make the
327
+ command fail; JSON output reports applied/materialized/removed counts.
328
+
329
+ This policy never auto-promotes architecture, business, decision, test, or
330
+ other semantic knowledge. Agents must follow the returned
331
+ `next_action.human_gate` instead of assuming every extraction requires Review.
332
+
284
333
  ### `reviewValidity`
285
334
 
286
335
  Declare the review step for a collection:
@@ -304,7 +353,7 @@ review:all:validity
304
353
 
305
354
  The review HTML and apply flow are CLI-owned.
306
355
 
307
- This phase marks a human review gate. Agents should open `context review html
356
+ This phase marks a human review gate when current candidates exist. Agents should open `context review html
308
357
  <collection> --open` or `context review html --all --open` and wait for the
309
358
  user-copied payload; they should not run the phase as an automatic approval step
310
359
  or synthesize a payload themselves.
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export type { CodegraphCollection, DocumentMainlineCollection, EntityStatus, Kno
5
5
  export { assertDocumentMainlineCollection, assertKnowledgeCollection, assertMainlineCollection, assertOkfRoot, assertTopLevelNamespace, DOC_MAINLINE_COLLECTIONS, KNOWLEDGE_COLLECTIONS, MAINLINE_COLLECTIONS, OKF_ROOTS, TOP_LEVEL_NAMESPACES, } from "./contracts.js";
6
6
  export { assertDocumentEvidenceSectionMetadata, DOCUMENT_COMPILE_ACTION_SCHEMA_VERSION, DOCUMENT_EVIDENCE_SECTION_VALIDATION_STAGES, DOCUMENT_SECTION_CONTENT_MODES, DOCUMENT_STRUCTURE_SCHEMA_VERSION, } from "./documentEvidence.js";
7
7
  export type { DocumentEvidenceSectionMetadata, DocumentEvidenceSectionValidationOptions, DocumentEvidenceSectionValidationStage, DocumentSectionContentMode, } from "./documentEvidence.js";
8
- export { alignProse, captureFile, captureLark, compileProse, customPhase, extractTs, mdxJsonDocs, reviewValidity, } from "./phases.js";
8
+ export { alignProse, captureFile, captureLark, compileProse, customPhase, extractTs, ExtractTsConfigurationError, NO_ENTRY_DETECTED, mdxJsonDocs, reviewValidity, } from "./phases.js";
9
9
  export type { AlignProsePhaseDefinition, CaptureFilePhaseDefinition, CaptureLarkPhaseDefinition, CompileProsePhaseDefinition, ContextPhase, ContextPhaseContext, CustomPhaseDefinition, ExtractTsPhaseDefinition, PhaseDefinition, PhaseResourceReference, ReviewValidityPhaseDefinition, ReviewValidityScope, } from "./phases.js";
10
10
  export { allSources, DEFAULT_FILE_SOURCES_REGISTRY_PATH, DEFAULT_LARK_SOURCES_REGISTRY_PATH, DEFAULT_REPO_SOURCES_REGISTRY_PATH, loadSourcesRegistry, resolveSourceReference, source, } from "./sources.js";
11
11
  export type { DocumentSourceDefinition, DocumentSourceReference, DocumentSourceType, FileSourceDefinition, FileSourceReference, FileSourceRegistryEntry, LarkSourceDefinition, LarkSourceReference, LarkSourceRegistryEntry, LoadSourcesRegistryOptions, ProjectSourceDefinition, RepoProjectSourceDefinition, RepoSourceDefinition, RepoSourceReference, RepoSourceRegistryEntry, RepoSourcesRegistry, SourceCollectionReference, SourceDefinition, SourceReference, SourcesRegistry, SourceType, } from "./sources.js";
package/index.js CHANGED
@@ -7016,6 +7016,23 @@ var assertDocumentEvidenceSectionMetadata = (section, options, field = "document
7016
7016
  assertHasSourceRefs(section, field);
7017
7017
  };
7018
7018
  // src/phases.ts
7019
+ var NO_ENTRY_DETECTED = "NO_ENTRY_DETECTED";
7020
+
7021
+ class ExtractTsConfigurationError extends TypeError {
7022
+ code = NO_ENTRY_DETECTED;
7023
+ constructor(message) {
7024
+ super(message);
7025
+ this.name = "ExtractTsConfigurationError";
7026
+ }
7027
+ }
7028
+ function normalizeExtractEntry(value) {
7029
+ const slashPath = value.trim().replace(/\\/gu, "/");
7030
+ const segments = slashPath.replace(/^\.\//u, "").split("/");
7031
+ if (slashPath.length === 0 || slashPath.startsWith("/") || /^[A-Za-z]:\//u.test(slashPath) || segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
7032
+ throw new TypeError(`extractTs entries must be source-relative file paths: ${value}`);
7033
+ }
7034
+ return segments.join("/");
7035
+ }
7019
7036
  var getSourceType = (sourceDefinition) => {
7020
7037
  if (sourceDefinition.kind === "source.collection" || sourceDefinition.kind === "source.ref") {
7021
7038
  if (!("type" in sourceDefinition)) {
@@ -7197,6 +7214,14 @@ var extractTs = (definition) => {
7197
7214
  throw new TypeError(`extractTs collection must be codegraph: ${definition.collection}`);
7198
7215
  }
7199
7216
  const sourceId = sourceDefinition.kind === "source.collection" ? sourceDefinition.type : sourceDefinition.name;
7217
+ const mode = definition.mode ?? "exports";
7218
+ if (mode === "scan" && definition.entries !== undefined) {
7219
+ throw new TypeError("extractTs entries cannot be combined with mode: scan; scan mode uses every file matched by include");
7220
+ }
7221
+ if (definition.entries !== undefined && definition.entries.length === 0) {
7222
+ throw new ExtractTsConfigurationError("extractTs entries must contain at least one source-relative file path");
7223
+ }
7224
+ const entries = definition.entries === undefined ? undefined : [...new Set(definition.entries.map(normalizeExtractEntry))];
7200
7225
  const phase = {
7201
7226
  kind: "phase.extract.ts",
7202
7227
  id: `extract:${sourceId}:${definition.collection}`,
@@ -7213,7 +7238,9 @@ var extractTs = (definition) => {
7213
7238
  source: sourceDefinition,
7214
7239
  collection: definition.collection,
7215
7240
  include: definition.include ?? ["src/**/*.{ts,tsx}"],
7216
- exportedOnly: definition.exportedOnly ?? true,
7241
+ mode,
7242
+ ...entries !== undefined ? { entries } : {},
7243
+ exportedOnly: definition.exportedOnly ?? mode === "exports",
7217
7244
  out: {
7218
7245
  kind: "codegraph-entities",
7219
7246
  candidateFile: "unapproved/entities.jsonl",
@@ -11797,8 +11824,10 @@ export {
11797
11824
  alignProse,
11798
11825
  TOP_LEVEL_NAMESPACES,
11799
11826
  OKF_ROOTS,
11827
+ NO_ENTRY_DETECTED,
11800
11828
  MAINLINE_COLLECTIONS,
11801
11829
  KNOWLEDGE_COLLECTIONS,
11830
+ ExtractTsConfigurationError,
11802
11831
  DOC_MAINLINE_COLLECTIONS,
11803
11832
  DOCUMENT_STRUCTURE_SCHEMA_VERSION,
11804
11833
  DOCUMENT_SECTION_CONTENT_MODES,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c4a/context",
3
- "version": "0.6.0-beta.3",
3
+ "version": "0.6.0-beta.5",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "yaml": "^2.5.1",
package/phases.d.ts CHANGED
@@ -60,6 +60,8 @@ export type ExtractTsPhaseDefinition = {
60
60
  source: RepoProjectSourceDefinition;
61
61
  collection: "codegraph";
62
62
  include: readonly string[];
63
+ mode: "exports" | "scan";
64
+ entries?: readonly string[];
63
65
  exportedOnly: boolean;
64
66
  transform?: MarkdownTransform | readonly MarkdownTransform[];
65
67
  out: {
@@ -69,6 +71,11 @@ export type ExtractTsPhaseDefinition = {
69
71
  initialStatus: "draft";
70
72
  };
71
73
  };
74
+ export declare const NO_ENTRY_DETECTED: "NO_ENTRY_DETECTED";
75
+ export declare class ExtractTsConfigurationError extends TypeError {
76
+ readonly code: "NO_ENTRY_DETECTED";
77
+ constructor(message: string);
78
+ }
72
79
  export type CaptureFilePhaseDefinition = {
73
80
  kind: "phase.capture.file";
74
81
  id: string;
@@ -153,6 +160,8 @@ export declare const extractTs: (definition: {
153
160
  source: RepoProjectSourceDefinition;
154
161
  collection: "codegraph";
155
162
  include?: readonly string[];
163
+ mode?: "exports" | "scan";
164
+ entries?: readonly string[];
156
165
  exportedOnly?: boolean;
157
166
  transform?: MarkdownTransform | readonly MarkdownTransform[];
158
167
  }) => ExtractTsPhaseDefinition;