@agentic-sdlc-kit/cli 0.0.0-stage → 0.8.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/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/application/agent/execution-store.d.ts +55 -0
- package/dist/application/agent/execution-store.d.ts.map +1 -0
- package/dist/application/agent/execution-store.js +90 -0
- package/dist/application/agent/execution-store.js.map +1 -0
- package/dist/application/agent/gateway.d.ts +74 -0
- package/dist/application/agent/gateway.d.ts.map +1 -0
- package/dist/application/agent/gateway.js +580 -0
- package/dist/application/agent/gateway.js.map +1 -0
- package/dist/application/agent/index.d.ts +6 -0
- package/dist/application/agent/index.d.ts.map +1 -0
- package/dist/application/agent/index.js +18 -0
- package/dist/application/agent/index.js.map +1 -0
- package/dist/application/agent/orchestrator.d.ts +76 -0
- package/dist/application/agent/orchestrator.d.ts.map +1 -0
- package/dist/application/agent/orchestrator.js +422 -0
- package/dist/application/agent/orchestrator.js.map +1 -0
- package/dist/application/agent/providers/claude-code/claude-argv.d.ts +15 -0
- package/dist/application/agent/providers/claude-code/claude-argv.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/claude-argv.js +98 -0
- package/dist/application/agent/providers/claude-code/claude-argv.js.map +1 -0
- package/dist/application/agent/providers/claude-code/index.d.ts +7 -0
- package/dist/application/agent/providers/claude-code/index.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/index.js +13 -0
- package/dist/application/agent/providers/claude-code/index.js.map +1 -0
- package/dist/application/agent/providers/claude-code/mod-parity.d.ts +15 -0
- package/dist/application/agent/providers/claude-code/mod-parity.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/mod-parity.js +41 -0
- package/dist/application/agent/providers/claude-code/mod-parity.js.map +1 -0
- package/dist/application/agent/providers/claude-code/permission-config.d.ts +59 -0
- package/dist/application/agent/providers/claude-code/permission-config.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/permission-config.js +189 -0
- package/dist/application/agent/providers/claude-code/permission-config.js.map +1 -0
- package/dist/application/agent/providers/claude-code/provider.d.ts +38 -0
- package/dist/application/agent/providers/claude-code/provider.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/provider.js +577 -0
- package/dist/application/agent/providers/claude-code/provider.js.map +1 -0
- package/dist/application/agent/providers/claude-code/resume-store.d.ts +25 -0
- package/dist/application/agent/providers/claude-code/resume-store.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/resume-store.js +120 -0
- package/dist/application/agent/providers/claude-code/resume-store.js.map +1 -0
- package/dist/application/agent/providers/claude-code/stream-parser.d.ts +50 -0
- package/dist/application/agent/providers/claude-code/stream-parser.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/stream-parser.js +129 -0
- package/dist/application/agent/providers/claude-code/stream-parser.js.map +1 -0
- package/dist/application/agent/test-fixture.d.ts +15 -0
- package/dist/application/agent/test-fixture.d.ts.map +1 -0
- package/dist/application/agent/test-fixture.js +93 -0
- package/dist/application/agent/test-fixture.js.map +1 -0
- package/dist/application/agent/workspace.d.ts +24 -0
- package/dist/application/agent/workspace.d.ts.map +1 -0
- package/dist/application/agent/workspace.js +139 -0
- package/dist/application/agent/workspace.js.map +1 -0
- package/dist/application/dispatcher.d.ts +13 -0
- package/dist/application/dispatcher.d.ts.map +1 -0
- package/dist/application/dispatcher.js +104 -0
- package/dist/application/dispatcher.js.map +1 -0
- package/dist/application/index.d.ts +5 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +6 -0
- package/dist/application/index.js.map +1 -0
- package/dist/application/registry.d.ts +8 -0
- package/dist/application/registry.d.ts.map +1 -0
- package/dist/application/registry.js +17 -0
- package/dist/application/registry.js.map +1 -0
- package/dist/application/version.d.ts +2 -0
- package/dist/application/version.d.ts.map +1 -0
- package/dist/application/version.js +7 -0
- package/dist/application/version.js.map +1 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +68 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/elicit.d.ts +3 -0
- package/dist/commands/elicit.d.ts.map +1 -0
- package/dist/commands/elicit.js +163 -0
- package/dist/commands/elicit.js.map +1 -0
- package/dist/commands/evolve.d.ts +3 -0
- package/dist/commands/evolve.d.ts.map +1 -0
- package/dist/commands/evolve.js +165 -0
- package/dist/commands/evolve.js.map +1 -0
- package/dist/commands/feature.d.ts +13 -0
- package/dist/commands/feature.d.ts.map +1 -0
- package/dist/commands/feature.js +326 -0
- package/dist/commands/feature.js.map +1 -0
- package/dist/commands/fix.d.ts +3 -0
- package/dist/commands/fix.d.ts.map +1 -0
- package/dist/commands/fix.js +61 -0
- package/dist/commands/fix.js.map +1 -0
- package/dist/commands/help.d.ts +4 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +32 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/index.d.ts +21 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +22 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +90 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/inspect.d.ts +3 -0
- package/dist/commands/inspect.d.ts.map +1 -0
- package/dist/commands/inspect.js +64 -0
- package/dist/commands/inspect.js.map +1 -0
- package/dist/commands/install.d.ts +3 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +329 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/journal.d.ts +3 -0
- package/dist/commands/journal.d.ts.map +1 -0
- package/dist/commands/journal.js +107 -0
- package/dist/commands/journal.js.map +1 -0
- package/dist/commands/memory.d.ts +3 -0
- package/dist/commands/memory.d.ts.map +1 -0
- package/dist/commands/memory.js +85 -0
- package/dist/commands/memory.js.map +1 -0
- package/dist/commands/new.d.ts +3 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +68 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/next.d.ts +3 -0
- package/dist/commands/next.d.ts.map +1 -0
- package/dist/commands/next.js +107 -0
- package/dist/commands/next.js.map +1 -0
- package/dist/commands/optimize.d.ts +3 -0
- package/dist/commands/optimize.d.ts.map +1 -0
- package/dist/commands/optimize.js +28 -0
- package/dist/commands/optimize.js.map +1 -0
- package/dist/commands/plugin-linker.d.ts +34 -0
- package/dist/commands/plugin-linker.d.ts.map +1 -0
- package/dist/commands/plugin-linker.js +177 -0
- package/dist/commands/plugin-linker.js.map +1 -0
- package/dist/commands/refactor.d.ts +3 -0
- package/dist/commands/refactor.d.ts.map +1 -0
- package/dist/commands/refactor.js +32 -0
- package/dist/commands/refactor.js.map +1 -0
- package/dist/commands/types.d.ts +19 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +7 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/validate-plan.d.ts +3 -0
- package/dist/commands/validate-plan.d.ts.map +1 -0
- package/dist/commands/validate-plan.js +62 -0
- package/dist/commands/validate-plan.js.map +1 -0
- package/dist/commands/validate-spec.d.ts +3 -0
- package/dist/commands/validate-spec.d.ts.map +1 -0
- package/dist/commands/validate-spec.js +62 -0
- package/dist/commands/validate-spec.js.map +1 -0
- package/dist/commands/verify.d.ts +3 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +103 -0
- package/dist/commands/verify.js.map +1 -0
- package/dist/commands/version.d.ts +3 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +12 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/output/formatter.d.ts +2 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +10 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/index.d.ts +2 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +3 -0
- package/dist/output/index.js.map +1 -0
- package/package.json +37 -3
- package/src/application/agent/execution-store.ts +162 -0
- package/src/application/agent/gateway.test.ts +529 -0
- package/src/application/agent/gateway.ts +744 -0
- package/src/application/agent/index.ts +18 -0
- package/src/application/agent/orchestrator.test.ts +341 -0
- package/src/application/agent/orchestrator.ts +628 -0
- package/src/application/agent/providers/claude-code/claude-argv.ts +119 -0
- package/src/application/agent/providers/claude-code/claude-code-smoke.test.ts +139 -0
- package/src/application/agent/providers/claude-code/fixtures/fake-claude.mjs +125 -0
- package/src/application/agent/providers/claude-code/index.ts +28 -0
- package/src/application/agent/providers/claude-code/mod-parity.ts +50 -0
- package/src/application/agent/providers/claude-code/permission-config.test.ts +221 -0
- package/src/application/agent/providers/claude-code/permission-config.ts +242 -0
- package/src/application/agent/providers/claude-code/provider.test.ts +378 -0
- package/src/application/agent/providers/claude-code/provider.ts +717 -0
- package/src/application/agent/providers/claude-code/resume-store.test.ts +161 -0
- package/src/application/agent/providers/claude-code/resume-store.ts +157 -0
- package/src/application/agent/providers/claude-code/stream-parser.ts +166 -0
- package/src/application/agent/test-fixture.ts +131 -0
- package/src/application/agent/workspace.test.ts +104 -0
- package/src/application/agent/workspace.ts +156 -0
- package/src/application/dispatcher.test.ts +89 -0
- package/src/application/dispatcher.ts +98 -0
- package/src/application/index.ts +5 -0
- package/src/application/registry.ts +24 -0
- package/src/application/version.ts +7 -0
- package/src/commands/clse.test.ts +181 -0
- package/src/commands/doctor.test.ts +29 -0
- package/src/commands/doctor.ts +78 -0
- package/src/commands/elicit.test.ts +111 -0
- package/src/commands/elicit.ts +188 -0
- package/src/commands/evolve.ts +209 -0
- package/src/commands/feature.test.ts +323 -0
- package/src/commands/feature.ts +405 -0
- package/src/commands/fix.test.ts +36 -0
- package/src/commands/fix.ts +69 -0
- package/src/commands/help.test.ts +33 -0
- package/src/commands/help.ts +35 -0
- package/src/commands/index.ts +21 -0
- package/src/commands/init.test.ts +65 -0
- package/src/commands/init.ts +103 -0
- package/src/commands/inspect.test.ts +57 -0
- package/src/commands/inspect.ts +73 -0
- package/src/commands/install.test.ts +61 -0
- package/src/commands/install.ts +375 -0
- package/src/commands/journal.ts +118 -0
- package/src/commands/memory.ts +96 -0
- package/src/commands/new.test.ts +44 -0
- package/src/commands/new.ts +77 -0
- package/src/commands/next.test.ts +241 -0
- package/src/commands/next.ts +124 -0
- package/src/commands/optimize.ts +30 -0
- package/src/commands/plugin-linker.test.ts +139 -0
- package/src/commands/plugin-linker.ts +196 -0
- package/src/commands/refactor.ts +34 -0
- package/src/commands/stack-commands.test.ts +67 -0
- package/src/commands/tier-c-conformance.test.ts +194 -0
- package/src/commands/types.ts +26 -0
- package/src/commands/validate-plan.test.ts +107 -0
- package/src/commands/validate-plan.ts +67 -0
- package/src/commands/validate-spec.test.ts +59 -0
- package/src/commands/validate-spec.ts +68 -0
- package/src/commands/verify.test.ts +117 -0
- package/src/commands/verify.ts +112 -0
- package/src/commands/version.test.ts +11 -0
- package/src/commands/version.ts +14 -0
- package/src/index.ts +30 -0
- package/src/output/formatter.ts +10 -0
- package/src/output/index.ts +2 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/providers/claude-code/resume-store.ts
|
|
2
|
+
//
|
|
3
|
+
// Encrypted resume-session store (ADR-0019 PR4 — the cross-process resume
|
|
4
|
+
// item PR3 deferred; ADR-0020 §6.8).
|
|
5
|
+
//
|
|
6
|
+
// RESUME TOKENS ARE CREDENTIALS: they are never logged, never included in
|
|
7
|
+
// events, and NEVER PERSISTED UNENCRYPTED. This store keeps, per execution,
|
|
8
|
+
// the Claude Code session id together with the resume token the provider
|
|
9
|
+
// issued — encrypted at rest with AES-256-GCM under a per-project key file
|
|
10
|
+
// (mode 0600 in a 0700 directory). A second process (the next
|
|
11
|
+
// `kit feature <id> run` invocation) can therefore resume a provider
|
|
12
|
+
// session WITHOUT the token ever existing in plaintext on disk.
|
|
13
|
+
//
|
|
14
|
+
// Honest threat model (documented, not hidden): the key lives on the same
|
|
15
|
+
// machine as the ciphertext, so the store protects against (a) plaintext
|
|
16
|
+
// leakage through the state directory (commits, copies, backups, other
|
|
17
|
+
// users' reads) and (b) accidental exposure of "just a JSON file" — it does
|
|
18
|
+
// NOT protect against a compromised same-user process on the same machine;
|
|
19
|
+
// that class can simply read the key. An OS keychain would narrow that
|
|
20
|
+
// further and remains open as a follow-up; the kit stays zero-dependency
|
|
21
|
+
// (ADR-0007) and this store never weakens the existing in-memory contract:
|
|
22
|
+
// the GATEWAY still holds tokens in memory only.
|
|
23
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes, timingSafeEqual, } from 'node:crypto';
|
|
24
|
+
import { promises as fs } from 'node:fs';
|
|
25
|
+
import path from 'node:path';
|
|
26
|
+
import { executionStoreDir, validateExecutionId } from '../../execution-store.js';
|
|
27
|
+
function keyPath(projectRoot) {
|
|
28
|
+
return path.resolve(projectRoot, '.ai-kit', 'keys', 'agent-session.key');
|
|
29
|
+
}
|
|
30
|
+
function recordPath(projectRoot, executionId) {
|
|
31
|
+
return path.join(executionStoreDir(projectRoot), `${executionId}.session.enc`);
|
|
32
|
+
}
|
|
33
|
+
async function loadOrCreateKey(projectRoot) {
|
|
34
|
+
const target = keyPath(projectRoot);
|
|
35
|
+
try {
|
|
36
|
+
const existing = await fs.readFile(target);
|
|
37
|
+
if (existing.length === 32)
|
|
38
|
+
return existing;
|
|
39
|
+
// A wrong-length key file is a corrupted security boundary: fail closed.
|
|
40
|
+
throw new Error(`agent-session key at ${target} is malformed (${existing.length} bytes, expected 32)`);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (e.code !== 'ENOENT')
|
|
44
|
+
throw e;
|
|
45
|
+
const fresh = randomBytes(32);
|
|
46
|
+
await fs.mkdir(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
47
|
+
await fs.writeFile(target, fresh, { mode: 0o600 });
|
|
48
|
+
return fresh;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function encrypt(key, plaintext) {
|
|
52
|
+
const iv = randomBytes(12);
|
|
53
|
+
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
54
|
+
const ct = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
|
|
55
|
+
return {
|
|
56
|
+
v: 1,
|
|
57
|
+
iv: iv.toString('base64'),
|
|
58
|
+
tag: cipher.getAuthTag().toString('base64'),
|
|
59
|
+
ct: ct.toString('base64'),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function decrypt(key, env) {
|
|
63
|
+
const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(env.iv, 'base64'));
|
|
64
|
+
decipher.setAuthTag(Buffer.from(env.tag, 'base64'));
|
|
65
|
+
return Buffer.concat([decipher.update(Buffer.from(env.ct, 'base64')), decipher.final()]).toString('utf8');
|
|
66
|
+
}
|
|
67
|
+
/** Persist a session record, encrypted at rest. Refuses invalid execution ids (path traversal). */
|
|
68
|
+
export async function saveSessionRecord(projectRoot, record) {
|
|
69
|
+
if (!validateExecutionId(record.executionId)) {
|
|
70
|
+
throw new Error(`invalid execution id '${record.executionId}' — refusing to store session record`);
|
|
71
|
+
}
|
|
72
|
+
const key = await loadOrCreateKey(projectRoot);
|
|
73
|
+
const envelope = encrypt(key, JSON.stringify(record));
|
|
74
|
+
const dir = executionStoreDir(projectRoot);
|
|
75
|
+
await fs.mkdir(dir, { recursive: true });
|
|
76
|
+
const target = recordPath(projectRoot, record.executionId);
|
|
77
|
+
const tmp = `${target}.tmp`;
|
|
78
|
+
await fs.writeFile(tmp, JSON.stringify(envelope) + '\n', { mode: 0o600 });
|
|
79
|
+
await fs.rename(tmp, target);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Load a session record. Returns undefined when absent. Fails closed (throws)
|
|
83
|
+
* on tampering — AES-GCM auth failure means the ciphertext or key changed,
|
|
84
|
+
* and a resumed session under an unverified record is unacceptable.
|
|
85
|
+
*/
|
|
86
|
+
export async function loadSessionRecord(projectRoot, executionId) {
|
|
87
|
+
if (!validateExecutionId(executionId))
|
|
88
|
+
return undefined;
|
|
89
|
+
let raw;
|
|
90
|
+
try {
|
|
91
|
+
raw = await fs.readFile(recordPath(projectRoot, executionId), 'utf8');
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
if (e.code === 'ENOENT')
|
|
95
|
+
return undefined;
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
98
|
+
const key = await loadOrCreateKey(projectRoot);
|
|
99
|
+
const env = JSON.parse(raw);
|
|
100
|
+
const record = JSON.parse(decrypt(key, env));
|
|
101
|
+
if (record.executionId !== executionId) {
|
|
102
|
+
throw new Error(`session record for '${executionId}' carries a mismatched execution id — refusing`);
|
|
103
|
+
}
|
|
104
|
+
return record;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Constant-time token verification. Hash both sides first so a length
|
|
108
|
+
* difference does not leak through timingSafeEqual's equal-length
|
|
109
|
+
* requirement; a missing token still hashes (fail closed, no early exit).
|
|
110
|
+
*/
|
|
111
|
+
export function verifyResumeToken(record, presented) {
|
|
112
|
+
const a = createHash('sha256').update(record.resumeToken, 'utf8').digest();
|
|
113
|
+
const b = createHash('sha256').update(typeof presented === 'string' ? presented : '', 'utf8').digest();
|
|
114
|
+
return timingSafeEqual(a, b);
|
|
115
|
+
}
|
|
116
|
+
/** Generate an opaque resume credential (256 bits, url-safe). */
|
|
117
|
+
export function generateResumeToken() {
|
|
118
|
+
return randomBytes(32).toString('base64url');
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=resume-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume-store.js","sourceRoot":"","sources":["../../../../../src/application/agent/providers/claude-code/resume-store.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,0EAA0E;AAC1E,qCAAqC;AACrC,EAAE;AACF,0EA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O,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { inferCapabilityFromToolUse, type ClaudeCodePermissionConfig } from './permission-config.js';
|
|
2
|
+
/** What the parser saw on one line. Never re-ordered; emitted in arrival order. */
|
|
3
|
+
export type StreamObservation = {
|
|
4
|
+
kind: 'init';
|
|
5
|
+
sessionId: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'text-delta';
|
|
8
|
+
content: string;
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'tool-use';
|
|
11
|
+
toolCallId: string;
|
|
12
|
+
toolName: string;
|
|
13
|
+
input: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'tool-result';
|
|
16
|
+
toolCallId: string;
|
|
17
|
+
status: 'succeeded' | 'failed' | 'denied';
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'result';
|
|
20
|
+
result: ClaudeFinalResult;
|
|
21
|
+
};
|
|
22
|
+
/** The normalized shape of Claude Code's final `result` object (honest subset). */
|
|
23
|
+
export interface ClaudeFinalResult {
|
|
24
|
+
readonly subtype: string;
|
|
25
|
+
readonly isError: boolean;
|
|
26
|
+
readonly text: string;
|
|
27
|
+
readonly sessionId: string | undefined;
|
|
28
|
+
readonly durationMs: number | undefined;
|
|
29
|
+
readonly numTurns: number | undefined;
|
|
30
|
+
readonly totalCostUsd: number | undefined;
|
|
31
|
+
readonly inputTokens: number | undefined;
|
|
32
|
+
readonly outputTokens: number | undefined;
|
|
33
|
+
}
|
|
34
|
+
export declare class ClaudeStreamParser {
|
|
35
|
+
private readonly onObservation;
|
|
36
|
+
private sessionAnnounced;
|
|
37
|
+
private unknownLines;
|
|
38
|
+
constructor(onObservation: (obs: StreamObservation) => void);
|
|
39
|
+
/** Feed one stdout line (already trimmed of the newline). */
|
|
40
|
+
consume(line: string): void;
|
|
41
|
+
/** Honest count of lines the parser could not interpret. */
|
|
42
|
+
unknownLineCount(): number;
|
|
43
|
+
}
|
|
44
|
+
/** Map tool-use observations to the capability that authorized them (may be undefined). */
|
|
45
|
+
export declare function capabilityOfToolUse(obs: Extract<StreamObservation, {
|
|
46
|
+
kind: 'tool-use';
|
|
47
|
+
}>): ReturnType<typeof inferCapabilityFromToolUse>;
|
|
48
|
+
/** Used by tests to prove the parser never reads the permission config: parity is table-driven. */
|
|
49
|
+
export type { ClaudeCodePermissionConfig };
|
|
50
|
+
//# sourceMappingURL=stream-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-parser.d.ts","sourceRoot":"","sources":["../../../../../src/application/agent/providers/claude-code/stream-parser.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,0BAA0B,EAC1B,KAAK,0BAA0B,EAChC,MAAM,wBAAwB,CAAC;AAEhC,mFAAmF;AACnF,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAA;CAAE,GACtF;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAElD,mFAAmF;AACnF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAmC;IACjE,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,YAAY,CAAK;gBAEb,aAAa,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,IAAI;IAI3D,6DAA6D;IAC7D,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAmE3B,4DAA4D;IAC5D,gBAAgB,IAAI,MAAM;CAG3B;AAmCD,2FAA2F;AAC3F,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,OAAO,CAAC,iBAAiB,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,GACpD,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAE/C;AAED,mGAAmG;AACnG,YAAY,EAAE,0BAA0B,EAAE,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/providers/claude-code/stream-parser.ts
|
|
2
|
+
//
|
|
3
|
+
// Claude Code stream-json parser (ADR-0019 PR4).
|
|
4
|
+
//
|
|
5
|
+
// Feeds line-by-line: the provider reads the headless CLI's NDJSON stdout
|
|
6
|
+
// and hands each line here. The parser emits normalized OBSERVATIONS (init,
|
|
7
|
+
// text delta, tool use, tool result, final result) and never fabricates
|
|
8
|
+
// anything it did not see: unknown lines are counted and skipped, a missing
|
|
9
|
+
// final result is surfaced as `undefined` so the provider can report an
|
|
10
|
+
// honest `interrupted` instead of inventing a status.
|
|
11
|
+
//
|
|
12
|
+
// Tool-call capability inference uses the SAME mapping table as the
|
|
13
|
+
// permission derivation (permission-config.ts) — an event can only claim
|
|
14
|
+
// the capability that authorized the tool rule (ADR-0020 parity).
|
|
15
|
+
import { inferCapabilityFromToolUse, } from './permission-config.js';
|
|
16
|
+
export class ClaudeStreamParser {
|
|
17
|
+
onObservation;
|
|
18
|
+
sessionAnnounced = false;
|
|
19
|
+
unknownLines = 0;
|
|
20
|
+
constructor(onObservation) {
|
|
21
|
+
this.onObservation = onObservation;
|
|
22
|
+
}
|
|
23
|
+
/** Feed one stdout line (already trimmed of the newline). */
|
|
24
|
+
consume(line) {
|
|
25
|
+
if (line.length === 0)
|
|
26
|
+
return;
|
|
27
|
+
let obj;
|
|
28
|
+
try {
|
|
29
|
+
obj = JSON.parse(line);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
this.unknownLines += 1;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!obj || typeof obj !== 'object') {
|
|
36
|
+
this.unknownLines += 1;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const rec = obj;
|
|
40
|
+
if (rec.type === 'system' && rec.subtype === 'init') {
|
|
41
|
+
const sessionId = typeof rec.session_id === 'string' ? rec.session_id : '';
|
|
42
|
+
if (sessionId) {
|
|
43
|
+
// Emit init once: providers replay it to late subscribers.
|
|
44
|
+
if (!this.sessionAnnounced) {
|
|
45
|
+
this.sessionAnnounced = true;
|
|
46
|
+
this.onObservation({ kind: 'init', sessionId });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (rec.type === 'assistant' || rec.type === 'user') {
|
|
52
|
+
const content = contentBlocks(rec.message);
|
|
53
|
+
if (rec.type === 'assistant') {
|
|
54
|
+
for (const block of content) {
|
|
55
|
+
if (block.type === 'text' && typeof block.text === 'string' && block.text.length > 0) {
|
|
56
|
+
this.onObservation({ kind: 'text-delta', content: block.text });
|
|
57
|
+
}
|
|
58
|
+
if (block.type === 'tool_use') {
|
|
59
|
+
const id = typeof block.id === 'string' ? block.id : '';
|
|
60
|
+
const name = typeof block.name === 'string' ? block.name : '';
|
|
61
|
+
if (id && name) {
|
|
62
|
+
this.onObservation({ kind: 'tool-use', toolCallId: id, toolName: name, input: block.input });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
for (const block of content) {
|
|
69
|
+
if (block.type === 'tool_result') {
|
|
70
|
+
const id = typeof block.tool_use_id === 'string' ? block.tool_use_id : '';
|
|
71
|
+
if (id) {
|
|
72
|
+
this.onObservation({
|
|
73
|
+
kind: 'tool-result',
|
|
74
|
+
toolCallId: id,
|
|
75
|
+
status: toolResultStatus(block),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (rec.type === 'result') {
|
|
84
|
+
this.onObservation({ kind: 'result', result: normalizeFinalResult(rec) });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.unknownLines += 1;
|
|
88
|
+
}
|
|
89
|
+
/** Honest count of lines the parser could not interpret. */
|
|
90
|
+
unknownLineCount() {
|
|
91
|
+
return this.unknownLines;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function contentBlocks(message) {
|
|
95
|
+
if (!message || typeof message !== 'object')
|
|
96
|
+
return [];
|
|
97
|
+
const content = message.content;
|
|
98
|
+
if (!Array.isArray(content))
|
|
99
|
+
return [];
|
|
100
|
+
return content.filter((b) => !!b && typeof b === 'object' && typeof b.type === 'string');
|
|
101
|
+
}
|
|
102
|
+
function toolResultStatus(block) {
|
|
103
|
+
if (block.is_error === true) {
|
|
104
|
+
const text = typeof block.content === 'string' ? block.content : JSON.stringify(block.content ?? '');
|
|
105
|
+
if (/permission|not allowed|denied|unauthorized/i.test(text))
|
|
106
|
+
return 'denied';
|
|
107
|
+
return 'failed';
|
|
108
|
+
}
|
|
109
|
+
return 'succeeded';
|
|
110
|
+
}
|
|
111
|
+
function normalizeFinalResult(rec) {
|
|
112
|
+
const usage = (rec.usage && typeof rec.usage === 'object' ? rec.usage : {});
|
|
113
|
+
return {
|
|
114
|
+
subtype: typeof rec.subtype === 'string' ? rec.subtype : '',
|
|
115
|
+
isError: rec.is_error === true,
|
|
116
|
+
text: typeof rec.result === 'string' ? rec.result : '',
|
|
117
|
+
sessionId: typeof rec.session_id === 'string' ? rec.session_id : undefined,
|
|
118
|
+
durationMs: typeof rec.duration_ms === 'number' ? rec.duration_ms : undefined,
|
|
119
|
+
numTurns: typeof rec.num_turns === 'number' ? rec.num_turns : undefined,
|
|
120
|
+
totalCostUsd: typeof rec.total_cost_usd === 'number' ? rec.total_cost_usd : undefined,
|
|
121
|
+
inputTokens: typeof usage.input_tokens === 'number' ? usage.input_tokens : undefined,
|
|
122
|
+
outputTokens: typeof usage.output_tokens === 'number' ? usage.output_tokens : undefined,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Map tool-use observations to the capability that authorized them (may be undefined). */
|
|
126
|
+
export function capabilityOfToolUse(obs) {
|
|
127
|
+
return inferCapabilityFromToolUse(obs.toolName, obs.input);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=stream-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-parser.js","sourceRoot":"","sources":["../../../../../src/application/agent/providers/claude-code/stream-parser.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAC5E,wEAAwE;AACxE,4EAA4E;AAC5E,wEAAwE;AACxE,sDAAsD;AACtD,EAAE;AACF,oEAAoE;AACpE,yEAAyE;AACzE,kEAAkE;AAElE,OAAO,E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K,CAAC,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;QACpF,YAAY,EAAE,OAAO,KAAK,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;KACxF,CAAC;AACJ,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,mBAAmB,CACjC,GAAqD;IAErD,OAAO,0BAA0B,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface OrchestrationFixture {
|
|
2
|
+
readonly root: string;
|
|
3
|
+
readonly featureId: 'FEATURE-001';
|
|
4
|
+
readonly taskIds: readonly ['TASK-001', 'TASK-002'];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Build the committed fixture repository. `check.js TASK-00N` fails with
|
|
8
|
+
* an assertion failure until `.done-TASK-00N` exists NEXT TO IT (it
|
|
9
|
+
* resolves the marker relative to the process cwd, so the same committed
|
|
10
|
+
* script works inside any worktree).
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildOrchestrationFixture(): Promise<OrchestrationFixture>;
|
|
13
|
+
/** The marker path a "green" agent creates for a task inside a workspace. */
|
|
14
|
+
export declare function markerPath(workspaceRoot: string, taskId: string): string;
|
|
15
|
+
//# sourceMappingURL=test-fixture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-fixture.d.ts","sourceRoot":"","sources":["../../../src/application/agent/test-fixture.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;CACrD;AAUD;;;;;GAKG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAiF/E;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAExE"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/test-fixture.ts
|
|
2
|
+
//
|
|
3
|
+
// Git-backed fixture project for Mode 1 (orchestration) tests, PR3.
|
|
4
|
+
//
|
|
5
|
+
// Mode 1 executes in a git WORKTREE, so the fixture must be a real git
|
|
6
|
+
// repository with everything the workflow needs COMMITTED: the project
|
|
7
|
+
// profile, the specification, the plan, and a per-task verification
|
|
8
|
+
// script. The script fails with a REAL assertion failure until a
|
|
9
|
+
// per-task marker file exists — the orchestration tests' mock provider
|
|
10
|
+
// "implements" a task by creating that marker inside the workspace,
|
|
11
|
+
// exactly where a real provider's edits would land.
|
|
12
|
+
//
|
|
13
|
+
// This file is test support (matched by the architecture gate's test-file
|
|
14
|
+
// rule); it imports only core and node builtins.
|
|
15
|
+
import { execFile } from 'node:child_process';
|
|
16
|
+
import { promises as fs } from 'node:fs';
|
|
17
|
+
import os from 'node:os';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import { promisify } from 'node:util';
|
|
20
|
+
import { scaffoldSpecification, serializeProfileYaml } from '@agentic-sdlc-kit/core';
|
|
21
|
+
const exec = promisify(execFile);
|
|
22
|
+
function git(args, cwd) {
|
|
23
|
+
return exec('git', ['-c', 'user.email=kit@example.com', '-c', 'user.name=kit-test', ...args], { cwd, timeout: 30_000 }).then((r) => r.stdout);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build the committed fixture repository. `check.js TASK-00N` fails with
|
|
27
|
+
* an assertion failure until `.done-TASK-00N` exists NEXT TO IT (it
|
|
28
|
+
* resolves the marker relative to the process cwd, so the same committed
|
|
29
|
+
* script works inside any worktree).
|
|
30
|
+
*/
|
|
31
|
+
export async function buildOrchestrationFixture() {
|
|
32
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-mode1-orchestration-'));
|
|
33
|
+
await git(['init', '-b', 'main'], root);
|
|
34
|
+
// Only the RUNTIME directories are ignored; the project profile under
|
|
35
|
+
// .ai-kit/ is project configuration and must be COMMITTED so every
|
|
36
|
+
// worktree checkout has it (the same convention the kit documents).
|
|
37
|
+
// The journal (.ai-kit/journal/) is runtime data like state/ — it is
|
|
38
|
+
// kit bookkeeping, never part of the reviewable agent footprint.
|
|
39
|
+
await fs.writeFile(path.join(root, '.gitignore'), ['.ai-kit/state/', '.ai-kit/journal/', '.ai-kit/worktrees/', 'node_modules/', ''].join('\n'));
|
|
40
|
+
await fs.writeFile(path.join(root, 'check.js'), [
|
|
41
|
+
'const task = process.argv[2];',
|
|
42
|
+
'if (!task) { console.error("AssertionError: missing task argument"); process.exit(1); }',
|
|
43
|
+
'const fs = require("node:fs");',
|
|
44
|
+
'if (!fs.existsSync(".done-" + task)) {',
|
|
45
|
+
' console.error("AssertionError: expected target for " + task + " to be implemented (marker .done-" + task + " missing)");',
|
|
46
|
+
' process.exit(1);',
|
|
47
|
+
'}',
|
|
48
|
+
'process.exit(0);',
|
|
49
|
+
].join('\n') + '\n');
|
|
50
|
+
await fs.mkdir(path.join(root, '.ai-kit'), { recursive: true });
|
|
51
|
+
await fs.writeFile(path.join(root, '.ai-kit', 'project.yml'), serializeProfileYaml({
|
|
52
|
+
schemaVersion: 1,
|
|
53
|
+
name: 'mode1-fixture-app',
|
|
54
|
+
stack: ['node-typescript'],
|
|
55
|
+
commands: {
|
|
56
|
+
test: [
|
|
57
|
+
['node', 'check.js', 'TASK-001'],
|
|
58
|
+
['node', 'check.js', 'TASK-002'],
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
}));
|
|
62
|
+
await scaffoldSpecification({
|
|
63
|
+
id: 'FEATURE-001',
|
|
64
|
+
title: 'Mode 1 Fixture',
|
|
65
|
+
targetDir: path.join(root, 'docs', 'specifications', 'features'),
|
|
66
|
+
});
|
|
67
|
+
const planDir = path.join(root, 'docs', 'plans', 'FEATURE-001');
|
|
68
|
+
await fs.mkdir(planDir, { recursive: true });
|
|
69
|
+
const taskIds = ['TASK-001', 'TASK-002'];
|
|
70
|
+
await fs.writeFile(path.join(planDir, 'plan.json'), JSON.stringify({
|
|
71
|
+
featureId: 'FEATURE-001',
|
|
72
|
+
tasks: taskIds.map((id) => ({
|
|
73
|
+
id,
|
|
74
|
+
description: `Implement ${id} of the Mode 1 fixture`,
|
|
75
|
+
acceptanceCriteria: [`${id} target implemented`, 'no regressions'],
|
|
76
|
+
verification: { command: ['node', 'check.js', id], expectedStatus: 'passed' },
|
|
77
|
+
dependencies: [],
|
|
78
|
+
likelyFiles: [`src/${id.toLowerCase()}.ts`],
|
|
79
|
+
estimatedScope: 's',
|
|
80
|
+
risk: 'low',
|
|
81
|
+
})),
|
|
82
|
+
edges: [],
|
|
83
|
+
verticalSlices: taskIds.map((id) => [id]),
|
|
84
|
+
}, null, 2) + '\n');
|
|
85
|
+
await git(['add', '.'], root);
|
|
86
|
+
await git(['commit', '-m', 'fixture: mode 1 orchestration baseline'], root);
|
|
87
|
+
return { root, featureId: 'FEATURE-001', taskIds };
|
|
88
|
+
}
|
|
89
|
+
/** The marker path a "green" agent creates for a task inside a workspace. */
|
|
90
|
+
export function markerPath(workspaceRoot, taskId) {
|
|
91
|
+
return path.join(workspaceRoot, `.done-${taskId}`);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=test-fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-fixture.js","sourceRoot":"","sources":["../../../src/application/agent/test-fixture.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,EAAE;AACF,oEAAoE;AACpE,EAAE;AACF,uEAAuE;AACvE,uEAAuE;AACvE,oEAAoE;AACpE,iEAAiE;AACjE,uEAAuE;AACvE,oEAAoE;AACpE,oD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 @@
|
|
|
1
|
+
import { type ExecutionWorkspace, type Result } from '@agentic-sdlc-kit/contracts';
|
|
2
|
+
export declare function worktreeDir(projectRoot: string, runId: string): string;
|
|
3
|
+
export declare function worktreeBranch(runId: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Create the isolated execution workspace for a run: a git worktree at
|
|
6
|
+
* .ai-kit/worktrees/<runId> on branch kit/<runId>, based at the current
|
|
7
|
+
* HEAD of the project. The workspace identity (branch + baseCommitSha) is
|
|
8
|
+
* frozen in the returned ExecutionWorkspace and persisted by the
|
|
9
|
+
* orchestrator, so later phases and audits can derive clean diffs.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createWorktreeWorkspace(projectRoot: string, runId: string, now?: () => Date): Promise<Result<ExecutionWorkspace>>;
|
|
12
|
+
/**
|
|
13
|
+
* Probe that a persisted workspace still exists on disk. A git worktree
|
|
14
|
+
* is marked by a `.git` FILE (not a directory) pointing at the main
|
|
15
|
+
* repo's worktree metadata — that is the check.
|
|
16
|
+
*/
|
|
17
|
+
export declare function workspaceExists(workspace: ExecutionWorkspace): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Remove a worktree and its branch. Used by tests and by explicit
|
|
20
|
+
* cleanup; the orchestrator does NOT auto-remove on completion — the
|
|
21
|
+
* worktree is the evidence (the diff) and stays for review/merge.
|
|
22
|
+
*/
|
|
23
|
+
export declare function removeWorktreeWorkspace(projectRoot: string, workspace: ExecutionWorkspace): Promise<Result<true>>;
|
|
24
|
+
//# sourceMappingURL=workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../../src/application/agent/workspace.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAU,KAAK,kBAAkB,EAAE,KAAK,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAqB3F,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AAWD;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,GAAG,GAAE,MAAM,IAAuB,GACjC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAyCrC;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQrF;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,kBAAkB,GAC5B,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAmBvB"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/workspace.ts
|
|
2
|
+
//
|
|
3
|
+
// Execution workspace manager (ADR-0019 v2 revision B, ADR-0020 §7).
|
|
4
|
+
//
|
|
5
|
+
// Every Mode 1 run executes in a DEDICATED GIT WORKTREE per workflow run,
|
|
6
|
+
// never in the developer's active working tree. This isolates repository
|
|
7
|
+
// changes and gives the orchestrator a clean diff for evidence (branch +
|
|
8
|
+
// baseCommitSha are recorded in the ExecutionWorkspace, which is exactly
|
|
9
|
+
// what the git-worktree schema variant requires).
|
|
10
|
+
//
|
|
11
|
+
// SECURITY QUALIFICATION (ADR-0020 §7, honest scope): a git worktree
|
|
12
|
+
// isolates REPOSITORY changes; it is NOT an OS sandbox. Provider
|
|
13
|
+
// processes must additionally run with restricted host permissions or in
|
|
14
|
+
// a container (PR4's concern). Nothing here claims otherwise.
|
|
15
|
+
//
|
|
16
|
+
// All git invocations are argument arrays via execFile — never a shell
|
|
17
|
+
// string, never shell:true (the kit's non-negotiable process rule).
|
|
18
|
+
import { execFile } from 'node:child_process';
|
|
19
|
+
import { promises as fs } from 'node:fs';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
import { Errors } from '@agentic-sdlc-kit/contracts';
|
|
22
|
+
const GIT_TIMEOUT_MS = 30_000;
|
|
23
|
+
function execGit(args, cwd) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
execFile('git', [...args], { cwd, timeout: GIT_TIMEOUT_MS, windowsHide: true }, (err, stdout, stderr) => {
|
|
26
|
+
if (err) {
|
|
27
|
+
reject(new Error(`git ${args.join(' ')} failed: ${String(stderr || err.message)}`));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
resolve({ stdout: String(stdout), stderr: String(stderr) });
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export function worktreeDir(projectRoot, runId) {
|
|
36
|
+
return path.resolve(projectRoot, '.ai-kit', 'worktrees', runId);
|
|
37
|
+
}
|
|
38
|
+
export function worktreeBranch(runId) {
|
|
39
|
+
return `kit/${runId}`;
|
|
40
|
+
}
|
|
41
|
+
async function pathExists(p) {
|
|
42
|
+
try {
|
|
43
|
+
await fs.stat(p);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create the isolated execution workspace for a run: a git worktree at
|
|
52
|
+
* .ai-kit/worktrees/<runId> on branch kit/<runId>, based at the current
|
|
53
|
+
* HEAD of the project. The workspace identity (branch + baseCommitSha) is
|
|
54
|
+
* frozen in the returned ExecutionWorkspace and persisted by the
|
|
55
|
+
* orchestrator, so later phases and audits can derive clean diffs.
|
|
56
|
+
*/
|
|
57
|
+
export async function createWorktreeWorkspace(projectRoot, runId, now = () => new Date()) {
|
|
58
|
+
const dir = worktreeDir(projectRoot, runId);
|
|
59
|
+
try {
|
|
60
|
+
if (await pathExists(dir)) {
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
error: Errors.contractInvalid(`Workspace directory ${dir} already exists — the orchestration state and the ` +
|
|
64
|
+
`filesystem have diverged; refusing to overwrite`),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const shaRes = await execGit(['rev-parse', 'HEAD'], projectRoot);
|
|
68
|
+
const baseCommitSha = shaRes.stdout.trim();
|
|
69
|
+
if (!/^[0-9a-f]{7,40}$/.test(baseCommitSha)) {
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
error: Errors.contractInvalid(`Could not resolve a commit HEAD for ${projectRoot} — the project must have ` +
|
|
73
|
+
`at least one commit before Mode 1 execution (spec, plan, and profile must be committed)`),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
await execGit(['worktree', 'add', '-b', worktreeBranch(runId), dir, baseCommitSha], projectRoot);
|
|
77
|
+
return {
|
|
78
|
+
ok: true,
|
|
79
|
+
value: {
|
|
80
|
+
id: `ws-${runId}`,
|
|
81
|
+
kind: 'git-worktree',
|
|
82
|
+
rootPath: dir,
|
|
83
|
+
branch: worktreeBranch(runId),
|
|
84
|
+
baseCommitSha,
|
|
85
|
+
createdAt: now().toISOString(),
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
error: Errors.internal(`Failed to create execution workspace: ${String(e)}`),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Probe that a persisted workspace still exists on disk. A git worktree
|
|
98
|
+
* is marked by a `.git` FILE (not a directory) pointing at the main
|
|
99
|
+
* repo's worktree metadata — that is the check.
|
|
100
|
+
*/
|
|
101
|
+
export async function workspaceExists(workspace) {
|
|
102
|
+
try {
|
|
103
|
+
const gitLink = path.join(workspace.rootPath, '.git');
|
|
104
|
+
const stat = await fs.stat(gitLink);
|
|
105
|
+
return stat.isFile();
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Remove a worktree and its branch. Used by tests and by explicit
|
|
113
|
+
* cleanup; the orchestrator does NOT auto-remove on completion — the
|
|
114
|
+
* worktree is the evidence (the diff) and stays for review/merge.
|
|
115
|
+
*/
|
|
116
|
+
export async function removeWorktreeWorkspace(projectRoot, workspace) {
|
|
117
|
+
try {
|
|
118
|
+
await execGit(['worktree', 'remove', '--force', workspace.rootPath], projectRoot);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// The worktree may already be gone; prune and continue.
|
|
122
|
+
try {
|
|
123
|
+
await execGit(['worktree', 'prune'], projectRoot);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// fall through: branch cleanup below is best-effort too
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
if (workspace.branch) {
|
|
131
|
+
await execGit(['branch', '-D', workspace.branch], projectRoot);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Branch may not exist (already merged/deleted) — not an error.
|
|
136
|
+
}
|
|
137
|
+
return { ok: true, value: true };
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../../../src/application/agent/workspace.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,EAAE;AACF,qEAAqE;AACrE,EAAE;AACF,0EAA0E;AAC1E,yEAAyE;AACzE,yEAAyE;AACzE,yEAAyE;AACzE,kDAAkD;AAClD,EAAE;AACF,qEAAqE;AACrE,iEAAiE;AACjE,yEAAyE;AACzE,8DAA8D;AAC9D,EAAE;AACF,uEAAuE;AACvE,oEAAoE;AAEpE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAA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IAAI,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CommandContext, CommandResult } from '../commands/types.js';
|
|
2
|
+
import { type CommandRegistry } from './registry.js';
|
|
3
|
+
export interface DispatchResult extends CommandResult {
|
|
4
|
+
command?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface DispatcherOptions {
|
|
7
|
+
registry?: CommandRegistry;
|
|
8
|
+
}
|
|
9
|
+
export declare function createDispatcher(opts?: DispatcherOptions): {
|
|
10
|
+
dispatch: (ctx: CommandContext) => Promise<DispatchResult>;
|
|
11
|
+
registry: CommandRegistry;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/application/dispatcher.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAW,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAG5E,MAAM,WAAW,cAAe,SAAQ,aAAa;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,iBAAsB,GAAG;IAC9D,QAAQ,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3D,QAAQ,EAAE,eAAe,CAAC;CAC3B,CA0DA"}
|