@nimiplatform/nimi-coding 0.5.0 → 0.6.0

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 (33) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +50 -25
  4. package/README.zh-CN.md +50 -25
  5. package/cli/commands/clear.mjs +3 -2
  6. package/cli/commands/code.mjs +225 -0
  7. package/cli/commands/start.mjs +3 -2
  8. package/cli/constants.mjs +2 -1
  9. package/cli/dev/run-cli-smoke.mjs +6 -0
  10. package/cli/help.mjs +8 -3
  11. package/cli/index.mjs +3 -2
  12. package/cli/lib/authority/diagnostics.mjs +3 -1
  13. package/cli/lib/code/authority-annotation-response.mjs +43 -0
  14. package/cli/lib/code/authority-annotation-scan.mjs +162 -0
  15. package/cli/lib/code/authority-annotations.mjs +293 -0
  16. package/cli/lib/code/context.mjs +710 -0
  17. package/cli/lib/code/response.mjs +165 -0
  18. package/cli/lib/doctor.mjs +3 -2
  19. package/cli/lib/entrypoints.mjs +12 -5
  20. package/cli/seeds/seed-policy.yaml +2 -2
  21. package/methodology/authority-authoring.yaml +67 -52
  22. package/methodology/core.yaml +6 -4
  23. package/package.json +5 -3
  24. package/spec/code-authority-annotations.yaml +42 -0
  25. package/spec/code-context.yaml +38 -0
  26. package/spec/product-scope.yaml +8 -3
  27. package/cli/commands/validate-ai-governance.mjs +0 -335
  28. package/cli/lib/internal/governance/ai/ai-context-budget-core.mjs +0 -377
  29. package/cli/lib/internal/governance/ai/ai-structure-budget-core.mjs +0 -376
  30. package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +0 -155
  31. package/cli/lib/internal/governance/ai/check-high-risk-doc-metadata-core.mjs +0 -173
  32. package/cli/lib/internal/governance/config.mjs +0 -114
  33. package/cli/lib/internal/governance/shared/read-yaml-with-fragments.mjs +0 -49
