@aiwg/cli 2026.10.11 → 2026.10.14
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/agentic/code/providers/model-catalog.v1.json +62 -12
- package/agentic/code/providers/pi/aiwg-bridge.ts +44 -1
- package/dist/src/artifacts/binding-target-identity.js +51 -0
- package/dist/src/artifacts/checksum-manifest.js +12 -0
- package/dist/src/artifacts/index-builder.js +11 -13
- package/dist/src/artifacts/query-engine.js +5 -11
- package/dist/src/cli/handlers/doctor-help.js +32 -0
- package/dist/src/cli/handlers/gates.js +19 -18
- package/dist/src/cli/handlers/models-help.js +7 -1
- package/dist/src/cli/handlers/models.js +3 -3
- package/dist/src/cli/handlers/script-runner.js +8 -5
- package/dist/src/cli/handlers/sessions-intake.js +104 -0
- package/dist/src/cli/handlers/sessions-tail.js +172 -0
- package/dist/src/cli/handlers/sessions.js +90 -17
- package/dist/src/cli/handlers/skill-lint.js +10 -3
- package/dist/src/cli/handlers/steward-format.js +100 -0
- package/dist/src/cli/handlers/steward-models.js +167 -0
- package/dist/src/cli/handlers/steward.js +14 -248
- package/dist/src/cli/handlers/use-bundle-counts.js +87 -0
- package/dist/src/cli/handlers/use-skill-assets.js +207 -0
- package/dist/src/cli/handlers/use.js +35 -216
- package/dist/src/cli/handlers/utilities.js +1 -24
- package/dist/src/config/aiwg-config.js +7 -0
- package/dist/src/config/authorization-cli.js +97 -0
- package/dist/src/config/cli-help.js +1 -0
- package/dist/src/config/cli.js +10 -1
- package/dist/src/decision/context-pruning-common.js +41 -0
- package/dist/src/decision/context-pruning-evaluation.js +366 -0
- package/dist/src/decision/context-pruning-pilot.js +431 -0
- package/dist/src/decision/context-pruning-types.js +19 -0
- package/dist/src/decision/context-pruning.js +5 -846
- package/dist/src/decision/ensemble/contract.js +17 -26
- package/dist/src/decision/ensemble-study/artifacts.js +5 -0
- package/dist/src/decision/ensemble-study/score.js +4 -3
- package/dist/src/decision/feature-export.js +3 -9
- package/dist/src/decision/heldout/collector.js +2 -2
- package/dist/src/decision/issue-triage/runtime.js +3 -9
- package/dist/src/decision/qualification/gates.js +2 -1
- package/dist/src/decision/qualification/release.js +6 -64
- package/dist/src/decision/routing/report.js +2 -0
- package/dist/src/decision/sdlc-screening.js +3 -5
- package/dist/src/decision/sensitivity/comparative.js +5 -3
- package/dist/src/extensions/manifest.js +8 -1
- package/dist/src/extensions/project-local-doctor.js +78 -2
- package/dist/src/extensions/validation.js +10 -11
- package/dist/src/gates/driver.js +6 -77
- package/dist/src/gates/evaluate.js +6 -23
- package/dist/src/gates/floors.js +4 -4
- package/dist/src/gates/index.js +3 -3
- package/dist/src/gates/lattice.js +26 -0
- package/dist/src/gates/registry.js +2 -1
- package/dist/src/gates/report.js +19 -7
- package/dist/src/gates/upstream-ceiling.js +111 -0
- package/dist/src/issues/audit-cli.js +120 -0
- package/dist/src/issues/audit-contract.js +64 -0
- package/dist/src/issues/audit-local.js +82 -0
- package/dist/src/issues/audit.js +220 -0
- package/dist/src/lint/rule-activation.js +15 -1
- package/dist/src/mission-protocol/canonical-codecs.js +270 -0
- package/dist/src/mission-protocol/codecs.js +22 -550
- package/dist/src/mission-protocol/health-trace-codecs.js +281 -0
- package/dist/src/mission-protocol/health-trace-types.js +43 -0
- package/dist/src/mission-protocol/types.js +2 -42
- package/dist/src/mission-protocol/worker-contract-json.js +10 -0
- package/dist/src/mission-protocol/worker-review-gate.js +100 -0
- package/dist/src/mission-protocol/worker-review-types.js +2 -0
- package/dist/src/models/catalog-policy.js +280 -0
- package/dist/src/models/index.js +1 -1
- package/dist/src/models/model-catalog.v1.json +62 -12
- package/dist/src/models/policy-resources.js +28 -0
- package/dist/src/models/provider-models.js +5 -8
- package/dist/src/models/provider-policy.js +10 -546
- package/dist/src/models/resolver.js +26 -8
- package/dist/src/models/router.js +15 -2
- package/dist/src/models/tiers.js +13 -0
- package/dist/src/models/types.js +0 -6
- package/dist/src/models/worker-ceilings.js +59 -0
- package/dist/src/models/worker-invocation-policy.js +243 -0
- package/dist/src/models/worker-plan.js +16 -20
- package/dist/src/models/worker-review-lineage.js +55 -0
- package/dist/src/models/worker-selection-policy.js +1 -1
- package/dist/src/models/wrapper-definitions.js +14 -0
- package/dist/src/models/wrapper-deployment.js +48 -25
- package/dist/src/models/wrapper-enforcement.js +72 -0
- package/dist/src/models/wrapper-route.js +6 -3
- package/dist/src/policy/authorization.js +1 -0
- package/dist/src/policy/hitl-check.js +80 -0
- package/dist/src/policy/hitl-config.js +63 -0
- package/dist/src/policy/hitl-receipt.js +57 -0
- package/dist/src/policy/hitl-types.js +4 -0
- package/dist/src/policy/hitl-validation.js +39 -0
- package/dist/src/policy/hitl.js +117 -0
- package/dist/src/rules/activation.d.mts +3 -1
- package/dist/src/rules/activation.mjs +23 -2
- package/dist/src/rules/gate-coverage.js +51 -0
- package/dist/src/rules/gate-references.js +16 -0
- package/dist/src/rules/rule-frontmatter.schema.json +7 -1
- package/dist/src/serve/worker-command-request.js +21 -4
- package/dist/src/serve/worker-invocation-preparation.js +3 -1
- package/dist/src/serve/worker-invocation.js +21 -10
- package/dist/src/sessions/adapters/deepseek-harness.js +1 -0
- package/dist/src/sessions/adapters/grok-build-native.js +269 -0
- package/dist/src/sessions/adapters/grok-build.js +57 -15
- package/dist/src/sessions/adapters/hermes-state-db.js +252 -0
- package/dist/src/sessions/adapters/hermes.js +42 -3
- package/dist/src/sessions/adapters/warp.js +1 -1
- package/dist/src/sessions/batch-import.js +10 -0
- package/dist/src/sessions/contracts.js +1 -1
- package/dist/src/sessions/discovery-capability.js +38 -0
- package/dist/src/sessions/importer.js +8 -251
- package/dist/src/sessions/index.js +4 -0
- package/dist/src/sessions/intake-dir.js +71 -0
- package/dist/src/sessions/normalization.js +251 -0
- package/dist/src/sessions/tail.js +91 -0
- package/dist/src/sessions/workspace-discovery.js +83 -7
- package/dist/src/skills/adapters/local.js +32 -9
- package/dist/src/skills/agent-skill-sidecar.js +28 -0
- package/dist/src/skills/agent-skills.js +6 -23
- package/dist/src/skills/claude-surface-projection.js +25 -0
- package/dist/src/skills/cli-display.js +33 -0
- package/dist/src/skills/cli.js +2 -26
- package/dist/src/skills/collision-discovery.js +84 -0
- package/dist/src/skills/deployer.js +26 -361
- package/dist/src/skills/deployment-ownership.js +74 -0
- package/dist/src/skills/deployment-policy.js +114 -0
- package/dist/src/skills/deployment-projection.js +152 -0
- package/dist/src/skills/deployment-types.js +20 -0
- package/dist/src/skills/doctor.js +2 -2
- package/dist/src/skills/exporter.js +8 -31
- package/dist/src/skills/importer.js +4 -26
- package/dist/src/skills/provider-extensions.js +41 -0
- package/dist/src/skills/registry.js +22 -7
- package/dist/src/skills/run.js +6 -0
- package/dist/src/skills/types.js +0 -8
- package/dist/src/skills/validator-resources.js +68 -0
- package/dist/src/skills/validator.js +6 -55
- package/dist/src/smiths/context-pipeline/parallelism-section.js +7 -3
- package/dist/src/storage/cli-migrate-options.js +125 -0
- package/dist/src/storage/cli-migrate.js +111 -0
- package/dist/src/storage/cli.js +4 -279
- package/dist/src/storage/migration-adapter.js +79 -0
- package/dist/src/storage/migration-copy.js +108 -0
- package/dist/src/storage/migration-protocol.js +14 -197
- package/dist/src/storage/migration-records.js +186 -0
- package/dist/src/storage/migration-types.js +12 -0
- package/dist/src/tracker/forge-http.js +2 -1
- package/dist/src/tracker/issue-pages.js +110 -0
- package/package.json +3 -1
- package/schemas/mission-v1.schema.json +335 -0
- package/schemas/models/model-catalog.v1.schema.json +19 -1
- package/schemas/models/model-config-compatibility.v1.schema.json +3 -2
- package/schemas/models/model-policy.v1.schema.json +1 -1
- package/tools/agents/providers/antigravity.mjs +3 -5
- package/tools/agents/providers/base.mjs +3 -3
- package/tools/agents/providers/claude.mjs +3 -5
- package/tools/agents/providers/codex.mjs +3 -5
- package/tools/agents/providers/copilot.mjs +3 -5
- package/tools/agents/providers/cursor.mjs +3 -5
- package/tools/agents/providers/factory.mjs +3 -5
- package/tools/agents/providers/grok-build.mjs +9 -7
- package/tools/agents/providers/model-wrapper.mjs +86 -0
- package/tools/agents/providers/omp.mjs +3 -1
- package/tools/agents/providers/openclaw.mjs +3 -5
- package/tools/agents/providers/opencode.mjs +3 -5
- package/tools/agents/providers/provider-paths-staging.mjs +44 -0
- package/tools/agents/providers/rule-binding-targets.mjs +146 -0
- package/tools/agents/providers/rule-delivery.mjs +9 -128
- package/tools/agents/providers/warp.mjs +3 -5
- package/tools/agents/providers/windsurf.mjs +3 -5
- package/tools/plugin/package-plugins.mjs +2 -2
- package/tools/skills/codex-skill-transform.mjs +232 -0
- package/tools/skills/deploy-skills-codex.mjs +8 -249
- package/tools/warp/warp-content.mjs +548 -0
- package/vscode-extension/schemas/aiwg.config.v1.json +177 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Adapt the existing local issue index and selective issue reads to the audit envelope.
|
|
2
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
3
|
+
import { join, resolve, sep } from 'node:path';
|
|
4
|
+
import { LocalIssueProviderCore } from './local.js';
|
|
5
|
+
import { AuditStop, auditDigest, auditBytes, boundedPageSize, decodeAuditCursor, encodeAuditCursor, parseAuditFilter } from './audit-contract.js';
|
|
6
|
+
export function createLocalAuditTracker(root) {
|
|
7
|
+
const provider = new LocalIssueProviderCore(root);
|
|
8
|
+
const identity = `local:${root}`;
|
|
9
|
+
return {
|
|
10
|
+
identity,
|
|
11
|
+
async listMetadata(options) {
|
|
12
|
+
options.signal?.throwIfAborted();
|
|
13
|
+
const size = boundedPageSize(options.pageSize);
|
|
14
|
+
const filter = parseAuditFilter(options.filter);
|
|
15
|
+
// Hash metadata only. Any changed index invalidates an offset cursor, avoiding silent omissions.
|
|
16
|
+
const fingerprint = auditDigest(await readFile(join(root, 'index/issues.index.json'), 'utf8'));
|
|
17
|
+
const scope = auditDigest([identity, size, filter]);
|
|
18
|
+
const cursor = options.cursor ? decodeAuditCursor(options.cursor) : null;
|
|
19
|
+
if (options.cursor && (!cursor || typeof cursor !== 'object'))
|
|
20
|
+
throw new AuditStop('cursor-invalidated');
|
|
21
|
+
if (cursor && (cursor.scope !== scope || typeof cursor.offset !== 'string' || !/^\d+$/.test(cursor.offset))) {
|
|
22
|
+
throw new AuditStop('cursor-invalidated');
|
|
23
|
+
}
|
|
24
|
+
if (cursor && cursor.fingerprint !== fingerprint)
|
|
25
|
+
throw new AuditStop('tracker-changed');
|
|
26
|
+
const result = await provider.listIssues({ limit: size, cursor: cursor?.offset,
|
|
27
|
+
filter: { status: filter.status === 'all' ? undefined : filter.status, labels: filter.labels } });
|
|
28
|
+
if (auditDigest(await readFile(join(root, 'index/issues.index.json'), 'utf8')) !== fingerprint)
|
|
29
|
+
throw new AuditStop('tracker-changed');
|
|
30
|
+
const items = result.issues.map(i => ({ id: i.id, title: i.title, status: i.status,
|
|
31
|
+
labels: [...i.labels, i.type, i.priority], updatedAt: i.updated_at }));
|
|
32
|
+
const bytes = auditBytes(items);
|
|
33
|
+
if (bytes > options.maxBytes)
|
|
34
|
+
throw new AuditStop('byte-budget');
|
|
35
|
+
return { items, bytes, complete: !result.nextCursor,
|
|
36
|
+
nextCursor: result.nextCursor ? encodeAuditCursor({ scope, fingerprint, offset: result.nextCursor }) : null };
|
|
37
|
+
},
|
|
38
|
+
async hydrate(issue, options) {
|
|
39
|
+
options.signal?.throwIfAborted();
|
|
40
|
+
if (!/^[A-Z][A-Z0-9]*-\d+$/.test(issue.id))
|
|
41
|
+
throw new AuditStop('invalid-issue-id');
|
|
42
|
+
// Preflight the selected files before the existing reader loads any bodies.
|
|
43
|
+
let bytes = 0;
|
|
44
|
+
const account = async (file) => {
|
|
45
|
+
const size = await stat(file).then(s => s.size).catch((error) => {
|
|
46
|
+
if (error.code === 'ENOENT')
|
|
47
|
+
return 0;
|
|
48
|
+
throw error;
|
|
49
|
+
});
|
|
50
|
+
bytes += size;
|
|
51
|
+
if (bytes > options.maxBytes)
|
|
52
|
+
throw new AuditStop('byte-budget');
|
|
53
|
+
};
|
|
54
|
+
await account(join(root, 'items', `${issue.id}.md`));
|
|
55
|
+
const eventsPath = join(root, 'events', `${issue.id}.jsonl`);
|
|
56
|
+
await account(eventsPath);
|
|
57
|
+
const events = await readFile(eventsPath, 'utf8').catch((error) => {
|
|
58
|
+
if (error.code === 'ENOENT')
|
|
59
|
+
return '';
|
|
60
|
+
throw error;
|
|
61
|
+
});
|
|
62
|
+
for (const line of events.split(/\r?\n/).filter(Boolean)) {
|
|
63
|
+
const event = JSON.parse(line);
|
|
64
|
+
if (!event.body_path)
|
|
65
|
+
continue;
|
|
66
|
+
const file = resolve(root, event.body_path);
|
|
67
|
+
if (!file.startsWith(resolve(root) + sep))
|
|
68
|
+
throw new AuditStop('invalid-comment-path');
|
|
69
|
+
await account(file);
|
|
70
|
+
}
|
|
71
|
+
const record = await provider.getIssue(issue.id, { body: true, comments: 'all' });
|
|
72
|
+
if (record.fields.updated_at !== issue.updatedAt)
|
|
73
|
+
throw new AuditStop('tracker-changed');
|
|
74
|
+
const content = { body: record.body, comments: record.events.filter(e => e.type === 'comment').map(e => e.body ?? '') };
|
|
75
|
+
bytes = Math.max(bytes, auditBytes(content));
|
|
76
|
+
if (bytes > options.maxBytes)
|
|
77
|
+
throw new AuditStop('byte-budget');
|
|
78
|
+
return { ...content, bytes };
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=audit-local.js.map
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Execute bounded audit batches with atomic, content-minimized item checkpoints.
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { atomicConfigWrite } from '../config/worker-write.js';
|
|
4
|
+
import { acquireDirectoryLock, DirectoryLockContentionError } from '../artifacts/prebuilt-build-lock.js';
|
|
5
|
+
import { ForgeReadError } from '../tracker/forge-http.js';
|
|
6
|
+
import { AuditStop, auditDigest, auditBytes, boundedPageSize, parseAuditFilter, } from './audit-contract.js';
|
|
7
|
+
export const needsAuditContent = (issue) => /\b(epic|deferred|duplicate|superseded|fixed)\b/i.test(`${issue.title} ${issue.labels.join(' ')}`);
|
|
8
|
+
/** Deterministic triage candidates; deeper semantic conclusions belong to the auditor. */
|
|
9
|
+
export function auditFinding(issue, content) {
|
|
10
|
+
const text = `${issue.title} ${issue.labels.join(' ')}`;
|
|
11
|
+
const references = content && /(?:#\d+|[A-Z][A-Z0-9]*-\d+)/.test(`${content.body}\n${content.comments.join('\n')}`);
|
|
12
|
+
if (/\b(blocker|critical|P[01])\b/i.test(text))
|
|
13
|
+
return { id: issue.id, category: 'High Priority', recommendation: 'Review blocker for address-issues' };
|
|
14
|
+
if (/\bepic\b/i.test(text))
|
|
15
|
+
return { id: issue.id, category: 'Epic Hygiene', recommendation: references
|
|
16
|
+
? 'Check linked child status and acceptance against current issues' : 'Add child issue references before checking epic completion' };
|
|
17
|
+
if (/\b(duplicate|overlap)\b/i.test(text))
|
|
18
|
+
return { id: issue.id, category: 'Duplicate / Relationship Candidates', recommendation: references
|
|
19
|
+
? 'Verify overlap with referenced issues before recommending cleanup' : 'Identify a related issue before recommending duplicate cleanup' };
|
|
20
|
+
if (/\b(deferred|superseded|fixed)\b/i.test(text))
|
|
21
|
+
return { id: issue.id, category: 'Cleanup Candidates', recommendation: content && !/\b\d{4}-\d{2}-\d{2}\b/.test(`${content.body}\n${content.comments.join('\n')}`)
|
|
22
|
+
? 'Add a follow-up date and verify the cleanup decision' : 'Verify cleanup decision and follow-up date' };
|
|
23
|
+
return { id: issue.id, category: 'Next Actions', recommendation: content && !content.body.trim()
|
|
24
|
+
? 'Add issue context and acceptance criteria' : 'Review priority and scope before address-issues' };
|
|
25
|
+
}
|
|
26
|
+
async function loadCheckpoint(file, scope) {
|
|
27
|
+
let raw;
|
|
28
|
+
try {
|
|
29
|
+
raw = await readFile(file, 'utf8');
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error.code !== 'ENOENT')
|
|
33
|
+
throw error;
|
|
34
|
+
return { version: 1, scope, cursor: null, pending: [], pageComplete: false, finished: false,
|
|
35
|
+
completed: [], findings: [], totalSeen: 0, totalHydrated: 0 };
|
|
36
|
+
}
|
|
37
|
+
let value;
|
|
38
|
+
try {
|
|
39
|
+
value = JSON.parse(raw);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw new AuditStop('checkpoint-invalid');
|
|
43
|
+
}
|
|
44
|
+
if (!value || value.version !== 1 || value.scope !== scope || !Array.isArray(value.completed)
|
|
45
|
+
|| !Array.isArray(value.pending) || !Array.isArray(value.findings)
|
|
46
|
+
|| typeof value.finished !== 'boolean' || typeof value.pageComplete !== 'boolean'
|
|
47
|
+
|| !(value.cursor === null || typeof value.cursor === 'string')
|
|
48
|
+
|| !Number.isSafeInteger(value.totalSeen) || value.totalSeen < 0
|
|
49
|
+
|| !Number.isSafeInteger(value.totalHydrated) || value.totalHydrated < 0
|
|
50
|
+
|| value.totalHydrated > value.completed.length || value.totalSeen < value.completed.length
|
|
51
|
+
|| new Set(value.completed).size !== value.completed.length
|
|
52
|
+
|| value.completed.some(id => typeof id !== 'string')
|
|
53
|
+
|| value.pending.some(i => !i || typeof i.id !== 'string' || typeof i.title !== 'string'
|
|
54
|
+
|| typeof i.status !== 'string' || typeof i.updatedAt !== 'string' || !Array.isArray(i.labels)
|
|
55
|
+
|| i.labels.some(l => typeof l !== 'string') || value.completed.includes(i.id))
|
|
56
|
+
|| new Set(value.pending.map(i => i.id)).size !== value.pending.length
|
|
57
|
+
|| value.totalSeen !== value.completed.length + value.pending.length
|
|
58
|
+
|| (value.finished && (value.pending.length > 0 || !value.pageComplete || value.cursor !== null))
|
|
59
|
+
|| value.findings.length !== value.completed.length
|
|
60
|
+
|| value.findings.some((f, i) => !f || f.id !== value.completed[i] || typeof f.recommendation !== 'string')) {
|
|
61
|
+
throw new AuditStop(value?.scope !== scope ? 'checkpoint-scope-mismatch' : 'checkpoint-invalid');
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
export async function runIssueAudit(tracker, options) {
|
|
66
|
+
const pageSize = boundedPageSize(options.pageSize ?? 25);
|
|
67
|
+
const maxItems = options.maxItems ?? 250;
|
|
68
|
+
const maxPages = options.maxPages ?? 100;
|
|
69
|
+
const maxBytes = options.maxBytes ?? 65_536;
|
|
70
|
+
const maxContext = options.maxContextBytes ?? 262_144;
|
|
71
|
+
for (const bound of [maxItems, maxPages, maxBytes, maxContext]) {
|
|
72
|
+
if (!Number.isSafeInteger(bound) || bound < 1)
|
|
73
|
+
throw new AuditStop('invalid-budget');
|
|
74
|
+
}
|
|
75
|
+
const filter = options.filter ?? 'status:open';
|
|
76
|
+
const guidance = options.guidance ?? '';
|
|
77
|
+
parseAuditFilter(filter);
|
|
78
|
+
if ((options.select || options.analyze) && !options.policyKey)
|
|
79
|
+
throw new AuditStop('policy-key-required');
|
|
80
|
+
const scope = auditDigest([tracker.identity, filter, guidance, pageSize, options.policyKey ?? 'metadata-triage-v1']);
|
|
81
|
+
let release;
|
|
82
|
+
try {
|
|
83
|
+
release = await acquireDirectoryLock(`${options.checkpoint}.lock`, { timeoutMs: 0, reclaimDeadOwner: true });
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error instanceof DirectoryLockContentionError)
|
|
87
|
+
throw new AuditStop('checkpoint-busy');
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
return await execute();
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
await release();
|
|
95
|
+
}
|
|
96
|
+
async function execute() {
|
|
97
|
+
let state = await loadCheckpoint(options.checkpoint, scope);
|
|
98
|
+
let durable = structuredClone(state);
|
|
99
|
+
const save = async () => {
|
|
100
|
+
try {
|
|
101
|
+
await atomicConfigWrite(options.checkpoint, `${JSON.stringify(state)}\n`);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
throw new AuditStop('checkpoint-write-error');
|
|
105
|
+
}
|
|
106
|
+
durable = structuredClone(state);
|
|
107
|
+
};
|
|
108
|
+
const completed = new Set(state.completed);
|
|
109
|
+
const batches = [];
|
|
110
|
+
const visited = new Set();
|
|
111
|
+
let contextBytes = 0;
|
|
112
|
+
let processed = 0;
|
|
113
|
+
let reason = null;
|
|
114
|
+
let batch = { items: 0, bytes: 0 };
|
|
115
|
+
await save();
|
|
116
|
+
try {
|
|
117
|
+
while (!state.finished) {
|
|
118
|
+
if (options.signal?.aborted)
|
|
119
|
+
throw new AuditStop('interrupted');
|
|
120
|
+
if (processed >= maxItems)
|
|
121
|
+
throw new AuditStop('item-budget');
|
|
122
|
+
if (!state.pending.length) {
|
|
123
|
+
if (batches.length >= maxPages)
|
|
124
|
+
throw new AuditStop('page-budget');
|
|
125
|
+
if (visited.has(state.cursor))
|
|
126
|
+
throw new AuditStop('cursor-invalidated');
|
|
127
|
+
if (contextBytes >= maxContext)
|
|
128
|
+
throw new AuditStop('context-budget');
|
|
129
|
+
const available = Math.min(maxBytes, maxContext - contextBytes);
|
|
130
|
+
const page = await tracker.listMetadata({ cursor: state.cursor, pageSize, maxBytes: available, filter, signal: options.signal })
|
|
131
|
+
.catch(error => { if (error instanceof AuditStop && error.reason === 'byte-budget' && available < maxBytes)
|
|
132
|
+
throw new AuditStop('context-budget'); throw error; });
|
|
133
|
+
if (page.items.length > pageSize || page.bytes > maxBytes)
|
|
134
|
+
throw new AuditStop('byte-budget');
|
|
135
|
+
if (page.bytes > maxContext - contextBytes)
|
|
136
|
+
throw new AuditStop('context-budget');
|
|
137
|
+
if (page.nextCursor !== null && page.nextCursor === state.cursor)
|
|
138
|
+
throw new AuditStop('cursor-invalidated');
|
|
139
|
+
if (!page.complete && page.nextCursor === null)
|
|
140
|
+
throw new AuditStop('pagination-incomplete');
|
|
141
|
+
const unique = new Map(page.items.filter(i => !completed.has(i.id)).map(i => [i.id, i]));
|
|
142
|
+
visited.add(state.cursor);
|
|
143
|
+
state.pending = [...unique.values()];
|
|
144
|
+
state.totalSeen += state.pending.length;
|
|
145
|
+
state.cursor = page.nextCursor;
|
|
146
|
+
state.pageComplete = page.complete;
|
|
147
|
+
batch = { items: 0, bytes: page.bytes };
|
|
148
|
+
batches.push(batch);
|
|
149
|
+
contextBytes += page.bytes;
|
|
150
|
+
state.finished = !state.pending.length && state.pageComplete;
|
|
151
|
+
await save();
|
|
152
|
+
if (!state.pending.length)
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
else if (!batches.length) {
|
|
156
|
+
batch = { items: 0, bytes: auditBytes(state.pending) };
|
|
157
|
+
if (batch.bytes > maxBytes)
|
|
158
|
+
throw new AuditStop('byte-budget');
|
|
159
|
+
contextBytes += batch.bytes;
|
|
160
|
+
batches.push(batch);
|
|
161
|
+
}
|
|
162
|
+
const issue = state.pending[0];
|
|
163
|
+
const metadataBytes = auditBytes(issue);
|
|
164
|
+
if (contextBytes + metadataBytes > maxContext)
|
|
165
|
+
throw new AuditStop('context-budget');
|
|
166
|
+
let content;
|
|
167
|
+
if ((options.select ?? needsAuditContent)(issue)) {
|
|
168
|
+
const remaining = Math.min(maxBytes - batch.bytes, maxContext - contextBytes - metadataBytes);
|
|
169
|
+
if (remaining < 1)
|
|
170
|
+
throw new AuditStop(batch.bytes >= maxBytes ? 'byte-budget' : 'context-budget');
|
|
171
|
+
content = await tracker.hydrate(issue, { maxBytes: remaining, signal: options.signal })
|
|
172
|
+
.catch(error => { if (error instanceof AuditStop && error.reason === 'byte-budget' && remaining < maxBytes - batch.bytes)
|
|
173
|
+
throw new AuditStop('context-budget'); throw error; });
|
|
174
|
+
if (content.bytes > remaining)
|
|
175
|
+
throw new AuditStop('byte-budget');
|
|
176
|
+
}
|
|
177
|
+
const finding = (options.analyze ?? auditFinding)(issue, content);
|
|
178
|
+
if (finding.id !== issue.id)
|
|
179
|
+
throw new AuditStop('finding-id-mismatch');
|
|
180
|
+
state.completed.push(issue.id);
|
|
181
|
+
completed.add(issue.id);
|
|
182
|
+
state.findings.push(finding);
|
|
183
|
+
state.totalHydrated += Number(!!content);
|
|
184
|
+
state.pending.shift();
|
|
185
|
+
state.finished = !state.pending.length && state.pageComplete;
|
|
186
|
+
batch.items++;
|
|
187
|
+
batch.bytes += content?.bytes ?? 0;
|
|
188
|
+
contextBytes += metadataBytes + (content?.bytes ?? 0);
|
|
189
|
+
processed++;
|
|
190
|
+
await save();
|
|
191
|
+
options.afterItem?.(issue.id);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
state = durable;
|
|
196
|
+
reason = options.signal?.aborted ? 'interrupted' : error instanceof AuditStop ? error.reason
|
|
197
|
+
: error instanceof ForgeReadError ? (error.code === 'oversized' ? 'byte-budget' : `tracker-${error.code}`) : 'tracker-error';
|
|
198
|
+
}
|
|
199
|
+
return { mode: 'read-only', guidance,
|
|
200
|
+
coverage: { totalSeen: state.totalSeen, totalHydrated: state.totalHydrated, totalCompleted: state.completed.length,
|
|
201
|
+
incomplete: reason !== null || !state.finished, reason },
|
|
202
|
+
continuation: { checkpoint: options.checkpoint, cursor: state.cursor, pending: state.pending.length },
|
|
203
|
+
batches, findings: state.findings };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export function renderIssueAudit(report) {
|
|
207
|
+
const { coverage: c } = report;
|
|
208
|
+
const lines = ['# Issue Audit', '', 'Mode: read-only', `Guidance: ${report.guidance || 'none'}`, '',
|
|
209
|
+
`Coverage: ${c.incomplete ? `INCOMPLETE (${c.reason ?? 'unfinished'})` : 'complete'}`,
|
|
210
|
+
`Total seen: ${c.totalSeen}; hydrated: ${c.totalHydrated}; completed: ${c.totalCompleted}`, '', '## Findings'];
|
|
211
|
+
for (const category of ['High Priority', 'Cleanup Candidates', 'Epic Hygiene', 'Duplicate / Relationship Candidates', 'Next Actions']) {
|
|
212
|
+
lines.push('', `### ${category}`);
|
|
213
|
+
for (const finding of report.findings.filter(f => f.category === category))
|
|
214
|
+
lines.push(`- ${finding.id} — ${finding.recommendation}`);
|
|
215
|
+
}
|
|
216
|
+
if (c.incomplete)
|
|
217
|
+
lines.push('', `Resume with checkpoint: ${report.continuation.checkpoint}`);
|
|
218
|
+
return `${lines.join('\n')}\n`;
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -6,12 +6,14 @@ import { resolveRuleBindingTarget } from '../artifacts/query-engine.js';
|
|
|
6
6
|
import { collectRuleBindingEntries } from '../artifacts/index-builder.js';
|
|
7
7
|
import { resolveFrameworkIndexRoot } from '../artifacts/framework-index-paths.js';
|
|
8
8
|
import { parseRuleFrontmatter, RULE_BINDING_TYPES, coreBodyPath, validateCoreBody } from '../rules/activation.mjs';
|
|
9
|
+
import { buildGatesRegistry } from '../gates/driver.js';
|
|
10
|
+
import { ruleGateReferenceErrors } from '../rules/gate-references.js';
|
|
9
11
|
export const ruleActivationRuleset = {
|
|
10
12
|
id: 'rule-activation', name: 'Rule activation', framework: 'core', version: '1.0.0',
|
|
11
13
|
description: 'Validate rule and behavior activation contracts and exact source bindings',
|
|
12
14
|
rules: [{
|
|
13
15
|
id: 'rules/activation', name: 'Rule activation contract', severity: 'error',
|
|
14
|
-
description: 'Validate activation, summaries, paths, bindings, and migration fallback',
|
|
16
|
+
description: 'Validate activation, summaries, paths, bindings, gate references, and migration fallback',
|
|
15
17
|
appliesTo: { glob: '**/{rules/**/*.md,behaviors/**/BEHAVIOR.md}' },
|
|
16
18
|
checks: [{ type: 'rule-activation' }],
|
|
17
19
|
}],
|
|
@@ -38,6 +40,18 @@ export function lintRuleActivation(content, file, projectRoot, entries = [], abs
|
|
|
38
40
|
}));
|
|
39
41
|
if (!result.rule)
|
|
40
42
|
return diagnostics;
|
|
43
|
+
if (result.rule.enforcedBy?.length) {
|
|
44
|
+
let errors;
|
|
45
|
+
try {
|
|
46
|
+
const { registry } = buildGatesRegistry({ cwd: projectRoot, aiwgRoot: resolveFrameworkIndexRoot(projectRoot) });
|
|
47
|
+
errors = ruleGateReferenceErrors(result.rule.enforcedBy, registry);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
errors = [`enforcedBy registry: ${error instanceof Error ? error.message : String(error)}`];
|
|
51
|
+
}
|
|
52
|
+
for (const message of errors)
|
|
53
|
+
diagnostics.push({ ruleId: 'rules/activation', ruleName: 'Rule activation contract', file, severity: 'error', message });
|
|
54
|
+
}
|
|
41
55
|
if (result.rule.activation === 'core') {
|
|
42
56
|
const body = coreBodyPath(absolutePath ?? (path.isAbsolute(file) ? file : path.resolve(projectRoot, file)));
|
|
43
57
|
const problems = fs.existsSync(body)
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// Canonical Mission projections and legacy transport codecs.
|
|
2
|
+
import { assertMissionWorkerHandoff } from './codecs.js';
|
|
3
|
+
import { MISSION_API_VERSION } from './types.js';
|
|
4
|
+
const TERMINAL = new Set(['completed', 'failed', 'incomplete', 'cancelled']);
|
|
5
|
+
function object(value, label = 'Mission input') {
|
|
6
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
7
|
+
throw new Error(`${label} must be an object.`);
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function string(value) {
|
|
11
|
+
return typeof value === 'string' && value.length ? value : undefined;
|
|
12
|
+
}
|
|
13
|
+
function requiredId(record) {
|
|
14
|
+
const metadata = record.metadata && typeof record.metadata === 'object' ? record.metadata : {};
|
|
15
|
+
const id = string(record.missionId) ?? string(record.mission_id) ?? string(record.id)
|
|
16
|
+
?? string(record.taskId) ?? string(record.task_id) ?? string(record.responseId) ?? string(metadata.id);
|
|
17
|
+
if (!id)
|
|
18
|
+
throw new Error('Mission source is missing a stable identifier.');
|
|
19
|
+
return id;
|
|
20
|
+
}
|
|
21
|
+
export function normalizeMissionState(nativeState) {
|
|
22
|
+
const state = String(nativeState ?? 'unknown').toLowerCase().replace(/_/g, '-');
|
|
23
|
+
if (['done', 'completed', 'succeeded', 'success'].includes(state))
|
|
24
|
+
return 'completed';
|
|
25
|
+
if (['aborted', 'cancelled', 'canceled'].includes(state))
|
|
26
|
+
return 'cancelled';
|
|
27
|
+
if (['failed', 'error', 'rejected', 'timed-out'].includes(state))
|
|
28
|
+
return 'failed';
|
|
29
|
+
if (['incomplete', 'budget-exhausted', 'max-iterations', 'max-tokens'].includes(state))
|
|
30
|
+
return 'incomplete';
|
|
31
|
+
if (['running', 'in-progress', 'working', 'started', 'assigned', 'admitted', 'starting'].includes(state))
|
|
32
|
+
return 'running';
|
|
33
|
+
if (['pending', 'submitted', 'queued', 'runnable', 'scheduled'].includes(state))
|
|
34
|
+
return 'pending';
|
|
35
|
+
if (['blocked', 'blocked-hitl', 'input-required', 'auth-required', 'paused', 'suspended'].includes(state))
|
|
36
|
+
return 'blocked';
|
|
37
|
+
if (['operator-review', 'operator-review-required', 'manual-review'].includes(state))
|
|
38
|
+
return 'operator-review';
|
|
39
|
+
if (['unknown', 'disconnected', 'detached', 'unreachable'].includes(state))
|
|
40
|
+
return 'unknown';
|
|
41
|
+
return 'unknown';
|
|
42
|
+
}
|
|
43
|
+
function knownKeysFor(source) {
|
|
44
|
+
const common = ['id', 'missionId', 'mission_id', 'taskId', 'task_id', 'responseId', 'title', 'goal', 'objective', 'prompt', 'completion', 'completionCriterion', 'completion_criterion', 'status', 'state', 'nativeState', 'createdAt', 'created_at', 'updatedAt', 'updated_at', 'metadata', 'spec', 'provenance', 'extensions', 'artifacts', 'output', 'partialOutput', 'error', 'checkpoint', 'cycles', 'activityLog', 'totalCost', 'runtimesUsed', 'apiVersion', 'api_version', 'schemaVersion', 'schema_version', 'kind', 'session_id', 'previous_response_id'];
|
|
45
|
+
if (source === 'uhp-2026-08-11')
|
|
46
|
+
common.push('object', 'model', 'incomplete_details', 'store', 'usage');
|
|
47
|
+
return new Set(common);
|
|
48
|
+
}
|
|
49
|
+
function extensions(record, source) {
|
|
50
|
+
const explicit = record.extensions && typeof record.extensions === 'object' ? structuredClone(record.extensions) : {};
|
|
51
|
+
if (record.metadata && typeof record.metadata === 'object')
|
|
52
|
+
explicit.metadata = structuredClone(record.metadata);
|
|
53
|
+
if (record.status && typeof record.status === 'object')
|
|
54
|
+
explicit.nativeStatus = structuredClone(record.status);
|
|
55
|
+
for (const [key, value] of Object.entries(record))
|
|
56
|
+
if (!knownKeysFor(source).has(key))
|
|
57
|
+
explicit[key] = structuredClone(value);
|
|
58
|
+
return explicit;
|
|
59
|
+
}
|
|
60
|
+
function artifacts(record) {
|
|
61
|
+
const values = Array.isArray(record.artifacts) ? record.artifacts : [];
|
|
62
|
+
return values.flatMap((item, index) => {
|
|
63
|
+
if (!item || typeof item !== 'object')
|
|
64
|
+
return [];
|
|
65
|
+
const artifact = item;
|
|
66
|
+
const id = string(artifact.id) ?? string(artifact.fileId) ?? string(artifact.file_id) ?? string(artifact.uri) ?? `artifact-${index}`;
|
|
67
|
+
return [{
|
|
68
|
+
id,
|
|
69
|
+
kind: string(artifact.kind) ?? 'other',
|
|
70
|
+
...(string(artifact.uri) ? { uri: string(artifact.uri) } : {}),
|
|
71
|
+
...(string(artifact.sha256) ? { sha256: string(artifact.sha256) } : {}),
|
|
72
|
+
...(string(artifact.mediaType) ?? string(artifact.media_type) ? { mediaType: string(artifact.mediaType) ?? string(artifact.media_type) } : {}),
|
|
73
|
+
extensions: structuredClone(artifact),
|
|
74
|
+
}];
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function uhpOutputArtifacts(record) {
|
|
78
|
+
const found = new Map();
|
|
79
|
+
function visit(value) {
|
|
80
|
+
if (Array.isArray(value)) {
|
|
81
|
+
value.forEach(visit);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (!value || typeof value !== 'object')
|
|
85
|
+
return;
|
|
86
|
+
const item = value;
|
|
87
|
+
const id = string(item.file_id);
|
|
88
|
+
if (id)
|
|
89
|
+
found.set(id, { id, kind: 'uhp-file', ...(string(item.media_type) ? { mediaType: string(item.media_type) } : {}), extensions: { 'uhp.file': structuredClone(item) } });
|
|
90
|
+
Object.values(item).forEach(visit);
|
|
91
|
+
}
|
|
92
|
+
visit(record.output);
|
|
93
|
+
return [...found.values()];
|
|
94
|
+
}
|
|
95
|
+
function nativeStateFor(source, record, statusRecord) {
|
|
96
|
+
const explicit = string(statusRecord.state) ?? string(record.nativeState) ?? string(record.status)
|
|
97
|
+
?? string(record.state) ?? string(record.observed_state) ?? string(record.observedState) ?? string(record.nodeState);
|
|
98
|
+
if (explicit)
|
|
99
|
+
return explicit;
|
|
100
|
+
if (source === 'mission-ledger' && record.checkpoint && typeof record.checkpoint === 'object') {
|
|
101
|
+
const checkpoint = record.checkpoint;
|
|
102
|
+
if (Array.isArray(checkpoint.pending) && checkpoint.pending.length)
|
|
103
|
+
return 'running';
|
|
104
|
+
if (Array.isArray(checkpoint.failed) && checkpoint.failed.length)
|
|
105
|
+
return 'failed';
|
|
106
|
+
if (Array.isArray(checkpoint.completed) && checkpoint.completed.length)
|
|
107
|
+
return 'completed';
|
|
108
|
+
}
|
|
109
|
+
return 'unknown';
|
|
110
|
+
}
|
|
111
|
+
function sourceVersion(source, record) {
|
|
112
|
+
if (source === 'canonical')
|
|
113
|
+
return string(record.apiVersion) ?? 'unknown';
|
|
114
|
+
if (source === 'uhp-2026-08-11')
|
|
115
|
+
return '2026-08-11';
|
|
116
|
+
if (source === 'executor-v1')
|
|
117
|
+
return 'executor.aiwg.io/v1';
|
|
118
|
+
if (source === 'fleet-workload-v1')
|
|
119
|
+
return 'fleet-workload/v1';
|
|
120
|
+
if (source === 'graph-flow-v1')
|
|
121
|
+
return 'graph.flow.aiwg.io/v1';
|
|
122
|
+
if (source === 'activity-v1')
|
|
123
|
+
return 'activity.aiwg.io/v1';
|
|
124
|
+
return string(record.apiVersion) ?? string(record.api_version) ?? string(record.schemaVersion) ?? string(record.schema_version) ?? 'unversioned';
|
|
125
|
+
}
|
|
126
|
+
function assertSupported(version) {
|
|
127
|
+
const supported = new Set(['unversioned', MISSION_API_VERSION, '2026-08-11', 'executor.aiwg.io/v1', 'fleet-workload/v1', 'graph.flow.aiwg.io/v1', 'activity.aiwg.io/v1']);
|
|
128
|
+
if (supported.has(version))
|
|
129
|
+
return;
|
|
130
|
+
const major = version.match(/(?:^|\/)v(\d+)(?:$|[.-])/)?.[1];
|
|
131
|
+
if (major && major !== '1')
|
|
132
|
+
throw new Error(`Unsupported Mission source major version '${version}'; supported major is v1.`);
|
|
133
|
+
throw new Error(`Unsupported Mission source version '${version}'.`);
|
|
134
|
+
}
|
|
135
|
+
export function validateCanonicalMission(value) {
|
|
136
|
+
const record = object(value, 'Canonical Mission');
|
|
137
|
+
assertMissionWorkerHandoff(record, 'canonical');
|
|
138
|
+
if (record.apiVersion !== MISSION_API_VERSION)
|
|
139
|
+
throw new Error(`Unsupported canonical Mission version '${String(record.apiVersion)}'.`);
|
|
140
|
+
if (record.kind !== 'Mission')
|
|
141
|
+
throw new Error("Canonical Mission kind must be 'Mission'.");
|
|
142
|
+
const metadata = object(record.metadata, 'Mission metadata');
|
|
143
|
+
const spec = object(record.spec, 'Mission spec');
|
|
144
|
+
const status = object(record.status, 'Mission status');
|
|
145
|
+
const provenance = object(record.provenance, 'Mission provenance');
|
|
146
|
+
if (!string(metadata.id) || !string(spec.objective) || !string(provenance.sourceContract) || !string(provenance.sourceVersion))
|
|
147
|
+
throw new Error('Canonical Mission is missing required identity, objective, or provenance.');
|
|
148
|
+
const state = normalizeMissionState(status.state);
|
|
149
|
+
if (status.state !== state)
|
|
150
|
+
throw new Error(`Canonical Mission state '${String(status.state)}' is not normalized.`);
|
|
151
|
+
if (status.terminal !== TERMINAL.has(state))
|
|
152
|
+
throw new Error(`Canonical Mission terminal flag contradicts state '${state}'.`);
|
|
153
|
+
if (!Array.isArray(status.artifacts))
|
|
154
|
+
throw new Error('Canonical Mission artifacts must be an array.');
|
|
155
|
+
return structuredClone(value);
|
|
156
|
+
}
|
|
157
|
+
export function decodeMission(input, source, workerConsumer) {
|
|
158
|
+
const record = object(input);
|
|
159
|
+
assertMissionWorkerHandoff(record, source, workerConsumer);
|
|
160
|
+
if (source === 'canonical') {
|
|
161
|
+
const value = validateCanonicalMission(record);
|
|
162
|
+
return { value, sourceVersion: MISSION_API_VERSION, warnings: [], preservedExtensions: structuredClone(value.extensions ?? {}), lossReport: [] };
|
|
163
|
+
}
|
|
164
|
+
const version = sourceVersion(source, record);
|
|
165
|
+
assertSupported(version);
|
|
166
|
+
const statusRecord = record.status && typeof record.status === 'object' ? record.status : {};
|
|
167
|
+
const nativeState = nativeStateFor(source, record, statusRecord);
|
|
168
|
+
const state = normalizeMissionState(nativeState);
|
|
169
|
+
const objective = string(record.goal) ?? string(record.objective) ?? string(record.title) ?? string(record.prompt) ?? '(legacy mission objective unavailable)';
|
|
170
|
+
const completionCriterion = string(record.completionCriterion) ?? string(record.completion_criterion) ?? string(record.completion);
|
|
171
|
+
const preserved = extensions(record, source);
|
|
172
|
+
const warnings = [];
|
|
173
|
+
const lossReport = [];
|
|
174
|
+
if (objective.startsWith('(legacy'))
|
|
175
|
+
warnings.push('Source did not contain a mission objective; placeholder retained.');
|
|
176
|
+
if (state === 'unknown' && nativeState !== 'unknown')
|
|
177
|
+
warnings.push(`Unknown native state '${nativeState}' preserved beside normalized unknown state.`);
|
|
178
|
+
const sourceArtifacts = artifacts(record);
|
|
179
|
+
if (source === 'uhp-2026-08-11') {
|
|
180
|
+
const ids = new Set(sourceArtifacts.map(artifact => artifact.id));
|
|
181
|
+
for (const artifact of uhpOutputArtifacts(record))
|
|
182
|
+
if (!ids.has(artifact.id))
|
|
183
|
+
sourceArtifacts.push(artifact);
|
|
184
|
+
}
|
|
185
|
+
const budgets = record.budgets && typeof record.budgets === 'object' ? record.budgets : undefined;
|
|
186
|
+
const lineage = Array.isArray(record.lineage) ? record.lineage.flatMap(item => {
|
|
187
|
+
if (!item || typeof item !== 'object')
|
|
188
|
+
return [];
|
|
189
|
+
const entry = item;
|
|
190
|
+
return string(entry.relation) && string(entry.id) ? [{ relation: string(entry.relation), id: string(entry.id) }] : [];
|
|
191
|
+
}) : undefined;
|
|
192
|
+
const value = {
|
|
193
|
+
apiVersion: MISSION_API_VERSION,
|
|
194
|
+
kind: 'Mission',
|
|
195
|
+
metadata: {
|
|
196
|
+
id: requiredId(record),
|
|
197
|
+
...(string(record.createdAt) ?? string(record.created_at) ? { createdAt: string(record.createdAt) ?? string(record.created_at) } : {}),
|
|
198
|
+
...(string(record.updatedAt) ?? string(record.updated_at) ? { updatedAt: string(record.updatedAt) ?? string(record.updated_at) } : {}),
|
|
199
|
+
...(string(record.previous_response_id) ? { previousId: string(record.previous_response_id) } : {}),
|
|
200
|
+
...(lineage?.length ? { lineage } : {}),
|
|
201
|
+
},
|
|
202
|
+
spec: { objective, ...(completionCriterion ? { completionCriterion } : {}), ...(budgets ? { budgets: structuredClone(budgets) } : {}) },
|
|
203
|
+
status: {
|
|
204
|
+
state,
|
|
205
|
+
terminal: TERMINAL.has(state),
|
|
206
|
+
nativeState,
|
|
207
|
+
artifacts: sourceArtifacts,
|
|
208
|
+
...(record.output !== undefined || record.partialOutput !== undefined || record.partial_output !== undefined ? { partialOutput: structuredClone(record.partialOutput ?? record.partial_output ?? record.output) } : {}),
|
|
209
|
+
},
|
|
210
|
+
provenance: { sourceContract: source, sourceVersion: version, ...(source === 'a2a' || source.startsWith('uhp') ? { transport: source.split('-')[0] } : {}), sourceId: requiredId(record) },
|
|
211
|
+
...(Object.keys(preserved).length ? { extensions: { [`aiwg.source.${source}`]: preserved } } : {}),
|
|
212
|
+
};
|
|
213
|
+
return { value, sourceVersion: version, warnings, preservedExtensions: preserved, lossReport };
|
|
214
|
+
}
|
|
215
|
+
function projectionLosses(value, target) {
|
|
216
|
+
const losses = [];
|
|
217
|
+
if (value.status.verification?.length)
|
|
218
|
+
losses.push({ path: '/status/verification', reason: `${target} has no native verification ledger`, severity: 'warning' });
|
|
219
|
+
if (value.metadata.lineage?.length && !['mission-ledger', 'fleet-workload-v1', 'canonical'].includes(target))
|
|
220
|
+
losses.push({ path: '/metadata/lineage', reason: `${target} cannot represent full lineage`, severity: 'required' });
|
|
221
|
+
if (value.spec.budgets && !['fleet-workload-v1', 'canonical'].includes(target))
|
|
222
|
+
losses.push({ path: '/spec/budgets', reason: `${target} cannot represent every canonical budget`, severity: 'warning' });
|
|
223
|
+
return losses;
|
|
224
|
+
}
|
|
225
|
+
export function encodeMission(value, target, options = {}) {
|
|
226
|
+
assertMissionWorkerHandoff(value, target, options.workerConsumer);
|
|
227
|
+
const mission = validateCanonicalMission(value);
|
|
228
|
+
if (target === 'canonical')
|
|
229
|
+
return { value: mission, targetVersion: MISSION_API_VERSION, warnings: [], lossReport: [] };
|
|
230
|
+
const lossReport = projectionLosses(mission, target);
|
|
231
|
+
const required = lossReport.filter(loss => loss.severity === 'required');
|
|
232
|
+
if (required.length && !options.allowLoss)
|
|
233
|
+
throw new Error(`Projection to ${target} would silently lose required semantics: ${required.map(loss => loss.path).join(', ')}.`);
|
|
234
|
+
const base = {
|
|
235
|
+
missionId: mission.metadata.id,
|
|
236
|
+
goal: mission.spec.objective,
|
|
237
|
+
completionCriterion: mission.spec.completionCriterion,
|
|
238
|
+
status: mission.status.nativeState ?? mission.status.state,
|
|
239
|
+
artifacts: structuredClone(mission.status.artifacts),
|
|
240
|
+
partialOutput: structuredClone(mission.status.partialOutput),
|
|
241
|
+
lineage: structuredClone(mission.metadata.lineage ?? []),
|
|
242
|
+
extensions: {
|
|
243
|
+
'aiwg.mission.canonical': { apiVersion: mission.apiVersion, state: mission.status.state, lossReport },
|
|
244
|
+
...(mission.extensions ?? {}),
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
let projected = base;
|
|
248
|
+
if (target === 'mission-plan')
|
|
249
|
+
projected = { missionId: base.missionId, goal: base.goal, completionCriterion: base.completionCriterion ?? '', cycles: [], extensions: base.extensions };
|
|
250
|
+
else if (target === 'mission-ledger')
|
|
251
|
+
projected = { ...base, activityLog: [], cycles: [], totalCost: 0, checkpoint: { completed: [], pending: [], failed: [] }, runtimesUsed: [] };
|
|
252
|
+
else if (target === 'uhp-2026-08-11')
|
|
253
|
+
projected = { id: mission.provenance.sourceId ?? mission.metadata.id, object: 'response', created_at: 0, status: base.status, model: '', output: mission.status.partialOutput ?? [], metadata: base.extensions };
|
|
254
|
+
else if (target === 'a2a')
|
|
255
|
+
projected = { id: mission.provenance.sourceId ?? mission.metadata.id, status: { state: base.status }, artifacts: base.artifacts, partialOutput: base.partialOutput, metadata: base.extensions };
|
|
256
|
+
else if (target === 'graph-flow-v1')
|
|
257
|
+
projected = { schemaVersion: 'graph.flow.aiwg.io/v1', runId: mission.metadata.id, nodeState: mission.status.state, metadata: base.extensions };
|
|
258
|
+
else if (target === 'cockpit')
|
|
259
|
+
projected = { id: mission.metadata.id, session_id: mission.metadata.id, source: mission.provenance.transport ?? mission.provenance.sourceContract, title: mission.spec.objective, completion: mission.spec.completionCriterion, status: mission.status.state, artifacts: base.artifacts, partialOutput: base.partialOutput, extensions: base.extensions };
|
|
260
|
+
else if (target === 'activity-v1')
|
|
261
|
+
projected = { event: 'mission.projected', missionId: mission.metadata.id, objective: mission.spec.objective, state: mission.status.state, metadata: base.extensions };
|
|
262
|
+
else if (target === 'executor-v1')
|
|
263
|
+
projected = { mission_id: mission.metadata.id, objective: mission.spec.objective, completion_criterion: mission.spec.completionCriterion, state: base.status, artifacts: base.artifacts, partial_output: base.partialOutput, metadata: base.extensions };
|
|
264
|
+
else if (target === 'fleet-workload-v1')
|
|
265
|
+
projected = { mission_id: mission.metadata.id, objective: mission.spec.objective, completion_criterion: mission.spec.completionCriterion, observed_state: base.status, budgets: mission.spec.budgets, artifacts: base.artifacts, partial_output: base.partialOutput, lineage: base.lineage, metadata: base.extensions };
|
|
266
|
+
else if (target === 'mission-control-session')
|
|
267
|
+
projected = { id: mission.metadata.id, objective: mission.spec.objective, status: mission.status.state, completion: mission.spec.completionCriterion, artifacts: base.artifacts, partialOutput: base.partialOutput, extensions: base.extensions };
|
|
268
|
+
return { value: projected, targetVersion: target, warnings: lossReport.map(loss => `${loss.path}: ${loss.reason}`), lossReport };
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=canonical-codecs.js.map
|