@nimiplatform/nimi-coding 0.1.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 (186) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +348 -0
  3. package/adapters/README.md +25 -0
  4. package/adapters/claude/README.md +89 -0
  5. package/adapters/claude/profile.yaml +70 -0
  6. package/adapters/codex/README.md +53 -0
  7. package/adapters/codex/profile.yaml +78 -0
  8. package/adapters/oh-my-codex/README.md +185 -0
  9. package/adapters/oh-my-codex/profile.yaml +46 -0
  10. package/bin/nimicoding.mjs +6 -0
  11. package/cli/commands/admit-high-risk-decision.mjs +108 -0
  12. package/cli/commands/audit-sweep.mjs +341 -0
  13. package/cli/commands/blueprint-audit.mjs +91 -0
  14. package/cli/commands/clear.mjs +168 -0
  15. package/cli/commands/closeout.mjs +183 -0
  16. package/cli/commands/decide-high-risk-execution.mjs +124 -0
  17. package/cli/commands/doctor.mjs +53 -0
  18. package/cli/commands/generate-spec-derived-docs.mjs +131 -0
  19. package/cli/commands/handoff.mjs +123 -0
  20. package/cli/commands/ingest-high-risk-execution.mjs +95 -0
  21. package/cli/commands/review-high-risk-execution.mjs +95 -0
  22. package/cli/commands/start.mjs +717 -0
  23. package/cli/commands/topic-formatters.mjs +382 -0
  24. package/cli/commands/topic-goal.mjs +33 -0
  25. package/cli/commands/topic-options-shared.mjs +27 -0
  26. package/cli/commands/topic-options-workflow.mjs +767 -0
  27. package/cli/commands/topic-options.mjs +626 -0
  28. package/cli/commands/topic-runner.mjs +169 -0
  29. package/cli/commands/topic.mjs +795 -0
  30. package/cli/commands/validate-acceptance.mjs +5 -0
  31. package/cli/commands/validate-ai-governance.mjs +214 -0
  32. package/cli/commands/validate-execution-packet.mjs +5 -0
  33. package/cli/commands/validate-orchestration-state.mjs +5 -0
  34. package/cli/commands/validate-prompt.mjs +5 -0
  35. package/cli/commands/validate-spec-audit.mjs +27 -0
  36. package/cli/commands/validate-spec-governance.mjs +124 -0
  37. package/cli/commands/validate-spec-tree.mjs +27 -0
  38. package/cli/commands/validate-worker-output.mjs +5 -0
  39. package/cli/constants.mjs +489 -0
  40. package/cli/help.mjs +134 -0
  41. package/cli/index.mjs +103 -0
  42. package/cli/lib/adapter-profiles.mjs +403 -0
  43. package/cli/lib/audit-execution.mjs +52 -0
  44. package/cli/lib/audit-sweep-runtime/admissions.mjs +381 -0
  45. package/cli/lib/audit-sweep-runtime/audit-validity.mjs +333 -0
  46. package/cli/lib/audit-sweep-runtime/chunks.mjs +697 -0
  47. package/cli/lib/audit-sweep-runtime/closeout.mjs +144 -0
  48. package/cli/lib/audit-sweep-runtime/codex-auditor-evidence.mjs +639 -0
  49. package/cli/lib/audit-sweep-runtime/codex-auditor.mjs +515 -0
  50. package/cli/lib/audit-sweep-runtime/common.mjs +329 -0
  51. package/cli/lib/audit-sweep-runtime/coverage-quality.mjs +172 -0
  52. package/cli/lib/audit-sweep-runtime/evidence-assignment.mjs +152 -0
  53. package/cli/lib/audit-sweep-runtime/format.mjs +57 -0
  54. package/cli/lib/audit-sweep-runtime/ingest.mjs +486 -0
  55. package/cli/lib/audit-sweep-runtime/inventory-spec-chunks.mjs +198 -0
  56. package/cli/lib/audit-sweep-runtime/inventory.mjs +728 -0
  57. package/cli/lib/audit-sweep-runtime/ledger.mjs +315 -0
  58. package/cli/lib/audit-sweep-runtime/p0p1-profile.mjs +101 -0
  59. package/cli/lib/audit-sweep-runtime/remediation.mjs +349 -0
  60. package/cli/lib/audit-sweep-runtime/rerun.mjs +129 -0
  61. package/cli/lib/audit-sweep-runtime/risk-budget.mjs +300 -0
  62. package/cli/lib/audit-sweep-runtime/status.mjs +62 -0
  63. package/cli/lib/audit-sweep-runtime/validators-ledger.mjs +215 -0
  64. package/cli/lib/audit-sweep-runtime/validators.mjs +758 -0
  65. package/cli/lib/audit-sweep.mjs +18 -0
  66. package/cli/lib/authority-convergence.mjs +309 -0
  67. package/cli/lib/blueprint-audit.mjs +370 -0
  68. package/cli/lib/bootstrap.mjs +228 -0
  69. package/cli/lib/closeout.mjs +623 -0
  70. package/cli/lib/codex-sdk-runner.mjs +76 -0
  71. package/cli/lib/contracts.mjs +180 -0
  72. package/cli/lib/doctor.mjs +18 -0
  73. package/cli/lib/entrypoints.mjs +274 -0
  74. package/cli/lib/external-execution.mjs +101 -0
  75. package/cli/lib/fs-helpers.mjs +33 -0
  76. package/cli/lib/handoff.mjs +785 -0
  77. package/cli/lib/high-risk-admission.mjs +442 -0
  78. package/cli/lib/high-risk-decision.mjs +324 -0
  79. package/cli/lib/high-risk-ingest.mjs +317 -0
  80. package/cli/lib/high-risk-review.mjs +263 -0
  81. package/cli/lib/internal/contracts-loaders.mjs +132 -0
  82. package/cli/lib/internal/contracts-parse-high-risk.mjs +131 -0
  83. package/cli/lib/internal/contracts-parse.mjs +457 -0
  84. package/cli/lib/internal/contracts-validators.mjs +398 -0
  85. package/cli/lib/internal/doctor-bootstrap-surface.mjs +359 -0
  86. package/cli/lib/internal/doctor-delegated-surface.mjs +256 -0
  87. package/cli/lib/internal/doctor-finalize.mjs +385 -0
  88. package/cli/lib/internal/doctor-format.mjs +286 -0
  89. package/cli/lib/internal/doctor-inspectors.mjs +294 -0
  90. package/cli/lib/internal/doctor-state.mjs +205 -0
  91. package/cli/lib/internal/governance/ai/ai-context-budget-core.mjs +315 -0
  92. package/cli/lib/internal/governance/ai/ai-structure-budget-core.mjs +358 -0
  93. package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +155 -0
  94. package/cli/lib/internal/governance/ai/check-high-risk-doc-metadata-core.mjs +173 -0
  95. package/cli/lib/internal/governance/config.mjs +150 -0
  96. package/cli/lib/internal/governance/runner.mjs +35 -0
  97. package/cli/lib/internal/governance/shared/read-yaml-with-fragments.mjs +49 -0
  98. package/cli/lib/internal/validators-artifacts.mjs +515 -0
  99. package/cli/lib/internal/validators-shared.mjs +28 -0
  100. package/cli/lib/internal/validators-spec-helpers.mjs +186 -0
  101. package/cli/lib/internal/validators-spec.mjs +410 -0
  102. package/cli/lib/shared.mjs +83 -0
  103. package/cli/lib/topic-draft-packets.mjs +48 -0
  104. package/cli/lib/topic-goal.mjs +361 -0
  105. package/cli/lib/topic-runner.mjs +772 -0
  106. package/cli/lib/topic.mjs +93 -0
  107. package/cli/lib/ui.mjs +178 -0
  108. package/cli/lib/validators.mjs +78 -0
  109. package/cli/lib/value-helpers.mjs +24 -0
  110. package/cli/lib/yaml-helpers.mjs +133 -0
  111. package/cli/nimicoding.mjs +1 -0
  112. package/cli/seeds/bootstrap.mjs +47 -0
  113. package/config/audit-execution-artifacts.yaml +20 -0
  114. package/config/bootstrap.yaml +6 -0
  115. package/config/external-execution-artifacts.yaml +16 -0
  116. package/config/host-adapter.yaml +30 -0
  117. package/config/host-profile.yaml +29 -0
  118. package/config/installer-evidence.yaml +31 -0
  119. package/config/skill-installer.yaml +23 -0
  120. package/config/skill-manifest.yaml +46 -0
  121. package/config/skills.yaml +30 -0
  122. package/config/spec-generation-inputs.yaml +25 -0
  123. package/contracts/acceptance.schema.yaml +16 -0
  124. package/contracts/admission-checklist.schema.yaml +15 -0
  125. package/contracts/audit-chunk.schema.yaml +110 -0
  126. package/contracts/audit-closeout.schema.yaml +51 -0
  127. package/contracts/audit-finding.schema.yaml +61 -0
  128. package/contracts/audit-ledger.schema.yaml +138 -0
  129. package/contracts/audit-plan.schema.yaml +123 -0
  130. package/contracts/audit-remediation-map.schema.yaml +51 -0
  131. package/contracts/audit-rerun.schema.yaml +31 -0
  132. package/contracts/audit-sweep-result.yaml +49 -0
  133. package/contracts/authority-convergence-audit.schema.yaml +19 -0
  134. package/contracts/closeout.schema.yaml +25 -0
  135. package/contracts/decision-review.schema.yaml +16 -0
  136. package/contracts/doc-spec-audit-result.yaml +19 -0
  137. package/contracts/execution-packet.schema.yaml +49 -0
  138. package/contracts/external-host-compatibility.yaml +22 -0
  139. package/contracts/forbidden-shortcuts.catalog.yaml +23 -0
  140. package/contracts/high-risk-admission.schema.yaml +23 -0
  141. package/contracts/high-risk-execution-result.yaml +20 -0
  142. package/contracts/orchestration-state.schema.yaml +41 -0
  143. package/contracts/overflow-continuation.schema.yaml +12 -0
  144. package/contracts/packet.schema.yaml +30 -0
  145. package/contracts/pending-note.schema.yaml +17 -0
  146. package/contracts/prompt.schema.yaml +12 -0
  147. package/contracts/remediation.schema.yaml +16 -0
  148. package/contracts/result.schema.yaml +24 -0
  149. package/contracts/spec-generation-audit.schema.yaml +31 -0
  150. package/contracts/spec-generation-inputs.schema.yaml +39 -0
  151. package/contracts/spec-reconstruction-result.yaml +37 -0
  152. package/contracts/topic-goal.schema.yaml +78 -0
  153. package/contracts/topic-run-ledger.schema.yaml +72 -0
  154. package/contracts/topic-step-decision.schema.yaml +45 -0
  155. package/contracts/topic.schema.yaml +65 -0
  156. package/contracts/true-close.schema.yaml +15 -0
  157. package/contracts/wave.schema.yaml +29 -0
  158. package/contracts/worker-output.schema.yaml +15 -0
  159. package/methodology/audit-sweep-p0p1-recall.yaml +45 -0
  160. package/methodology/authority-convergence-policy.yaml +42 -0
  161. package/methodology/core.yaml +25 -0
  162. package/methodology/four-closure-policy.yaml +28 -0
  163. package/methodology/overflow-continuation-policy.yaml +14 -0
  164. package/methodology/role-separation-policy.yaml +28 -0
  165. package/methodology/skill-exchange-projection.yaml +114 -0
  166. package/methodology/skill-handoff.yaml +34 -0
  167. package/methodology/skill-installer-result.yaml +27 -0
  168. package/methodology/skill-installer-summary-projection.yaml +181 -0
  169. package/methodology/skill-runtime.yaml +23 -0
  170. package/methodology/spec-reconstruction.yaml +63 -0
  171. package/methodology/spec-target-truth-profile.yaml +53 -0
  172. package/methodology/topic-lifecycle-report.yaml +144 -0
  173. package/methodology/topic-lifecycle.yaml +37 -0
  174. package/methodology/topic-naming-ontology.yaml +21 -0
  175. package/methodology/topic-ontology.yaml +38 -0
  176. package/methodology/topic-validation-policy.yaml +9 -0
  177. package/methodology/wave-dag-policy.yaml +14 -0
  178. package/package.json +50 -0
  179. package/spec/_meta/command-gating-matrix.yaml +110 -0
  180. package/spec/_meta/generate-drift-migration-checklist.yaml +155 -0
  181. package/spec/_meta/governance-routing-cutover-checklist.yaml +35 -0
  182. package/spec/_meta/phase2-impacted-surface-matrix.yaml +44 -0
  183. package/spec/_meta/spec-authority-cutover-readiness.yaml +104 -0
  184. package/spec/_meta/spec-tree-model.yaml +72 -0
  185. package/spec/bootstrap-state.yaml +99 -0
  186. package/spec/product-scope.yaml +56 -0