@@ -0,0 +1,165 @@
1
+ import { Buffer } from "node:buffer";
2
+
3
+ export const CODE_CONTEXT_FORMAT = "nimicoding.code-context-response/v1";
4
+ export const MIN_CODE_CONTEXT_BYTES = 512;
5
+
6
+ const MAX_ERROR_MESSAGE_BYTES = 160;
7
+
8
+ function serialized(value) {
9
+ return JSON.stringify(value);
10
+ }
11
+
12
+ function serializedBytes(value) {
13
+ return Buffer.byteLength(value, "utf8");
14
+ }
15
+
16
+ function prefixByteLengths(fragments) {
17
+ const totals = [0];
18
+ for (const fragment of fragments) {
19
+ totals.push(totals.at(-1) + serializedBytes(fragment));
20
+ }
21
+ return totals;
22
+ }
23
+
24
+ function arrayBytes(prefixTotals, count) {
25
+ return 2 + prefixTotals[count] + Math.max(0, count - 1);
26
+ }
27
+
28
+ function arrayText(fragments, count) {
29
+ return `[${fragments.slice(0, count).join(",")}]`;
30
+ }
31
+
32
+ export function refusedCodeResponse(code, message) {
33
+ if (Buffer.byteLength(message, "utf8") > MAX_ERROR_MESSAGE_BYTES) {
34
+ throw new Error("code response error message exceeds its fixed protocol bound");
35
+ }
36
+ return {
37
+ format: CODE_CONTEXT_FORMAT,
38
+ status: "refused",
39
+ scope: null,
40
+ coverage: null,
41
+ missing_frontier: null,
42
+ result: null,
43
+ error: { code, message },
44
+ };
45
+ }
46
+
47
+ export function serializeCodeResponse(response) {
48
+ return `${serialized(response)}\n`;
49
+ }
50
+
51
+ function targetCountsBySemanticPrefix(targets, semanticItems) {
52
+ const known = new Set();
53
+ const counts = [0];
54
+ for (const item of semanticItems) {
55
+ if (item.target_id !== undefined && item.target_id !== null) known.add(item.target_id);
56
+ counts.push(known.size);
57
+ }
58
+ if (known.size !== targets.length) throw new Error("semantic projection contains an unused target descriptor");
59
+ return counts;
60
+ }
61
+
62
+ function responseParts({ scopeText, rootText, targetFragments, semanticFragments, sourceFragments }, state) {
63
+ const coverage = {
64
+ semantic_items: state.semanticCount === semanticFragments.length ? "complete" : "truncated",
65
+ source_units: state.sourceCount === sourceFragments.length ? "complete" : "truncated",
66
+ };
67
+ const complete = state.semanticCount === semanticFragments.length && state.sourceCount === sourceFragments.length;
68
+ const frontier = complete ? null : {
69
+ next_semantic_site: state.nextSemanticSite,
70
+ next_source_target: state.nextSourceTarget,
71
+ };
72
+ if (!complete && frontier.next_semantic_site === null && frontier.next_source_target === null) {
73
+ throw new Error("partial code response has no missing frontier");
74
+ }
75
+ const head = [
76
+ `{"format":${serialized(CODE_CONTEXT_FORMAT)}`,
77
+ `,"status":${serialized(complete ? "completed" : "partial")}`,
78
+ `,"scope":${scopeText}`,
79
+ `,"coverage":${serialized(coverage)}`,
80
+ `,"missing_frontier":${serialized(frontier)}`,
81
+ `,"result":{"root":${rootText},"targets":`,
82
+ ].join("");
83
+ return {
84
+ head,
85
+ betweenTargetsAndSemantic: ",\"semantic_items\":",
86
+ betweenSemanticAndSources: ",\"source_units\":",
87
+ tail: "},\"error\":null}\n",
88
+ };
89
+ }
90
+
91
+ function codeResponseBytes(parts, targetBytes, semanticBytes, sourceBytes, state) {
92
+ return serializedBytes(parts.head)
93
+ + arrayBytes(targetBytes, state.targetCount)
94
+ + serializedBytes(parts.betweenTargetsAndSemantic)
95
+ + arrayBytes(semanticBytes, state.semanticCount)
96
+ + serializedBytes(parts.betweenSemanticAndSources)
97
+ + arrayBytes(sourceBytes, state.sourceCount)
98
+ + serializedBytes(parts.tail);
99
+ }
100
+
101
+ function stateForPrefix({ targets, semanticItems, sourceUnits, targetCounts }, prefix) {
102
+ const semanticCount = Math.min(prefix, semanticItems.length);
103
+ const sourceCount = prefix <= semanticItems.length ? 0 : prefix - semanticItems.length;
104
+ const targetCount = targetCounts[semanticCount];
105
+ const nextSemantic = semanticItems[semanticCount];
106
+ let nextSourceTarget = null;
107
+ if (semanticCount === semanticItems.length) {
108
+ nextSourceTarget = sourceUnits[sourceCount]?.target_id ?? null;
109
+ } else if (sourceUnits.length > 0) {
110
+ const targetIndex = targets.findIndex((target) => target.id === sourceUnits[0].target_id);
111
+ if (targetIndex >= 0 && targetIndex < targetCount) nextSourceTarget = sourceUnits[0].target_id;
112
+ }
113
+ return {
114
+ semanticCount,
115
+ sourceCount,
116
+ targetCount,
117
+ nextSemanticSite: nextSemantic === undefined ? null : {
118
+ line: nextSemantic.site.range.start_line,
119
+ column: nextSemantic.site.range.start_column,
120
+ },
121
+ nextSourceTarget,
122
+ };
123
+ }
124
+
125
+ export function renderContextResponse({ scope, projection, maxBytes }) {
126
+ const scopeText = serialized(scope);
127
+ const rootText = serialized(projection.root);
128
+ const targetFragments = projection.targets.map(serialized);
129
+ const semanticFragments = projection.semanticItems.map(serialized);
130
+ const sourceFragments = projection.sourceUnits.map(serialized);
131
+ const targetBytes = prefixByteLengths(targetFragments);
132
+ const semanticBytes = prefixByteLengths(semanticFragments);
133
+ const sourceBytes = prefixByteLengths(sourceFragments);
134
+ const targetCounts = targetCountsBySemanticPrefix(projection.targets, projection.semanticItems);
135
+ const totalItems = semanticFragments.length + sourceFragments.length;
136
+ let selected = null;
137
+
138
+ for (let prefix = 0; prefix <= totalItems; prefix += 1) {
139
+ const state = stateForPrefix({
140
+ targets: projection.targets,
141
+ semanticItems: projection.semanticItems,
142
+ sourceUnits: projection.sourceUnits,
143
+ targetCounts,
144
+ }, prefix);
145
+ const parts = responseParts({ scopeText, rootText, targetFragments, semanticFragments, sourceFragments }, state);
146
+ const bytes = codeResponseBytes(parts, targetBytes, semanticBytes, sourceBytes, state);
147
+ if (bytes <= maxBytes) selected = { state, parts, bytes };
148
+ }
149
+
150
+ if (selected === null) return null;
151
+ const { state, parts, bytes } = selected;
152
+ const text = [
153
+ parts.head,
154
+ arrayText(targetFragments, state.targetCount),
155
+ parts.betweenTargetsAndSemantic,
156
+ arrayText(semanticFragments, state.semanticCount),
157
+ parts.betweenSemanticAndSources,
158
+ arrayText(sourceFragments, state.sourceCount),
159
+ parts.tail,
160
+ ].join("");
161
+ if (serializedBytes(text) !== bytes || bytes > maxBytes) {
162
+ throw new Error("code response renderer byte accounting is inconsistent");
163
+ }
164
+ return { text, bytes, status: state.semanticCount === semanticFragments.length && state.sourceCount === sourceFragments.length ? "completed" : "partial" };
165
+ }
@@ -1,6 +1,7 @@
1
1
  import { readdir } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
 
4
+ import { PROJECT_LOCAL_CLI_INVOCATION } from "../constants.mjs";
4
5
  import { getBootstrapSeedEntries } from "../seeds/bootstrap.mjs";
5
6
  import { pathExists, preflightManagedProjectPaths } from "./fs-helpers.mjs";
6
7
  import { runSeedSync, SYNC_MODE } from "./sync.mjs";
