@yasaswy.nagavolu/agents 0.26.3 → 0.26.5
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/content/mods/handoff/.claude-plugin/plugin.json +1 -1
- package/content/mods/handoff/README.md +15 -15
- package/content/mods/handoff/hooks/register.js +22 -24
- package/content/mods/handoff/lib/activework.mjs +2 -2
- package/content/mods/handoff/lib/auto.mjs +4 -13
- package/content/mods/handoff/lib/template.mjs +3 -2
- package/content/mods/handoff/prompts/handoff-prep.md +3 -3
- package/content/mods/handoff/tests/activework.test.mjs +5 -5
- package/content/mods/handoff/tests/auto.test.mjs +10 -23
- package/content/mods/handoff/tests/e2e/run_e2e.py +25 -5
- package/content/mods/handoff/tests/gitgate.test.mjs +3 -3
- package/content/mods/handoff/tests/register.test.mjs +130 -42
- package/content/mods/handoff/tests/template.test.mjs +13 -3
- package/content/proxy/agent_model_guard.py +53 -45
- package/content/proxy/execution_worker_review_gate.py +5 -8
- package/content/proxy/headless_process.py +6 -5
- package/content/proxy/route_lock.py +20 -1
- package/content/proxy/shared_worktree_revert_guard.py +34 -1
- package/content/scripts/item.py +126 -0
- package/content/scripts/tests/test_item_cli.py +66 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "handoff",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "One-click session handoff: prepares the work, writes a lean handoff file, verifies it, clears the session and submits the handoff as the first message",
|
|
5
5
|
"author": { "name": "Yasaswy Nagavolu" },
|
|
6
6
|
"metadata": { "minClaudeCodeVersion": "2.1.287" }
|
|
@@ -28,31 +28,31 @@ an unattended session's prompt cache warm. Needs Claude Code 2.1.287 or later (m
|
|
|
28
28
|
chord shows the toast `handoff already running (<phase>)` and starts nothing.
|
|
29
29
|
- Busy chat (a turn runs, a user prompt waits, or a nudge is in flight): the handoff queues. The band reads
|
|
30
30
|
`Handoff queued: waiting for the current turn to finish...` with a `Cancel` button. The prep prompt is submitted
|
|
31
|
-
when the turn ends (or at the next keep-warm tick),
|
|
31
|
+
when the turn ends (or at the next keep-warm tick), and the running-work note shows then.
|
|
32
32
|
- The prep prompt opens with `[Handoff prep - this is not the handoff itself]` and a one-line note, so the
|
|
33
33
|
chat shows it is not the handoff. The label is added by code (`lib/prep.mjs`), not by the prompt file.
|
|
34
34
|
- The prep reply is the turn whose start text carries that label and this session's handoff path; only its turn id
|
|
35
35
|
is scored, so an earlier queued message or nudge cannot cause "no HANDOFF_READY line". A prep that never starts aborts after 30 min.
|
|
36
36
|
- Phase A: `prompts/handoff-prep.md` syncs tasks and PRD, fixes docs, runs tests, commits and pushes,
|
|
37
37
|
writes `~/.claude/handoffs/<session_id>.md`, then prints `HANDOFF_READY <path>` or `HANDOFF_ABORT <reason>`.
|
|
38
|
-
- Phase B (turn complete): sentinel, `lib/validate.mjs`, git gate (`lib/gitgate.mjs`)
|
|
38
|
+
- Phase B (turn complete): sentinel, `lib/validate.mjs`, git gate (`lib/gitgate.mjs`).
|
|
39
39
|
Only then: clipboard, `/clear`, submit the handoff. Any failed check keeps the session and the file.
|
|
40
|
-
- Git gate:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
- Running
|
|
45
|
-
tasks (
|
|
46
|
-
|
|
40
|
+
- Git gate (advisory): dirty tracked files, unpushed commits, detached HEAD or no upstream never abort. It counts
|
|
41
|
+
`@{upstream}..HEAD`, else commits not on the remote default branch (`origin/HEAD`, `origin/main`, `origin/master`).
|
|
42
|
+
On a reason: one toast `Handoff continues: <reason>` and `Warning: <reason>.` ends the submitted text (file unchanged).
|
|
43
|
+
Prep step 4 commits only this session's work and lists the rest in open risks.
|
|
44
|
+
- Running work never blocks: at start (or queue release) the mod counts running subagents (`$.agent.list()`, live) and
|
|
45
|
+
background tasks (`background_tasks` of the last `classic.Stop`) and shows one toast if any run. Nothing is stopped or
|
|
46
|
+
waited for; prep step 0 lists them in the handoff's open risks.
|
|
47
47
|
|
|
48
48
|
## Auto-handoff
|
|
49
49
|
|
|
50
|
-
- On by default.
|
|
51
|
-
|
|
52
|
-
- Idle
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
- On by default. At 65% context or more with an idle chat, the mod runs the same flow as `Alt+H` and shows
|
|
51
|
+
the toast `Auto-handoff: context is at N% ...`.
|
|
52
|
+
- Idle: no running turn, prompt waiting, nudge or handoff, and an empty prompt box. Busy defers to the next tick (15 s). Unknown context never fires.
|
|
53
|
+
- At most one automatic attempt per session. After any abort (auto or manual) auto turns itself off for the rest of
|
|
54
|
+
the session with one toast and leaves the saved `auto` value alone. `/handoff auto on` or the toggle re-arms it;
|
|
55
|
+
a new session reads the saved value. Manual `Alt+H` or a click always works. One run at a time.
|
|
56
56
|
- The toggle button or `/handoff auto on|off|status` flips it. The value is saved with `$.store` (key `auto`,
|
|
57
57
|
file `~/.claude/plugins/store/handoff_inline-*.json`), read at each session start.
|
|
58
58
|
|
|
@@ -6,9 +6,9 @@ import { copyViaSystem } from '../lib/clipboard.mjs'
|
|
|
6
6
|
import { TONES, busyBand, idleBand, textBand } from '../lib/band.mjs'
|
|
7
7
|
import { renderPrep, isPrepTurn, prepStartExpired } from '../lib/prep.mjs'
|
|
8
8
|
import { evaluateGitState, collectGitState } from '../lib/gitgate.mjs'
|
|
9
|
-
import { summarizeActiveWork,
|
|
9
|
+
import { summarizeActiveWork, activeWorkNote } from '../lib/activework.mjs'
|
|
10
10
|
import { claudeSubdir, sessionFilePath, cacheInfoFromState, cacheRemainingMs } from '../lib/cache.mjs'
|
|
11
|
-
import { AUTO_THRESHOLD_PERCENT, AUTO_STORE_KEY, HANDOFF_USAGE, newAuto, storedEnabled,
|
|
11
|
+
import { AUTO_THRESHOLD_PERCENT, AUTO_STORE_KEY, HANDOFF_USAGE, newAuto, storedEnabled, onAutoFailure, decideAuto, autoLabel, autoStatusText, parseHandoffArgs } from '../lib/auto.mjs'
|
|
12
12
|
import {
|
|
13
13
|
NUDGE_WINDOW_MS,
|
|
14
14
|
TICK_MS,
|
|
@@ -33,31 +33,30 @@ import {
|
|
|
33
33
|
applyVerdict,
|
|
34
34
|
} from '../lib/keepwarm.mjs'
|
|
35
35
|
|
|
36
|
+
const AUTO_STOPPED_TOAST = 'Auto-handoff stopped after a failed attempt. Use /handoff or the band button; /handoff auto on re-enables it'
|
|
36
37
|
const REFRESH_MS = 30000
|
|
37
38
|
const TOAST_MS = 8000
|
|
38
39
|
const TICK_STUCK_MS = 20000
|
|
39
40
|
const REREAD_DELAYS_MS = [1500, 3500, 7000, 12000, 20000]
|
|
40
41
|
|
|
41
|
-
const flow = { phase: 'idle', path: '', error: '', text: '', turnId: null, submittedAt: null,
|
|
42
|
+
const flow = { phase: 'idle', path: '', error: '', text: '', turnId: null, submittedAt: null, byAuto: false }
|
|
42
43
|
let supported = false
|
|
43
44
|
let stopTick = null
|
|
44
45
|
|
|
45
46
|
function setPhase($, phase, error) {
|
|
46
47
|
flow.phase = phase
|
|
47
48
|
flow.error = error || ''
|
|
48
|
-
if (phase === 'idle') Object.assign(flow, { text: '', turnId: null, submittedAt: null,
|
|
49
|
+
if (phase === 'idle') Object.assign(flow, { text: '', turnId: null, submittedAt: null, byAuto: false })
|
|
49
50
|
$.ui.invalidate('ui.render')
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
const level = flow.autoLevel
|
|
53
|
+
function fail($, message) {
|
|
54
54
|
setPhase($, 'idle', message)
|
|
55
55
|
$.ui.log('Handoff aborted, session kept: ' + message)
|
|
56
56
|
$.ui.toast('Handoff aborted: ' + message, { timeoutMs: TOAST_MS })
|
|
57
|
-
if (
|
|
58
|
-
auto =
|
|
59
|
-
|
|
60
|
-
if (usage) auto = onAutoAbort(auto, usage.context.percent)
|
|
57
|
+
if (!auto.enabled) return
|
|
58
|
+
auto = onAutoFailure()
|
|
59
|
+
$.ui.toast(AUTO_STOPPED_TOAST, { timeoutMs: TOAST_MS })
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
async function tryOr($, what, fn, fallback) {
|
|
@@ -76,14 +75,13 @@ async function copyToClipboard($, text, file) {
|
|
|
76
75
|
return copyViaSystem({ osEnv, file, text, run: (argv, init) => $.process.run(argv, init) })
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
async function startHandoff($,
|
|
78
|
+
async function startHandoff($, byAuto = false) {
|
|
80
79
|
if (!supported) return fail($, 'needs Claude Code ' + MIN_CLAUDE_CODE_VERSION + ' or later')
|
|
81
80
|
if (flow.phase !== 'idle') return
|
|
82
|
-
flow.
|
|
81
|
+
flow.byAuto = byAuto
|
|
83
82
|
setPhase($, 'starting')
|
|
84
83
|
try {
|
|
85
84
|
const work = await activeWork($)
|
|
86
|
-
if (work.total > 0) return fail($, activeWorkReason(work))
|
|
87
85
|
const sessionId = await $.session.id()
|
|
88
86
|
const home = (await $.env.get('USERPROFILE')) || (await $.env.get('HOME'))
|
|
89
87
|
const dir = (await $.env.get('HANDOFF_DIR')) || defaultHandoffDir(home)
|
|
@@ -93,17 +91,22 @@ async function startHandoff($, autoLevel = null) {
|
|
|
93
91
|
flow.path = path
|
|
94
92
|
flow.text = renderPrep(normalize(template), { path, root })
|
|
95
93
|
if (isBusy(state, await $.clock.now())) {
|
|
96
|
-
if (
|
|
94
|
+
if (byAuto) return setPhase($, 'idle')
|
|
97
95
|
setPhase($, 'queued')
|
|
98
96
|
$.ui.toast('Handoff queued - waiting for the current turn to finish', { timeoutMs: TOAST_MS })
|
|
99
97
|
return
|
|
100
98
|
}
|
|
99
|
+
noteActiveWork($, work)
|
|
101
100
|
await submitPrep($)
|
|
102
101
|
} catch (err) {
|
|
103
102
|
return fail($, 'could not start (' + err + ')')
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
105
|
|
|
106
|
+
function noteActiveWork($, work) {
|
|
107
|
+
if (work.total > 0) $.ui.toast(activeWorkNote(work), { timeoutMs: TOAST_MS })
|
|
108
|
+
}
|
|
109
|
+
|
|
107
110
|
async function submitPrep($) {
|
|
108
111
|
flow.turnId = null
|
|
109
112
|
flow.submittedAt = await $.clock.now()
|
|
@@ -115,8 +118,7 @@ async function releaseQueued($) {
|
|
|
115
118
|
if (flow.phase !== 'queued' || isBusy(state, await $.clock.now())) return
|
|
116
119
|
flow.phase = 'prep'
|
|
117
120
|
try {
|
|
118
|
-
|
|
119
|
-
if (work.total > 0) return fail($, activeWorkReason(work))
|
|
121
|
+
noteActiveWork($, await activeWork($))
|
|
120
122
|
await submitPrep($)
|
|
121
123
|
} catch (err) {
|
|
122
124
|
return fail($, 'could not start (' + err + ')')
|
|
@@ -143,13 +145,10 @@ async function finishHandoff($, reason) {
|
|
|
143
145
|
const verdict = validateHandoff(handoff)
|
|
144
146
|
if (!verdict.ok) return fail($, verdict.errors.join('; '))
|
|
145
147
|
|
|
146
|
-
const gate = evaluateGitState(await collectGitState((argv) => $.process.run(argv)))
|
|
147
|
-
if (!gate.ok)
|
|
148
|
-
|
|
149
|
-
const work = await activeWork($)
|
|
150
|
-
if (work.total > 0) return fail($, activeWorkReason(work))
|
|
148
|
+
const gate = evaluateGitState(await tryOr($, 'git state', () => collectGitState((argv) => $.process.run(argv)), { isRepo: false }))
|
|
149
|
+
if (!gate.ok) $.ui.toast('Handoff continues: ' + gate.reason, { timeoutMs: TOAST_MS })
|
|
151
150
|
|
|
152
|
-
const submission = prepareSubmission(handoff)
|
|
151
|
+
const submission = prepareSubmission(handoff, gate.reason)
|
|
153
152
|
const copied = await copyToClipboard($, handoff, flow.path)
|
|
154
153
|
await $.command.run({ command: 'clear', args: '' })
|
|
155
154
|
try {
|
|
@@ -259,7 +258,6 @@ async function tick($) {
|
|
|
259
258
|
}
|
|
260
259
|
|
|
261
260
|
function autoFires($, now, contextPercent, draft) {
|
|
262
|
-
auto = settleAuto(auto, contextPercent, settings.autoPercent)
|
|
263
261
|
const verdict = decideAuto({
|
|
264
262
|
auto,
|
|
265
263
|
contextPercent,
|
|
@@ -271,7 +269,7 @@ function autoFires($, now, contextPercent, draft) {
|
|
|
271
269
|
})
|
|
272
270
|
if (!verdict.fire) return false
|
|
273
271
|
$.ui.toast('Auto-handoff: context is at ' + Math.round(contextPercent) + '% (limit ' + settings.autoPercent + '%). Starting the handoff.', { timeoutMs: TOAST_MS })
|
|
274
|
-
$.clock.after(0, () => startHandoff($,
|
|
272
|
+
$.clock.after(0, () => startHandoff($, true))
|
|
275
273
|
return true
|
|
276
274
|
}
|
|
277
275
|
|
|
@@ -7,9 +7,9 @@ export function summarizeActiveWork(agents, background) {
|
|
|
7
7
|
return { subagents, tasks: others, total: subagents + others }
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function
|
|
10
|
+
export function activeWorkNote({ subagents, tasks }) {
|
|
11
11
|
const parts = []
|
|
12
12
|
if (subagents > 0) parts.push(subagents + ' subagent(s)')
|
|
13
13
|
if (tasks > 0) parts.push(tasks + ' background task(s)')
|
|
14
|
-
return parts.join(' and ') + ' still running
|
|
14
|
+
return 'Handoff continues with ' + parts.join(' and ') + ' still running; they are not stopped'
|
|
15
15
|
}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
export const AUTO_THRESHOLD_PERCENT = 65
|
|
2
|
-
export const AUTO_REARM_PERCENT = 5
|
|
3
2
|
export const AUTO_STORE_KEY = 'auto'
|
|
4
3
|
export const HANDOFF_USAGE = 'usage: /handoff | /handoff auto on | off | status'
|
|
5
4
|
|
|
6
5
|
export function newAuto(enabled) {
|
|
7
|
-
return { enabled,
|
|
6
|
+
return { enabled, stopped: false }
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
export function storedEnabled(value) {
|
|
11
10
|
return value !== false
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
export function
|
|
15
|
-
|
|
16
|
-
return { ...auto, abortLevel: auto.abortLevel === null ? level : Math.max(level, auto.abortLevel) }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function settleAuto(auto, contextPercent, thresholdPercent) {
|
|
20
|
-
const dropped = typeof contextPercent === 'number' && contextPercent < thresholdPercent
|
|
21
|
-
return dropped && auto.abortLevel !== null ? { ...auto, abortLevel: null } : auto
|
|
13
|
+
export function onAutoFailure() {
|
|
14
|
+
return { enabled: false, stopped: true }
|
|
22
15
|
}
|
|
23
16
|
|
|
24
17
|
export function decideAuto({ auto, contextPercent, thresholdPercent, supported, phase, busy, draft }) {
|
|
@@ -27,7 +20,6 @@ export function decideAuto({ auto, contextPercent, thresholdPercent, supported,
|
|
|
27
20
|
if (!supported) return none('unsupported')
|
|
28
21
|
if (typeof contextPercent !== 'number') return none('unknown')
|
|
29
22
|
if (contextPercent < thresholdPercent) return none('below')
|
|
30
|
-
if (auto.abortLevel !== null && contextPercent < auto.abortLevel + AUTO_REARM_PERCENT) return none('cooldown')
|
|
31
23
|
if (phase !== 'idle') return none('flow')
|
|
32
24
|
if (busy) return none('busy')
|
|
33
25
|
if (String(draft || '').trim() !== '') return none('typing')
|
|
@@ -40,8 +32,7 @@ export function autoLabel(auto, thresholdPercent) {
|
|
|
40
32
|
|
|
41
33
|
export function autoStatusText(auto, thresholdPercent) {
|
|
42
34
|
const text = 'auto-handoff ' + (auto.enabled ? 'on' : 'off') + ' at ' + thresholdPercent + '% context'
|
|
43
|
-
|
|
44
|
-
return text + ', paused after an abort until context ' + Math.max(thresholdPercent, Math.ceil(auto.abortLevel + AUTO_REARM_PERCENT)) + '%'
|
|
35
|
+
return auto.stopped ? text + ', stopped after a failed attempt (use /handoff auto on to re-enable)' : text
|
|
45
36
|
}
|
|
46
37
|
|
|
47
38
|
export function parseHandoffArgs(args) {
|
|
@@ -22,6 +22,7 @@ export function handoffPathFor(dir, sessionId) {
|
|
|
22
22
|
return base + '/' + String(sessionId).replace(/[^A-Za-z0-9_-]/g, '') + '.md'
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export function prepareSubmission(text) {
|
|
26
|
-
|
|
25
|
+
export function prepareSubmission(text, warning = '') {
|
|
26
|
+
const body = 'Session handoff from the previous session. Continue from the state below.\n\n' + normalize(text).trim()
|
|
27
|
+
return warning ? body + '\n\nWarning: ' + warning + '.' : body
|
|
27
28
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Prepare this session for a handoff. The session is cleared after you finish, so leave nothing only in this conversation. Do the steps in order. Do not ask questions.
|
|
2
2
|
|
|
3
|
-
0. Running work. List running subagents and background tasks
|
|
3
|
+
0. Running work. List any running subagents and background tasks (name and goal) in the open risks of the handoff file. Do not wait for them, stop them or abort because of them. Running work never blocks the handoff.
|
|
4
4
|
1. Tasks. Use TaskList and TaskUpdate so every task matches reality (done, in progress, pending).
|
|
5
5
|
2. PRD issue. Find the single open PRD issue for this session (task metadata or this conversation). Update its description (TODO mirror and status) and post one status comment, using the issue-tracker access this project already uses (a repo script or the tracker's CLI). Never print the token. If no PRD issue exists, write "none" in the PRD section.
|
|
6
6
|
3. Docs. Update only the markdown docs, README rows and memory that this session touched or made stale.
|
|
7
|
-
4. Code. Run the tests that cover the changed
|
|
7
|
+
4. Code. Run the tests that cover the files this session changed. If they pass, commit and push only what this session changed: pull and rebase on the default branch (on a conflict, resolve it keeping both sides' intent, re-run the tests, and record any override in open risks), then push to the default branch. Other uncommitted files, unpushed commits or a detached HEAD may belong to other sessions: leave them, do not abort, and list them (paths, owner if known) in open risks.
|
|
8
8
|
5. Handoff file. Write the handoff to `{{handoff_path}}` (not a transcript, at most {{max_chars}} characters, about 1500 tokens). Use these level-2 headers, each with content: {{required_headers}}. Include the goal, current state, decisions, commit SHAs, PRD IID and task list, exact next steps, file paths and open risks. Write it after the last commit and push, list the final HEAD SHA, and make no commit or tracked-file change after it.
|
|
9
9
|
6. Check. Run `{{validator_cmd}}`. Fix the file until it exits 0.
|
|
10
10
|
7. Finish. Print exactly one final line: `HANDOFF_READY {{handoff_path}}`.
|
|
11
11
|
|
|
12
|
-
Abort rule: if tests fail or the push fails, do not write the ready line. Print one final line `HANDOFF_ABORT <short reason>` instead. Keep the handoff file if you wrote it.
|
|
12
|
+
Abort rule: only if tests of files this session changed fail or the push of this session's own commits fails, do not write the ready line. Print one final line `HANDOFF_ABORT <short reason>` instead. Keep the handoff file if you wrote it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import test from 'node:test'
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
|
-
import { summarizeActiveWork,
|
|
3
|
+
import { summarizeActiveWork, activeWorkNote } from '../lib/activework.mjs'
|
|
4
4
|
|
|
5
5
|
test('only running agents count', () => {
|
|
6
6
|
const agents = [{ status: 'running' }, { status: 'completed' }, { status: 'killed' }, { status: 'running' }]
|
|
@@ -17,10 +17,10 @@ test('bad input counts as nothing', () => {
|
|
|
17
17
|
assert.deepEqual(summarizeActiveWork(undefined, null), { subagents: 0, tasks: 0, total: 0 })
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
test('
|
|
20
|
+
test('note names the counts and says the work is not stopped', () => {
|
|
21
21
|
assert.equal(
|
|
22
|
-
|
|
23
|
-
'2 subagent(s) and 1 background task(s) still running
|
|
22
|
+
activeWorkNote({ subagents: 2, tasks: 1 }),
|
|
23
|
+
'Handoff continues with 2 subagent(s) and 1 background task(s) still running; they are not stopped',
|
|
24
24
|
)
|
|
25
|
-
assert.equal(
|
|
25
|
+
assert.equal(activeWorkNote({ subagents: 0, tasks: 3 }), 'Handoff continues with 3 background task(s) still running; they are not stopped')
|
|
26
26
|
})
|
|
@@ -4,8 +4,7 @@ import {
|
|
|
4
4
|
AUTO_THRESHOLD_PERCENT,
|
|
5
5
|
newAuto,
|
|
6
6
|
storedEnabled,
|
|
7
|
-
|
|
8
|
-
settleAuto,
|
|
7
|
+
onAutoFailure,
|
|
9
8
|
decideAuto,
|
|
10
9
|
autoLabel,
|
|
11
10
|
autoStatusText,
|
|
@@ -38,26 +37,11 @@ test('threshold default is 65 percent', () => {
|
|
|
38
37
|
assert.equal(AUTO_THRESHOLD_PERCENT, 65)
|
|
39
38
|
})
|
|
40
39
|
|
|
41
|
-
test('
|
|
42
|
-
const
|
|
43
|
-
assert.
|
|
44
|
-
assert.
|
|
45
|
-
assert.deepEqual(decide({ auto:
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
test('cooldown keeps the highest abort level and ignores an unknown level', () => {
|
|
49
|
-
const a = onAutoAbort(onAutoAbort(newAuto(true), 70), 66)
|
|
50
|
-
assert.equal(a.abortLevel, 70)
|
|
51
|
-
assert.equal(onAutoAbort(a, undefined), a)
|
|
52
|
-
assert.equal(onAutoAbort(newAuto(true), 66).abortLevel, 66)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
test('cooldown clears when context drops below the threshold (clear or compact)', () => {
|
|
56
|
-
const aborted = onAutoAbort(newAuto(true), 70)
|
|
57
|
-
assert.equal(settleAuto(aborted, 80, 65), aborted)
|
|
58
|
-
assert.equal(settleAuto(aborted, undefined, 65), aborted)
|
|
59
|
-
assert.equal(settleAuto(aborted, 12, 65).abortLevel, null)
|
|
60
|
-
assert.equal(settleAuto(newAuto(true), 12, 65).abortLevel, null)
|
|
40
|
+
test('a failed attempt turns auto off for the session and never re-arms by context growth', () => {
|
|
41
|
+
const stopped = onAutoFailure(newAuto(true))
|
|
42
|
+
assert.deepEqual(stopped, { enabled: false, stopped: true })
|
|
43
|
+
for (const contextPercent of [65, 70, 99]) assert.deepEqual(decide({ auto: stopped, contextPercent }), { fire: false, reason: 'disabled' })
|
|
44
|
+
assert.deepEqual(decide({ auto: newAuto(true), contextPercent: 99 }), { fire: true, reason: 'context' })
|
|
61
45
|
})
|
|
62
46
|
|
|
63
47
|
test('stored value: only an explicit false turns auto off', () => {
|
|
@@ -73,7 +57,10 @@ test('label and status text', () => {
|
|
|
73
57
|
assert.equal(autoLabel(newAuto(false), 65), 'auto 65%: off')
|
|
74
58
|
assert.equal(autoStatusText(newAuto(true), 65), 'auto-handoff on at 65% context')
|
|
75
59
|
assert.equal(autoStatusText(newAuto(false), 65), 'auto-handoff off at 65% context')
|
|
76
|
-
assert.equal(
|
|
60
|
+
assert.equal(
|
|
61
|
+
autoStatusText(onAutoFailure(newAuto(true)), 65),
|
|
62
|
+
'auto-handoff off at 65% context, stopped after a failed attempt (use /handoff auto on to re-enable)',
|
|
63
|
+
)
|
|
77
64
|
})
|
|
78
65
|
|
|
79
66
|
test('command parsing: bare starts, auto takes on, off or status, anything else is usage', () => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Copies the mod to a temp dir, swaps the real prep prompt for a stub that needs no
|
|
4
4
|
git or network work, drives /handoff, and asserts on the observer plugin's log.
|
|
5
|
-
Run: python mods/handoff/tests/e2e/run_e2e.py [success|abort|invalid|all]
|
|
5
|
+
Run: python mods/handoff/tests/e2e/run_e2e.py [success|dirty|abort|invalid|all]
|
|
6
6
|
"""
|
|
7
7
|
import json
|
|
8
8
|
import os
|
|
@@ -53,6 +53,7 @@ STUBS = {
|
|
|
53
53
|
"`{{validator_cmd}}` with Bash, then print one final line `HANDOFF_READY {{handoff_path}}` and nothing after it. "
|
|
54
54
|
"Required headers: {{required_headers}} (max {{max_chars}} chars).\n<<<\n" + HANDOFF_BODY + ">>>\n"
|
|
55
55
|
),
|
|
56
|
+
"dirty": None,
|
|
56
57
|
"abort": "Do not write any file. Print exactly one line: HANDOFF_ABORT tests failed in stub. Ignore: {{handoff_path}} {{validator_cmd}} {{required_headers}} {{max_chars}}",
|
|
57
58
|
"invalid": (
|
|
58
59
|
"Use the Write tool to create the file {{handoff_path}} containing only the text `too short`, then print one final line "
|
|
@@ -61,6 +62,23 @@ STUBS = {
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
|
|
65
|
+
STUBS["dirty"] = STUBS["success"]
|
|
66
|
+
FLOW_SCENARIOS = ("success", "dirty")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def make_dirty_repo(cwd):
|
|
70
|
+
def git(*args):
|
|
71
|
+
subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True, creationflags=CREATE_NO_WINDOW if os.name == "nt" else 0)
|
|
72
|
+
|
|
73
|
+
git("init", "-q")
|
|
74
|
+
git("config", "user.email", "e2e@example.invalid")
|
|
75
|
+
git("config", "user.name", "e2e")
|
|
76
|
+
(cwd / "tracked.txt").write_text("one" + chr(10), encoding="utf-8")
|
|
77
|
+
git("add", "tracked.txt")
|
|
78
|
+
git("commit", "-q", "-m", "init")
|
|
79
|
+
(cwd / "tracked.txt").write_text("two" + chr(10), encoding="utf-8")
|
|
80
|
+
|
|
81
|
+
|
|
64
82
|
def claude_exe():
|
|
65
83
|
cand = Path(os.environ.get("APPDATA", "")) / "npm/node_modules/@anthropic-ai/claude-code/bin/claude.exe"
|
|
66
84
|
return str(cand) if cand.exists() else shutil.which("claude")
|
|
@@ -86,6 +104,8 @@ def run(scenario, timeout=150):
|
|
|
86
104
|
(mod / "prompts" / "handoff-prep.md").write_text(STUBS[scenario], encoding="utf-8")
|
|
87
105
|
cwd = work / "cwd"
|
|
88
106
|
cwd.mkdir()
|
|
107
|
+
if scenario == "dirty":
|
|
108
|
+
make_dirty_repo(cwd)
|
|
89
109
|
log = work / "observer.log"
|
|
90
110
|
env = dict(
|
|
91
111
|
os.environ,
|
|
@@ -134,15 +154,15 @@ def run(scenario, timeout=150):
|
|
|
134
154
|
|
|
135
155
|
def done():
|
|
136
156
|
text = observed_text()
|
|
137
|
-
if scenario
|
|
157
|
+
if scenario in FLOW_SCENARIOS:
|
|
138
158
|
tail = text.split("session.end reason=clear")[-1] if "session.end reason=clear" in text else ""
|
|
139
159
|
return "turn.complete" in tail
|
|
140
160
|
return "turn.complete" in text.split("handoff")[-1] and text.count("turn.complete") >= 2
|
|
141
161
|
|
|
142
|
-
end = time.time() + (200 if scenario
|
|
162
|
+
end = time.time() + (200 if scenario in FLOW_SCENARIOS else 90)
|
|
143
163
|
while time.time() < end and not done():
|
|
144
164
|
time.sleep(1)
|
|
145
|
-
time.sleep(
|
|
165
|
+
time.sleep(2 if scenario in FLOW_SCENARIOS else 10)
|
|
146
166
|
try:
|
|
147
167
|
proc.stdin.close()
|
|
148
168
|
except OSError:
|
|
@@ -170,7 +190,7 @@ def run(scenario, timeout=150):
|
|
|
170
190
|
def check(report):
|
|
171
191
|
obs = report["observer"]
|
|
172
192
|
cleared = "session.end reason=clear" in obs
|
|
173
|
-
if report["scenario"]
|
|
193
|
+
if report["scenario"] in FLOW_SCENARIOS:
|
|
174
194
|
ok = (cleared and "asUser" in obs and any("HANDOFF-RECEIVED" in r for r in report["results"])
|
|
175
195
|
and report["clipboard_matches_handoff"])
|
|
176
196
|
else:
|
|
@@ -12,13 +12,13 @@ test('evaluate: non-repo, clean synced and remote-less repos pass', () => {
|
|
|
12
12
|
assert.equal(evaluateGitState({ isRepo: true, porcelain: '', hasRemote: false }).ok, true)
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
test('evaluate: dirty tracked files
|
|
15
|
+
test('evaluate: dirty tracked files are reported first', () => {
|
|
16
16
|
const v = evaluateGitState({ isRepo: true, porcelain: ' M a.js\n', upstreamAhead: 0 })
|
|
17
17
|
assert.equal(v.ok, false)
|
|
18
18
|
assert.match(v.reason, /1 tracked file/)
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
test('evaluate: ahead of upstream
|
|
21
|
+
test('evaluate: ahead of upstream is reported', () => {
|
|
22
22
|
assert.match(evaluateGitState({ isRepo: true, porcelain: '', upstreamAhead: 2 }).reason, /2 commit\(s\) not pushed/)
|
|
23
23
|
})
|
|
24
24
|
|
|
@@ -85,7 +85,7 @@ test('real git: not a repository passes', async (t) => {
|
|
|
85
85
|
assert.equal((await verdict(scratch(t, 'gitgate-none-'))).ok, true)
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
-
test('real git: pushed branch passes, an unpushed commit and a dirty file
|
|
88
|
+
test('real git: pushed branch passes, an unpushed commit and a dirty file are reported', async (t) => {
|
|
89
89
|
const { proj } = sandbox(t)
|
|
90
90
|
assert.equal((await verdict(proj)).ok, true)
|
|
91
91
|
commit(proj, 'b.txt')
|