@@ -0,0 +1,183 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ import {
5
+ buildCloseoutPayload,
6
+ formatCloseoutPayload,
7
+ loadImportedCloseoutOptions,
8
+ } from "../lib/shared.mjs";
9
+ import { localize } from "../lib/ui.mjs";
10
+
11
+ function parseCloseoutOptions(args) {
12
+ const options = {
13
+ json: false,
14
+ writeLocal: false,
15
+ fromPath: null,
16
+ skill: null,
17
+ outcome: null,
18
+ verifiedAt: null,
19
+ };
20
+
21
+ for (let index = 0; index < args.length; index += 1) {
22
+ const arg = args[index];
23
+
24
+ if (arg === "--json") {
25
+ options.json = true;
26
+ continue;
27
+ }
28
+
29
+ if (arg === "--write-local") {
30
+ options.writeLocal = true;
31
+ continue;
32
+ }
33
+
34
+ if (arg === "--skill" || arg === "--outcome" || arg === "--verified-at" || arg === "--from") {
35
+ const next = args[index + 1];
36
+ if (!next || next.startsWith("--")) {
37
+ return {
38
+ ok: false,
39
+ error: `${localize(
40
+ `nimicoding closeout refused: ${arg} requires a value.`,
41
+ `nimicoding closeout 已拒绝:${arg} 需要一个值。`,
42
+ )}\n`,
43
+ };
44
+ }
45
+
46
+ if (arg === "--skill") {
47
+ options.skill = next;
48
+ } else if (arg === "--outcome") {
49
+ options.outcome = next;
50
+ } else if (arg === "--from") {
51
+ options.fromPath = next;
52
+ } else {
53
+ options.verifiedAt = next;
54
+ }
55
+ index += 1;
56
+ continue;
57
+ }
58
+
59
+ return {
60
+ ok: false,
61
+ error: `${localize(
62
+ `nimicoding closeout refused: unknown option ${arg}.`,
63
+ `nimicoding closeout 已拒绝:未知选项 ${arg}。`,
64
+ )}\n`,
65
+ };
66
+ }
67
+
68
+ if (options.fromPath && (options.skill || options.outcome || options.verifiedAt)) {
69
+ return {
70
+ ok: false,
71
+ error: `${localize(
72
+ "nimicoding closeout refused: --from cannot be combined with --skill, --outcome, or --verified-at.",
73
+ "nimicoding closeout 已拒绝:`--from` 不能与 `--skill`、`--outcome` 或 `--verified-at` 同时使用。",
74
+ )}\n`,
75
+ };
76
+ }
77
+
78
+ if (options.fromPath) {
79
+ return {
80
+ ok: true,
81
+ options,
82
+ };
83
+ }
84
+
85
+ if (!options.skill) {
86
+ return {
87
+ ok: false,
88
+ error: `${localize(
89
+ "nimicoding closeout refused: explicit --skill is required.",
90
+ "nimicoding closeout 已拒绝:必须显式提供 `--skill`。",
91
+ )}\n`,
92
+ };
93
+ }
94
+
95
+ if (!options.outcome) {
96
+ return {
97
+ ok: false,
98
+ error: `${localize(
99
+ "nimicoding closeout refused: explicit --outcome is required.",
100
+ "nimicoding closeout 已拒绝:必须显式提供 `--outcome`。",
101
+ )}\n`,
102
+ };
103
+ }
104
+
105
+ if (!["completed", "blocked", "failed"].includes(options.outcome)) {
106
+ return {
107
+ ok: false,
108
+ error: `${localize(
109
+ `nimicoding closeout refused: unsupported outcome ${options.outcome}.`,
110
+ `nimicoding closeout 已拒绝:不支持的 outcome ${options.outcome}。`,
111
+ )}\n`,
112
+ };
113
+ }
114
+
115
+ if (!options.verifiedAt) {
116
+ return {
117
+ ok: false,
118
+ error: `${localize(
119
+ "nimicoding closeout refused: explicit --verified-at is required.",
120
+ "nimicoding closeout 已拒绝:必须显式提供 `--verified-at`。",
121
+ )}\n`,
122
+ };
123
+ }
124
+
125
+ const verifiedDate = new Date(options.verifiedAt);
126
+ if (Number.isNaN(verifiedDate.getTime()) || verifiedDate.toISOString() !== options.verifiedAt) {
127
+ return {
128
+ ok: false,
129
+ error: `${localize(
130
+ "nimicoding closeout refused: --verified-at must be an ISO-8601 UTC timestamp.",
131
+ "nimicoding closeout 已拒绝:`--verified-at` 必须是 ISO-8601 UTC 时间戳。",
132
+ )}\n`,
133
+ };
134
+ }
135
+
136
+ return {
137
+ ok: true,
138
+ options,
139
+ };
140
+ }
141
+
142
+ export async function runCloseout(args) {
143
+ const parsed = parseCloseoutOptions(args);
144
+ if (!parsed.ok) {
145
+ process.stderr.write(parsed.error);
146
+ return 2;
147
+ }
148
+
149
+ let effectiveOptions = parsed.options;
150
+ if (parsed.options.fromPath) {
151
+ const imported = await loadImportedCloseoutOptions(process.cwd(), parsed.options.fromPath);
152
+ if (!imported.ok) {
153
+ process.stderr.write(imported.error);
154
+ return 2;
155
+ }
156
+
157
+ effectiveOptions = {
158
+ ...parsed.options,
159
+ ...imported.options,
160
+ };
161
+ }
162
+
163
+ const payload = await buildCloseoutPayload(process.cwd(), effectiveOptions);
164
+ if (payload.inputError) {
165
+ process.stderr.write(payload.error);
166
+ return payload.exitCode;
167
+ }
168
+
169
+ if (payload.ok && parsed.options.writeLocal) {
170
+ await mkdir(path.dirname(payload.artifactPath), { recursive: true });
171
+ await writeFile(payload.artifactPath, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
172
+ }
173
+
174
+ if (parsed.options.json) {
175
+ process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
176
+ } else {
177
+ process.stdout.write(formatCloseoutPayload(payload));
178
+ }
179
+
180
+ return payload.exitCode;
181
+ }
182
+
183
+ export { parseCloseoutOptions };
@@ -0,0 +1,124 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ import {
5
+ buildHighRiskDecisionPayload,
6
+ formatHighRiskDecisionPayload,
7
+ } from "../lib/high-risk-decision.mjs";
8
+ import { localize } from "../lib/ui.mjs";
9
+
10
+ function parseDecideHighRiskExecutionOptions(args) {
11
+ const options = {
12
+ fromPath: null,
13
+ acceptancePath: null,
14
+ verifiedAt: null,
15
+ json: false,
16
+ writeLocal: false,
17
+ };
18
+
19
+ for (let index = 0; index < args.length; index += 1) {
20
+ const arg = args[index];
21
+
22
+ if (arg === "--json") {
23
+ options.json = true;
24
+ continue;
25
+ }
26
+
27
+ if (arg === "--write-local") {
28
+ options.writeLocal = true;
29
+ continue;
30
+ }
31
+
32
+ if (arg === "--from" || arg === "--acceptance" || arg === "--verified-at") {
33
+ const next = args[index + 1];
34
+ if (!next || next.startsWith("--")) {
35
+ return {
36
+ ok: false,
37
+ error: `${localize(
38
+ `nimicoding decide-high-risk-execution refused: ${arg} requires a value.`,
39
+ `nimicoding decide-high-risk-execution 已拒绝:${arg} 需要一个值。`,
40
+ )}\n`,
41
+ };
42
+ }
43
+
44
+ if (arg === "--from") {
45
+ options.fromPath = next;
46
+ } else if (arg === "--acceptance") {
47
+ options.acceptancePath = next;
48
+ } else {
49
+ options.verifiedAt = next;
50
+ }
51
+ index += 1;
52
+ continue;
53
+ }
54
+
55
+ return {
56
+ ok: false,
57
+ error: `${localize(
58
+ `nimicoding decide-high-risk-execution refused: unknown option ${arg}.`,
59
+ `nimicoding decide-high-risk-execution 已拒绝:未知选项 ${arg}。`,
60
+ )}\n`,
61
+ };
62
+ }
63
+
64
+ if (!options.fromPath) {
65
+ return {
66
+ ok: false,
67
+ error: `${localize(
68
+ "nimicoding decide-high-risk-execution refused: explicit --from is required.",
69
+ "nimicoding decide-high-risk-execution 已拒绝:必须显式提供 `--from`。",
70
+ )}\n`,
71
+ };
72
+ }
73
+
74
+ if (!options.acceptancePath) {
75
+ return {
76
+ ok: false,
77
+ error: `${localize(
78
+ "nimicoding decide-high-risk-execution refused: explicit --acceptance is required.",
79
+ "nimicoding decide-high-risk-execution 已拒绝:必须显式提供 `--acceptance`。",
80
+ )}\n`,
81
+ };
82
+ }
83
+
84
+ if (!options.verifiedAt) {
85
+ return {
86
+ ok: false,
87
+ error: `${localize(
88
+ "nimicoding decide-high-risk-execution refused: explicit --verified-at is required.",
89
+ "nimicoding decide-high-risk-execution 已拒绝:必须显式提供 `--verified-at`。",
90
+ )}\n`,
91
+ };
92
+ }
93
+
94
+ return { ok: true, options };
95
+ }
96
+
97
+ export async function runDecideHighRiskExecution(args) {
98
+ const parsed = parseDecideHighRiskExecutionOptions(args);
99
+ if (!parsed.ok) {
100
+ process.stderr.write(parsed.error);
101
+ return 2;
102
+ }
103
+
104
+ const payload = await buildHighRiskDecisionPayload(process.cwd(), parsed.options);
105
+ if (payload.inputError) {
106
+ process.stderr.write(payload.error);
107
+ return payload.exitCode;
108
+ }
109
+
110
+ if (parsed.options.writeLocal && payload.ok) {
111
+ await mkdir(path.dirname(payload.artifactPath), { recursive: true });
112
+ await writeFile(payload.artifactPath, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
113
+ }
114
+
115
+ if (parsed.options.json) {
116
+ process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
117
+ } else {
118
+ process.stdout.write(formatHighRiskDecisionPayload(payload));
119
+ }
120
+
121
+ return payload.exitCode;
122
+ }
123
+
124
+ export { parseDecideHighRiskExecutionOptions };
@@ -0,0 +1,53 @@
1
+ import { formatDoctorResult, inspectDoctorState } from "../lib/shared.mjs";
2
+ import { localize } from "../lib/ui.mjs";
3
+
4
+ function parseDoctorOptions(args) {
5
+ const options = {
6
+ json: false,
7
+ verbose: false,
8
+ };
9
+
10
+ for (const arg of args) {
11
+ if (arg === "--json") {
12
+ options.json = true;
13
+ continue;
14
+ }
15
+
16
+ if (arg === "--verbose") {
17
+ options.verbose = true;
18
+ continue;
19
+ }
20
+
21
+ return {
22
+ ok: false,
23
+ error: `${localize(
24
+ `nimicoding doctor refused: unknown option ${arg}.`,
25
+ `nimicoding doctor 已拒绝:未知选项 ${arg}。`,
26
+ )}\n`,
27
+ };
28
+ }
29
+
30
+ return {
31
+ ok: true,
32
+ options,
33
+ };
34
+ }
35
+
36
+ export async function runDoctor(args) {
37
+ const parsed = parseDoctorOptions(args);
38
+ if (!parsed.ok) {
39
+ process.stderr.write(parsed.error);
40
+ return 2;
41
+ }
42
+
43
+ const result = await inspectDoctorState(process.cwd());
44
+ if (parsed.options.json) {
45
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
46
+ } else {
47
+ process.stdout.write(formatDoctorResult(result, { verbose: parsed.options.verbose }));
48
+ }
49
+
50
+ return result.ok ? 0 : 1;
51
+ }
52
+
53
+ export { parseDoctorOptions };
@@ -0,0 +1,131 @@
1
+ import { localize } from "../lib/ui.mjs";
2
+ import { loadGovernanceConfig, requireProfile } from "../lib/internal/governance/config.mjs";
3
+ import { runCommand } from "../lib/internal/governance/runner.mjs";
4
+
5
+ function parseOptions(args) {
6
+ const options = {
7
+ profile: null,
8
+ scope: "all",
9
+ check: false,
10
+ };
11
+
12
+ for (let index = 0; index < args.length; index += 1) {
13
+ const arg = args[index];
14
+
15
+ if (arg === "--profile") {
16
+ const value = args[index + 1];
17
+ if (!value || value.startsWith("--")) {
18
+ return { ok: false, error: "nimicoding generate-spec-derived-docs refused: --profile requires a value.\n" };
19
+ }
20
+ options.profile = value;
21
+ index += 1;
22
+ continue;
23
+ }
24
+
25
+ if (arg === "--scope") {
26
+ const value = args[index + 1];
27
+ if (!value || value.startsWith("--")) {
28
+ return { ok: false, error: "nimicoding generate-spec-derived-docs refused: --scope requires a value.\n" };
29
+ }
30
+ options.scope = value;
31
+ index += 1;
32
+ continue;
33
+ }
34
+
35
+ if (arg === "--check") {
36
+ options.check = true;
37
+ continue;
38
+ }
39
+
40
+ return {
41
+ ok: false,
42
+ error: `nimicoding generate-spec-derived-docs refused: unknown option ${arg}.\n`,
43
+ };
44
+ }
45
+
46
+ return { ok: true, options };
47
+ }
48
+
49
+ function resolveScopes(scope, governanceConfig) {
50
+ const configuredScopes = Object.keys(governanceConfig.specGovernance.generateCommands || {});
51
+ if (scope === "all") {
52
+ return {
53
+ ok: true,
54
+ scopes: configuredScopes,
55
+ error: null,
56
+ };
57
+ }
58
+ if (!configuredScopes.includes(scope)) {
59
+ return {
60
+ ok: false,
61
+ scopes: [],
62
+ error: `nimicoding generate-spec-derived-docs refused: unsupported --scope value ${scope}.\n`,
63
+ };
64
+ }
65
+ return {
66
+ ok: true,
67
+ scopes: [scope],
68
+ error: null,
69
+ };
70
+ }
71
+
72
+ export async function runGenerateSpecDerivedDocs(args) {
73
+ const parsed = parseOptions(args);
74
+ if (!parsed.ok) {
75
+ process.stderr.write(localize(parsed.error, parsed.error));
76
+ return 2;
77
+ }
78
+
79
+ const governance = await loadGovernanceConfig(process.cwd());
80
+ if (!governance.ok) {
81
+ process.stderr.write(localize(
82
+ `nimicoding generate-spec-derived-docs refused: ${governance.reason} at ${governance.path}.\n`,
83
+ `nimicoding generate-spec-derived-docs 已拒绝:${governance.path} 的治理配置不可用。\n`,
84
+ ));
85
+ return 2;
86
+ }
87
+
88
+ const profileCheck = requireProfile(governance.config, parsed.options.profile);
89
+ if (!profileCheck.ok) {
90
+ process.stderr.write(localize(
91
+ `nimicoding generate-spec-derived-docs refused: ${profileCheck.error}.\n`,
92
+ `nimicoding generate-spec-derived-docs 已拒绝:${profileCheck.error}。\n`,
93
+ ));
94
+ return 2;
95
+ }
96
+
97
+ const scopeResolution = resolveScopes(parsed.options.scope, governance.config);
98
+ if (!scopeResolution.ok) {
99
+ process.stderr.write(localize(scopeResolution.error, scopeResolution.error));
100
+ return 2;
101
+ }
102
+
103
+ let failed = false;
104
+ for (const scope of scopeResolution.scopes) {
105
+ const commands = governance.config.specGovernance.generateCommands[scope] || [];
106
+ if (commands.length === 0) {
107
+ process.stderr.write(localize(
108
+ `nimicoding generate-spec-derived-docs refused: scope ${scope} is not configured in .nimi/config/governance.yaml.\n`,
109
+ `nimicoding generate-spec-derived-docs 已拒绝:.nimi/config/governance.yaml 未配置 ${scope}。\n`,
110
+ ));
111
+ return 2;
112
+ }
113
+
114
+ for (const command of commands) {
115
+ const commandToRun = parsed.options.check ? `${command} --check` : command;
116
+ const result = runCommand(commandToRun, { cwd: process.cwd() });
117
+ if (result.stdout) process.stdout.write(result.stdout);
118
+ if (result.stderr) process.stderr.write(result.stderr);
119
+ if (!result.ok) {
120
+ failed = true;
121
+ break;
122
+ }
123
+ }
124
+
125
+ if (failed) {
126
+ break;
127
+ }
128
+ }
129
+
130
+ return failed ? 1 : 0;
131
+ }
@@ -0,0 +1,123 @@
1
+ import {
2
+ buildHandoffPayload,
3
+ formatHandoffPayload,
4
+ writeHandoffPromptArtifacts,
5
+ } from "../lib/shared.mjs";
6
+ import {
7
+ localize,
8
+ styleCommand,
9
+ styleHeading,
10
+ styleLabel,
11
+ } from "../lib/ui.mjs";
12
+
13
+ function parseHandoffOptions(args) {
14
+ const options = {
15
+ json: false,
16
+ prompt: false,
17
+ skill: null,
18
+ };
19
+
20
+ for (let index = 0; index < args.length; index += 1) {
21
+ const arg = args[index];
22
+
23
+ if (arg === "--json") {
24
+ options.json = true;
25
+ continue;
26
+ }
27
+
28
+ if (arg === "--prompt") {
29
+ options.prompt = true;
30
+ continue;
31
+ }
32
+
33
+ if (arg === "--skill") {
34
+ const next = args[index + 1];
35
+ if (!next || next.startsWith("--")) {
36
+ return {
37
+ ok: false,
38
+ error: localize(
39
+ "nimicoding handoff refused: --skill requires a skill id.\n",
40
+ "nimicoding handoff 拒绝执行:--skill 需要一个 skill id。\n",
41
+ ),
42
+ };
43
+ }
44
+ options.skill = next;
45
+ index += 1;
46
+ continue;
47
+ }
48
+
49
+ return {
50
+ ok: false,
51
+ error: localize(
52
+ `nimicoding handoff refused: unknown option ${arg}.\n`,
53
+ `nimicoding handoff 拒绝执行:未知选项 ${arg}。\n`,
54
+ ),
55
+ };
56
+ }
57
+
58
+ if (!options.skill) {
59
+ return {
60
+ ok: false,
61
+ error: localize(
62
+ "nimicoding handoff refused: explicit --skill is required.\n",
63
+ "nimicoding handoff 拒绝执行:必须显式提供 --skill。\n",
64
+ ),
65
+ };
66
+ }
67
+
68
+ if (options.json && options.prompt) {
69
+ return {
70
+ ok: false,
71
+ error: localize(
72
+ "nimicoding handoff refused: --json and --prompt are mutually exclusive.\n",
73
+ "nimicoding handoff 拒绝执行:--json 与 --prompt 不能同时使用。\n",
74
+ ),
75
+ };
76
+ }
77
+
78
+ return {
79
+ ok: true,
80
+ options,
81
+ };
82
+ }
83
+
84
+ export async function runHandoff(args) {
85
+ const parsed = parseHandoffOptions(args);
86
+ if (!parsed.ok) {
87
+ process.stderr.write(parsed.error);
88
+ return 2;
89
+ }
90
+
91
+ const payload = await buildHandoffPayload(process.cwd(), parsed.options.skill);
92
+ if (parsed.options.json) {
93
+ process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
94
+ } else if (parsed.options.prompt) {
95
+ if (!payload.ok) {
96
+ process.stderr.write(`${localize(payload.nextAction, payload.nextAction
97
+ .replace("Bootstrap or handoff validation is failing; repair doctor errors before exporting handoff payloads", "bootstrap 或 handoff 校验失败;请先修复 doctor 报错,再导出 handoff payload")
98
+ .replace("Projects may delegate spec reconstruction to an external AI host when lifecycle repair or reconstruction work is needed", "当需要 lifecycle repair 或 reconstruction 工作时,项目可以将 spec reconstruction 委托给外部 AI host")
99
+ .replace("This skill requires the canonical tree under `.nimi/spec` before handoff", "该 skill 在 handoff 前需要 `.nimi/spec` 下的 canonical tree")
100
+ .replace("Skill prerequisites are satisfied by the current project-local truth", "当前项目本地 truth 已满足该 skill 的前置条件"))}\n`);
101
+ return payload.exitCode;
102
+ }
103
+
104
+ const refs = await writeHandoffPromptArtifacts(process.cwd(), payload);
105
+ process.stdout.write(`${styleHeading(localize(`Prepared local handoff refs for ${payload.skill.id}`, `已为 ${payload.skill.id} 准备本地 handoff ref`))}
106
+
107
+ ${styleLabel(localize("Created:", "已创建:"))}
108
+ - ${refs.jsonRef}
109
+ - ${refs.promptRef}
110
+
111
+ ${styleLabel(localize("Use:", "使用方式:"))}
112
+ - ${localize(`Treat ${refs.jsonRef} as the authoritative machine contract`, `将 ${refs.jsonRef} 作为权威机器契约`)}
113
+ - ${localize(`Paste the contents of ${refs.promptRef} into the external AI host when needed`, `需要时将 ${refs.promptRef} 的内容粘贴给外部 AI host`)}
114
+ - ${localize("Optional command preview:", "可选命令预览:")} ${styleCommand(`nimicoding handoff --skill ${payload.skill.id} --json`)}
115
+ `);
116
+ } else {
117
+ process.stdout.write(formatHandoffPayload(payload));
118
+ }
119
+
120
+ return payload.exitCode;
121
+ }
122
+
123
+ export { parseHandoffOptions };
@@ -0,0 +1,95 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ import {
5
+ buildHighRiskIngestPayload,
6
+ formatHighRiskIngestPayload,
7
+ } from "../lib/high-risk-ingest.mjs";
8
+ import { localize } from "../lib/ui.mjs";
9
+
10
+ function parseIngestHighRiskExecutionOptions(args) {
11
+ const options = {
12
+ fromPath: null,
13
+ json: false,
14
+ writeLocal: false,
15
+ };
16
+
17
+ for (let index = 0; index < args.length; index += 1) {
18
+ const arg = args[index];
19
+
20
+ if (arg === "--json") {
21
+ options.json = true;
22
+ continue;
23
+ }
24
+
25
+ if (arg === "--write-local") {
26
+ options.writeLocal = true;
27
+ continue;
28
+ }
29
+
30
+ if (arg === "--from") {
31
+ const next = args[index + 1];
32
+ if (!next || next.startsWith("--")) {
33
+ return {
34
+ ok: false,
35
+ error: `${localize(
36
+ "nimicoding ingest-high-risk-execution refused: --from requires a value.",
37
+ "nimicoding ingest-high-risk-execution 已拒绝:`--from` 需要一个值。",
38
+ )}\n`,
39
+ };
40
+ }
41
+ options.fromPath = next;
42
+ index += 1;
43
+ continue;
44
+ }
45
+
46
+ return {
47
+ ok: false,
48
+ error: `${localize(
49
+ `nimicoding ingest-high-risk-execution refused: unknown option ${arg}.`,
50
+ `nimicoding ingest-high-risk-execution 已拒绝:未知选项 ${arg}。`,
51
+ )}\n`,
52
+ };
53
+ }
54
+
55
+ if (!options.fromPath) {
56
+ return {
57
+ ok: false,
58
+ error: `${localize(
59
+ "nimicoding ingest-high-risk-execution refused: explicit --from is required.",
60
+ "nimicoding ingest-high-risk-execution 已拒绝:必须显式提供 `--from`。",
61
+ )}\n`,
62
+ };
63
+ }
64
+
65
+ return { ok: true, options };
66
+ }
67
+
68
+ export async function runIngestHighRiskExecution(args) {
69
+ const parsed = parseIngestHighRiskExecutionOptions(args);
70
+ if (!parsed.ok) {
71
+ process.stderr.write(parsed.error);
72
+ return 2;
73
+ }
74
+
75
+ const payload = await buildHighRiskIngestPayload(process.cwd(), parsed.options.fromPath, parsed.options);
76
+ if (payload.inputError) {
77
+ process.stderr.write(payload.error);
78
+ return payload.exitCode;
79
+ }
80
+
81
+ if (parsed.options.writeLocal && payload.ok) {
82
+ await mkdir(path.dirname(payload.artifactPath), { recursive: true });
83
+ await writeFile(payload.artifactPath, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
84
+ }
85
+
86
+ if (parsed.options.json) {
87
+ process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
88
+ } else {
89
+ process.stdout.write(formatHighRiskIngestPayload(payload));
90
+ }
91
+
92
+ return payload.exitCode;
93
+ }
94
+
95
+ export { parseIngestHighRiskExecutionOptions };