@@ -34,7 +35,7 @@ export async function inspectDoctorState(projectRoot) {
34
35
  true,
35
36
  "info",
36
37
  specPresent
37
- ? "canonical authority is present; run nimicoding authority check .nimi/spec for admission"
38
+ ? `canonical authority is present; run ${PROJECT_LOCAL_CLI_INVOCATION} authority check .nimi/spec for admission`
38
39
  : "canonical authority has not been authored; the project owns all product semantics under .nimi/spec",
39
40
  ),
40
41
  ];
@@ -74,7 +75,7 @@ export function formatDoctorResult(result, options = {}) {
74
75
  if (visible.length === 0) lines.push(` - ${localize("No blocking integration issues found.", "没有发现阻塞性的集成问题。")}`);
75
76
  else for (const entry of visible) lines.push(` - [${entry.ok ? "info" : entry.severity}] ${entry.detail}`);
76
77
  if (!result.spec.present) {
77
- lines.push("", styleLabel(localize("Next:", "下一步:")), " - Author canonical authority under .nimi/spec, format changed files, then run nimicoding authority check .nimi/spec.");
78
+ lines.push("", styleLabel(localize("Next:", "下一步:")), ` - Author canonical authority under .nimi/spec, format changed files, then run ${PROJECT_LOCAL_CLI_INVOCATION} authority check .nimi/spec.`);
78
79
  }
79
80
  return `${lines.join("\n")}\n`;
80
81
  }
@@ -6,6 +6,7 @@ import {
6
6
  AGENTS_END,
7
7
  CLAUDE_BEGIN,
8
8
  CLAUDE_END,
9
+ PROJECT_LOCAL_CLI_INVOCATION,
9
10
  } from "../constants.mjs";
10
11
  import { pathExists, preflightManagedProjectPaths, readUtf8FileFatal } from "./fs-helpers.mjs";
11
12
 
