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.
Files changed (56) hide show
  1. package/README.md +204 -204
  2. package/assets/manifest/toolkit-bundle.manifest.json +147 -147
  3. package/assets/manifest/toolkit-bundle.sha256.txt +5 -5
  4. package/bin/sdtk-code.js +14 -14
  5. package/package.json +44 -44
  6. package/src/commands/agent-team.js +425 -174
  7. package/src/commands/build.js +53 -53
  8. package/src/commands/doctor.js +51 -51
  9. package/src/commands/generate.js +11 -11
  10. package/src/commands/guardrails.js +215 -215
  11. package/src/commands/help.js +264 -257
  12. package/src/commands/init.js +98 -98
  13. package/src/commands/plan.js +53 -53
  14. package/src/commands/readiness.js +77 -77
  15. package/src/commands/resume.js +61 -61
  16. package/src/commands/runtime.js +224 -224
  17. package/src/commands/ship.js +59 -59
  18. package/src/commands/sleep.js +132 -132
  19. package/src/commands/start.js +89 -89
  20. package/src/commands/status.js +77 -77
  21. package/src/commands/update.js +11 -11
  22. package/src/commands/verify.js +71 -71
  23. package/src/index.js +112 -112
  24. package/src/lib/agent-team-author.js +521 -0
  25. package/src/lib/agent-team-evidence.js +302 -0
  26. package/src/lib/agent-team-execute.js +892 -0
  27. package/src/lib/agent-team-export.js +411 -409
  28. package/src/lib/agent-team-plan.js +514 -514
  29. package/src/lib/agent-team-readiness.js +161 -0
  30. package/src/lib/agent-team-report.js +165 -0
  31. package/src/lib/args.js +107 -107
  32. package/src/lib/errors.js +41 -41
  33. package/src/lib/model-provider.js +219 -0
  34. package/src/lib/powershell.js +65 -65
  35. package/src/lib/project-target-guard.js +53 -53
  36. package/src/lib/scope.js +72 -72
  37. package/src/lib/ship-readiness.js +281 -281
  38. package/src/lib/sleep-plan.js +175 -175
  39. package/src/lib/sleep-report.js +229 -229
  40. package/src/lib/toolkit-payload.js +72 -72
  41. package/src/lib/trust-events.js +252 -185
  42. package/src/lib/trust-file-scope.js +154 -154
  43. package/src/lib/trust-policy.js +212 -212
  44. package/src/lib/trust-redact.js +58 -35
  45. package/src/lib/trust-trace.js +179 -179
  46. package/src/lib/update.js +344 -344
  47. package/src/lib/workflow-artifact.js +503 -503
  48. package/src/lib/workflow-build.js +127 -127
  49. package/src/lib/workflow-doctor.js +83 -83
  50. package/src/lib/workflow-handoff.js +1029 -1029
  51. package/src/lib/workflow-intake.js +101 -101
  52. package/src/lib/workflow-plan.js +193 -193
  53. package/src/lib/workflow-review-packet.js +650 -650
  54. package/src/lib/workflow-ship.js +213 -213
  55. package/src/lib/workflow-state.js +438 -438
  56. package/src/lib/workflow-verify.js +393 -393
