sdtk-code-kit 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +204 -204
- package/assets/manifest/toolkit-bundle.manifest.json +147 -147
- package/assets/manifest/toolkit-bundle.sha256.txt +5 -5
- package/bin/sdtk-code.js +14 -14
- package/package.json +44 -44
- package/src/commands/agent-team.js +425 -174
- package/src/commands/build.js +53 -53
- package/src/commands/doctor.js +51 -51
- package/src/commands/generate.js +11 -11
- package/src/commands/guardrails.js +215 -215
- package/src/commands/help.js +264 -257
- package/src/commands/init.js +98 -98
- package/src/commands/plan.js +53 -53
- package/src/commands/readiness.js +77 -77
- package/src/commands/resume.js +61 -61
- package/src/commands/runtime.js +224 -224
- package/src/commands/ship.js +59 -59
- package/src/commands/sleep.js +132 -132
- package/src/commands/start.js +89 -89
- package/src/commands/status.js +77 -77
- package/src/commands/update.js +11 -11
- package/src/commands/verify.js +71 -71
- package/src/index.js +112 -112
- package/src/lib/agent-team-author.js +521 -0
- package/src/lib/agent-team-evidence.js +302 -0
- package/src/lib/agent-team-execute.js +892 -0
- package/src/lib/agent-team-export.js +411 -409
- package/src/lib/agent-team-plan.js +514 -514
- package/src/lib/agent-team-readiness.js +161 -0
- package/src/lib/agent-team-report.js +165 -0
- package/src/lib/args.js +107 -107
- package/src/lib/errors.js +41 -41
- package/src/lib/model-provider.js +219 -0
- package/src/lib/powershell.js +65 -65
- package/src/lib/project-target-guard.js +53 -53
- package/src/lib/scope.js +72 -72
- package/src/lib/ship-readiness.js +281 -281
- package/src/lib/sleep-plan.js +175 -175
- package/src/lib/sleep-report.js +229 -229
- package/src/lib/toolkit-payload.js +72 -72
- package/src/lib/trust-events.js +252 -185
- package/src/lib/trust-file-scope.js +154 -154
- package/src/lib/trust-policy.js +212 -212
- package/src/lib/trust-redact.js +58 -35
- package/src/lib/trust-trace.js +179 -179
- package/src/lib/update.js +344 -344
- package/src/lib/workflow-artifact.js +503 -503
- package/src/lib/workflow-build.js +127 -127
- package/src/lib/workflow-doctor.js +83 -83
- package/src/lib/workflow-handoff.js +1029 -1029
- package/src/lib/workflow-intake.js +101 -101
- package/src/lib/workflow-plan.js +193 -193
- package/src/lib/workflow-review-packet.js +650 -650
- package/src/lib/workflow-ship.js +213 -213
- package/src/lib/workflow-state.js +438 -438
- package/src/lib/workflow-verify.js +393 -393
package/src/lib/trust-events.js
CHANGED
|
@@ -1,185 +1,252 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const crypto = require("crypto");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const { redact } = require("./trust-redact");
|
|
7
|
-
|
|
8
|
-
const locks = new Map();
|
|
9
|
-
const MAX_COMMAND_LENGTH = 2000;
|
|
10
|
-
|
|
11
|
-
function generateId(prefix) {
|
|
12
|
-
const ts = Date.now().toString(36);
|
|
13
|
-
const rand = crypto.randomUUID().replace(/-/g, "").slice(0, 12);
|
|
14
|
-
return `${prefix}_${ts}_${rand}`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function fingerprintId(prefix, content) {
|
|
18
|
-
const hash = crypto.createHash("sha256").update(String(content)).digest("hex");
|
|
19
|
-
return `${prefix}_${hash.slice(0, 16)}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function eventsDir(projectPath) {
|
|
23
|
-
return path.join(path.resolve(projectPath || "."), ".sdtk", "trust", "events");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function eventsFile(projectPath, date) {
|
|
27
|
-
const day = typeof date === "string" ? date : new Date(date || Date.now()).toISOString().slice(0, 10);
|
|
28
|
-
return path.join(eventsDir(projectPath), `${day}.jsonl`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function nullableString(value) {
|
|
32
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function normalizeStatus(value) {
|
|
36
|
-
return typeof value === "string" && value.length > 0 ? value : "info";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function inferEventType(raw) {
|
|
40
|
-
if (!raw || typeof raw !== "object") {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
if (typeof raw.event_type === "string" && raw.event_type.length > 0) {
|
|
44
|
-
return raw.event_type;
|
|
45
|
-
}
|
|
46
|
-
const hookType = typeof raw.hook_type === "string" ? raw.hook_type : "";
|
|
47
|
-
const toolName = typeof raw.tool_name === "string" ? raw.tool_name : "";
|
|
48
|
-
if (hookType === "post_tool_failure") {
|
|
49
|
-
return "command_failure";
|
|
50
|
-
}
|
|
51
|
-
if (hookType === "post_tool" || hookType === "task_completed") {
|
|
52
|
-
return "post_command";
|
|
53
|
-
}
|
|
54
|
-
if (hookType === "pre_tool" || /(?:bash|shell|exec|run)/i.test(toolName)) {
|
|
55
|
-
return "pre_command";
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function normalizeFiles(value) {
|
|
61
|
-
if (!Array.isArray(value)) {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
return value.filter((entry) => typeof entry === "string").map((entry) => redact(entry));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
()
|
|
172
|
-
()
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const crypto = require("crypto");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const { redact } = require("./trust-redact");
|
|
7
|
+
|
|
8
|
+
const locks = new Map();
|
|
9
|
+
const MAX_COMMAND_LENGTH = 2000;
|
|
10
|
+
|
|
11
|
+
function generateId(prefix) {
|
|
12
|
+
const ts = Date.now().toString(36);
|
|
13
|
+
const rand = crypto.randomUUID().replace(/-/g, "").slice(0, 12);
|
|
14
|
+
return `${prefix}_${ts}_${rand}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function fingerprintId(prefix, content) {
|
|
18
|
+
const hash = crypto.createHash("sha256").update(String(content)).digest("hex");
|
|
19
|
+
return `${prefix}_${hash.slice(0, 16)}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function eventsDir(projectPath) {
|
|
23
|
+
return path.join(path.resolve(projectPath || "."), ".sdtk", "trust", "events");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function eventsFile(projectPath, date) {
|
|
27
|
+
const day = typeof date === "string" ? date : new Date(date || Date.now()).toISOString().slice(0, 10);
|
|
28
|
+
return path.join(eventsDir(projectPath), `${day}.jsonl`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function nullableString(value) {
|
|
32
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function normalizeStatus(value) {
|
|
36
|
+
return typeof value === "string" && value.length > 0 ? value : "info";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function inferEventType(raw) {
|
|
40
|
+
if (!raw || typeof raw !== "object") {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (typeof raw.event_type === "string" && raw.event_type.length > 0) {
|
|
44
|
+
return raw.event_type;
|
|
45
|
+
}
|
|
46
|
+
const hookType = typeof raw.hook_type === "string" ? raw.hook_type : "";
|
|
47
|
+
const toolName = typeof raw.tool_name === "string" ? raw.tool_name : "";
|
|
48
|
+
if (hookType === "post_tool_failure") {
|
|
49
|
+
return "command_failure";
|
|
50
|
+
}
|
|
51
|
+
if (hookType === "post_tool" || hookType === "task_completed") {
|
|
52
|
+
return "post_command";
|
|
53
|
+
}
|
|
54
|
+
if (hookType === "pre_tool" || /(?:bash|shell|exec|run)/i.test(toolName)) {
|
|
55
|
+
return "pre_command";
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function normalizeFiles(value) {
|
|
61
|
+
if (!Array.isArray(value)) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return value.filter((entry) => typeof entry === "string").map((entry) => redact(entry));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
function normalizeContextManifest(value) {
|
|
69
|
+
if (!Array.isArray(value)) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
return value.map((entry) => {
|
|
73
|
+
const source = entry && typeof entry === "object" ? entry : {};
|
|
74
|
+
return {
|
|
75
|
+
path: source.path != null ? redact(String(source.path)) : null,
|
|
76
|
+
snapshot_sha256: typeof source.snapshot_sha256 === "string" ? source.snapshot_sha256 : null,
|
|
77
|
+
};
|
|
78
|
+
}).filter((entry) => entry.path && entry.snapshot_sha256);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function normalizeTokensUsed(value) {
|
|
82
|
+
if (!value || typeof value !== "object") {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
input_tokens: typeof value.input_tokens === "number" ? value.input_tokens : null,
|
|
87
|
+
output_tokens: typeof value.output_tokens === "number" ? value.output_tokens : null,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function normalizeCommand(value) {
|
|
92
|
+
if (typeof value !== "string") {
|
|
93
|
+
return { command: null, truncated: false };
|
|
94
|
+
}
|
|
95
|
+
const redacted = redact(value);
|
|
96
|
+
if (redacted.length > MAX_COMMAND_LENGTH) {
|
|
97
|
+
return { command: redacted.slice(0, MAX_COMMAND_LENGTH), truncated: true };
|
|
98
|
+
}
|
|
99
|
+
return { command: redacted, truncated: false };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function buildEvent(raw) {
|
|
103
|
+
const source = raw && typeof raw === "object" ? raw : {};
|
|
104
|
+
const timestamp = typeof source.timestamp === "string" && source.timestamp.length > 0
|
|
105
|
+
? source.timestamp
|
|
106
|
+
: new Date().toISOString();
|
|
107
|
+
const { command, truncated } = normalizeCommand(source.command);
|
|
108
|
+
const sessionId = nullableString(source.session_id);
|
|
109
|
+
const toolkit = nullableString(source.toolkit);
|
|
110
|
+
const eventType = inferEventType(source);
|
|
111
|
+
// Agent-team traceability (BK-260). Redacted like any other string field and
|
|
112
|
+
// folded into the dedup identity so distinct runs/roles emitting the same
|
|
113
|
+
// command are not collapsed into a single event. Existing callers omit these,
|
|
114
|
+
// so the fields default to null and keep dedup deterministic.
|
|
115
|
+
const runId = source.run_id != null ? redact(String(source.run_id)) : null;
|
|
116
|
+
const agentRole = source.agent_role != null ? redact(String(source.agent_role)) : null;
|
|
117
|
+
const taskId = source.task_id != null ? redact(String(source.task_id)) : null;
|
|
118
|
+
const featureKey = source.feature_key != null ? redact(String(source.feature_key)) : null;
|
|
119
|
+
const stopConditionHit = source.stop_condition_hit != null
|
|
120
|
+
? String(source.stop_condition_hit) : null;
|
|
121
|
+
const evidenceQualityOk = typeof source.evidence_quality_ok === "boolean"
|
|
122
|
+
? source.evidence_quality_ok : null;
|
|
123
|
+
const overallVerdict = source.overall_verdict != null
|
|
124
|
+
? String(source.overall_verdict) : null;
|
|
125
|
+
const rolesNotReadyCount = typeof source.roles_not_ready_count === "number"
|
|
126
|
+
? source.roles_not_ready_count : null;
|
|
127
|
+
const reportPath = source.report_path != null ? redact(String(source.report_path)) : null;
|
|
128
|
+
const worktreePath = source.worktree_path != null ? redact(String(source.worktree_path)) : null;
|
|
129
|
+
const actionsExecuted = typeof source.actions_executed === "number"
|
|
130
|
+
? source.actions_executed : null;
|
|
131
|
+
const executionMode = source.execution_mode != null
|
|
132
|
+
? String(source.execution_mode) : null;
|
|
133
|
+
const workflowType = source.workflow_type != null
|
|
134
|
+
? String(source.workflow_type) : null;
|
|
135
|
+
const modelProvider = source.model_provider != null ? redact(String(source.model_provider)) : null;
|
|
136
|
+
const modelId = source.model_id != null ? redact(String(source.model_id)) : null;
|
|
137
|
+
const promptSha256 = source.prompt_sha256 != null ? String(source.prompt_sha256) : null;
|
|
138
|
+
const contextManifest = normalizeContextManifest(source.context_manifest);
|
|
139
|
+
const producedPatchSha256 = source.produced_patch_sha256 != null
|
|
140
|
+
? String(source.produced_patch_sha256) : null;
|
|
141
|
+
const modelCallCount = typeof source.model_call_count === "number"
|
|
142
|
+
? source.model_call_count : null;
|
|
143
|
+
const tokensUsed = normalizeTokensUsed(source.tokens_used);
|
|
144
|
+
const canonical = [
|
|
145
|
+
sessionId || "",
|
|
146
|
+
toolkit || "",
|
|
147
|
+
eventType || "",
|
|
148
|
+
command || "",
|
|
149
|
+
runId || "",
|
|
150
|
+
agentRole || "",
|
|
151
|
+
taskId || "",
|
|
152
|
+
timestamp,
|
|
153
|
+
].join("|");
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
event_id: fingerprintId("evt", canonical),
|
|
157
|
+
session_id: sessionId,
|
|
158
|
+
toolkit,
|
|
159
|
+
phase: nullableString(source.phase),
|
|
160
|
+
event_type: eventType,
|
|
161
|
+
command,
|
|
162
|
+
run_id: runId,
|
|
163
|
+
agent_role: agentRole,
|
|
164
|
+
task_id: taskId,
|
|
165
|
+
feature_key: featureKey,
|
|
166
|
+
stop_condition_hit: stopConditionHit,
|
|
167
|
+
evidence_quality_ok: evidenceQualityOk,
|
|
168
|
+
overall_verdict: overallVerdict,
|
|
169
|
+
roles_not_ready_count: rolesNotReadyCount,
|
|
170
|
+
report_path: reportPath,
|
|
171
|
+
...(Object.prototype.hasOwnProperty.call(source, "worktree_path") ? { worktree_path: worktreePath } : {}),
|
|
172
|
+
...(Object.prototype.hasOwnProperty.call(source, "actions_executed") ? { actions_executed: actionsExecuted } : {}),
|
|
173
|
+
...(Object.prototype.hasOwnProperty.call(source, "execution_mode") ? { execution_mode: executionMode } : {}),
|
|
174
|
+
...(Object.prototype.hasOwnProperty.call(source, "workflow_type") ? { workflow_type: workflowType } : {}),
|
|
175
|
+
...(Object.prototype.hasOwnProperty.call(source, "model_provider") ? { model_provider: modelProvider } : {}),
|
|
176
|
+
...(Object.prototype.hasOwnProperty.call(source, "model_id") ? { model_id: modelId } : {}),
|
|
177
|
+
...(Object.prototype.hasOwnProperty.call(source, "prompt_sha256") ? { prompt_sha256: promptSha256 } : {}),
|
|
178
|
+
...(Object.prototype.hasOwnProperty.call(source, "context_manifest") ? { context_manifest: contextManifest } : {}),
|
|
179
|
+
...(Object.prototype.hasOwnProperty.call(source, "produced_patch_sha256") ? { produced_patch_sha256: producedPatchSha256 } : {}),
|
|
180
|
+
...(Object.prototype.hasOwnProperty.call(source, "model_call_count") ? { model_call_count: modelCallCount } : {}),
|
|
181
|
+
...(Object.prototype.hasOwnProperty.call(source, "tokens_used") ? { tokens_used: tokensUsed } : {}),
|
|
182
|
+
status: normalizeStatus(source.status),
|
|
183
|
+
cwd: typeof source.cwd === "string" ? redact(source.cwd) : null,
|
|
184
|
+
files: normalizeFiles(source.files),
|
|
185
|
+
timestamp,
|
|
186
|
+
redaction: "applied",
|
|
187
|
+
truncated,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function readExistingEventIds(file) {
|
|
192
|
+
if (!fs.existsSync(file)) {
|
|
193
|
+
return new Set();
|
|
194
|
+
}
|
|
195
|
+
const ids = new Set();
|
|
196
|
+
const content = fs.readFileSync(file, "utf8");
|
|
197
|
+
for (const line of content.split(/\r?\n/)) {
|
|
198
|
+
if (!line.trim()) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const event = JSON.parse(line);
|
|
203
|
+
if (event && typeof event.event_id === "string") {
|
|
204
|
+
ids.add(event.event_id);
|
|
205
|
+
}
|
|
206
|
+
} catch (_error) {
|
|
207
|
+
// Append-only logs should remain writable even if one old line is malformed.
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return ids;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Append a redacted trust event.
|
|
215
|
+
*
|
|
216
|
+
* The caller must provide a stable timestamp when retry-idempotency is desired.
|
|
217
|
+
* If timestamp is omitted, each call receives the current ISO timestamp and is
|
|
218
|
+
* treated as a distinct observation.
|
|
219
|
+
*/
|
|
220
|
+
function appendEvent(projectPath, raw) {
|
|
221
|
+
const event = buildEvent(raw);
|
|
222
|
+
const file = eventsFile(projectPath, event.timestamp.slice(0, 10));
|
|
223
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
224
|
+
|
|
225
|
+
const existingIds = readExistingEventIds(file);
|
|
226
|
+
if (existingIds.has(event.event_id)) {
|
|
227
|
+
return { event, written: false };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fs.appendFileSync(file, `${JSON.stringify(event)}\n`, "utf8");
|
|
231
|
+
return { event, written: true };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function withKeyedLock(key, fn) {
|
|
235
|
+
const prev = locks.get(key) || Promise.resolve();
|
|
236
|
+
const next = prev.then(fn, fn);
|
|
237
|
+
const cleanup = next.then(
|
|
238
|
+
() => {},
|
|
239
|
+
() => {},
|
|
240
|
+
);
|
|
241
|
+
locks.set(key, cleanup);
|
|
242
|
+
cleanup.then(() => {
|
|
243
|
+
if (locks.get(key) === cleanup) {
|
|
244
|
+
locks.delete(key);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
return next;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
void withKeyedLock;
|
|
251
|
+
|
|
252
|
+
module.exports = { generateId, fingerprintId, buildEvent, appendEvent, eventsDir, eventsFile };
|