@@ -18,14 +19,20 @@ export class ManagedBlockError extends Error {
18
19
 
19
20
  function authorityAuthoringLines() {
20
21
  return [
22
+ `- From the repository root, invoke the pinned project-local CLI as \`${PROJECT_LOCAL_CLI_INVOCATION}\`; do not probe or rely on a global \`nimicoding\` binary in \`PATH\`.`,
21
23
  "- Product authority lives under `.nimi/spec/**`.",
22
24
  "- For canonical authority authoring, read only `.nimi/methodology/authority-authoring.yaml`, the affected authority files or bounded task context, and CLI diagnostics.",
23
- "- Use `nimicoding authority context <path> <id> --max-units <n> --max-bytes <n> --json` only for the complete declared outgoing interpretation closure; it is not complete task context, and failure never permits guessed or partial context.",
24
- "- Use `nimicoding authority diff` and `authority impact` with explicit `--max-bytes`; impact reports declared review obligations and does not prove implementation, consumers, or tests are synchronized.",
25
- "- Use `nimicoding authority change-candidates` only with explicit channels and budgets; its complete union is recall input, never conflict, retirement, absence, authority, or conformance judgment.",
25
+ `- Use \`${PROJECT_LOCAL_CLI_INVOCATION} authority context <path> <id> --max-units <n> --max-bytes <n> --json\` only for the complete declared outgoing interpretation closure; it is not complete task context, and failure never permits guessed or partial context.`,
26
+ `- Use \`${PROJECT_LOCAL_CLI_INVOCATION} authority diff\` and \`${PROJECT_LOCAL_CLI_INVOCATION} authority impact\` with explicit \`--max-bytes\`; impact reports declared review obligations and does not prove implementation, consumers, or tests are synchronized.`,
27
+ `- Use \`${PROJECT_LOCAL_CLI_INVOCATION} authority change-candidates\` only with explicit channels and budgets; its complete union is recall input, never conflict, retirement, absence, authority, or conformance judgment.`,
28
+ `- For implementation audits with an exact authority ID, use \`${PROJECT_LOCAL_CLI_INVOCATION} code authority --repo <root> --authority <id> --max-files <n> --max-bytes <n>\` to locate annotated code, and use \`--source <path>\` for code-to-authority lookup. Results cover only explicit markers and authority lifecycle; they do not prove implementation conformance or evaluate unannotated code.`,
29
+ `- For a new or changed authority-governed feature, add \`// nimi-authority: <exact-id>\` only at the small number of key semantic owner files or declarations. Multiple markers are allowed; do not blanket-annotate mechanical helpers or tests.`,
30
+ `- Use \`// nimi-deprecated: <exact-id>\` only after direct authority evidence or a real product failure confirms obsolete semantics; find it with \`${PROJECT_LOCAL_CLI_INVOCATION} code authority --repo <root> --audit --max-files <n> --max-bytes <n>\` and remove the marker with the hard cut.`,
31
+ `- After selecting an explicit TypeScript or TSX consumer, use \`${PROJECT_LOCAL_CLI_INVOCATION} code context <path> --repo <root> --symbol <identifier> --tsconfig <path> --max-bytes <n>\` for bounded root-direct static dependencies; it is not inbound impact, runtime dispatch, or complete task context.`,
32
+ `- Use \`${PROJECT_LOCAL_CLI_INVOCATION} sync --check\` to diagnose drift in package-owned managed projections, \`${PROJECT_LOCAL_CLI_INVOCATION} sync --apply\` to restore them, and \`${PROJECT_LOCAL_CLI_INVOCATION} doctor\` to diagnose package/managed compatibility. These commands do not validate product authority, implementation conformance, or task readiness.`,
26
33
  "- Under `.nimi/spec/**`, author only closed multi-unit `*.authority.yaml` containers or single-unit `*.authority.md`; historical document formats are unsupported and never inferred.",
27
- "- Run `nimicoding authority fmt` on each changed file, then `nimicoding authority check` on the complete authority input set.",
28
- "- Never bypass a failure with inferred or fallback semantics; choose repair values only from product/task authority.",
34
+ `- Run \`${PROJECT_LOCAL_CLI_INVOCATION} authority fmt\` on each changed file, then \`${PROJECT_LOCAL_CLI_INVOCATION} authority check\` on the complete authority input set.`,
35
+ `- A failed project-local \`${PROJECT_LOCAL_CLI_INVOCATION} ...\` invocation blocks only the requested CLI product and never permits guessed, partial, corpus-wide, or fallback context; choose repair values only from product/task authority.`,
29
36
  "- Keep derived and local verification output under `.nimi/local/**`; it is never product authority.",
30
37
  ];
31
38
  }
@@ -1,10 +1,10 @@
1
1
  policy_id: nimicoding.seed-projection.v3
2
- description: Exact downstream projection registry for canonical authority authoring.
2
+ description: Exact downstream projection registry for authority authoring and bounded implementation navigation.
3
3
  projections:
4
4
  - source: methodology/authority-authoring.yaml
5
5
  output: .nimi/methodology/authority-authoring.yaml
6
6
  ownership: package_canonical
7
- downstream_consumer: project AI reads the compact canonical authority authoring guide
7
+ downstream_consumer: project AI reads the compact authority and implementation-navigation guide
8
8
  deprecated_projections:
9
9
  - .nimi/config/spec-generation-inputs.yaml
10
10
  - .nimi/contracts/domain-admission.schema.yaml
@@ -1,45 +1,62 @@
1
- version: 4
1
+ version: 6
2
2
  id: nimicoding.authority-authoring
3
- purpose: Author explicit .nimi/spec authority without inference.
3
+ purpose: Author explicit authority and navigate current implementation without inference.
4
4
  authority_boundary:
5
5
  canonical_root: .nimi/spec
6
6
  sources: ["*.authority.yaml", "*.authority.md"]
7
- rule: The project owns product meaning; nimicoding formats, validates, and derives read-only results.
8
- AI_inputs: [this_guide, task_authority, bounded_discovery, exact_query_or_bounded_context, diagnostics]
7
+ rule: The project owns meaning; nimicoding formats, validates, and derives read-only results.
8
+ AI_inputs: [this_guide, task_authority, bounded_authority_or_code_query, diagnostics]
9
9
  do_not_read: [complete_authority_corpus, contracts, package_internal_specs]
10
10
 
11
+ cli_execution:
12
+ cwd: repository_root
13
+ command_prefix: pnpm exec nimicoding
14
+ rule: Resolve the pinned local package; never probe global PATH. Failure blocks only the requested CLI product.
15
+
11
16
  daily_workflow:
12
- - If no exact ID is known, run nimicoding authority discover <path> <query> --max-candidates 10 --max-snippet-terms 24 --max-bytes 131072 --json. Filters are exact; pass --preview-direction, --relations, and --max-edges together. It neither selects nor proves absence.
13
- - Select an ID only from task or product authority. Use nimicoding authority query <path> <id> --max-bytes <positive-integer> --json for one unit, or context <path> <id> --max-units <positive-integer> --max-bytes <positive-integer> --json for its declared outgoing applies_to/supersedes closure. Context is not complete task context.
14
- - Modify only project-owned canonical authority. Choose every product value before writing; never infer an ID, owner, scope, condition, failure, or relation.
15
- - Run nimicoding authority fmt <changed-file> for each changed file.
16
- - Run nimicoding authority check <complete-path> [--scope-bindings <file>] --json; then compile. For repository anchors run nimicoding authority anchors <repository-path> --spec <corpus-path> [--scope-bindings <file>] --max-units <positive-safe-integer> --max-anchors <positive-safe-integer> --max-bytes <positive-safe-integer> --json.
17
- - For semantic changes, run diff and impact with explicit budgets and complete inputs. Treat returned obligations only as host-owned follow-up targets; run the project's real code, type, test, and gate workflow separately.
18
- - Never continue from compiler diagnostics, unknown IDs, budget failures, or partial/guessed results.
17
+ - Without an exact ID, run pnpm exec nimicoding authority discover <path> <query> --max-candidates 10 --max-snippet-terms 24 --max-bytes 131072 --json. It returns candidates, never selection or absence proof.
18
+ - Select IDs only from task/product authority. pnpm exec nimicoding authority query <path> <id> --max-bytes <n> --json returns one unit; pnpm exec nimicoding authority context <path> <id> --max-units <n> --max-bytes <n> --json returns its outgoing applies_to/supersedes closure, not task context.
19
+ - Modify only project authority; never infer product values or relations.
20
+ - Run pnpm exec nimicoding authority fmt <changed-file> for each changed file.
21
+ - Run pnpm exec nimicoding authority check <complete-path> [--scope-bindings <file>] --json, then pnpm exec nimicoding authority compile <complete-path> --json. For anchors run pnpm exec nimicoding authority anchors <repo> --spec <corpus> [--scope-bindings <file>] --max-units <n> --max-anchors <n> --max-bytes <n> --json.
22
+ - For semantic changes, run complete-input diff and impact with budgets; obligations are host follow-up targets, not results.
23
+ - Never continue from diagnostics, unknown IDs, budget failures, or guessed/partial results.
24
+
25
+ implementation_navigation:
26
+ authority_to_code: pnpm exec nimicoding code authority --repo <root> --authority <exact-id> --max-files <n> --max-bytes <n>
27
+ code_to_authority: pnpm exec nimicoding code authority --repo <root> --source <tracked-path> --max-files <n> --max-bytes <n>
28
+ context: pnpm exec nimicoding code context <ts-or-tsx-path> --repo <root> --symbol <top-level-identifier> --tsconfig <path> --max-bytes <n>
29
+ markers:
30
+ authority: "// nimi-authority: <exact-id>"
31
+ deprecated: "// nimi-deprecated: <same-exact-id>"
32
+ rule: Put optional markers near key semantic owners; add deprecated only from direct authority/product failure, then remove with the hard cut.
33
+ boundary: Markers return authored locations/lifecycle; TypeScript context is root-direct static outbound only. Neither evaluates unannotated code, conformance, inbound impact, runtime dispatch, or completion.
34
+
35
+ managed_surfaces:
36
+ check: pnpm exec nimicoding sync --check
37
+ restore: pnpm exec nimicoding sync --apply
38
+ doctor: pnpm exec nimicoding doctor
39
+ boundary: Sync diagnoses exact package-owned projection/block drift and apply restores it; doctor diagnoses package/managed compatibility. Neither validates authority, code, or task readiness.
19
40
 
20
41
  source_profiles:
21
42
  yaml:
22
- shape: "Closed mapping: format nimicoding.authority/v2; owner?; scope string?; units. Units/IDs/order unchanged."
23
- defaults: owner/rule scope inherit; unit overrides; definitions lack scope.
24
- omissions: lifecycle active and relations [] may be omitted; removed/reason stay explicit; missing owner/rule scope at both levels fails.
43
+ shape: "Closed nimicoding.authority/v2 mapping with optional owner/scope defaults and units."
44
+ defaults: owner/rule scope inherit; unit values override; definitions have no scope.
45
+ omissions: active lifecycle and empty relations may be omitted; removed reason stays explicit.
25
46
  format: nimicoding.authority/v2_only_without_legacy_migration_or_history_input
26
47
  markdown:
27
- shape: One unit per file. Front matter carries format, id, kind, owner, lifecycle, rule modality/scope, and relations.
48
+ shape: One unit per file; front matter carries fields and relations.
28
49
  title: One plain H1.
29
50
  sections:
30
51
  active_definition: [Meaning]
31
52
  active_rule: [Statement, Condition, Failure]
32
53
  removed_unit: [Removal reason]
33
- boundary: Each section is one plain-text line; no free prose or unknown structures.
34
- shared_text_rule: Text fields are non-empty trimmed single-line Unicode.
54
+ boundary: One plain-text line per section; no free prose or unknown structures.
55
+ shared_text_rule: Text is non-empty trimmed single-line Unicode.
35
56
 
36
57
  common_fields:
37
- id: Stable dot-separated lower-case identity; never reuse a removed ID.
38
- kind: rule or definition.
39
- owner: Accountable dotted lower-case unit or container value.
40
- lifecycle: active or explicit removed.
41
- title: Required display label.
42
- relations: Type/target pairs; omitted means [].
58
+ id: Stable lower-case dot identity; never reuse a removed ID.
59
+ owner: Accountable lower-case dotted identity.
43
60
 
44
61
  unit_shapes:
45
62
  active_definition:
@@ -50,38 +67,37 @@ unit_shapes:
50
67
  required: [id, kind, title, modality, statement, condition, failure]
51
68
  fixed: {kind: rule, lifecycle: active}
52
69
  modality: must or must_not.
53
- scope: Non-empty unique unit list or one inherited container value.
54
- condition: Write the actual condition; use Always. only when unconditional.
55
- failure: State observable failure; never pseudo-success or silent fallback.
70
+ scope: Unique non-empty unit list or inherited container value.
71
+ condition: Actual condition; use Always. only when unconditional.
72
+ failure: Observable failure, never pseudo-success or fallback.
56
73
  forbidden: [meaning, reason]
57
74
  removed_tombstone:
58
75
  required: [id, kind, lifecycle, title, reason]
59
76
  fixed: {lifecycle: removed}
60
- boundary: Preserve the stable identity and kind. reason is lifecycle rationale, not normative replacement content.
77
+ boundary: Preserve identity/kind; reason is rationale, not replacement content.
61
78
  forbidden: [meaning, modality, scope, statement, condition, failure]
62
79
 
63
80
  relation_rules:
64
- applies_to: Required one or more times from each active rule to active definitions only.
65
- supersedes: Optional from active or removed to one removed unit of the same kind; at most one incoming/outgoing edge, acyclic linear lineage.
66
- resolution: Targets resolve by exact ID in the complete input; invalid, dangling, mismatched, cyclic, duplicate, or inferred edges fail.
81
+ applies_to: Each active rule targets one or more active definitions only.
82
+ supersedes: Optional edge to one removed unit of the same kind; one incoming/outgoing maximum, acyclic.
83
+ resolution: Exact IDs in complete input; invalid, dangling, mismatched, cyclic, duplicate, or inferred edges fail.
67
84
 
68
85
  formatter_and_diagnostics:
69
- - fmt canonicalizes; v2 strips redundant unit defaults but keeps container choices.
70
- - Any source format other than nimicoding.authority/v2 fails fmt, check, compile, diff, impact, and review admission.
71
- - check/compile use the complete path and fail closed; no public or partial AuthorityIR is emitted.
72
- - Diagnostics give locations, reasons, conflicts, and repair categories, never product values.
73
- - Fix values only from task or product authority. Do not invent container defaults, fallback data, historical inference, internal contracts, or wildcard corpus reading.
86
+ - fmt canonicalizes v2 and strips redundant unit defaults.
87
+ - Non-v2 input fails fmt/check/compile/diff/impact/review.
88
+ - check/compile use complete paths and emit no public/partial AuthorityIR.
89
+ - Diagnostics give locations and repair categories, never product values.
74
90
 
75
91
  change_workflow:
76
- diff: nimicoding authority diff <before-path> <after-path> --max-bytes <positive-integer> --json
77
- candidates: nimicoding authority change-candidates <before-path> <after-path> --channels <comma-separated-closed-set> --max-candidates <positive-safe-integer> --max-reasons <positive-safe-integer> --max-bytes <positive-safe-integer> --json
78
- impact: nimicoding authority impact <before-path> <after-path> --max-bytes <positive-integer> --json
92
+ diff: pnpm exec nimicoding authority diff <before-path> <after-path> --max-bytes <positive-integer> --json
93
+ candidates: pnpm exec nimicoding authority change-candidates <before-path> <after-path> --channels <comma-separated-closed-set> --max-candidates <positive-safe-integer> --max-reasons <positive-safe-integer> --max-bytes <positive-safe-integer> --json
94
+ impact: pnpm exec nimicoding authority impact <before-path> <after-path> --max-bytes <positive-integer> --json
79
95
  boundaries:
80
96
  - Diff compares complete canonical inputs; formatting, profile, file, and order-only changes are semantic zero.
81
- - Change candidates are the complete union only for caller-requested exact owner, scope, changed-term, direct-relation, Definition-identity, and Definition-title channels. They are recall inputs for AI or human judgment, never conflict, retirement, authority, absence, or conformance findings.
82
- - Impact follows declared reverse applies_to/supersedes only and reports every before/after scope consumer plus one test follow-up target for each impacted active rule.
83
- - Diff/impact budgets cover complete compact payloads; budget failure returns no partial result.
84
- - Impact accepts no disposition, receipt, external result, test outcome, or completion state. The host owns execution and workflow state.
97
+ - Candidates cover only requested exact channels, never semantic judgment.
98
+ - Impact reports declared reverse-relation consumers and one test target per impacted active rule.
99
+ - Diff/impact budget failure returns no partial result.
100
+ - Impact accepts no disposition, receipt, external result, test outcome, or completion state; workflow stays host-owned.
85
101
 
86
102
  canonical_examples:
87
103
  complete_yaml_lifecycle: |
@@ -92,13 +108,13 @@ canonical_examples:
92
108
  kind: definition
93
109
  owner: team.identity
94
110
  lifecycle: removed
95
- title: Legacy session
96
- reason: Replaced by the current session definition.
111
+ title: Old session
112
+ reason: Replaced by definition.session.
97
113
  - id: definition.session
98
114
  kind: definition
99
115
  owner: team.identity
100
116
  title: Session
101
- meaning: A server-issued identity context presented with a protected request.
117
+ meaning: A server-issued request identity.
102
118
  relations:
103
119
  - type: supersedes
104
120
  target: definition.session-v0
@@ -106,16 +122,16 @@ canonical_examples:
106
122
  kind: rule
107
123
  owner: team.checkout
108
124
  lifecycle: removed
109
- title: Legacy anonymous checkout prohibition
110
- reason: Replaced by the current checkout prohibition.
125
+ title: Old checkout rule
126
+ reason: Replaced by rule.checkout-no-anonymous.
111
127
  - id: rule.checkout-no-anonymous
112
128
  kind: rule
113
129
  owner: team.checkout
114
- title: Anonymous checkout is prohibited
130
+ title: Require checkout session
115
131
  modality: must_not
116
- statement: Checkout creates an order without a valid session.
132
+ statement: Checkout creates an order without a session.
117
133
  condition: Always.
118
- failure: Reject the request before creating an order.
134
+ failure: Reject before creating the order.
119
135
  relations:
120
136
  - type: applies_to
121
137
  target: definition.session
@@ -123,5 +139,4 @@ canonical_examples:
123
139
  target: rule.checkout-no-anonymous-v0
124
140
 
125
141
  final_boundaries:
126
- - Authority is only project-authored *.authority.yaml or *.authority.md under .nimi/spec; derived/local output is not authority.
127
- - Derived reads are bounded and read-only; none selects authority, supplies complete task context, or proves completion.
142
+ - Only project-authored sources under .nimi/spec are authority; derived/local output is not.
@@ -1,7 +1,7 @@
1
- version: 6
1
+ version: 7
2
2
  methodology:
3
3
  id: nimi-coding
4
- mission: Preserve explicit project-authored canonical authority through deterministic formatting, compilation, and fail-closed gates.
4
+ mission: Preserve explicit project-authored canonical authority and derive bounded read-only code context or explicit authored code links from current implementation inputs.
5
5
  package_boundary:
6
6
  owns:
7
7
  - compact_canonical_authority_authoring_methodology
@@ -14,7 +14,8 @@ methodology:
14
14
  - bounded_explicit_relation_graph_navigation
15
15
  - project_bound_deterministic_authority_audit_and_SARIF_projection
16
16
  - semantic_diff_and_declared_review_obligations
17
- - optional_L3_repository_governance_checks
17
+ - explicit_TypeScript_5_9_3_root_direct_bounded_code_context
18
+ - transient_exact_code_authority_marker_lookup_and_lifecycle_audit
18
19
  does_not_own:
19
20
  - project_product_semantics
20
21
  - historical_document_reconstruction_or_inference
@@ -24,6 +25,7 @@ methodology:
24
25
  - implementation_or_review_completion
25
26
  - host_workflow_commands
26
27
  - storage_semantic_search_visualization_or_Atlas
28
+ - code_location_inbound_impact_structural_advice_other_languages_or_task_completion
27
29
  authority_order:
28
30
  - host_canonical_authority_under_.nimi/spec
29
31
  - projected_compact_authoring_methodology
@@ -36,5 +38,5 @@ methodology:
36
38
  graph: bounded_explicit_relation_navigation_not_semantic_inference_or_raw_IR
37
39
  audit: explicit_project_verifier_bindings_not_prose_inference_plugin_execution_or_product_authority
38
40
  impact: declared_relation_impact_and_host_follow_up_targets_not_implementation_consumer_or_test_sync_proof
41
+ code_context: current_filesystem_complete_selected_TypeScript_Program_root_direct_static_outbound_projection_not_location_impact_runtime_dispatch_or_task_context
39
42
  authority_admission: nimicoding_authority_check_on_complete_canonical_root
40
- optional_repository_governance: separate_L3_not_authority_admission
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@nimiplatform/nimi-coding",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "private": false,
5
- "description": "Canonical authority methodology, formatter, compiler primitives, and deterministic gates.",
5
+ "description": "Canonical authority products and bounded read-only code context for AI coding systems.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://docs.nimi.ai/nimicoding",
8
8
  "repository": {
@@ -33,12 +33,14 @@
33
33
  "keywords": [
34
34
  "ai",
35
35
  "coding",
36
- "governance",
36
+ "authority",
37
+ "code-intelligence",
37
38
  "methodology",
38
39
  "spec",
39
40
  "nimicoding"
40
41
  ],
41
42
  "dependencies": {
43
+ "typescript": "5.9.3",
42
44
  "yaml": "^2.8.1"
43
45
  },
44
46
  "files": [
@@ -0,0 +1,42 @@
1
+ version: 1
2
+ spec:
3
+ id: nimicoding.code-authority-annotations.v1
4
+ owner: nimi-coding
5
+ status: experimental
6
+ product_claim: exact_standalone_markers_link_selected_tracked_current_source_to_current_canonical_authority_lifecycle
7
+ command: nimicoding code authority --repo <exact-git-worktree-root> (--authority <exact-id>|--source <repo-relative-.ts-.tsx-or-.go-path>|--audit) --max-files <integer> --max-bytes <integer>=512
8
+ markers:
9
+ authority: "// nimi-authority: <exact-authority-id>"
10
+ deprecated: "// nimi-deprecated: <exact-authority-id>"
11
+ optional: true
12
+ attachment: source_file_with_exact_marker_and_bounded_nearby_source_only
13
+ declaration_ownership: not_evaluated
14
+ deprecated_pairing: not_evaluated
15
+ scan:
16
+ authority_corpus: complete_repository_.nimi/spec
17
+ source_inventory: Git_tracked_current_filesystem
18
+ source_languages: [TypeScript, TSX, Go]
19
+ persistent_index_or_cache: none
20
+ ordering: deterministic
21
+ operations:
22
+ authority_to_code: all_exact_marker_occurrences_in_the_complete_admitted_source_scan
23
+ code_to_authority: exact_marker_occurrences_in_one_tracked_source_file
24
+ lifecycle_audit: [active-reference, explicit-deprecated, removed-reference, superseded-reference, missing-reference, invalid-annotation]
25
+ response:
26
+ format: nimicoding.code-authority-response/v1
27
+ transport: one_compact_JSON_object_on_stdout_with_terminating_newline
28
+ stderr: empty_for_recognized_code_operations
29
+ statuses: [completed, findings, refused]
30
+ public_budgets: [max-files, max-bytes]
31
+ minimum_valid_max_bytes: 512
32
+ partial_results: forbidden
33
+ boundaries:
34
+ annotation_is_authority: false
35
+ annotation_proves_conformance: false
36
+ unannotated_source: not_evaluated
37
+ active_authority_statement_drift: not_evaluated
38
+ automatic_legacy_detection: false
39
+ annotation_coverage_gate: false
40
+ scope_binding_dependency: none
41
+ writes_repository: false
42
+ workflow_task_or_completion_state: none
@@ -0,0 +1,38 @@
1
+ version: 1
2
+ spec:
3
+ id: nimicoding.code-context.v1
4
+ owner: nimi-coding
5
+ status: experimental
6
+ product_claim: explicit_TypeScript_root_returns_one_bounded_root_direct_static_outbound_projection_or_fails
7
+ command: nimicoding code context <repo-relative-.ts-or-.tsx-path> --repo <exact-git-worktree-root> --symbol <top-level-identifier> --tsconfig <repo-relative-tsconfig> --max-bytes <integer>=512
8
+ compiler:
9
+ language: TypeScript_TSX
10
+ version: 5.9.3
11
+ source: nearest_repo_contained_tsconfig_owner_package
12
+ program: fresh_complete_selected_config_without_project_references
13
+ root:
14
+ selector: one_exact_top_level_Identifier
15
+ admitted: [function, class, interface, type_alias, single_declarator_variable_statement]
16
+ merged_overloaded_nested_member_namespace_enum_or_declaration_root: refused
17
+ projection:
18
+ scope: selected_root_AST_only
19
+ relations: [static_value_binding, static_type_binding, static_constructor_binding, static_JSX_binding]
20
+ target: complete_nonempty_portable_declaration_set
21
+ target_source: optional_single_repository_declaration_syntactic_slice
22
+ runtime_dispatch: not_evaluated
23
+ response:
24
+ format: nimicoding.code-context-response/v1
25
+ transport: one_compact_JSON_object_on_stdout_with_terminating_newline
26
+ stderr: empty_for_recognized_code_operations
27
+ statuses: [completed, partial, refused]
28
+ public_budget: complete_UTF-8_response_max_bytes
29
+ minimum_valid_max_bytes: 512
30
+ partial: deterministic_longest_atomic_prefix_with_first_missing_frontier
31
+ boundaries:
32
+ writes_repository: false
33
+ persistent_index_or_cache: none
34
+ authority_association: not_claimed
35
+ source_location_or_inbound_impact: not_admitted
36
+ structural_advice: not_admitted
37
+ task_workflow_verification_or_completion: not_admitted
38
+ other_languages: not_admitted
@@ -1,7 +1,7 @@
1
- version: 9
1
+ version: 11
2
2
  product:
3
3
  package_name: "@nimiplatform/nimi-coding"
4
- mission: canonical_authority_methodology_formatter_compiler_primitives_and_deterministic_gates
4
+ mission: canonical_authority_products_bounded_read_only_code_context_and_explicit_code_authority_marker_lookup
5
5
  owned_surfaces:
6
6
  - compact_authority_authoring_methodology
7
7
  - exact_authority_guide_projection_and_managed_instruction_blocks
@@ -12,7 +12,8 @@ owned_surfaces:
12
12
  - bounded_direct_references_exact_relation_paths_and_local_subgraphs
13
13
  - project_bound_deterministic_graph_and_exact_lexical_authority_audit_and_SARIF_projection
14
14
  - git_aware_exact_read_only_authority_change_review
15
- - optional_L3_repository_governance_not_authority_admission
15
+ - explicit_TypeScript_5_9_3_root_direct_bounded_code_context
16
+ - transient_exact_code_authority_marker_lookup_and_lifecycle_audit_for_tracked_current_TypeScript_TSX_and_Go_source
16
17
  canonical_boundary:
17
18
  host_product_authority: .nimi/spec/**/*.authority.{yaml,md}
18
19
  sole_conformance_gate: nimicoding_authority_check_complete_.nimi/spec
@@ -31,6 +32,8 @@ out_of_scope:
31
32
  - host_workflow_command_aggregation
32
33
  - external_probe_result_attestation_test_execution_or_proof_packet_aggregation
33
34
  - sqlite_cache_incremental_embedding_semantic_search_visualization_AI_execution_or_Atlas
35
+ - code_location_inbound_impact_structural_advice_other_semantic_languages_or_task_completeness
36
+ - annotation_coverage_ownership_conformance_inference_or_unannotated_legacy_detection
34
37
  claims:
35
38
  discovery: bounded_deterministic_exact_filtered_lexical_candidates_with_SourceMapped_field_snippets_and_optional_M1_direct_authored_relation_preview_not_semantic_search_selection_context_or_absence_proof
36
39
  change_candidates: complete_union_of_caller_requested_exact_channels_with_raw_fields_modality_and_reasons_not_semantic_relevance_conflict_retirement_absence_or_conformance
@@ -39,3 +42,5 @@ claims:
39
42
  graph: complete_bounded_explicit_relation_navigation_not_semantic_inference_or_raw_IR
40
43
  audit: configured_graph_and_exact_case_sensitive_lexical_results_not_prose_predicate_inference_semantic_synonym_or_plugin_execution
41
44
  review: immutable_base_OID_and_stable_worktree_exact_snapshots_composed_through_existing_compiler_diff_impact_and_current_audit_oracles_with_business_and_implementation_status_not_evaluated
45
+ code_context: complete_selected_TypeScript_Program_root_direct_static_outbound_projection_with_output_budget_and_explicit_frontier_not_location_impact_runtime_dispatch_or_task_context
46
+ code_authority: complete_transient_scan_of_selected_tracked_current_source_scope_for_exact_authored_markers_and_current_canonical_lifecycle_not_attachment_ownership_conformance_or_unannotated_semantics