slicekit 0.0.1 → 0.1.2
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 +252 -3
- package/bin/slicekit.js +4 -0
- package/package.json +21 -4
- package/src/adapters/githost/errors.js +17 -0
- package/src/adapters/githost/fixture.js +136 -0
- package/src/adapters/githost/gh-json.js +99 -0
- package/src/adapters/githost/github.js +127 -0
- package/src/adapters/githost/index.js +12 -0
- package/src/adapters/tracker/errors.js +53 -0
- package/src/adapters/tracker/fixture.js +71 -0
- package/src/adapters/tracker/github-issues.js +65 -0
- package/src/adapters/tracker/index.js +14 -0
- package/src/baseline.js +109 -0
- package/src/build/commit.js +201 -0
- package/src/build/decline.js +81 -0
- package/src/build/finish.js +155 -0
- package/src/build/order.js +158 -0
- package/src/build/overlap.js +173 -0
- package/src/build/parallel.js +50 -0
- package/src/build/pr.js +263 -0
- package/src/build/record.js +28 -0
- package/src/build/red.js +207 -0
- package/src/build/review.js +123 -0
- package/src/build/sync.js +47 -0
- package/src/build/verdict.js +410 -0
- package/src/build/worktree.js +169 -0
- package/src/check/ci-event.js +52 -0
- package/src/check/context.js +129 -0
- package/src/check/index.js +140 -0
- package/src/check/rules/.gitkeep +0 -0
- package/src/check/rules/ci-body.js +22 -0
- package/src/check/rules/ci-title.js +43 -0
- package/src/check/rules/citations.js +224 -0
- package/src/check/rules/commands.js +146 -0
- package/src/check/rules/coverage.js +248 -0
- package/src/check/rules/hooks.js +58 -0
- package/src/check/rules/journal.js +17 -0
- package/src/check/rules/layout.js +56 -0
- package/src/check/rules/managed.js +31 -0
- package/src/check/rules/queue.js +106 -0
- package/src/check/rules/references.js +249 -0
- package/src/check/rules/style.js +177 -0
- package/src/check/rules/trailer.js +67 -0
- package/src/cli/baseline.js +66 -0
- package/src/cli/branch.js +86 -0
- package/src/cli/build.js +239 -0
- package/src/cli/check.js +40 -0
- package/src/cli/decide.js +59 -0
- package/src/cli/gaps.js +73 -0
- package/src/cli/hook.js +28 -0
- package/src/cli/index.js +83 -0
- package/src/cli/init.js +96 -0
- package/src/cli/instructions.js +63 -0
- package/src/cli/intake.js +107 -0
- package/src/cli/journal.js +82 -0
- package/src/cli/plan.js +29 -0
- package/src/cli/pr.js +83 -0
- package/src/cli/process.js +59 -0
- package/src/cli/ready-label.js +119 -0
- package/src/cli/review.js +64 -0
- package/src/cli/spec.js +31 -0
- package/src/cli/stage.js +37 -0
- package/src/cli/state.js +106 -0
- package/src/cli/status.js +108 -0
- package/src/cli/update.js +62 -0
- package/src/cli/workflow.js +48 -0
- package/src/config.js +203 -0
- package/src/decisions.js +289 -0
- package/src/evidence.js +27 -0
- package/src/fs.js +38 -0
- package/src/gaps.js +271 -0
- package/src/git.js +209 -0
- package/src/githooks.js +37 -0
- package/src/hook-cli.js +63 -0
- package/src/hooks/io.js +205 -0
- package/src/hooks/paths.js +82 -0
- package/src/hooks/pre-bash.js +715 -0
- package/src/hooks/pre-compact.js +139 -0
- package/src/hooks/pre-edit.js +170 -0
- package/src/hooks/session-end.js +118 -0
- package/src/hooks/session-start.js +209 -0
- package/src/hooks/shapes.js +103 -0
- package/src/hooks/stop.js +37 -0
- package/src/hooks/subagent-marker.js +88 -0
- package/src/hooks/subagent-start.js +100 -0
- package/src/hooks/subagent-stop.js +106 -0
- package/src/ids.js +43 -0
- package/src/init.js +281 -0
- package/src/instructions.js +235 -0
- package/src/intake.js +409 -0
- package/src/journal.js +326 -0
- package/src/lock.js +35 -0
- package/src/markdown.js +155 -0
- package/src/paths.js +33 -0
- package/src/plan.js +25 -0
- package/src/pr.js +73 -0
- package/src/prbody.js +266 -0
- package/src/ready-label.js +107 -0
- package/src/redact.js +33 -0
- package/src/render/compare.js +23 -0
- package/src/render/entry.js +101 -0
- package/src/render/index.js +27 -0
- package/src/render/managed.js +128 -0
- package/src/render/manifest.js +24 -0
- package/src/render/settings.js +76 -0
- package/src/render/update.js +151 -0
- package/src/slicefile.js +173 -0
- package/src/spec-verify.js +58 -0
- package/src/stage.js +325 -0
- package/src/state/build.js +156 -0
- package/src/state/covers.js +58 -0
- package/src/state/index.js +191 -0
- package/src/state/sync.js +64 -0
- package/src/state/transitions.js +282 -0
- package/src/verdict.js +203 -0
- package/src/which.js +37 -0
- package/src/workflow.js +177 -0
- package/src/worktrees.js +68 -0
- package/templates/claude-code/agents/auditor.md +7 -0
- package/templates/claude-code/agents/designer.md +7 -0
- package/templates/claude-code/agents/developer.md +7 -0
- package/templates/claude-code/agents/fixer.md +7 -0
- package/templates/claude-code/agents/ops.md +7 -0
- package/templates/claude-code/agents/reviewer.md +7 -0
- package/templates/claude-code/commands/slicekit-audit.md +7 -0
- package/templates/claude-code/commands/slicekit-build.md +7 -0
- package/templates/claude-code/commands/slicekit-gaps.md +6 -0
- package/templates/claude-code/commands/slicekit-intake.md +7 -0
- package/templates/claude-code/commands/slicekit-ops.md +7 -0
- package/templates/claude-code/commands/slicekit-plan.md +6 -0
- package/templates/claude-code/commands/slicekit-release.md +7 -0
- package/templates/claude-code/commands/slicekit-review.md +7 -0
- package/templates/claude-code/commands/slicekit-specify.md +6 -0
- package/templates/claude-code/commands/slicekit.md +7 -0
- package/templates/claude-code/hooks.json +90 -0
- package/templates/claude-code/manifest.json +171 -0
- package/templates/claude-code/skills/slicekit-ids/SKILL.md +16 -0
- package/templates/claude-code/skills/slicekit-loop/SKILL.md +23 -0
- package/templates/claude-code/skills/slicekit-writing/SKILL.md +24 -0
- package/templates/docs/BUILD.md +5 -0
- package/templates/docs/decisions.md +15 -0
- package/templates/docs/intake/.keep +0 -0
- package/templates/docs/observability.md +25 -0
- package/templates/docs/phases/.keep +0 -0
- package/templates/docs/platform.md +25 -0
- package/templates/docs/releases/.keep +0 -0
- package/templates/docs/runbook.md +21 -0
- package/templates/docs/spec/00-overview.md +8 -0
- package/templates/docs/spec/contracts/.keep +0 -0
- package/templates/docs/spec/gaps.md +6 -0
- package/templates/docs/spec/stack.md +3 -0
- package/templates/githooks/pre-commit +79 -0
- package/templates/githooks/pre-merge-commit +79 -0
- package/templates/githooks/prepare-commit-msg +110 -0
- package/templates/instructions/agents/auditor.md +33 -0
- package/templates/instructions/agents/designer.md +21 -0
- package/templates/instructions/agents/developer.md +49 -0
- package/templates/instructions/agents/fixer.md +41 -0
- package/templates/instructions/agents/ops.md +21 -0
- package/templates/instructions/agents/reviewer.md +63 -0
- package/templates/instructions/commands/build.md +234 -0
- package/templates/instructions/commands/gaps.md +65 -0
- package/templates/instructions/commands/intake.md +90 -0
- package/templates/instructions/commands/plan.md +60 -0
- package/templates/instructions/commands/review.md +117 -0
- package/templates/instructions/commands/specify.md +49 -0
- package/templates/style.json +11 -0
- package/templates/workflow/pins.json +6 -0
- package/templates/workflow/slicekit.yml +110 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// pre-compact (REQ-3.6): before Claude Code compacts the conversation, writes a handoff into the active
|
|
2
|
+
// slice's state file so session-start can re-inject it on `compact` (REQ-3.1). Fails open through io.js:
|
|
3
|
+
// it never blocks compaction, and a failure (state unreadable, lock busy) is a stderr note.
|
|
4
|
+
//
|
|
5
|
+
// The handoff is plain keys with one-line values, so session-start prints it as `handoff: key: value`:
|
|
6
|
+
// at when it was written (ISO 8601)
|
|
7
|
+
// state the slice's stage
|
|
8
|
+
// openFindings the B-<n> ids of the latest verdict when that verdict is BLOCK, comma-joined; `none`
|
|
9
|
+
// lastCommand the last `ran: <command> → exit <n>` line in the tail of the main session's transcript,
|
|
10
|
+
// assistant text before tool output, secrets masked, cut to 200 characters; `none`
|
|
11
|
+
// nextStep by stage (nextStep below)
|
|
12
|
+
// Only the handoff changes: setHandoff re-reads the state under the slice lock and leaves state and
|
|
13
|
+
// history alone, and skips a slice with no state file yet. The lock is waited on for at most
|
|
14
|
+
// LOCK_BUDGET_MS.
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
import { redact } from '../redact.js';
|
|
18
|
+
import { setHandoff } from '../state/index.js';
|
|
19
|
+
import { parseVerdict } from '../verdict.js';
|
|
20
|
+
import { allow } from './io.js';
|
|
21
|
+
import { activeSlice, fromGitBash, transcriptTail } from './paths.js';
|
|
22
|
+
import { RAN } from './shapes.js';
|
|
23
|
+
|
|
24
|
+
export const TRANSCRIPT_TAIL = 256 * 1024;
|
|
25
|
+
export const LOCK_BUDGET_MS = 2_000;
|
|
26
|
+
const COMMAND_MAX = 200;
|
|
27
|
+
|
|
28
|
+
// The texts of one transcript entry: {assistant, tool}. Text the user typed is in neither.
|
|
29
|
+
function texts(content, role) {
|
|
30
|
+
const out = { assistant: [], tool: [] };
|
|
31
|
+
if (typeof content === 'string') {
|
|
32
|
+
if (role === 'assistant') out.assistant.push(content);
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
if (!Array.isArray(content)) return out;
|
|
36
|
+
for (const part of content) {
|
|
37
|
+
if (role === 'assistant' && part?.type === 'text' && typeof part.text === 'string') out.assistant.push(part.text);
|
|
38
|
+
if (part?.type === 'tool_result') {
|
|
39
|
+
if (typeof part.content === 'string') out.tool.push(part.content);
|
|
40
|
+
else if (Array.isArray(part.content)) {
|
|
41
|
+
for (const p of part.content) if (p?.type === 'text' && typeof p.text === 'string') out.tool.push(p.text);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const lastRan = (list) => list.flatMap((t) => t.split(/\r?\n/)).filter((l) => RAN.test(l)).at(-1);
|
|
49
|
+
|
|
50
|
+
// The last `ran: <command> → exit <n>` line (shapes.js RAN) in the transcript's last TRANSCRIPT_TAIL
|
|
51
|
+
// bytes: from assistant text when any has one (the agent's own report), else from tool output (which
|
|
52
|
+
// may only echo an old line). Secrets are masked (redact) before the line is trimmed and cut to
|
|
53
|
+
// COMMAND_MAX characters. null when there is none or the file cannot be read.
|
|
54
|
+
export function lastRanLine(file) {
|
|
55
|
+
const lines = transcriptTail(file, TRANSCRIPT_TAIL);
|
|
56
|
+
if (lines === null) return null;
|
|
57
|
+
let fromTool;
|
|
58
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
59
|
+
let entry;
|
|
60
|
+
try {
|
|
61
|
+
entry = JSON.parse(lines[i]);
|
|
62
|
+
} catch {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const role = entry?.message?.role;
|
|
66
|
+
if (role !== 'assistant' && role !== 'user') continue;
|
|
67
|
+
const t = texts(entry.message.content, role);
|
|
68
|
+
const said = lastRan(t.assistant);
|
|
69
|
+
if (said !== undefined) return clip(said);
|
|
70
|
+
fromTool ??= lastRan(t.tool);
|
|
71
|
+
}
|
|
72
|
+
return fromTool === undefined ? null : clip(fromTool);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const clip = (line) => redact(line).trim().slice(0, COMMAND_MAX);
|
|
76
|
+
|
|
77
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
78
|
+
|
|
79
|
+
// The highest-round verdict file of the slice: {shown, ids} where ids are its blockers when its verdict
|
|
80
|
+
// is BLOCK; null when the slice has no readable verdict file.
|
|
81
|
+
function latestVerdict(root, id) {
|
|
82
|
+
const dir = path.join(root, '.slicekit', 'reviews');
|
|
83
|
+
const name = new RegExp(`^${escapeRe(id.replace('/', '-'))}-r(\\d+)\\.md$`);
|
|
84
|
+
let names;
|
|
85
|
+
try {
|
|
86
|
+
names = fs.readdirSync(dir);
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const rounds = names.map((n) => [n, name.exec(n)]).filter(([, m]) => m).map(([n, m]) => [n, Number(m[1])])
|
|
91
|
+
.sort((a, b) => b[1] - a[1]);
|
|
92
|
+
for (const [n] of rounds) {
|
|
93
|
+
const file = path.join(dir, n);
|
|
94
|
+
let text;
|
|
95
|
+
try {
|
|
96
|
+
if (!fs.lstatSync(file).isFile()) continue;
|
|
97
|
+
text = fs.readFileSync(file);
|
|
98
|
+
} catch {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const shown = `.slicekit/reviews/${n}`;
|
|
102
|
+
const v = parseVerdict(text, shown);
|
|
103
|
+
const ids = v.verdict === 'BLOCK'
|
|
104
|
+
? [...new Set(v.findings.filter((f) => f.kind === 'blocker').map((f) => f.id))] : [];
|
|
105
|
+
return { shown, ids };
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function nextStep(state, verdict) {
|
|
111
|
+
if (state === 'tests-red') return 'build until the frozen tests pass';
|
|
112
|
+
if (state === 'building') return 'run the test command; when green run slicekit check and push';
|
|
113
|
+
if (state === 'changes-requested' && verdict?.ids.length) return `fix blockers ${verdict.ids.join(', ')}`;
|
|
114
|
+
if (['draft-pr', 'in-review', 'changes-requested'].includes(state) && verdict) return `address verdict ${verdict.shown}`;
|
|
115
|
+
return 'run slicekit status';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function transcriptOf(input) {
|
|
119
|
+
const p = input?.transcript_path;
|
|
120
|
+
if (typeof p !== 'string' || p === '') return null;
|
|
121
|
+
return lastRanLine(path.resolve(fromGitBash(p.replace(/\\/g, '/'))));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function handle(input, { root, cfg }) {
|
|
125
|
+
const active = activeSlice(root, cfg);
|
|
126
|
+
if (!active) return allow();
|
|
127
|
+
if (active.error) throw new Error(`state of ${active.id} unreadable: ${active.error}`);
|
|
128
|
+
const state = String(active.state.state);
|
|
129
|
+
const verdict = latestVerdict(root, active.id);
|
|
130
|
+
const handoff = {
|
|
131
|
+
at: new Date().toISOString(),
|
|
132
|
+
state,
|
|
133
|
+
openFindings: verdict?.ids.length ? verdict.ids.join(', ') : 'none',
|
|
134
|
+
lastCommand: transcriptOf(input) ?? 'none',
|
|
135
|
+
nextStep: nextStep(state, verdict),
|
|
136
|
+
};
|
|
137
|
+
setHandoff(root, cfg, active.id, handoff, { budgetMs: LOCK_BUDGET_MS });
|
|
138
|
+
return allow();
|
|
139
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// pre-edit (REQ-3.3, D-10): the PreToolUse guard on Edit, Write, MultiEdit and NotebookEdit. Fails
|
|
2
|
+
// closed through io.js.
|
|
3
|
+
//
|
|
4
|
+
// Every path the tool names (`file_path`, `notebook_path`) is judged; any deny wins. Rules, first deny
|
|
5
|
+
// wins: (3) a kit-owned file — a path with a `.slicekit/journal/`, `.slicekit/state/`,
|
|
6
|
+
// `.slicekit/baselines/`, `.slicekit/.subagent-*`, `.slicekit/.retry-*` or `.slicekit/.agents-*` segment
|
|
7
|
+
// under any root, or a `slicekit/subagent-*` marker, `slicekit/retry-*` retry state or `slicekit/agents-*`
|
|
8
|
+
// started-agents record in a git directory (`.git` or `*.git`), or the `slicekit/interview.json` intake
|
|
9
|
+
// session in one (a linked worktree's included)
|
|
10
|
+
// — always; then, only while
|
|
11
|
+
// the file's own root has an active slice (a `slice/*` branch with a state file) in `tests-red` or
|
|
12
|
+
// `building`: (1) a frozen test of that slice, unless `unfrozen` lists it; (2) a file under the docs root
|
|
13
|
+
// that does not exist yet (only a create can name a missing file), except the runbook and anything in
|
|
14
|
+
// the slice's own phase directory.
|
|
15
|
+
//
|
|
16
|
+
// The file's own root is the nearest directory above it holding `.slicekit/config.json`, else its git
|
|
17
|
+
// top level, else the session's root: a session in the main checkout editing a nested worktree is
|
|
18
|
+
// judged by the worktree's branch, state and config. Paths are canonicalised through the real path of
|
|
19
|
+
// their deepest existing ancestor, so 8.3 short names and links resolve; on win32 a `:` after the drive
|
|
20
|
+
// (an NTFS stream name) is refused outright.
|
|
21
|
+
//
|
|
22
|
+
// Limits: a Bash command that writes the same file is pre-bash's business.
|
|
23
|
+
import fs from 'node:fs';
|
|
24
|
+
import path from 'node:path';
|
|
25
|
+
import { CONFIG_PATH, loadConfig } from '../config.js';
|
|
26
|
+
import { GitError, git } from '../git.js';
|
|
27
|
+
import { parseSliceAddr } from '../ids.js';
|
|
28
|
+
import { kitPaths } from '../paths.js';
|
|
29
|
+
import { phaseOfDir } from '../slicefile.js';
|
|
30
|
+
import { allow, deny } from './io.js';
|
|
31
|
+
import { activeSlice, existingAncestor, fromGitBash, real, toPosix } from './paths.js';
|
|
32
|
+
|
|
33
|
+
const WIN = process.platform === 'win32';
|
|
34
|
+
const GUARDED_STATES = new Set(['tests-red', 'building']);
|
|
35
|
+
const PATH_KEYS = ['file_path', 'notebook_path'];
|
|
36
|
+
|
|
37
|
+
const key = (p) => (WIN ? p.toLowerCase() : p);
|
|
38
|
+
const same = (a, b) => key(a) === key(b);
|
|
39
|
+
const under = (p, dir) => same(p, dir) || key(p).startsWith(`${key(dir)}/`);
|
|
40
|
+
|
|
41
|
+
function relInside(root, abs) {
|
|
42
|
+
const rel = path.relative(root, abs);
|
|
43
|
+
if (rel === '' || rel.startsWith('..') || path.isAbsolute(rel)) return null;
|
|
44
|
+
return toPosix(rel);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// -> the canonical absolute path. Accepts absolute Windows paths with either slash, Git Bash `/c/...`
|
|
48
|
+
// on win32, and relative paths (against cwd, else root). Throws on a win32 stream name.
|
|
49
|
+
function absolute(filePath, root, cwd) {
|
|
50
|
+
const p = fromGitBash(String(filePath).replace(/\\/g, '/'));
|
|
51
|
+
if (WIN && p.replace(/^[A-Za-z]:/, '').includes(':')) {
|
|
52
|
+
throw new Error(`${filePath}: a stream name is not a file path`);
|
|
53
|
+
}
|
|
54
|
+
const base = typeof cwd === 'string' && cwd !== '' ? path.resolve(root, fromGitBash(cwd.replace(/\\/g, '/'))) : root;
|
|
55
|
+
return real(path.resolve(base, p));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// -> the POSIX path relative to root, or null when it is outside root.
|
|
59
|
+
export function normalise(filePath, root, cwd) {
|
|
60
|
+
return relInside(real(path.resolve(root)), absolute(filePath, root, cwd));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A kit-owned segment anywhere in the path, whatever root it belongs to; the kit's files in a git
|
|
64
|
+
// directory (`<.git>/slicekit/`: `agents-*`, `retry-*`, `clone-id`, and the old `subagent-*` name)
|
|
65
|
+
// count too, though they lie outside every work tree.
|
|
66
|
+
function kitOwned(abs) {
|
|
67
|
+
const segs = toPosix(abs).split('/').map(key);
|
|
68
|
+
return segs.some((s, i) => {
|
|
69
|
+
if (s !== '.slicekit' || i + 1 >= segs.length) return false;
|
|
70
|
+
const next = segs[i + 1];
|
|
71
|
+
return next === 'journal' || next === 'state' || next === 'baselines' || next.startsWith('.subagent-')
|
|
72
|
+
|| next.startsWith('.retry-') || next.startsWith('.agents-');
|
|
73
|
+
}) || segs.some((s, i) => i > 0 && (segs[i - 1] === '.git' || segs[i - 1].endsWith('.git'))
|
|
74
|
+
&& s === 'slicekit' && (segs[i + 1] === 'clone-id'
|
|
75
|
+
|| ['subagent-', 'retry-', 'agents-'].some((p) => segs[i + 1]?.startsWith(p))))
|
|
76
|
+
// The intake interview session, also in a linked worktree's own git directory
|
|
77
|
+
// (`<.git>/worktrees/<name>/slicekit/interview.json`).
|
|
78
|
+
|| segs.some((s, i) => s === 'slicekit' && segs[i + 1] === 'interview.json'
|
|
79
|
+
&& segs.slice(0, i).some((p) => p === '.git' || p.endsWith('.git')));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The file's own root: the deeper of the nearest `.slicekit/config.json` above it and its git top
|
|
83
|
+
// level (a config in the main checkout never stands in for a nested worktree); null for neither.
|
|
84
|
+
function ownRoot(abs) {
|
|
85
|
+
let start = existingAncestor(abs);
|
|
86
|
+
if (!fs.statSync(start).isDirectory()) start = path.dirname(start);
|
|
87
|
+
let configured = null;
|
|
88
|
+
for (let dir = start; ; dir = path.dirname(dir)) {
|
|
89
|
+
if (fs.existsSync(path.join(dir, CONFIG_PATH))) {
|
|
90
|
+
configured = real(dir);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (path.dirname(dir) === dir) break;
|
|
94
|
+
}
|
|
95
|
+
let top = null;
|
|
96
|
+
try {
|
|
97
|
+
top = real(path.resolve(git(start, ['rev-parse', '--show-toplevel'])));
|
|
98
|
+
} catch (e) {
|
|
99
|
+
if (!(e instanceof GitError)) throw e;
|
|
100
|
+
}
|
|
101
|
+
if (configured && (!top || under(toPosix(configured), toPosix(top)))) return { root: configured, config: true };
|
|
102
|
+
return top ? { root: top, config: false } : null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const stringList = (v) => Array.isArray(v) && v.every((s) => typeof s === 'string');
|
|
106
|
+
|
|
107
|
+
// Whether rel lies inside the slice's own phase directory, `<docs>/phases/P<n>[-name]/`.
|
|
108
|
+
function inOwnPhase(rel, phasesRel, sliceId) {
|
|
109
|
+
if (!under(rel, phasesRel) || same(rel, phasesRel)) return false;
|
|
110
|
+
const [dir, ...inside] = rel.slice(phasesRel.length + 1).split('/');
|
|
111
|
+
const phase = phaseOfDir(dir);
|
|
112
|
+
return inside.length > 0 && phase !== null && phase.n === parseSliceAddr(sliceId).phase;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function judge(filePath, input, hookRoot, hookCfg) {
|
|
116
|
+
const abs = absolute(filePath, hookRoot, input.cwd);
|
|
117
|
+
const hookCanon = real(path.resolve(hookRoot));
|
|
118
|
+
const own = ownRoot(abs);
|
|
119
|
+
let root = hookCanon;
|
|
120
|
+
let cfg = hookCfg;
|
|
121
|
+
if (own && !same(toPosix(own.root), toPosix(hookCanon))) {
|
|
122
|
+
root = own.root;
|
|
123
|
+
if (own.config) cfg = loadConfig(root);
|
|
124
|
+
}
|
|
125
|
+
const rel = relInside(root, abs);
|
|
126
|
+
|
|
127
|
+
// (3)
|
|
128
|
+
if (kitOwned(abs)) return deny(`${rel ?? toPosix(abs)} is written only by the slicekit CLI`);
|
|
129
|
+
if (rel === null) return allow();
|
|
130
|
+
|
|
131
|
+
const active = activeSlice(root, cfg);
|
|
132
|
+
if (active?.error) throw new Error(active.error);
|
|
133
|
+
if (active) {
|
|
134
|
+
for (const field of ['frozenTests', 'unfrozen']) {
|
|
135
|
+
if (!stringList(active.state[field])) throw new Error(`${active.id} state: ${field} must be an array of strings`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!active || !GUARDED_STATES.has(active.state.state)) return allow();
|
|
139
|
+
const { id, state } = active;
|
|
140
|
+
|
|
141
|
+
// (1)
|
|
142
|
+
if (cfg.freezeTests) {
|
|
143
|
+
const listed = (list) => list.some((f) => same(rel, normalise(f, root) ?? ''));
|
|
144
|
+
if (listed(state.frozenTests) && !listed(state.unfrozen)) {
|
|
145
|
+
return deny(`frozen for ${id}; amend the slice file to change the evaluation set`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// (2)
|
|
150
|
+
const k = kitPaths(root, cfg);
|
|
151
|
+
const docs = toPosix(path.relative(root, k.docs));
|
|
152
|
+
if (under(rel, docs) && !same(rel, docs) && !fs.existsSync(abs)
|
|
153
|
+
&& !same(rel, toPosix(path.relative(root, k.runbook)))
|
|
154
|
+
&& !inOwnPhase(rel, toPosix(path.relative(root, k.phases)), id)) {
|
|
155
|
+
return deny("no slice starts a document; a document changes only when this slice's code made it wrong");
|
|
156
|
+
}
|
|
157
|
+
return allow();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function handle(input, { root, cfg }) {
|
|
161
|
+
const given = PATH_KEYS.filter((k) => input?.tool_input?.[k] !== undefined);
|
|
162
|
+
if (!given.length) throw new Error('tool_input.file_path is missing');
|
|
163
|
+
for (const k of given) {
|
|
164
|
+
const p = input.tool_input[k];
|
|
165
|
+
if (typeof p !== 'string' || p === '') throw new Error(`tool_input.${k} is not a path`);
|
|
166
|
+
const r = judge(p, input, root, cfg);
|
|
167
|
+
if (r.hookSpecificOutput?.permissionDecision === 'deny') return r;
|
|
168
|
+
}
|
|
169
|
+
return allow();
|
|
170
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// session-end (REQ-3.8, D-32, D-34, D-36): appends one line to this clone's journal file for the current
|
|
2
|
+
// branch, `.slicekit/journal/<branch-part>--<clone-id>.log`. Fails open through io.js: a refused append
|
|
3
|
+
// (torn or unparseable last line, lock busy) is a stderr note and nothing is written.
|
|
4
|
+
//
|
|
5
|
+
// Since the last line in that file (from the start of the branch when the file is empty):
|
|
6
|
+
// commits short shas of commits on the branch beyond the default branch, committed since that line
|
|
7
|
+
// (same-second commits the last line already named are left out); `-` outside a repository
|
|
8
|
+
// verdicts stems of `.slicekit/reviews/*.md` files modified since that line
|
|
9
|
+
// decisions `D-<n>` ids in the decisions table now, minus those in it at the commit HEAD stood at when
|
|
10
|
+
// that line was written (the merge base with the default branch when the file is empty);
|
|
11
|
+
// `-` outside a repository
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { GitError, assertRef, git as runGit, isRepo, resolveCommit } from '../git.js';
|
|
15
|
+
import { re } from '../ids.js';
|
|
16
|
+
import { appendJournal, journalBranch, readLast } from '../journal.js';
|
|
17
|
+
import { tables } from '../markdown.js';
|
|
18
|
+
import { kitPaths } from '../paths.js';
|
|
19
|
+
import { programStage } from '../stage.js';
|
|
20
|
+
import { allow } from './io.js';
|
|
21
|
+
import { activeSlice, toPosix } from './paths.js';
|
|
22
|
+
|
|
23
|
+
function tryGit(git, args) {
|
|
24
|
+
try {
|
|
25
|
+
return git(args);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
if (e instanceof GitError) return null;
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The default branch as a commit: local first, then origin's; null when neither resolves.
|
|
33
|
+
function defaultBase(root, cfg) {
|
|
34
|
+
const def = assertRef(cfg?.defaultBranch ?? 'main');
|
|
35
|
+
for (const ref of [def, `origin/${def}`]) {
|
|
36
|
+
const sha = resolveCommit(root, ref);
|
|
37
|
+
if (sha) return sha;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function commitsSince(git, base, last) {
|
|
43
|
+
const range = base ? `${base}..HEAD` : 'HEAD';
|
|
44
|
+
const out = tryGit(git, ['log', '--format=%H %ct', '--end-of-options', range, '--']);
|
|
45
|
+
if (!out) return [];
|
|
46
|
+
const sinceSec = last ? Math.floor(Date.parse(last.at) / 1000) : -Infinity;
|
|
47
|
+
const named = new Set(last?.commits ?? []);
|
|
48
|
+
return out.split('\n').map((l) => l.split(' ')).filter(([, ct]) => Number(ct) >= sinceSec)
|
|
49
|
+
.map(([sha]) => sha.slice(0, 7)).filter((s) => !named.has(s));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function verdictsSince(root, last) {
|
|
53
|
+
const dir = path.join(root, '.slicekit', 'reviews');
|
|
54
|
+
const since = last ? Date.parse(last.at) : -Infinity;
|
|
55
|
+
let names;
|
|
56
|
+
try {
|
|
57
|
+
names = fs.readdirSync(dir);
|
|
58
|
+
} catch {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
return names.filter((n) => n.endsWith('.md')).filter((n) => {
|
|
62
|
+
try {
|
|
63
|
+
const st = fs.lstatSync(path.join(dir, n));
|
|
64
|
+
return st.isFile() && st.mtimeMs > since;
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}).map((n) => n.slice(0, -'.md'.length));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const ID_RE = new RegExp(`^${re('decision').source}$`);
|
|
72
|
+
function decisionIds(text) {
|
|
73
|
+
const out = new Set();
|
|
74
|
+
for (const t of tables(text ?? '')) for (const row of t.rows) if (ID_RE.test(row[0] ?? '')) out.add(row[0]);
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function decisionsSince(root, cfg, git, base, last) {
|
|
79
|
+
const file = kitPaths(root, cfg).decisions;
|
|
80
|
+
let now = '';
|
|
81
|
+
try {
|
|
82
|
+
now = fs.readFileSync(file, 'utf8');
|
|
83
|
+
} catch {
|
|
84
|
+
// no decisions file: nothing added
|
|
85
|
+
}
|
|
86
|
+
const then = last
|
|
87
|
+
? tryGit(git, ['rev-list', '-1', `--before=${last.at}`, 'HEAD'])
|
|
88
|
+
: base && tryGit(git, ['merge-base', base, 'HEAD']);
|
|
89
|
+
// `./` makes the path relative to root, which may sit below the git top level.
|
|
90
|
+
const rel = toPosix(path.relative(root, file));
|
|
91
|
+
const old = then ? decisionIds(tryGit(git, ['show', `${then}:./${rel}`])) : new Set();
|
|
92
|
+
return [...decisionIds(now)].filter((d) => !old.has(d));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function stageOf(root, cfg) {
|
|
96
|
+
try {
|
|
97
|
+
return programStage(root, cfg).stage;
|
|
98
|
+
} catch {
|
|
99
|
+
return '-';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function handle(_input, { root, cfg, env = process.env, git = (args) => runGit(root, args) }) {
|
|
104
|
+
const branch = journalBranch(root);
|
|
105
|
+
const last = readLast(root, branch, cfg);
|
|
106
|
+
const repo = isRepo(root);
|
|
107
|
+
const base = repo ? defaultBase(root, cfg) : null;
|
|
108
|
+
const active = activeSlice(root, cfg);
|
|
109
|
+
appendJournal(root, {
|
|
110
|
+
actor: env.SLICEKIT_ACTOR || env.USER || env.USERNAME || 'unknown',
|
|
111
|
+
slice: active?.id ?? '-',
|
|
112
|
+
stage: stageOf(root, cfg),
|
|
113
|
+
commits: repo ? commitsSince(git, base, last) : [],
|
|
114
|
+
verdicts: verdictsSince(root, last),
|
|
115
|
+
decisions: repo ? decisionsSince(root, cfg, git, base, last) : [],
|
|
116
|
+
}, { branch, cfg });
|
|
117
|
+
return allow();
|
|
118
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// session-start (REQ-3.1): tells the agent how the branch stands against origin's default branch and
|
|
2
|
+
// which slice is active; after `compact` it re-injects the slice's handoff and points at the brief.
|
|
3
|
+
// Fails open through io.js. Never pulls, merges or blocks: the only network call is one fetch of the
|
|
4
|
+
// default branch into origin/<default> (an explicit refspec, so a narrowed remote.origin.fetch cannot
|
|
5
|
+
// leave the counts stale), run without a shell, with no credential prompt, no ext:: transport and no
|
|
6
|
+
// submodule recursion, killed after FETCH_TIMEOUT_MS (inside the 18 s deadline io.js derives from the
|
|
7
|
+
// 20 s hooks.json timeout).
|
|
8
|
+
//
|
|
9
|
+
// Text from the state file is untrusted: every value goes through oneLine and every handoff line is
|
|
10
|
+
// prefixed `handoff: `, so it can never print a line the hook itself prints.
|
|
11
|
+
//
|
|
12
|
+
// It also sweeps the per-session files subagent-start and subagent-stop leave in
|
|
13
|
+
// `<git-common-dir>/slicekit/` (`agents-*`, `retry-*`) once they are older than LEFTOVER_MS: a session
|
|
14
|
+
// that ended with a subagent open never removes its own. The clone id there is never touched.
|
|
15
|
+
import { execFile } from 'node:child_process';
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import { GitError, assertRef, currentBranch, git, hasCommits, isRepo } from '../git.js';
|
|
19
|
+
import { stateFileName } from '../ids.js';
|
|
20
|
+
import { kitPaths } from '../paths.js';
|
|
21
|
+
import { context, oneLine } from './io.js';
|
|
22
|
+
import { activeSlice } from './paths.js';
|
|
23
|
+
|
|
24
|
+
export const FETCH_TIMEOUT_MS = 15_000;
|
|
25
|
+
export const LEFTOVER_MS = 24 * 60 * 60 * 1000;
|
|
26
|
+
const LEFTOVER_PREFIXES = ['agents-', 'retry-'];
|
|
27
|
+
const REASON_MAX = 120;
|
|
28
|
+
const HANDOFF_MAX = 4000;
|
|
29
|
+
const WIN = process.platform === 'win32';
|
|
30
|
+
|
|
31
|
+
// Removes regular `agents-*` and `retry-*` files older than LEFTOVER_MS from the kit's directory in the
|
|
32
|
+
// git common directory. Best effort: a file that cannot be read or removed is left.
|
|
33
|
+
function sweepLeftovers(root) {
|
|
34
|
+
let dir;
|
|
35
|
+
try {
|
|
36
|
+
dir = path.join(path.resolve(root, git(root, ['rev-parse', '--path-format=absolute', '--git-common-dir'])), 'slicekit');
|
|
37
|
+
} catch (e) {
|
|
38
|
+
if (e instanceof GitError) return;
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
let names;
|
|
42
|
+
try {
|
|
43
|
+
names = fs.readdirSync(dir);
|
|
44
|
+
} catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const cutoff = Date.now() - LEFTOVER_MS;
|
|
48
|
+
for (const name of names.filter((n) => LEFTOVER_PREFIXES.some((p) => n.startsWith(p)))) {
|
|
49
|
+
const file = path.join(dir, name);
|
|
50
|
+
try {
|
|
51
|
+
const st = fs.lstatSync(file);
|
|
52
|
+
if (st.isFile() && st.mtimeMs < cutoff) fs.rmSync(file, { force: true });
|
|
53
|
+
} catch {
|
|
54
|
+
// gone already, or not ours to remove
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
60
|
+
|
|
61
|
+
// Every spelling of root git might print: as given, real path, either slash. Longest first.
|
|
62
|
+
function rootSpellings(root) {
|
|
63
|
+
const forms = new Set();
|
|
64
|
+
let realRoot = root;
|
|
65
|
+
try {
|
|
66
|
+
realRoot = fs.realpathSync.native(root);
|
|
67
|
+
} catch {
|
|
68
|
+
// keep root as given
|
|
69
|
+
}
|
|
70
|
+
for (const r of [path.resolve(root), realRoot]) {
|
|
71
|
+
forms.add(r.replace(/\\/g, '/'));
|
|
72
|
+
forms.add(r.replace(/\//g, '\\'));
|
|
73
|
+
}
|
|
74
|
+
return [...forms].sort((a, b) => b.length - a.length);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Absolute paths under root, made relative to it.
|
|
78
|
+
function relativise(text, root) {
|
|
79
|
+
if (!root) return text;
|
|
80
|
+
let out = text;
|
|
81
|
+
for (const r of rootSpellings(root)) {
|
|
82
|
+
out = out.replace(new RegExp(`${escapeRe(r)}[\\\\/]`, WIN ? 'gi' : 'g'), '');
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// One line, at most 120 characters, cut from the middle so git's head and tail both survive.
|
|
88
|
+
function reasonOf(text, root) {
|
|
89
|
+
const first = String(text ?? '').split(/\r?\n/).map((l) => l.trim()).find((l) => l !== '') ?? 'unknown error';
|
|
90
|
+
const line = relativise(first, root);
|
|
91
|
+
if (line.length <= REASON_MAX) return line;
|
|
92
|
+
const head = Math.ceil((REASON_MAX - 1) / 2);
|
|
93
|
+
return `${line.slice(0, head)}…${line.slice(line.length - (REASON_MAX - 1 - head))}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function succeeds(root, args) {
|
|
97
|
+
try {
|
|
98
|
+
git(root, args);
|
|
99
|
+
return true;
|
|
100
|
+
} catch (e) {
|
|
101
|
+
if (e instanceof GitError) return false;
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// def has passed assertRef (and config's branch-name check).
|
|
107
|
+
export function fetchArgs(def) {
|
|
108
|
+
return [
|
|
109
|
+
'-c', 'protocol.ext.allow=never', 'fetch', '--quiet', '--no-recurse-submodules', 'origin',
|
|
110
|
+
`+refs/heads/${def}:refs/remotes/origin/${def}`,
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// -> null on success, else the one-line reason.
|
|
115
|
+
function fetchOrigin(root, def, env, timeoutMs) {
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
execFile('git', fetchArgs(def), {
|
|
118
|
+
cwd: root,
|
|
119
|
+
env: { ...env, GIT_TERMINAL_PROMPT: '0' },
|
|
120
|
+
timeout: timeoutMs,
|
|
121
|
+
killSignal: 'SIGKILL',
|
|
122
|
+
windowsHide: true,
|
|
123
|
+
encoding: 'utf8',
|
|
124
|
+
}, (err, _stdout, stderr) => {
|
|
125
|
+
if (!err) return resolve(null);
|
|
126
|
+
if (err.killed) return resolve(`timed out after ${timeoutMs % 1000 === 0 ? `${timeoutMs / 1000} s` : `${timeoutMs} ms`}`);
|
|
127
|
+
resolve(reasonOf(stderr || err.message, root));
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function divergence(root, branch, cfg, env, timeoutMs) {
|
|
133
|
+
const name = branch ?? 'HEAD';
|
|
134
|
+
if (!hasCommits(root)) return `slicekit: ${name} has no commits yet`;
|
|
135
|
+
if (!succeeds(root, ['remote', 'get-url', 'origin'])) return 'slicekit: could not fetch origin (no origin remote)';
|
|
136
|
+
let def;
|
|
137
|
+
try {
|
|
138
|
+
def = assertRef(cfg?.defaultBranch);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
if (e instanceof GitError) return `slicekit: could not fetch origin (${reasonOf(e.stderr, root)})`;
|
|
141
|
+
throw e;
|
|
142
|
+
}
|
|
143
|
+
const failure = await fetchOrigin(root, def, env, timeoutMs);
|
|
144
|
+
const ref = `refs/remotes/origin/${def}`;
|
|
145
|
+
const haveRef = succeeds(root, ['rev-parse', '--verify', '--quiet', ref]);
|
|
146
|
+
if (failure && !haveRef) return `slicekit: could not fetch origin (${failure})`;
|
|
147
|
+
if (!haveRef) return `slicekit: could not fetch origin (origin/${def} not found after the fetch)`;
|
|
148
|
+
const [ahead, behind] = git(root, ['rev-list', '--left-right', '--count', `HEAD...${ref}`]).split(/\s+/);
|
|
149
|
+
const counts = `${name} is ${ahead} ahead / ${behind} behind origin/${def}`;
|
|
150
|
+
return failure
|
|
151
|
+
? `slicekit: could not fetch origin (${failure}); ${counts} (as of the last fetch)`
|
|
152
|
+
: `slicekit: ${counts}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const text = (v) => oneLine(typeof v === 'string' ? v : JSON.stringify(v) ?? String(v));
|
|
156
|
+
|
|
157
|
+
function handoffLines(handoff) {
|
|
158
|
+
if (handoff == null) return [];
|
|
159
|
+
if (typeof handoff === 'string') {
|
|
160
|
+
return handoff.split(/\r?\n/).filter((l) => l.trim() !== '').map((l) => `handoff: ${text(l)}`);
|
|
161
|
+
}
|
|
162
|
+
if (typeof handoff === 'object' && !Array.isArray(handoff)) {
|
|
163
|
+
return Object.entries(handoff).map(([k, v]) => `handoff: ${text(k)}: ${text(v)}`);
|
|
164
|
+
}
|
|
165
|
+
return [`handoff: ${text(handoff)}`];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Whole lines up to HANDOFF_MAX characters, then a pointer to the state file.
|
|
169
|
+
function capped(lines, root, cfg, id) {
|
|
170
|
+
const full = lines.join('\n').length;
|
|
171
|
+
if (full <= HANDOFF_MAX) return lines;
|
|
172
|
+
const kept = [];
|
|
173
|
+
let used = 0;
|
|
174
|
+
for (const l of lines) {
|
|
175
|
+
const add = (kept.length ? 1 : 0) + l.length;
|
|
176
|
+
if (used + add > HANDOFF_MAX) break;
|
|
177
|
+
kept.push(l);
|
|
178
|
+
used += add;
|
|
179
|
+
}
|
|
180
|
+
const file = path.relative(root, path.join(kitPaths(root, cfg).state, stateFileName(id))).split(path.sep).join('/');
|
|
181
|
+
return [...kept, `(handoff truncated, ${full} chars; see ${file})`];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function handle(input, { root, cfg, env = process.env, fetchTimeoutMs = FETCH_TIMEOUT_MS }) {
|
|
185
|
+
if (!isRepo(root)) return context('SessionStart', 'slicekit: not a git repository\nno active slice');
|
|
186
|
+
sweepLeftovers(root);
|
|
187
|
+
const source = ['startup', 'resume', 'clear', 'compact'].includes(input?.source) ? input.source : 'startup';
|
|
188
|
+
let branch;
|
|
189
|
+
try {
|
|
190
|
+
branch = currentBranch(root);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
if (!(e instanceof GitError)) throw e;
|
|
193
|
+
branch = null;
|
|
194
|
+
}
|
|
195
|
+
const out = [await divergence(root, branch, cfg, env, fetchTimeoutMs)];
|
|
196
|
+
const active = activeSlice(root, cfg);
|
|
197
|
+
if (!active) {
|
|
198
|
+
out.push('no active slice');
|
|
199
|
+
} else if (active.error) {
|
|
200
|
+
out.push(`active slice: ${active.id} (state unreadable: ${reasonOf(active.error, root)})`);
|
|
201
|
+
} else {
|
|
202
|
+
out.push(`active slice: ${active.id} (${text(active.state.state)})`);
|
|
203
|
+
if (source === 'compact') {
|
|
204
|
+
out.push(...capped(handoffLines(active.state.handoff), root, cfg, active.id),
|
|
205
|
+
`Brief: run slicekit instructions developer ${active.id}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return context('SessionStart', out.join('\n'));
|
|
209
|
+
}
|