@@ -1,179 +1,179 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { eventsDir } = require("./trust-events");
6
-
7
- function compareTimestamp(left, right) {
8
- return String(left.timestamp || "").localeCompare(String(right.timestamp || ""));
9
- }
10
-
11
- function normalizeEvent(event) {
12
- return event && typeof event === "object" ? event : {};
13
- }
14
-
15
- function phaseName(event) {
16
- return typeof event.phase === "string" && event.phase.length > 0 ? event.phase : "ungrouped";
17
- }
18
-
19
- function isFailure(event) {
20
- return event.status === "fail";
21
- }
22
-
23
- function isBlocked(event) {
24
- return event.status === "blocked";
25
- }
26
-
27
- function isDecisionGate(event) {
28
- if (event.event_type === "file_scope_check" && event.status === "fail") {
29
- return true;
30
- }
31
- if (event.event_type === "guardrail_check" && (event.status === "fail" || event.status === "blocked" || event.decision === "deny")) {
32
- return true;
33
- }
34
- return false;
35
- }
36
-
37
- function loadEvents(projectPath, opts = {}) {
38
- const dir = eventsDir(projectPath);
39
- if (!fs.existsSync(dir)) {
40
- return [];
41
- }
42
-
43
- const files = fs.readdirSync(dir)
44
- .filter((name) => name.endsWith(".jsonl"))
45
- .filter((name) => !opts.date || name === `${opts.date}.jsonl`)
46
- .sort();
47
-
48
- const events = [];
49
- for (const fileName of files) {
50
- const filePath = path.join(dir, fileName);
51
- const content = fs.readFileSync(filePath, "utf8");
52
- for (const line of content.split(/\r?\n/)) {
53
- if (!line.trim()) {
54
- continue;
55
- }
56
- try {
57
- const event = JSON.parse(line);
58
- if (event && typeof event === "object") {
59
- events.push(event);
60
- }
61
- } catch (_error) {
62
- // Trust trace replay is resilient: malformed JSONL lines are skipped.
63
- }
64
- }
65
- }
66
- return events.sort(compareTimestamp);
67
- }
68
-
69
- function buildTrace(events) {
70
- const sorted = Array.isArray(events) ? events.map(normalizeEvent).slice().sort(compareTimestamp) : [];
71
- const phaseMap = new Map();
72
- const sourceEventIds = [];
73
- let failures = 0;
74
- let blocked = 0;
75
- let decisionGates = 0;
76
-
77
- for (const event of sorted) {
78
- const phase = phaseName(event);
79
- if (!phaseMap.has(phase)) {
80
- phaseMap.set(phase, { phase, events: [], failures: 0, blocked: 0, decisionGates: 0 });
81
- }
82
-
83
- const group = phaseMap.get(phase);
84
- group.events.push(Object.assign({}, event));
85
- if (typeof event.event_id === "string") {
86
- sourceEventIds.push(event.event_id);
87
- }
88
- if (isFailure(event)) {
89
- failures += 1;
90
- group.failures += 1;
91
- }
92
- if (isBlocked(event)) {
93
- blocked += 1;
94
- group.blocked += 1;
95
- }
96
- if (isDecisionGate(event)) {
97
- decisionGates += 1;
98
- group.decisionGates += 1;
99
- }
100
- }
101
-
102
- return {
103
- phases: Array.from(phaseMap.values()),
104
- totals: {
105
- events: sorted.length,
106
- failures,
107
- blocked,
108
- decisionGates,
109
- },
110
- sourceEventIds,
111
- };
112
- }
113
-
114
- function commandText(event) {
115
- if (typeof event.command === "string" && event.command.length > 0) {
116
- return event.command;
117
- }
118
- return "(no command recorded)";
119
- }
120
-
121
- function renderTraceMarkdown(trace, meta = {}) {
122
- const title = meta.title || `Trust Trace ${meta.featureKey || ""}`.trim() || "Trust Trace";
123
- const lines = [
124
- `# ${title}`,
125
- "",
126
- "Replay mode: reconstruction only. This report does not re-run commands and does not mutate events.",
127
- "",
128
- "## Summary",
129
- "",
130
- `- Events: ${trace.totals.events}`,
131
- `- Failures: ${trace.totals.failures}`,
132
- `- Blocked: ${trace.totals.blocked}`,
133
- `- Decision gates: ${trace.totals.decisionGates}`,
134
- "",
135
- "## Source Event IDs",
136
- "",
137
- ];
138
-
139
- if (trace.sourceEventIds.length === 0) {
140
- lines.push("- None");
141
- } else {
142
- for (const id of trace.sourceEventIds) {
143
- lines.push(`- \`${id}\``);
144
- }
145
- }
146
-
147
- for (const phase of trace.phases) {
148
- lines.push("", `## Phase: ${phase.phase}`, "", `- Events: ${phase.events.length}`, `- Failures: ${phase.failures}`, `- Blocked: ${phase.blocked}`, `- Decision gates: ${phase.decisionGates}`, "");
149
-
150
- for (const event of phase.events) {
151
- const gate = isDecisionGate(event) ? " Decision Gate" : "";
152
- const eventId = event.event_id || "missing-event-id";
153
- const timestamp = event.timestamp || "unknown-time";
154
- const type = event.event_type || "unknown";
155
- const status = event.status || "info";
156
- lines.push(`- ${timestamp} - ${status} - ${type}${gate} - \`${eventId}\``);
157
- lines.push(` - Command: ${commandText(event)}`);
158
- if (Array.isArray(event.files) && event.files.length > 0) {
159
- lines.push(` - Files: ${event.files.join(", ")}`);
160
- }
161
- }
162
- }
163
-
164
- return `${lines.join("\n")}\n`;
165
- }
166
-
167
- function writeTraceReport(projectPath, featureKey) {
168
- const project = path.resolve(projectPath || ".");
169
- const events = loadEvents(project);
170
- const trace = buildTrace(events);
171
- const markdown = renderTraceMarkdown(trace, { featureKey, title: `Trust Trace ${featureKey}` });
172
- const reportDir = path.join(project, "docs", "trust");
173
- const reportPath = path.join(reportDir, `TRUST_TRACE_${featureKey}.md`);
174
- fs.mkdirSync(reportDir, { recursive: true });
175
- fs.writeFileSync(reportPath, markdown, "utf8");
176
- return { path: reportPath, events: trace.totals.events, trace };
177
- }
178
-
179
- module.exports = { loadEvents, buildTrace, renderTraceMarkdown, writeTraceReport };
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { eventsDir } = require("./trust-events");
6
+
7
+ function compareTimestamp(left, right) {
8
+ return String(left.timestamp || "").localeCompare(String(right.timestamp || ""));
9
+ }
10
+
11
+ function normalizeEvent(event) {
12
+ return event && typeof event === "object" ? event : {};
13
+ }
14
+
15
+ function phaseName(event) {
16
+ return typeof event.phase === "string" && event.phase.length > 0 ? event.phase : "ungrouped";
17
+ }
18
+
19
+ function isFailure(event) {
20
+ return event.status === "fail";
21
+ }
22
+
23
+ function isBlocked(event) {
24
+ return event.status === "blocked";
25
+ }
26
+
27
+ function isDecisionGate(event) {
28
+ if (event.event_type === "file_scope_check" && event.status === "fail") {
29
+ return true;
30
+ }
31
+ if (event.event_type === "guardrail_check" && (event.status === "fail" || event.status === "blocked" || event.decision === "deny")) {
32
+ return true;
33
+ }
34
+ return false;
35
+ }
36
+
37
+ function loadEvents(projectPath, opts = {}) {
38
+ const dir = eventsDir(projectPath);
39
+ if (!fs.existsSync(dir)) {
40
+ return [];
41
+ }
42
+
43
+ const files = fs.readdirSync(dir)
44
+ .filter((name) => name.endsWith(".jsonl"))
45
+ .filter((name) => !opts.date || name === `${opts.date}.jsonl`)
46
+ .sort();
47
+
48
+ const events = [];
49
+ for (const fileName of files) {
50
+ const filePath = path.join(dir, fileName);
51
+ const content = fs.readFileSync(filePath, "utf8");
52
+ for (const line of content.split(/\r?\n/)) {
53
+ if (!line.trim()) {
54
+ continue;
55
+ }
56
+ try {
57
+ const event = JSON.parse(line);
58
+ if (event && typeof event === "object") {
59
+ events.push(event);
60
+ }
61
+ } catch (_error) {
62
+ // Trust trace replay is resilient: malformed JSONL lines are skipped.
63
+ }
64
+ }
65
+ }
66
+ return events.sort(compareTimestamp);
67
+ }
68
+
69
+ function buildTrace(events) {
70
+ const sorted = Array.isArray(events) ? events.map(normalizeEvent).slice().sort(compareTimestamp) : [];
71
+ const phaseMap = new Map();
72
+ const sourceEventIds = [];
73
+ let failures = 0;
74
+ let blocked = 0;
75
+ let decisionGates = 0;
76
+
77
+ for (const event of sorted) {
78
+ const phase = phaseName(event);
79
+ if (!phaseMap.has(phase)) {
80
+ phaseMap.set(phase, { phase, events: [], failures: 0, blocked: 0, decisionGates: 0 });
81
+ }
82
+
83
+ const group = phaseMap.get(phase);
84
+ group.events.push(Object.assign({}, event));
85
+ if (typeof event.event_id === "string") {
86
+ sourceEventIds.push(event.event_id);
87
+ }
88
+ if (isFailure(event)) {
89
+ failures += 1;
90
+ group.failures += 1;
91
+ }
92
+ if (isBlocked(event)) {
93
+ blocked += 1;
94
+ group.blocked += 1;
95
+ }
96
+ if (isDecisionGate(event)) {
97
+ decisionGates += 1;
98
+ group.decisionGates += 1;
99
+ }
100
+ }
101
+
102
+ return {
103
+ phases: Array.from(phaseMap.values()),
104
+ totals: {
105
+ events: sorted.length,
106
+ failures,
107
+ blocked,
108
+ decisionGates,
109
+ },
110
+ sourceEventIds,
111
+ };
112
+ }
113
+
114
+ function commandText(event) {
115
+ if (typeof event.command === "string" && event.command.length > 0) {
116
+ return event.command;
117
+ }
118
+ return "(no command recorded)";
119
+ }
120
+
121
+ function renderTraceMarkdown(trace, meta = {}) {
122
+ const title = meta.title || `Trust Trace ${meta.featureKey || ""}`.trim() || "Trust Trace";
123
+ const lines = [
124
+ `# ${title}`,
125
+ "",
126
+ "Replay mode: reconstruction only. This report does not re-run commands and does not mutate events.",
127
+ "",
128
+ "## Summary",
129
+ "",
130
+ `- Events: ${trace.totals.events}`,
131
+ `- Failures: ${trace.totals.failures}`,
132
+ `- Blocked: ${trace.totals.blocked}`,
133
+ `- Decision gates: ${trace.totals.decisionGates}`,
134
+ "",
135
+ "## Source Event IDs",
136
+ "",
137
+ ];
138
+
139
+ if (trace.sourceEventIds.length === 0) {
140
+ lines.push("- None");
141
+ } else {
142
+ for (const id of trace.sourceEventIds) {
143
+ lines.push(`- \`${id}\``);
144
+ }
145
+ }
146
+
147
+ for (const phase of trace.phases) {
148
+ lines.push("", `## Phase: ${phase.phase}`, "", `- Events: ${phase.events.length}`, `- Failures: ${phase.failures}`, `- Blocked: ${phase.blocked}`, `- Decision gates: ${phase.decisionGates}`, "");
149
+
150
+ for (const event of phase.events) {
151
+ const gate = isDecisionGate(event) ? " Decision Gate" : "";
152
+ const eventId = event.event_id || "missing-event-id";
153
+ const timestamp = event.timestamp || "unknown-time";
154
+ const type = event.event_type || "unknown";
155
+ const status = event.status || "info";
156
+ lines.push(`- ${timestamp} - ${status} - ${type}${gate} - \`${eventId}\``);
157
+ lines.push(` - Command: ${commandText(event)}`);
158
+ if (Array.isArray(event.files) && event.files.length > 0) {
159
+ lines.push(` - Files: ${event.files.join(", ")}`);
160
+ }
161
+ }
162
+ }
163
+
164
+ return `${lines.join("\n")}\n`;
165
+ }
166
+
167
+ function writeTraceReport(projectPath, featureKey) {
168
+ const project = path.resolve(projectPath || ".");
169
+ const events = loadEvents(project);
170
+ const trace = buildTrace(events);
171
+ const markdown = renderTraceMarkdown(trace, { featureKey, title: `Trust Trace ${featureKey}` });
172
+ const reportDir = path.join(project, "docs", "trust");
173
+ const reportPath = path.join(reportDir, `TRUST_TRACE_${featureKey}.md`);
174
+ fs.mkdirSync(reportDir, { recursive: true });
175
+ fs.writeFileSync(reportPath, markdown, "utf8");
176
+ return { path: reportPath, events: trace.totals.events, trace };
177
+ }
178
+
179
+ module.exports = { loadEvents, buildTrace, renderTraceMarkdown, writeTraceReport };