@nimiplatform/nimi-coding 0.1.0 → 0.2.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.
- package/README.md +19 -20
- package/adapters/oh-my-codex/README.md +8 -9
- package/cli/commands/audit-sweep.mjs +10 -10
- package/cli/commands/classify-spec-tree.mjs +5 -0
- package/cli/commands/closeout.mjs +3 -0
- package/cli/commands/generate-spec-derived-docs.mjs +20 -0
- package/cli/commands/generate-spec-migration-plan.mjs +30 -0
- package/cli/commands/start.mjs +5 -1
- package/cli/commands/surface-validator-command.mjs +49 -0
- package/cli/commands/sweep-design.mjs +295 -0
- package/cli/commands/sweep.mjs +22 -0
- package/cli/commands/sync.mjs +132 -0
- package/cli/commands/topic-formatters.mjs +8 -8
- package/cli/commands/validate-ai-governance.mjs +167 -46
- package/cli/commands/validate-domain-admission.mjs +5 -0
- package/cli/commands/validate-guidance-bodies.mjs +5 -0
- package/cli/commands/validate-placement.mjs +5 -0
- package/cli/commands/validate-projection-edges.mjs +5 -0
- package/cli/commands/validate-spec-audit.mjs +5 -1
- package/cli/commands/validate-table-family.mjs +5 -0
- package/cli/commands/validate-tracked-output-admission.mjs +5 -0
- package/cli/constants.mjs +5 -49
- package/cli/help.mjs +33 -11
- package/cli/index.mjs +20 -2
- package/cli/lib/audit-sweep-runtime/admissions.mjs +38 -29
- package/cli/lib/audit-sweep-runtime/audit-validity.mjs +8 -0
- package/cli/lib/audit-sweep-runtime/chunks.mjs +11 -11
- package/cli/lib/audit-sweep-runtime/closeout.mjs +8 -8
- package/cli/lib/audit-sweep-runtime/codex-auditor-evidence.mjs +3 -3
- package/cli/lib/audit-sweep-runtime/codex-auditor.mjs +10 -10
- package/cli/lib/audit-sweep-runtime/common.mjs +7 -7
- package/cli/lib/audit-sweep-runtime/format.mjs +3 -3
- package/cli/lib/audit-sweep-runtime/ingest.mjs +8 -8
- package/cli/lib/audit-sweep-runtime/inventory-spec-chunks.mjs +24 -27
- package/cli/lib/audit-sweep-runtime/inventory.mjs +58 -18
- package/cli/lib/audit-sweep-runtime/ledger.mjs +1 -1
- package/cli/lib/audit-sweep-runtime/p0p1-profile.mjs +2 -2
- package/cli/lib/audit-sweep-runtime/remediation.mjs +6 -6
- package/cli/lib/audit-sweep-runtime/rerun.mjs +6 -6
- package/cli/lib/audit-sweep-runtime/status.mjs +1 -1
- package/cli/lib/audit-sweep-runtime/validators.mjs +2 -2
- package/cli/lib/authority-convergence.mjs +397 -2
- package/cli/lib/blueprint-audit.mjs +5 -5
- package/cli/lib/closeout.mjs +126 -3
- package/cli/lib/contracts.mjs +21 -17
- package/cli/lib/handoff.mjs +29 -11
- package/cli/lib/high-risk-admission.mjs +60 -11
- package/cli/lib/high-risk-decision.mjs +31 -2
- package/cli/lib/high-risk-ingest.mjs +5 -1
- package/cli/lib/high-risk-review.mjs +5 -1
- package/cli/lib/internal/contracts-parse.mjs +195 -24
- package/cli/lib/internal/contracts-validators.mjs +3 -2
- package/cli/lib/internal/doctor-bootstrap-surface.mjs +82 -35
- package/cli/lib/internal/doctor-delegated-surface.mjs +1 -1
- package/cli/lib/internal/doctor-finalize.mjs +12 -8
- package/cli/lib/internal/doctor-inspectors.mjs +34 -1
- package/cli/lib/internal/governance/ai/ai-context-budget-core.mjs +74 -12
- package/cli/lib/internal/governance/ai/ai-structure-budget-core.mjs +24 -6
- package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +18 -23
- package/cli/lib/internal/surface-taxonomy-validators.mjs +931 -0
- package/cli/lib/internal/validators-spec.mjs +229 -20
- package/cli/lib/sweep-design-runtime/common.mjs +246 -0
- package/cli/lib/sweep-design-runtime/engine.mjs +733 -0
- package/cli/lib/sweep-design-runtime/fix-topic.mjs +414 -0
- package/cli/lib/sweep-design-runtime/lifecycle.mjs +54 -0
- package/cli/lib/sweep-design-runtime/results.mjs +324 -0
- package/cli/lib/sweep-design.mjs +8 -0
- package/cli/lib/sync.mjs +143 -0
- package/cli/lib/topic-artifacts.mjs +186 -0
- package/cli/lib/topic-authority-coverage.mjs +73 -0
- package/cli/lib/topic-closeout.mjs +560 -0
- package/cli/lib/topic-common.mjs +404 -0
- package/cli/lib/topic-decisions.mjs +332 -0
- package/cli/lib/topic-draft-packets.mjs +126 -7
- package/cli/lib/topic-execution.mjs +515 -0
- package/cli/lib/topic-goal.mjs +112 -33
- package/cli/lib/topic-ledger.mjs +281 -0
- package/cli/lib/topic-lifecycle-artifacts.mjs +173 -0
- package/cli/lib/topic-root-validation.mjs +288 -0
- package/cli/lib/topic-runner-commands.mjs +174 -0
- package/cli/lib/topic-runner-deferral.mjs +532 -0
- package/cli/lib/topic-runner-stale-gates.mjs +114 -0
- package/cli/lib/topic-runner-validation.mjs +138 -0
- package/cli/lib/topic-runner.mjs +109 -154
- package/cli/lib/topic-scaffold.mjs +252 -0
- package/cli/lib/topic-waves.mjs +403 -0
- package/cli/lib/topic.mjs +81 -93
- package/cli/lib/value-helpers.mjs +6 -1
- package/cli/seeds/bootstrap.mjs +96 -20
- package/cli/seeds/seed-policy.yaml +67 -0
- package/config/bootstrap.yaml +1 -1
- package/config/skill-manifest.yaml +4 -2
- package/config/spec-generation-inputs.yaml +41 -19
- package/contracts/audit-remediation-map.schema.yaml +1 -0
- package/contracts/audit-sweep-result.yaml +4 -0
- package/contracts/domain-admission.schema.yaml +56 -0
- package/contracts/migration-inventory.schema.yaml +80 -0
- package/contracts/negative-fixtures.yaml +91 -0
- package/contracts/placement-contract.schema.yaml +163 -0
- package/contracts/projection-edge.schema.yaml +130 -0
- package/contracts/shared-enums.yaml +68 -0
- package/contracts/spec-generation-audit.schema.yaml +19 -4
- package/contracts/spec-generation-inputs.schema.yaml +130 -29
- package/contracts/spec-reconstruction-result.yaml +9 -5
- package/contracts/surface-taxonomy.schema.yaml +201 -0
- package/contracts/sweep-design-result.yaml +349 -0
- package/contracts/table-family.schema.yaml +114 -0
- package/contracts/topic-goal.schema.yaml +10 -1
- package/contracts/tracked-output-admission.schema.yaml +70 -0
- package/contracts/workflow-consumer.schema.yaml +112 -0
- package/methodology/audit-sweep-p0p1-recall.yaml +1 -1
- package/methodology/spec-reconstruction.yaml +53 -30
- package/package.json +5 -4
- package/spec/_meta/command-gating-matrix.yaml +33 -0
- package/spec/_meta/generate-drift-migration-checklist.yaml +44 -62
- package/spec/_meta/governance-routing-cutover-checklist.yaml +3 -3
- package/spec/_meta/phase2-impacted-surface-matrix.yaml +14 -14
- package/spec/_meta/spec-authority-cutover-readiness.yaml +3 -5
- package/spec/_meta/spec-tree-model.yaml +104 -36
- package/spec/bootstrap-state.yaml +36 -36
- package/spec/product-scope.yaml +13 -10
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { readdir } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
function getTopicWaves(topic) {
|
|
4
|
+
return Array.isArray(topic.waves) ? topic.waves.map((entry) => ({ ...entry })) : [];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function fileReferencesWave(fileName, waveId) {
|
|
8
|
+
return fileName.includes(waveId);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function buildObservedLineage(entry) {
|
|
12
|
+
if (entry.closeouts > 0) return "closed_lineage";
|
|
13
|
+
if (entry.results > 0) return "result_lineage";
|
|
14
|
+
if (entry.packets > 0) return "packet_lineage";
|
|
15
|
+
if (entry.remediations > 0 || entry.exec_packs > 0 || entry.decision_reviews > 0) {
|
|
16
|
+
return "auxiliary_lineage";
|
|
17
|
+
}
|
|
18
|
+
return "declared_only";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isRecognizedLifecycleArtifactName(fileName) {
|
|
22
|
+
if (!fileName.endsWith(".md")) return true;
|
|
23
|
+
if (fileName.startsWith("packet-")) {
|
|
24
|
+
return /^packet-wave-[a-z0-9]+(?:-[a-z0-9]+)*\.md$/.test(fileName)
|
|
25
|
+
|| /^packet-true-close(?:-[a-z0-9]+)*\.md$/.test(fileName);
|
|
26
|
+
}
|
|
27
|
+
if (fileName.startsWith("result-")) {
|
|
28
|
+
return /^result-wave-[a-z0-9]+(?:-[a-z0-9]+)*\.md$/.test(fileName)
|
|
29
|
+
|| /^result-topic-true-close(?:-[a-z0-9]+)*\.md$/.test(fileName)
|
|
30
|
+
|| /^result-true-close(?:-[a-z0-9]+)*\.md$/.test(fileName);
|
|
31
|
+
}
|
|
32
|
+
if (fileName.startsWith("closeout-")) {
|
|
33
|
+
return /^closeout-wave-[a-z0-9]+(?:-[a-z0-9]+)*\.md$/.test(fileName)
|
|
34
|
+
|| /^closeout-topic(?:-[a-z0-9]+)*\.md$/.test(fileName)
|
|
35
|
+
|| /^closeout-true-close(?:-[a-z0-9]+)*\.md$/.test(fileName);
|
|
36
|
+
}
|
|
37
|
+
if (fileName.startsWith("decision-review-")) {
|
|
38
|
+
return /^decision-review-[a-z0-9]+(?:-[a-z0-9]+)*\.md$/.test(fileName);
|
|
39
|
+
}
|
|
40
|
+
if (fileName.startsWith("prompt-")) {
|
|
41
|
+
return /^prompt-[a-z0-9-]+-(worker|audit)\.md$/.test(fileName);
|
|
42
|
+
}
|
|
43
|
+
if (fileName.startsWith("overflow-continuation-")) {
|
|
44
|
+
return /^overflow-continuation-wave-[a-z0-9]+(?:-[a-z0-9]+)*\.md$/.test(fileName);
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function resolveDeclaredWaveArtifactLineage(fileNames, topicWaveIds) {
|
|
50
|
+
const declared = Array.from(topicWaveIds);
|
|
51
|
+
const resolved = [];
|
|
52
|
+
const unresolved = [];
|
|
53
|
+
const ambiguous = [];
|
|
54
|
+
|
|
55
|
+
for (const fileName of fileNames) {
|
|
56
|
+
const matches = declared.filter((waveId) => fileReferencesWave(fileName, waveId));
|
|
57
|
+
if (matches.length === 1) {
|
|
58
|
+
resolved.push({ fileName, waveId: matches[0] });
|
|
59
|
+
} else if (matches.length === 0) {
|
|
60
|
+
unresolved.push(fileName);
|
|
61
|
+
} else {
|
|
62
|
+
ambiguous.push({ fileName, waveIds: matches });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return { resolved, unresolved, ambiguous };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function formatLifecycleLineageFailures(lineage) {
|
|
70
|
+
return [
|
|
71
|
+
...lineage.unresolved.map((fileName) => `${fileName}:unresolved`),
|
|
72
|
+
...lineage.ambiguous.map((entry) => `${entry.fileName}:ambiguous:${entry.waveIds.join(",")}`),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function analyzeTopicArtifacts(topicDir, topic) {
|
|
77
|
+
const files = (await readdir(topicDir, { withFileTypes: true }))
|
|
78
|
+
.filter((entry) => entry.isFile())
|
|
79
|
+
.map((entry) => entry.name);
|
|
80
|
+
const packetFiles = files.filter((name) => name.startsWith("packet-") && name.endsWith(".md"));
|
|
81
|
+
const resultFiles = files.filter((name) => name.startsWith("result-") && name.endsWith(".md"));
|
|
82
|
+
const closeoutFiles = files.filter((name) => name.startsWith("closeout-") && name.endsWith(".md"));
|
|
83
|
+
const decisionReviewFiles = files.filter((name) => name.startsWith("decision-review-") && name.endsWith(".md"));
|
|
84
|
+
const remediationFiles = files.filter((name) => name.includes("remediation") && name.endsWith(".md"));
|
|
85
|
+
const overflowFiles = files.filter((name) => name.includes("overflow-continuation") || name.includes("remediation-continuation"));
|
|
86
|
+
const execPackFiles = files.filter((name) => name.includes("exec-pack-") && name.endsWith(".md"));
|
|
87
|
+
const trueCloseFiles = files.filter((name) => name === "topic-true-close-audit.md"
|
|
88
|
+
|| name.startsWith("result-topic-true-close")
|
|
89
|
+
|| name === "closeout-topic-true-close.md");
|
|
90
|
+
const ambiguousLifecycleFiles = files.filter((name) => /^(packet|result|closeout|decision-review|prompt|overflow-continuation)-/.test(name)
|
|
91
|
+
&& !isRecognizedLifecycleArtifactName(name));
|
|
92
|
+
const topicWaveIds = new Set(getTopicWaves(topic).map((entry) => entry.wave_id));
|
|
93
|
+
const packetWaveFiles = packetFiles.filter((name) => !name.startsWith("packet-true-close"));
|
|
94
|
+
const resultWaveFiles = resultFiles.filter((name) => !name.startsWith("result-topic-true-close") && !name.startsWith("result-true-close"));
|
|
95
|
+
const closeoutWaveFiles = closeoutFiles.filter((name) => !name.startsWith("closeout-topic") && !name.startsWith("closeout-true-close"));
|
|
96
|
+
const packetLineage = resolveDeclaredWaveArtifactLineage(packetWaveFiles, topicWaveIds);
|
|
97
|
+
const resultLineage = resolveDeclaredWaveArtifactLineage(resultWaveFiles, topicWaveIds);
|
|
98
|
+
const closeoutLineage = resolveDeclaredWaveArtifactLineage(closeoutWaveFiles, topicWaveIds);
|
|
99
|
+
const packetWaveIds = new Set(packetLineage.resolved.map((entry) => entry.waveId));
|
|
100
|
+
const resultWaveIds = resultLineage.resolved.map((entry) => entry.waveId);
|
|
101
|
+
const closeoutWaveIds = new Set(closeoutLineage.resolved.map((entry) => entry.waveId));
|
|
102
|
+
const closeoutWaveIdsArray = Array.from(closeoutWaveIds);
|
|
103
|
+
const unresolvedPacketWaveRefs = formatLifecycleLineageFailures(packetLineage);
|
|
104
|
+
const unresolvedResultWaveIds = formatLifecycleLineageFailures(resultLineage);
|
|
105
|
+
const unresolvedCloseoutWaveRefs = formatLifecycleLineageFailures(closeoutLineage);
|
|
106
|
+
const activeWaveCloseoutConflicts = getTopicWaves(topic)
|
|
107
|
+
.filter((entry) => !["closed", "retired", "superseded"].includes(entry.state)
|
|
108
|
+
&& closeoutFiles.some((name) => fileReferencesWave(name, entry.wave_id) || closeoutWaveIds.has(entry.wave_id)))
|
|
109
|
+
.map((entry) => `${entry.wave_id}:${entry.state}`);
|
|
110
|
+
const topicHasOpenBlockers = getTopicWaves(topic).some((entry) => !["closed", "retired", "superseded"].includes(entry.state))
|
|
111
|
+
|| (typeof topic.selected_next_target === "string"
|
|
112
|
+
&& topic.selected_next_target.length > 0
|
|
113
|
+
&& topic.selected_next_target !== "topic_design_baseline");
|
|
114
|
+
const prematureTrueClose = trueCloseFiles.length > 0 && topicHasOpenBlockers;
|
|
115
|
+
const observedWaveIds = Array.from(new Set([
|
|
116
|
+
...Array.from(topicWaveIds),
|
|
117
|
+
...Array.from(packetWaveIds),
|
|
118
|
+
...closeoutWaveIdsArray,
|
|
119
|
+
...resultWaveIds,
|
|
120
|
+
])).sort();
|
|
121
|
+
const observedWaves = observedWaveIds.map((waveId) => {
|
|
122
|
+
const observed = {
|
|
123
|
+
wave_id: waveId,
|
|
124
|
+
packets: packetFiles.filter((name) => fileReferencesWave(name, waveId)).length,
|
|
125
|
+
results: resultFiles.filter((name) => fileReferencesWave(name, waveId)).length,
|
|
126
|
+
closeouts: closeoutFiles.filter((name) => fileReferencesWave(name, waveId)).length,
|
|
127
|
+
decision_reviews: decisionReviewFiles.filter((name) => fileReferencesWave(name, waveId)).length,
|
|
128
|
+
remediations: remediationFiles.filter((name) => fileReferencesWave(name, waveId)).length,
|
|
129
|
+
overflow_continuations: overflowFiles.filter((name) => fileReferencesWave(name, waveId)).length,
|
|
130
|
+
exec_packs: execPackFiles.filter((name) => fileReferencesWave(name, waveId)).length,
|
|
131
|
+
declared_in_topic_yaml: topicWaveIds.has(waveId),
|
|
132
|
+
};
|
|
133
|
+
return { ...observed, observed_lineage: buildObservedLineage(observed) };
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
files,
|
|
138
|
+
counts: {
|
|
139
|
+
files: files.length,
|
|
140
|
+
packets: packetFiles.length,
|
|
141
|
+
results: resultFiles.length,
|
|
142
|
+
closeouts: closeoutFiles.length,
|
|
143
|
+
decision_reviews: decisionReviewFiles.length,
|
|
144
|
+
remediations: remediationFiles.length,
|
|
145
|
+
overflow_continuations: overflowFiles.length,
|
|
146
|
+
exec_packs: execPackFiles.length,
|
|
147
|
+
true_close_artifacts: trueCloseFiles.length,
|
|
148
|
+
},
|
|
149
|
+
waveIds: observedWaveIds,
|
|
150
|
+
observedWaves,
|
|
151
|
+
featureFlags: {
|
|
152
|
+
decision_review_lineage: decisionReviewFiles.length > 0,
|
|
153
|
+
remediation_lineage: remediationFiles.length > 0,
|
|
154
|
+
overflow_lineage: overflowFiles.length > 0,
|
|
155
|
+
true_close_lineage: trueCloseFiles.length >= 2,
|
|
156
|
+
exec_pack_lineage: execPackFiles.length > 0,
|
|
157
|
+
},
|
|
158
|
+
unresolvedPacketWaveRefs,
|
|
159
|
+
unresolvedResultWaveIds,
|
|
160
|
+
unresolvedCloseoutWaveRefs,
|
|
161
|
+
closeoutWaveIds: closeoutWaveIdsArray,
|
|
162
|
+
ambiguousLifecycleFiles,
|
|
163
|
+
activeWaveCloseoutConflicts,
|
|
164
|
+
prematureTrueClose,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export {
|
|
169
|
+
analyzeTopicArtifacts,
|
|
170
|
+
fileReferencesWave,
|
|
171
|
+
isRecognizedLifecycleArtifactName,
|
|
172
|
+
resolveDeclaredWaveArtifactLineage,
|
|
173
|
+
};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import { pathExists } from "./fs-helpers.mjs";
|
|
4
|
+
import { analyzeTopicArtifacts } from "./topic-lifecycle-artifacts.mjs";
|
|
5
|
+
import { DEFAULT_TOPIC_RUNTIME_AUTHORITY, loadTopicRuntimeAuthority, toPortableRelativePath } from "./topic-common.mjs";
|
|
6
|
+
import {
|
|
7
|
+
getTopicWaves,
|
|
8
|
+
loadTopicReport,
|
|
9
|
+
topicHasEnrichedShape,
|
|
10
|
+
validateTopicId,
|
|
11
|
+
} from "./topic-scaffold.mjs";
|
|
12
|
+
import {
|
|
13
|
+
getPendingEntryBlockers,
|
|
14
|
+
loadPendingNote,
|
|
15
|
+
loadTopicValidationPolicy,
|
|
16
|
+
} from "./topic-waves.mjs";
|
|
17
|
+
|
|
18
|
+
export async function validateTopicRoot(projectRoot, input = null) {
|
|
19
|
+
const loaded = await loadTopicReport(projectRoot, input);
|
|
20
|
+
if (!loaded.ok) return { ok: false, error: loaded.error, checks: [], warnings: [] };
|
|
21
|
+
const { topicDir, topicId, state, topic } = loaded,
|
|
22
|
+
authority = await loadTopicRuntimeAuthority(projectRoot),
|
|
23
|
+
validationPolicy = await loadTopicValidationPolicy(projectRoot),
|
|
24
|
+
ignoredByPolicy = validationPolicy.ignoredTopicIds.get(topicId) ?? null,
|
|
25
|
+
checks = [],
|
|
26
|
+
warnings = [],
|
|
27
|
+
relativeTopicDir = toPortableRelativePath(path.relative(projectRoot, topicDir)),
|
|
28
|
+
artifactAnalysis = await analyzeTopicArtifacts(topicDir, topic),
|
|
29
|
+
pendingNoteLoaded = await loadPendingNote(topicDir),
|
|
30
|
+
topicIdMatchesFolder = topic.topic_id === topicId;
|
|
31
|
+
checks.push({
|
|
32
|
+
id: "topic_id_matches_folder",
|
|
33
|
+
ok: topicIdMatchesFolder,
|
|
34
|
+
reason: topicIdMatchesFolder
|
|
35
|
+
? "topic.yaml topic_id matches the topic folder"
|
|
36
|
+
: `topic.yaml topic_id does not match folder name (${topic.topic_id ?? "missing"} vs ${topicId})`,
|
|
37
|
+
});
|
|
38
|
+
const stateMatchesRoot = topic.state === state;
|
|
39
|
+
checks.push({
|
|
40
|
+
id: "state_matches_root",
|
|
41
|
+
ok: stateMatchesRoot,
|
|
42
|
+
reason: stateMatchesRoot
|
|
43
|
+
? "topic.yaml state matches the lifecycle root"
|
|
44
|
+
: `topic.yaml state does not match lifecycle root (${topic.state ?? "missing"} vs ${state})`,
|
|
45
|
+
});
|
|
46
|
+
const missingMinimalFields = authority.minimalRequiredFields.filter((field) => {
|
|
47
|
+
const value = topic[field];
|
|
48
|
+
return value == null || value === "";
|
|
49
|
+
});
|
|
50
|
+
checks.push({
|
|
51
|
+
id: "minimal_state_evidence",
|
|
52
|
+
ok: missingMinimalFields.length === 0,
|
|
53
|
+
reason:
|
|
54
|
+
missingMinimalFields.length === 0
|
|
55
|
+
? "topic.yaml contains the required lifecycle evidence fields"
|
|
56
|
+
: `topic.yaml is missing required lifecycle evidence fields: ${missingMinimalFields.join(", ")}`,
|
|
57
|
+
});
|
|
58
|
+
const topicIdFormatValid = validateTopicId(topicId);
|
|
59
|
+
checks.push({
|
|
60
|
+
id: "topic_id_format",
|
|
61
|
+
ok: topicIdFormatValid,
|
|
62
|
+
reason: topicIdFormatValid
|
|
63
|
+
? "topic id remains date-first and sortable"
|
|
64
|
+
: `topic id is not date-first and sortable: ${topicId}`,
|
|
65
|
+
});
|
|
66
|
+
const missingRecommendedFiles = [];
|
|
67
|
+
for (const fileName of authority.recommendedFiles)
|
|
68
|
+
(await pathExists(path.join(topicDir, fileName)))?.isFile() ||
|
|
69
|
+
missingRecommendedFiles.push(fileName);
|
|
70
|
+
missingRecommendedFiles.length > 0 &&
|
|
71
|
+
warnings.push(
|
|
72
|
+
`recommended topic companion files are missing: ${missingRecommendedFiles.join(", ")}`,
|
|
73
|
+
);
|
|
74
|
+
const missingEnrichedFields = authority.enrichedRequiredFields.filter((field) => {
|
|
75
|
+
const value = topic[field];
|
|
76
|
+
return field === "selected_next_target"
|
|
77
|
+
? !(
|
|
78
|
+
value === null ||
|
|
79
|
+
value === "topic_design_baseline" ||
|
|
80
|
+
(typeof value == "string" && value.length > 0)
|
|
81
|
+
)
|
|
82
|
+
: value == null || value === "" || (Array.isArray(value) && value.length === 0);
|
|
83
|
+
}),
|
|
84
|
+
enumViolations = [];
|
|
85
|
+
if (
|
|
86
|
+
(topic.mode !== void 0 &&
|
|
87
|
+
!authority.topicEnums.mode.includes(topic.mode) &&
|
|
88
|
+
enumViolations.push(`mode=${topic.mode}`),
|
|
89
|
+
topic.posture !== void 0 &&
|
|
90
|
+
!authority.topicEnums.posture.includes(topic.posture) &&
|
|
91
|
+
enumViolations.push(`posture=${topic.posture}`),
|
|
92
|
+
topic.design_policy !== void 0 &&
|
|
93
|
+
!authority.topicEnums.designPolicy.includes(topic.design_policy) &&
|
|
94
|
+
enumViolations.push(`design_policy=${topic.design_policy}`),
|
|
95
|
+
topic.parallel_truth !== void 0 &&
|
|
96
|
+
!authority.topicEnums.parallelTruth.includes(topic.parallel_truth) &&
|
|
97
|
+
enumViolations.push(`parallel_truth=${topic.parallel_truth}`),
|
|
98
|
+
topic.layering !== void 0 &&
|
|
99
|
+
!authority.topicEnums.layering.includes(topic.layering) &&
|
|
100
|
+
enumViolations.push(`layering=${topic.layering}`),
|
|
101
|
+
topic.risk !== void 0 &&
|
|
102
|
+
!authority.topicEnums.risk.includes(topic.risk) &&
|
|
103
|
+
enumViolations.push(`risk=${topic.risk}`),
|
|
104
|
+
topic.applicability !== void 0 &&
|
|
105
|
+
!authority.topicEnums.applicability.includes(topic.applicability) &&
|
|
106
|
+
enumViolations.push(`applicability=${topic.applicability}`),
|
|
107
|
+
topic.execution_mode !== void 0 &&
|
|
108
|
+
!authority.topicEnums.executionMode.includes(topic.execution_mode) &&
|
|
109
|
+
enumViolations.push(`execution_mode=${topic.execution_mode}`),
|
|
110
|
+
topic.current_true_close_status !== void 0 &&
|
|
111
|
+
!authority.topicEnums.trueCloseStatus.includes(topic.current_true_close_status) &&
|
|
112
|
+
enumViolations.push(`current_true_close_status=${topic.current_true_close_status}`),
|
|
113
|
+
missingEnrichedFields.length > 0 &&
|
|
114
|
+
warnings.push(
|
|
115
|
+
`topic.yaml is using the legacy minimal shape and is missing enriched fields: ${missingEnrichedFields.join(", ")}`,
|
|
116
|
+
),
|
|
117
|
+
enumViolations.length > 0 &&
|
|
118
|
+
warnings.push(
|
|
119
|
+
`topic.yaml contains values outside the current enriched enums: ${enumViolations.join(", ")}`,
|
|
120
|
+
),
|
|
121
|
+
checks.push({
|
|
122
|
+
id: "packet_wave_lineage_resolves",
|
|
123
|
+
ok: artifactAnalysis.unresolvedPacketWaveRefs.length === 0,
|
|
124
|
+
reason:
|
|
125
|
+
artifactAnalysis.unresolvedPacketWaveRefs.length === 0
|
|
126
|
+
? "packet artifacts resolve to exactly one declared wave lineage"
|
|
127
|
+
: `packet artifacts do not resolve to exactly one declared wave lineage: ${artifactAnalysis.unresolvedPacketWaveRefs.join(", ")}`,
|
|
128
|
+
}),
|
|
129
|
+
checks.push({
|
|
130
|
+
id: "result_wave_lineage_resolves",
|
|
131
|
+
ok: artifactAnalysis.unresolvedResultWaveIds.length === 0,
|
|
132
|
+
reason:
|
|
133
|
+
artifactAnalysis.unresolvedResultWaveIds.length === 0
|
|
134
|
+
? "result artifacts resolve to exactly one declared wave lineage"
|
|
135
|
+
: `result artifacts do not resolve to exactly one declared wave lineage: ${artifactAnalysis.unresolvedResultWaveIds.join(", ")}`,
|
|
136
|
+
}),
|
|
137
|
+
checks.push({
|
|
138
|
+
id: "closeout_wave_lineage_resolves",
|
|
139
|
+
ok: artifactAnalysis.unresolvedCloseoutWaveRefs.length === 0,
|
|
140
|
+
reason:
|
|
141
|
+
artifactAnalysis.unresolvedCloseoutWaveRefs.length === 0
|
|
142
|
+
? "closeout artifacts resolve to exactly one declared wave lineage"
|
|
143
|
+
: `closeout artifacts do not resolve to exactly one declared wave lineage: ${artifactAnalysis.unresolvedCloseoutWaveRefs.join(", ")}`,
|
|
144
|
+
}),
|
|
145
|
+
topic.state === "pending")
|
|
146
|
+
) {
|
|
147
|
+
const pendingNote = pendingNoteLoaded.ok ? pendingNoteLoaded.note : null;
|
|
148
|
+
if (
|
|
149
|
+
(checks.push({
|
|
150
|
+
id: "pending_note_exists",
|
|
151
|
+
ok: pendingNoteLoaded.ok,
|
|
152
|
+
reason: pendingNoteLoaded.ok ? "pending note artifact exists" : pendingNoteLoaded.error,
|
|
153
|
+
}),
|
|
154
|
+
pendingNote)
|
|
155
|
+
) {
|
|
156
|
+
const pendingNoteMissingFields = authority.pendingNoteRequiredFields.filter((field) => {
|
|
157
|
+
const value = pendingNote[field];
|
|
158
|
+
return value == null || value === "";
|
|
159
|
+
});
|
|
160
|
+
(checks.push({
|
|
161
|
+
id: "pending_note_required_fields",
|
|
162
|
+
ok: pendingNoteMissingFields.length === 0,
|
|
163
|
+
reason:
|
|
164
|
+
pendingNoteMissingFields.length === 0
|
|
165
|
+
? "pending note contains required fields"
|
|
166
|
+
: `pending note is missing required fields: ${pendingNoteMissingFields.join(", ")}`,
|
|
167
|
+
}),
|
|
168
|
+
checks.push({
|
|
169
|
+
id: "pending_note_topic_matches",
|
|
170
|
+
ok: pendingNote.topic_id === topicId,
|
|
171
|
+
reason:
|
|
172
|
+
pendingNote.topic_id === topicId
|
|
173
|
+
? "pending note topic_id matches the topic"
|
|
174
|
+
: `pending note topic_id does not match topic (${pendingNote.topic_id ?? "missing"} vs ${topicId})`,
|
|
175
|
+
}),
|
|
176
|
+
checks.push({
|
|
177
|
+
id: "pending_note_status_active",
|
|
178
|
+
ok:
|
|
179
|
+
pendingNote.status === "active" &&
|
|
180
|
+
authority.pendingNoteStatuses.includes(pendingNote.status),
|
|
181
|
+
reason:
|
|
182
|
+
pendingNote.status === "active"
|
|
183
|
+
? "pending note remains active while topic is pending"
|
|
184
|
+
: `pending note status must be active while pending, found ${pendingNote.status ?? "missing"}`,
|
|
185
|
+
}),
|
|
186
|
+
checks.push({
|
|
187
|
+
id: "pending_note_reopen_or_close_defined",
|
|
188
|
+
ok:
|
|
189
|
+
typeof pendingNote.reopen_criteria == "string" ||
|
|
190
|
+
typeof pendingNote.close_trigger == "string",
|
|
191
|
+
reason:
|
|
192
|
+
typeof pendingNote.reopen_criteria == "string" ||
|
|
193
|
+
typeof pendingNote.close_trigger == "string"
|
|
194
|
+
? "pending note declares reopen criteria or close trigger"
|
|
195
|
+
: "pending note must declare reopen criteria or close trigger",
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
const pendingBlockers = getPendingEntryBlockers(topic);
|
|
199
|
+
checks.push({
|
|
200
|
+
id: "pending_has_no_active_implementation_wave",
|
|
201
|
+
ok: pendingBlockers.length === 0,
|
|
202
|
+
reason:
|
|
203
|
+
pendingBlockers.length === 0
|
|
204
|
+
? "pending topic has no active implementation wave"
|
|
205
|
+
: `pending topic still has active implementation waves: ${pendingBlockers.join(", ")}`,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
ignoredByPolicy
|
|
209
|
+
? (warnings.push(
|
|
210
|
+
`topic is ignored by default strict validate policy: ${ignoredByPolicy.reason ?? topicId}`,
|
|
211
|
+
),
|
|
212
|
+
checks.push({
|
|
213
|
+
id: "strict_validate_policy_ignored",
|
|
214
|
+
ok: true,
|
|
215
|
+
reason: `strict topic rails skipped by policy (${ignoredByPolicy.posture ?? "ignored"})`,
|
|
216
|
+
}))
|
|
217
|
+
: (checks.push({
|
|
218
|
+
id: "artifact_naming_unambiguous",
|
|
219
|
+
ok: artifactAnalysis.ambiguousLifecycleFiles.length === 0,
|
|
220
|
+
reason:
|
|
221
|
+
artifactAnalysis.ambiguousLifecycleFiles.length === 0
|
|
222
|
+
? "lifecycle artifact naming remains unambiguous"
|
|
223
|
+
: `ambiguous lifecycle artifact names: ${artifactAnalysis.ambiguousLifecycleFiles.join(", ")}`,
|
|
224
|
+
}),
|
|
225
|
+
checks.push({
|
|
226
|
+
id: "no_active_wave_closeout_conflict",
|
|
227
|
+
ok: artifactAnalysis.activeWaveCloseoutConflicts.length === 0,
|
|
228
|
+
reason:
|
|
229
|
+
artifactAnalysis.activeWaveCloseoutConflicts.length === 0
|
|
230
|
+
? "no closeout artifact claims closure for an active wave"
|
|
231
|
+
: `closeout artifacts exist for non-terminal waves: ${artifactAnalysis.activeWaveCloseoutConflicts.join(", ")}`,
|
|
232
|
+
}),
|
|
233
|
+
checks.push({
|
|
234
|
+
id: "true_close_not_premature",
|
|
235
|
+
ok: !artifactAnalysis.prematureTrueClose,
|
|
236
|
+
reason: artifactAnalysis.prematureTrueClose
|
|
237
|
+
? "true-close artifacts exist while open blockers remain"
|
|
238
|
+
: "true-close artifacts do not coexist with known open blockers",
|
|
239
|
+
}));
|
|
240
|
+
const ok = checks.every((entry) => entry.ok),
|
|
241
|
+
schemaMode =
|
|
242
|
+
missingEnrichedFields.length === 0 && enumViolations.length === 0
|
|
243
|
+
? "enriched"
|
|
244
|
+
: "legacy_minimal",
|
|
245
|
+
migrationPosture =
|
|
246
|
+
schemaMode === "legacy_minimal" && artifactAnalysis.counts.files > 0
|
|
247
|
+
? "explicit_legacy_reconstruction_required"
|
|
248
|
+
: "not_required",
|
|
249
|
+
validationDisposition = ignoredByPolicy
|
|
250
|
+
? validationPolicy.ignoredTopicValidateSemantics.status
|
|
251
|
+
: "strict",
|
|
252
|
+
canonicalValidated = ignoredByPolicy
|
|
253
|
+
? validationPolicy.ignoredTopicValidateSemantics.canonicalSuccess
|
|
254
|
+
: ok;
|
|
255
|
+
return {
|
|
256
|
+
ok,
|
|
257
|
+
topicId,
|
|
258
|
+
topicDir,
|
|
259
|
+
topicRef: relativeTopicDir,
|
|
260
|
+
state,
|
|
261
|
+
schemaMode,
|
|
262
|
+
selectedNextTarget:
|
|
263
|
+
typeof topic.selected_next_target == "string" ? topic.selected_next_target : null,
|
|
264
|
+
currentTrueCloseStatus:
|
|
265
|
+
typeof topic.current_true_close_status == "string" ? topic.current_true_close_status : null,
|
|
266
|
+
title: typeof topic.title == "string" ? topic.title : null,
|
|
267
|
+
pendingNoteStatus:
|
|
268
|
+
pendingNoteLoaded.ok && typeof pendingNoteLoaded.note.status == "string"
|
|
269
|
+
? pendingNoteLoaded.note.status
|
|
270
|
+
: null,
|
|
271
|
+
missingEnrichedFields,
|
|
272
|
+
artifactSummary: artifactAnalysis.counts,
|
|
273
|
+
waveIds: artifactAnalysis.waveIds,
|
|
274
|
+
observedWaves: artifactAnalysis.observedWaves,
|
|
275
|
+
featureFlags: artifactAnalysis.featureFlags,
|
|
276
|
+
unresolvedPacketWaveRefs: artifactAnalysis.unresolvedPacketWaveRefs,
|
|
277
|
+
unresolvedResultWaveIds: artifactAnalysis.unresolvedResultWaveIds,
|
|
278
|
+
unresolvedCloseoutWaveRefs: artifactAnalysis.unresolvedCloseoutWaveRefs,
|
|
279
|
+
migrationPosture,
|
|
280
|
+
validationDisposition,
|
|
281
|
+
canonicalValidated,
|
|
282
|
+
ignoredByPolicy: ignoredByPolicy !== null,
|
|
283
|
+
ignorePolicyReason: ignoredByPolicy?.reason ?? null,
|
|
284
|
+
ignorePolicyPosture: ignoredByPolicy?.posture ?? null,
|
|
285
|
+
checks,
|
|
286
|
+
warnings,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
function hasPlaceholder(value) {
|
|
2
|
+
return /<[^>]+>/.test(value);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function commandOptionValue(parts, flag) {
|
|
6
|
+
const index = parts.indexOf(flag);
|
|
7
|
+
return index >= 0 ? parts[index + 1] : null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function commandRequiredOption(parts, flag, commandRef, actionLabel) {
|
|
11
|
+
const value = commandOptionValue(parts, flag);
|
|
12
|
+
if (!value || value.startsWith("--")) {
|
|
13
|
+
return {
|
|
14
|
+
ok: false,
|
|
15
|
+
error: `topic-runner refused: ${actionLabel} command is missing ${flag}: ${commandRef}`,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return { ok: true, value };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function parseMechanicalCommandRef(commandRef, topicId) {
|
|
22
|
+
if (typeof commandRef !== "string" || commandRef.trim().length === 0) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
error: "topic-runner refused: decision.next_command_ref is empty",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (hasPlaceholder(commandRef)) {
|
|
29
|
+
return {
|
|
30
|
+
ok: false,
|
|
31
|
+
error: `topic-runner refused: decision.next_command_ref contains a placeholder: ${commandRef}`,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const parts = commandRef.trim().split(/\s+/);
|
|
36
|
+
if (parts[0] !== "nimicoding" || parts[1] !== "topic") {
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
error: `topic-runner refused: next command is not a package-owned topic command: ${commandRef}`,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const [domain, action, commandTopicId] = parts.slice(2, 5);
|
|
44
|
+
if (domain === "wave" && action === "admit") {
|
|
45
|
+
const waveId = parts[5] ?? null;
|
|
46
|
+
if (commandTopicId !== topicId) {
|
|
47
|
+
return {
|
|
48
|
+
ok: false,
|
|
49
|
+
error: `topic-runner refused: next command topic ${commandTopicId} does not match ${topicId}`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (!waveId || waveId.startsWith("--")) {
|
|
53
|
+
return {
|
|
54
|
+
ok: false,
|
|
55
|
+
error: `topic-runner refused: wave admit command is missing wave id: ${commandRef}`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, action: "admit_wave", waveId };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (domain === "packet" && action === "freeze") {
|
|
62
|
+
if (commandTopicId !== topicId) {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
error: `topic-runner refused: next command topic ${commandTopicId} does not match ${topicId}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const draftPath = commandOptionValue(parts, "--from");
|
|
69
|
+
if (!draftPath || draftPath.startsWith("--")) {
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
error: `topic-runner refused: packet freeze command is missing --from: ${commandRef}`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, action: "freeze_packet", draftPath };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (domain === "result" && action === "record") {
|
|
79
|
+
if (commandTopicId !== topicId) {
|
|
80
|
+
return {
|
|
81
|
+
ok: false,
|
|
82
|
+
error: `topic-runner refused: next command topic ${commandTopicId} does not match ${topicId}`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const required = [
|
|
86
|
+
["--kind", "result record"],
|
|
87
|
+
["--verdict", "result record"],
|
|
88
|
+
["--from", "result record"],
|
|
89
|
+
["--verified-at", "result record"],
|
|
90
|
+
].map(([flag, label]) => [flag, commandRequiredOption(parts, flag, commandRef, label)]);
|
|
91
|
+
const failed = required.find(([, check]) => !check.ok);
|
|
92
|
+
if (failed) return failed[1];
|
|
93
|
+
const values = Object.fromEntries(required.map(([flag, check]) => [flag, check.value]));
|
|
94
|
+
return {
|
|
95
|
+
ok: true,
|
|
96
|
+
action: "record_result",
|
|
97
|
+
resultKind: values["--kind"],
|
|
98
|
+
verdict: values["--verdict"],
|
|
99
|
+
fromPath: values["--from"],
|
|
100
|
+
verifiedAt: values["--verified-at"],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (["worker", "audit"].includes(domain) && action === "dispatch") {
|
|
105
|
+
if (commandTopicId !== topicId) {
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
error: `topic-runner refused: next command topic ${commandTopicId} does not match ${topicId}`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const packetId = commandOptionValue(parts, "--packet");
|
|
112
|
+
if (!packetId || packetId.startsWith("--")) {
|
|
113
|
+
return {
|
|
114
|
+
ok: false,
|
|
115
|
+
error: `topic-runner refused: dispatch command is missing --packet: ${commandRef}`,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
ok: true,
|
|
120
|
+
action: domain === "audit" ? "dispatch_audit" : "dispatch_worker",
|
|
121
|
+
role: domain,
|
|
122
|
+
packetId,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (domain === "closeout" && action === "wave") {
|
|
127
|
+
if (commandTopicId !== topicId) {
|
|
128
|
+
return {
|
|
129
|
+
ok: false,
|
|
130
|
+
error: `topic-runner refused: next command topic ${commandTopicId} does not match ${topicId}`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const waveId = parts[5] ?? null;
|
|
134
|
+
if (!waveId || waveId.startsWith("--")) {
|
|
135
|
+
return {
|
|
136
|
+
ok: false,
|
|
137
|
+
error: `topic-runner refused: closeout wave command is missing wave id: ${commandRef}`,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const authorityClosure = commandOptionValue(parts, "--authority");
|
|
141
|
+
const semanticClosure = commandOptionValue(parts, "--semantic");
|
|
142
|
+
const consumerClosure = commandOptionValue(parts, "--consumer");
|
|
143
|
+
const driftResistanceClosure = commandOptionValue(parts, "--drift-resistance");
|
|
144
|
+
const disposition = commandOptionValue(parts, "--disposition");
|
|
145
|
+
if (
|
|
146
|
+
!authorityClosure || authorityClosure.startsWith("--") ||
|
|
147
|
+
!semanticClosure || semanticClosure.startsWith("--") ||
|
|
148
|
+
!consumerClosure || consumerClosure.startsWith("--") ||
|
|
149
|
+
!driftResistanceClosure || driftResistanceClosure.startsWith("--") ||
|
|
150
|
+
!disposition || disposition.startsWith("--")
|
|
151
|
+
) {
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
error: `topic-runner refused: closeout wave command is missing required closure flags: ${commandRef}`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
ok: true,
|
|
160
|
+
action: "closeout_wave",
|
|
161
|
+
waveId,
|
|
162
|
+
authorityClosure,
|
|
163
|
+
semanticClosure,
|
|
164
|
+
consumerClosure,
|
|
165
|
+
driftResistanceClosure,
|
|
166
|
+
disposition,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
ok: false,
|
|
172
|
+
error: `topic-runner refused: unsupported mechanical next command: ${commandRef}`,
|
|
173
|
+
};
|
|
174
|
+
}
|