claude-dev-env 8.118.1 → 8.119.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/bin/git_hooks_installer.mjs +26 -2
- package/bin/git_hooks_installer.test.mjs +36 -0
- package/bin/install-transaction.mjs +3 -1
- package/bin/install.mjs +12 -8
- package/bin/install.test.mjs +89 -0
- package/bin/install.transaction.test.mjs +34 -0
- package/bin/merge_profile_settings.mjs +3 -2
- package/bin/merge_profile_settings.test.mjs +25 -1
- package/bin/profile-stop-gate.mjs +2 -1
- package/bin/profile-stop-gate.test.mjs +26 -1
- package/bin/write-file-atomically.mjs +148 -0
- package/bin/write-file-atomically.test.mjs +263 -0
- package/docs/agents-guidance/asks.md +1 -1
- package/docs/rule-guides/session-title.md +18 -2
- package/hooks/features/conduct-gates.md +2 -2
- package/hooks/hooks_constants/session_title_constants.py +13 -0
- package/hooks/session/test_tracking_nudge.py +212 -4
- package/hooks/session/tracking_nudge.py +86 -7
- package/package.json +1 -1
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import { strict as assert } from 'node:assert';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import {
|
|
5
|
+
chmodSync,
|
|
6
|
+
lstatSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
mkdtempSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
readdirSync,
|
|
11
|
+
readlinkSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
statSync,
|
|
14
|
+
symlinkSync,
|
|
15
|
+
utimesSync,
|
|
16
|
+
writeFileSync,
|
|
17
|
+
} from 'node:fs';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
|
|
21
|
+
import { writeFileAtomically } from './write-file-atomically.mjs';
|
|
22
|
+
|
|
23
|
+
const FILE_SIZE_LIMIT_COMMAND = 'prlimit';
|
|
24
|
+
const isFileSizeLimitAvailable = spawnSync(FILE_SIZE_LIMIT_COMMAND, ['--version']).status === 0;
|
|
25
|
+
const isPosixPlatform = process.platform !== 'win32';
|
|
26
|
+
const PRIOR_SETTINGS_TEXT = '{\n "prior": true\n}\n';
|
|
27
|
+
const NEW_SETTINGS_TEXT = `{\n "next": "${'x'.repeat(4096)}"\n}\n`;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function withSandbox(runInSandbox) {
|
|
31
|
+
const sandboxRoot = mkdtempSync(join(tmpdir(), 'cdev-atomic-write-'));
|
|
32
|
+
try {
|
|
33
|
+
runInSandbox(sandboxRoot);
|
|
34
|
+
} finally {
|
|
35
|
+
rmSync(sandboxRoot, { recursive: true, force: true });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
test('writeFileAtomically should replace an existing file with the complete new text and leave no temporary file', () => {
|
|
41
|
+
withSandbox((sandboxRoot) => {
|
|
42
|
+
const settingsPath = join(sandboxRoot, 'settings.json');
|
|
43
|
+
writeFileSync(settingsPath, PRIOR_SETTINGS_TEXT);
|
|
44
|
+
|
|
45
|
+
writeFileAtomically(settingsPath, NEW_SETTINGS_TEXT);
|
|
46
|
+
|
|
47
|
+
assert.equal(readFileSync(settingsPath, 'utf8'), NEW_SETTINGS_TEXT);
|
|
48
|
+
assert.deepEqual(readdirSync(sandboxRoot), ['settings.json']);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
test('writeFileAtomically should create a file that does not exist yet', () => {
|
|
54
|
+
withSandbox((sandboxRoot) => {
|
|
55
|
+
const settingsPath = join(sandboxRoot, 'settings.json');
|
|
56
|
+
|
|
57
|
+
writeFileAtomically(settingsPath, NEW_SETTINGS_TEXT);
|
|
58
|
+
|
|
59
|
+
assert.equal(readFileSync(settingsPath, 'utf8'), NEW_SETTINGS_TEXT);
|
|
60
|
+
assert.deepEqual(readdirSync(sandboxRoot), ['settings.json']);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
test(
|
|
66
|
+
'writeFileAtomically should keep the mode of the file it replaces',
|
|
67
|
+
{ skip: isPosixPlatform ? false : 'Windows keeps no POSIX mode bits' },
|
|
68
|
+
() => {
|
|
69
|
+
withSandbox((sandboxRoot) => {
|
|
70
|
+
const settingsPath = join(sandboxRoot, 'settings.json');
|
|
71
|
+
writeFileSync(settingsPath, PRIOR_SETTINGS_TEXT);
|
|
72
|
+
chmodSync(settingsPath, 0o600);
|
|
73
|
+
|
|
74
|
+
writeFileAtomically(settingsPath, NEW_SETTINGS_TEXT);
|
|
75
|
+
|
|
76
|
+
assert.equal(statSync(settingsPath).mode & 0o777, 0o600);
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
test(
|
|
83
|
+
'writeFileAtomically should write through a linked settings.json and keep the link',
|
|
84
|
+
{ skip: isPosixPlatform ? false : 'creating a file link on Windows needs a privilege the runner may lack' },
|
|
85
|
+
() => {
|
|
86
|
+
withSandbox((sandboxRoot) => {
|
|
87
|
+
const sharedDirectory = join(sandboxRoot, 'shared');
|
|
88
|
+
const profileDirectory = join(sandboxRoot, 'profile');
|
|
89
|
+
mkdirSync(sharedDirectory);
|
|
90
|
+
mkdirSync(profileDirectory);
|
|
91
|
+
const sharedSettingsPath = join(sharedDirectory, 'settings.json');
|
|
92
|
+
const linkedSettingsPath = join(profileDirectory, 'settings.json');
|
|
93
|
+
writeFileSync(sharedSettingsPath, PRIOR_SETTINGS_TEXT);
|
|
94
|
+
symlinkSync(sharedSettingsPath, linkedSettingsPath);
|
|
95
|
+
|
|
96
|
+
writeFileAtomically(linkedSettingsPath, NEW_SETTINGS_TEXT);
|
|
97
|
+
|
|
98
|
+
assert.equal(lstatSync(linkedSettingsPath).isSymbolicLink(), true, 'the profile entry is still a link');
|
|
99
|
+
assert.equal(readlinkSync(linkedSettingsPath), sharedSettingsPath);
|
|
100
|
+
assert.equal(readFileSync(sharedSettingsPath, 'utf8'), NEW_SETTINGS_TEXT);
|
|
101
|
+
assert.deepEqual(readdirSync(sharedDirectory), ['settings.json']);
|
|
102
|
+
assert.deepEqual(readdirSync(profileDirectory), ['settings.json']);
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
test(
|
|
109
|
+
'writeFileAtomically should create the missing file at the end of a chain of links and keep every link',
|
|
110
|
+
{ skip: isPosixPlatform ? false : 'creating a file link on Windows needs a privilege the runner may lack' },
|
|
111
|
+
() => {
|
|
112
|
+
withSandbox((sandboxRoot) => {
|
|
113
|
+
const profileDirectory = join(sandboxRoot, 'profile');
|
|
114
|
+
const dotfilesDirectory = join(sandboxRoot, 'dotfiles');
|
|
115
|
+
const storeDirectory = join(sandboxRoot, 'store');
|
|
116
|
+
mkdirSync(profileDirectory);
|
|
117
|
+
mkdirSync(dotfilesDirectory);
|
|
118
|
+
mkdirSync(storeDirectory);
|
|
119
|
+
const profileSettingsPath = join(profileDirectory, 'settings.json');
|
|
120
|
+
const dotfilesSettingsPath = join(dotfilesDirectory, 'settings.json');
|
|
121
|
+
const storedSettingsPath = join(storeDirectory, 'settings.json');
|
|
122
|
+
symlinkSync(dotfilesSettingsPath, profileSettingsPath);
|
|
123
|
+
symlinkSync(join('..', 'store', 'settings.json'), dotfilesSettingsPath);
|
|
124
|
+
|
|
125
|
+
writeFileAtomically(profileSettingsPath, NEW_SETTINGS_TEXT);
|
|
126
|
+
|
|
127
|
+
assert.equal(lstatSync(profileSettingsPath).isSymbolicLink(), true, 'the profile entry is still a link');
|
|
128
|
+
assert.equal(lstatSync(dotfilesSettingsPath).isSymbolicLink(), true, 'the middle entry is still a link');
|
|
129
|
+
assert.equal(readFileSync(storedSettingsPath, 'utf8'), NEW_SETTINGS_TEXT);
|
|
130
|
+
assert.deepEqual(readdirSync(storeDirectory), ['settings.json']);
|
|
131
|
+
assert.deepEqual(readdirSync(dotfilesDirectory), ['settings.json']);
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
test(
|
|
138
|
+
'writeFileAtomically should refuse a link that loops back to itself and leave the link in place',
|
|
139
|
+
{ skip: isPosixPlatform ? false : 'creating a file link on Windows needs a privilege the runner may lack' },
|
|
140
|
+
() => {
|
|
141
|
+
withSandbox((sandboxRoot) => {
|
|
142
|
+
const settingsPath = join(sandboxRoot, 'settings.json');
|
|
143
|
+
symlinkSync('settings.json', settingsPath);
|
|
144
|
+
|
|
145
|
+
assert.throws(() => writeFileAtomically(settingsPath, NEW_SETTINGS_TEXT), { code: 'ELOOP' });
|
|
146
|
+
|
|
147
|
+
assert.equal(lstatSync(settingsPath).isSymbolicLink(), true, 'the looping entry is still a link');
|
|
148
|
+
assert.deepEqual(readdirSync(sandboxRoot), ['settings.json']);
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
test(
|
|
155
|
+
'writeFileAtomically should keep the prior file whole and remove its temporary file when the write fails part way',
|
|
156
|
+
{ skip: isFileSizeLimitAvailable ? false : `${FILE_SIZE_LIMIT_COMMAND} is not on PATH` },
|
|
157
|
+
() => {
|
|
158
|
+
withSandbox((sandboxRoot) => {
|
|
159
|
+
const settingsPath = join(sandboxRoot, 'settings.json');
|
|
160
|
+
writeFileSync(settingsPath, PRIOR_SETTINGS_TEXT);
|
|
161
|
+
const writerScriptPath = join(sandboxRoot, 'write.mjs');
|
|
162
|
+
writeFileSync(writerScriptPath, [
|
|
163
|
+
`import { writeFileAtomically } from ${JSON.stringify(new URL('./write-file-atomically.mjs', import.meta.url).href)};`,
|
|
164
|
+
`writeFileAtomically(${JSON.stringify(settingsPath)}, ${JSON.stringify(NEW_SETTINGS_TEXT)});`,
|
|
165
|
+
].join('\n'));
|
|
166
|
+
|
|
167
|
+
const limitedRun = spawnSync(
|
|
168
|
+
FILE_SIZE_LIMIT_COMMAND,
|
|
169
|
+
[`--fsize=${Math.floor(NEW_SETTINGS_TEXT.length / 2)}`, process.execPath, writerScriptPath],
|
|
170
|
+
{ encoding: 'utf8' },
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
assert.notEqual(limitedRun.status, 0, 'the write past the file size limit fails');
|
|
174
|
+
assert.match(limitedRun.stderr, /EFBIG/);
|
|
175
|
+
assert.equal(readFileSync(settingsPath, 'utf8'), PRIOR_SETTINGS_TEXT);
|
|
176
|
+
assert.deepEqual(readdirSync(sandboxRoot).sort(), ['settings.json', 'write.mjs']);
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
const KILL_AT_TARGET_CHANGE_PRELOAD = `
|
|
183
|
+
const fs = require('node:fs');
|
|
184
|
+
const targetPath = process.env.KILL_TARGET_PATH;
|
|
185
|
+
const originalWriteFileSync = fs.writeFileSync;
|
|
186
|
+
const originalRenameSync = fs.renameSync;
|
|
187
|
+
fs.writeFileSync = function (filePath, data, options) {
|
|
188
|
+
if (String(filePath) === targetPath) {
|
|
189
|
+
const text = String(data);
|
|
190
|
+
originalWriteFileSync(filePath, text.slice(0, Math.floor(text.length / 2)));
|
|
191
|
+
process.kill(process.pid, 'SIGKILL');
|
|
192
|
+
}
|
|
193
|
+
return originalWriteFileSync.apply(this, arguments);
|
|
194
|
+
};
|
|
195
|
+
fs.renameSync = function (sourcePath, destinationPath) {
|
|
196
|
+
if (String(destinationPath) === targetPath) {
|
|
197
|
+
process.kill(process.pid, 'SIGKILL');
|
|
198
|
+
}
|
|
199
|
+
return originalRenameSync.apply(this, arguments);
|
|
200
|
+
};
|
|
201
|
+
require('node:module').syncBuiltinESMExports();
|
|
202
|
+
`;
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
test(
|
|
206
|
+
'writeFileAtomically should keep the prior file whole when the writer is killed as the target changes',
|
|
207
|
+
{ skip: isPosixPlatform ? false : 'a SIGKILL a process sends itself is POSIX only' },
|
|
208
|
+
() => {
|
|
209
|
+
withSandbox((sandboxRoot) => {
|
|
210
|
+
const settingsPath = join(sandboxRoot, 'settings.json');
|
|
211
|
+
writeFileSync(settingsPath, PRIOR_SETTINGS_TEXT);
|
|
212
|
+
const preloadPath = join(sandboxRoot, 'kill-at-target-change.cjs');
|
|
213
|
+
writeFileSync(preloadPath, KILL_AT_TARGET_CHANGE_PRELOAD);
|
|
214
|
+
const writerScriptPath = join(sandboxRoot, 'write.mjs');
|
|
215
|
+
writeFileSync(writerScriptPath, [
|
|
216
|
+
`import { writeFileAtomically } from ${JSON.stringify(new URL('./write-file-atomically.mjs', import.meta.url).href)};`,
|
|
217
|
+
`writeFileAtomically(${JSON.stringify(settingsPath)}, ${JSON.stringify(NEW_SETTINGS_TEXT)});`,
|
|
218
|
+
].join('\n'));
|
|
219
|
+
|
|
220
|
+
const killedRun = spawnSync(
|
|
221
|
+
process.execPath,
|
|
222
|
+
['--require', preloadPath, writerScriptPath],
|
|
223
|
+
{ encoding: 'utf8', env: { ...process.env, KILL_TARGET_PATH: settingsPath } },
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
assert.equal(killedRun.signal, 'SIGKILL', killedRun.stderr);
|
|
227
|
+
assert.equal(readFileSync(settingsPath, 'utf8'), PRIOR_SETTINGS_TEXT);
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
function exitedProcessId() {
|
|
234
|
+
return spawnSync(process.execPath, ['-e', '']).pid;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
test('writeFileAtomically should remove old temporary files of this target whose writer is gone', () => {
|
|
239
|
+
withSandbox((sandboxRoot) => {
|
|
240
|
+
const settingsPath = join(sandboxRoot, 'settings.json');
|
|
241
|
+
writeFileSync(settingsPath, PRIOR_SETTINGS_TEXT);
|
|
242
|
+
const goneWriterId = exitedProcessId();
|
|
243
|
+
const hourAgo = new Date(Date.now() - 60 * 60 * 1000);
|
|
244
|
+
const staleName = `.settings.json.${goneWriterId}.aaaaaaaaaaaa.tmp`;
|
|
245
|
+
const liveWriterName = `.settings.json.${process.pid}.bbbbbbbbbbbb.tmp`;
|
|
246
|
+
const freshName = `.settings.json.${goneWriterId}.cccccccccccc.tmp`;
|
|
247
|
+
const otherTargetName = `.other.json.${goneWriterId}.dddddddddddd.tmp`;
|
|
248
|
+
for (const eachName of [staleName, liveWriterName, freshName, otherTargetName]) {
|
|
249
|
+
writeFileSync(join(sandboxRoot, eachName), '{"half":');
|
|
250
|
+
}
|
|
251
|
+
for (const eachName of [staleName, liveWriterName, otherTargetName]) {
|
|
252
|
+
utimesSync(join(sandboxRoot, eachName), hourAgo, hourAgo);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
writeFileAtomically(settingsPath, NEW_SETTINGS_TEXT);
|
|
256
|
+
|
|
257
|
+
assert.equal(readFileSync(settingsPath, 'utf8'), NEW_SETTINGS_TEXT);
|
|
258
|
+
assert.deepEqual(
|
|
259
|
+
readdirSync(sandboxRoot).sort(),
|
|
260
|
+
[freshName, otherTargetName, liveWriterName, 'settings.json'].sort(),
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
@@ -49,7 +49,7 @@ The gate never reads the reply text. A held turn passes, so the gate adds at mos
|
|
|
49
49
|
|
|
50
50
|
In Claude Code, `task_subject_outcome_gate.py` denies a task list item named as a procedure step. [Conduct gates](../../hooks/features/conduct-gates.md) lists what it matches.
|
|
51
51
|
|
|
52
|
-
In Claude Code, `tracking_nudge.py` runs on `UserPromptSubmit`. For the session's first prompt that asks for work, and the first after each compaction, it adds one note that asks for an item in the session's task list tool, so the agent tracks the ask before it starts. The note never blocks.
|
|
52
|
+
In Claude Code, `tracking_nudge.py` runs on `UserPromptSubmit`. For the session's first prompt that asks for work, and the first after each compaction, it adds one note that asks for an item in the session's task list tool, so the agent tracks the ask before it starts. On a turn that an event starts, such as a `<task-notification>` or a queued `<agent-message>` with no message from the user, it adds one note while the session title shows the red flag, so the agent clears the flag when the event leaves the user nothing to do. The hook runs only when a prompt starts a turn, so a notification that arrives in the middle of a turn gets no note. These prompts get no wake note: a `<wake reason="external-event">` envelope, a plain `[SYSTEM NOTIFICATION - NOT USER INPUT]` prompt, a body that quotes its own closing tag, two envelopes in one prompt, an envelope with a lead line before it, and an agent message whose sender is empty or `human` in any letter case. The note never blocks.
|
|
53
53
|
|
|
54
54
|
## Cursor
|
|
55
55
|
|
|
@@ -6,7 +6,7 @@ Back to the [rules index](../../rules/index.md).
|
|
|
6
6
|
|
|
7
7
|
Keep the title's status current. Set `<emoji> <name>` when the status changes. Set the hourglass when a new ask starts work. Use the red flag when the user must act, the construction sign when an outside dependency blocks the work, the check mark when the work is done, and the hourglass while work, CI, or a merge queue runs. The name has 25 characters or fewer, in sentence case, with concrete nouns and no IDs, dates, or branch names.
|
|
8
8
|
|
|
9
|
-
**Enforcement:** `hooks/blocking/session_title_format_gate.py` denies a malformed title. `hooks/session/tracking_nudge.py` adds a quiet note to a new ask when the title is missing or stale.
|
|
9
|
+
**Enforcement:** `hooks/blocking/session_title_format_gate.py` denies a malformed title. `hooks/session/tracking_nudge.py` adds a quiet note to a new ask when the title is missing or stale, and to an event turn while the title shows the red flag.
|
|
10
10
|
|
|
11
11
|
**When this applies:** The session has a tool whose name ends in `__set_session_title`, such as `mcp__claude-code-remote__set_session_title` in a cloud session or `mcp__ccd_session_mgmt__set_session_title` in the desktop app.
|
|
12
12
|
|
|
@@ -35,10 +35,26 @@ The name has 25 characters or fewer and names the main change or outcome in conc
|
|
|
35
35
|
|
|
36
36
|
No hook holds the end of a turn for the title.
|
|
37
37
|
|
|
38
|
-
`hooks/session/tracking_nudge.py` runs when the user
|
|
38
|
+
`hooks/session/tracking_nudge.py` runs on `UserPromptSubmit`, when a prompt from the user or from an event starts a turn. A notification that reaches the agent in the middle of a turn starts no turn, so the hook does not run for it. The hook adds a quiet note when the prompt asks for work:
|
|
39
39
|
|
|
40
40
|
- The title shows the red flag or the check mark. The note names that title and asks for the hourglass before other work.
|
|
41
41
|
- The session has no title yet. The note names the title tool and asks for `⏳ <name>` before other work. It shows at most once in a session, compactions included.
|
|
42
42
|
- The title shows the hourglass or the construction sign. No note.
|
|
43
43
|
|
|
44
|
+
On a turn that an event starts, the user sent no message. The hook counts a prompt as an event when it opens with one envelope and only `<system-reminder>` blocks follow it. The envelope is a `<task-notification>` with a bare opening tag, such as a finished delegate, a finished background command, a pull request wake, or a turn review notice. It can also be a queued `<agent-message>` hand-back whose opening tag has `from` as its only attribute. Both tags are lower case. A sender that is empty or `human`, in any letter case and with white space around it ignored, is no event. While the title shows the red flag, the hook adds the wake note on each such prompt. The note names that title and asks the agent to set the status that fits now if the event cleared what the user had to do. The red flag stays only while the user still has to act. A check mark, hourglass, or construction sign title gets no wake note.
|
|
45
|
+
|
|
46
|
+
These prompts get no wake note either:
|
|
47
|
+
|
|
48
|
+
- Typed text after the envelope.
|
|
49
|
+
- A body that quotes its own closing tag. The first closing tag ends the envelope, so the rest reads as typed text.
|
|
50
|
+
- Two envelopes in one prompt.
|
|
51
|
+
- An envelope with a lead line before it, such as "Another Claude session sent a message:".
|
|
52
|
+
- An agent message whose sender is empty or `human`.
|
|
53
|
+
- An opening tag with another attribute or in another letter case, and an envelope with no closing tag.
|
|
54
|
+
- A `<wake>` envelope, such as `<wake reason="external-event">`.
|
|
55
|
+
- A plain `[SYSTEM NOTIFICATION - NOT USER INPUT]` prompt.
|
|
56
|
+
- A prompt of only reminder blocks, and an empty prompt.
|
|
57
|
+
|
|
58
|
+
A prompt with a lead line, a plain system notification prompt, and a tag in another letter case can still get the ask notes above when they ask for work. The hook adds no note to the other shapes.
|
|
59
|
+
|
|
44
60
|
The note never blocks. It applies when the transcript shows the title tool. A cloud session lists the tool only partway through its first turn, so the no title note can come on the second ask.
|
|
@@ -6,7 +6,7 @@ This family stops a chat reply, edited message, or tool call when its payload br
|
|
|
6
6
|
|
|
7
7
|
- `blocking/final_reply_gate.py` checks the reply a session ends its turn with. Its `windows_path_violation` blocks a path the terminal would render without one of its backslashes. Its `unbriefed_question_violation` blocks a reply whose last paragraph, with fences, quotes, and code spans left out, ends with a question mark or says a question still stands, when the turn sent no `AskUserQuestion`, hearthbot decision card, or Codex `request_user_input` call; it is skipped when the transcript cannot be read.
|
|
8
8
|
- `blocking/open_tasks_stop_gate.py` holds the end of a turn once when the prompt that started it asks for work, the turn ran a work tool, and the turn made no tracker call: TaskCreate, TaskUpdate, TodoWrite, the Codex `update_plan`, or the desktop `mcp__ccd_turn__update_plan`. A work tool is any tool but a tracker call, the session title tool, `AskUserQuestion`, a hearthbot decision card, Codex `request_user_input`, `ToolSearch`, `TaskList`, or `TaskGet`. It also holds the turn once when completed items sit beside open ones on the task list the user sees: the session's task store, or the transcript's list when the session has no store. A list that `CLAUDE_CODE_TASK_LIST_ID` shares with other sessions is left alone. It also holds the turn once when the closing reply, or a Markdown, text, or HTML file the turn sent with `SendUserFile`, says something waits on the user and the turn ran no read call or sent no question tool call. `blocking/user_step_wording.py` finds that wording: phrases such as "needs you", "waiting on you", "you need to", and "say when", outside fences, quotes, and code spans, unless a negation on the same line covers the phrase ("Nothing here needs you", "This change does not need you") or the phrase is a label with nothing under it ("Action required: none."). The module docstring of `blocking/user_step_wording.py` names each skip shape. Every other wording is held, because a wrong hold costs the agent one step and a wrong skip hides a step from the user. "Say when" counts only at the start of its clause. Markdown and plain text are read one paragraph at a time. In an HTML file it reads the text one block at a time, counts white space in the source as one space and a `br` as a line break, and leaves out the contents of `script`, `style`, `template`, `title`, `textarea`, `noscript`, `code`, `pre`, and `blockquote` elements; text under a hidden attribute still counts. It skips a sent path that is no regular file and a file over 256 KB, and reads a path sent twice once. A read call is a shell, a file or web read, a subagent, a Codex `local_shell_call`, or a tool whose name carries a read word such as `get`, `list`, or `read` and no write word such as `update` or `append`. Only the part of an MCP tool name after the server is read, and it is split into words at underscores, hyphens, and a capital that follows a lower-case letter or a digit. `TaskList`, `TaskGet`, `ToolSearch`, and the question tools do not count. The gate checks that a read ran and leaves which item it read to the agent, so each such hold tells the agent to read the live state of every item it shows as open, and to end the turn when the wording hands the user no step. One reason carries every finding. `open_task_asks.is_ask` decides whether a prompt asks for work: a question-only prompt, an acknowledgement such as `thanks!`, an empty prompt, a prompt of only `<system-reminder>` blocks, and an envelope such as `<agent-message>` or `<task-notification>` do not. `blocking/open_tasks_transcript.py` replays the transcript for it: the turn's prompt, its tool calls, and the task list. `session_task_items` merges the task store with the transcript items whose subject the store does not hold.
|
|
9
|
-
- `session/tracking_nudge.py` adds one `additionalContext` note to a prompt that asks for work. The note asks for an item in the session's task list tool. It shows on the session's first ask and on the first ask after each compaction, through `once_per_session.py`. When the title shows the red flag or the check mark, it also asks for the hourglass before other work. In a session that has a `__set_session_title` tool and no title yet, it asks once for a first title in the `⏳ <name>` form, and never again in that session, compactions included, through `once_per_session.claim_only_showing`. `session_title_transcript.py` reads the title tool and the shown title from the transcript. It never blocks. No hook holds the end of a turn for the title.
|
|
9
|
+
- `session/tracking_nudge.py` adds one `additionalContext` note to a prompt that asks for work. The note asks for an item in the session's task list tool. It shows on the session's first ask and on the first ask after each compaction, through `once_per_session.py`. When the title shows the red flag or the check mark, it also asks for the hourglass before other work. In a session that has a `__set_session_title` tool and no title yet, it asks once for a first title in the `⏳ <name>` form, and never again in that session, compactions included, through `once_per_session.claim_only_showing`. On a turn that an event starts, with no message from the user, it adds one wake note while the title shows the red flag. The note names that title and asks for the status that fits now if the event cleared what the user had to do. It shows on each such prompt and on no other title. The hook runs only when a prompt starts a turn, so a notification that reaches the agent in the middle of a turn gets no note. `tracking_nudge.is_event_wake` counts a prompt as an event only when it opens with one `<task-notification>` envelope with a bare opening tag, or one `<agent-message>` whose opening tag has `from` as its only attribute, both in lower case, with nothing after it but `<system-reminder>` blocks. A sender that is empty or `human`, in any letter case and with white space around it ignored, is no event. The first closing tag ends the envelope, so a body that quotes its own closing tag reads as typed text after the envelope and gets no wake note. A `<wake reason="external-event">` envelope, a plain `[SYSTEM NOTIFICATION - NOT USER INPUT]` prompt, two envelopes in one prompt, an envelope with a lead line before it, and an opening tag with another attribute or letter case get no wake note. Of these, a prompt with a lead line, a plain system notification prompt, and a tag in another letter case can still get the ask notes when they ask for work. `session_title_transcript.py` reads the title tool and the shown title from the transcript. It never blocks. No hook holds the end of a turn for the title.
|
|
10
10
|
- `session/background_silence_prompt.py` adds one `additionalContext` note to a background event prompt, one that starts with `<task-notification>` or opens itself or a `<system-reminder>` block with `[SYSTEM NOTIFICATION - NOT USER INPUT]`, while the user asked for silence. The newest user-typed message that sets silence ("silent unless", "stay silent", "silent on updates", "no updates unless") or lifts it ("you can talk again", "updates are fine", "stop being silent") decides. The note quotes the user's "unless" or "except" clause word for word, or the whole message when it has no such clause, and says to end the turn with no text unless that exception applies now. Envelope prompts, compaction summaries, and quoted `>` lines are not the user's words. It never blocks.
|
|
11
11
|
- The claim judge is a `prompt` hook in `hooks.json`, with no `model` set, so Claude Code's small default hook model reads each chat message and denies every claim, numbered in one refusal, about how code, a file, a tool, a service, a run, or a process behaves, or why something happened, when nothing in the message shows it: inline code that quotes output or a code line, a file and line, or a link. A pull request link covers what that change does, what it blocks or lets through, and its checks. The author's own actions, a restatement of the user's words, questions, instructions, and a decision card's option consequences pass. It catches plain claims such as "The code lets any of them rewrite it mid-check." `continueOnBlock` returns the reason to the agent as the tool error, so it can add the source and send again. The installer owns it through the `claude-dev-env: ` prefix on its `statusMessage`. It skips `post_widget`, whose input is SVG or HTML markup.
|
|
12
12
|
- `blocking/edit_marker_gate.py` rejects strikethrough and edit-note markers in replacement chat text or cards.
|
|
@@ -61,7 +61,7 @@ Preconditions:
|
|
|
61
61
|
- **Resolve reply.** Input is a transcript where a thread reply came back refused, or with no reply, or with one reply already spent on a resolve, or with a reply on another thread, then a resolve call, a `pull_request_review_write` `resolve_thread` call, a graphql `resolveReviewThread` command, or a `ccr/comments/<id>/resolve` call. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_resolve_thread_reply_gate.py -q`. The adjacent test observes a deny whose reason says to post the reply, confirm it posted, then resolve. A reply that posted before the resolve passes, and an unreadable transcript passes.
|
|
62
62
|
- **Final reply.** Input is a closing reply. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_final_reply_gate.py -q`. The adjacent test observes a `block` decision for a path in plain text. A reply with a plain-text `D:\Reports\.claude\report.html` is blocked; the same path in backticks or a fenced block passes.
|
|
63
63
|
- **Open tasks.** Input is a transcript whose last prompt asks for work and whose turn ran a Bash call and no tracker call. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_open_tasks_stop_gate.py -q`. The adjacent test observes one `block` decision; the same turn with a TaskCreate, TaskUpdate, TodoWrite, or desktop plan call passes. A question, an acknowledgement, a `<task-notification>` envelope, a tool-free turn, and a held stop pass. The same file covers Codex and Cursor payloads.
|
|
64
|
-
- **Ask nudge.** Input is a `UserPromptSubmit` payload with a work prompt, a question, and a `<task-notification>` envelope, after a transcript whose title shows the red flag. Run `python -m pytest packages/claude-dev-env/hooks/session/test_tracking_nudge.py -q`. The adjacent test observes a task list note and a title note for the work prompt,
|
|
64
|
+
- **Ask nudge.** Input is a `UserPromptSubmit` payload with a work prompt, a question, and a `<task-notification>` envelope, after a transcript whose title shows the red flag. Run `python -m pytest packages/claude-dev-env/hooks/session/test_tracking_nudge.py -q`. The adjacent test observes a task list note and a title note for the work prompt, empty stdout for the question, and the wake note alone for the envelope. The wake note also shows for a queued `<agent-message>` hand-back. A check mark, hourglass, or construction sign title, a session without the title tool, typed text after the envelope, a body that quotes its own closing tag, two envelopes in one prompt, a mention wake, an empty prompt, and a prompt of only reminder blocks get empty stdout. A second ask in the same session gets no task list note until the transcript records a compaction.
|
|
65
65
|
- **Background silence.** Input is a `UserPromptSubmit` payload whose prompt is a `<task-notification>` envelope, after a transcript whose user message reads "Silent on updates unless something merges or youre blocked". Run `python -m pytest packages/claude-dev-env/hooks/session/test_background_silence_prompt.py -q`. The adjacent test observes a note that quotes "unless something merges or youre blocked", and empty stdout for a user-typed prompt, after a lift, and with no silence message.
|
|
66
66
|
- **Claim judge.** Input is a headless `claude -p` session with a stub MCP server named `hearthbot` that exposes `reply` and `ask_decision`, told to send "The code lets any of them rewrite it mid-check." The session settings add the `hooks.json` prompt hook. The stub logs zero bytes sent, and the tool error reads `PreToolUse:mcp__hearthbot__reply hook error: [<the prompt>]: Facts with no source: 1. ...`, numbering every failing claim. The same sentence with a `file:line` in backticks posts. A hook whose `model` Claude Code does not recognize lets every message through, so leave `model` unset. Run `node --test packages/claude-dev-env/bin/install.prompt-hook.test.mjs` for the installer side; it observes one managed prompt hook after two installs and none after uninstall.
|
|
67
67
|
- **Edit marker.** Input is an update message with strikethrough or an edit note. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_edit_marker_gate.py -q`. The adjacent test observes a denial; clean replacement text passes.
|
|
@@ -66,3 +66,16 @@ NO_TITLE_NUDGE_TEMPLATE = (
|
|
|
66
66
|
" '⏳ <name>' before other work, so the user sees the session working."
|
|
67
67
|
)
|
|
68
68
|
NO_TITLE_NUDGE_ONCE_MARKER_NAME = "no_title_nudge"
|
|
69
|
+
WAKE_FLAG_NUDGE_TEMPLATE = (
|
|
70
|
+
"An event started this turn. The user sent no message. The session title still shows"
|
|
71
|
+
" '{title}'. If this event leaves the user nothing to do, set the title with"
|
|
72
|
+
" {tool_name} to the status that fits now before you reply. Keep the red flag only"
|
|
73
|
+
" while the user still has to act."
|
|
74
|
+
)
|
|
75
|
+
WAKE_EVENT_ENVELOPE_PATTERN = re.compile(
|
|
76
|
+
r"<task-notification>.*?</task-notification>"
|
|
77
|
+
r'|<agent-message from="(?P<sender>[^"]*)">.*?</agent-message>',
|
|
78
|
+
re.DOTALL,
|
|
79
|
+
)
|
|
80
|
+
WAKE_SENDER_GROUP_NAME = "sender"
|
|
81
|
+
ALL_NO_WAKE_SENDER_NAMES = frozenset({"", "human"})
|
|
@@ -120,10 +120,7 @@ def test_should_ask_to_refresh_a_title_that_says_the_session_waits_or_is_done(
|
|
|
120
120
|
assert TITLE_TOOL in context_text
|
|
121
121
|
|
|
122
122
|
|
|
123
|
-
@pytest.mark.parametrize(
|
|
124
|
-
"prompt_text",
|
|
125
|
-
["did the export fail?", "thanks!", "<task-notification>done</task-notification>"],
|
|
126
|
-
)
|
|
123
|
+
@pytest.mark.parametrize("prompt_text", ["did the export fail?", "thanks!"])
|
|
127
124
|
def test_should_stay_silent_for_a_prompt_that_asks_for_no_work(
|
|
128
125
|
monkeypatch: pytest.MonkeyPatch,
|
|
129
126
|
capsys: pytest.CaptureFixture[str],
|
|
@@ -199,6 +196,216 @@ def script_context(completed_process: subprocess.CompletedProcess[str]) -> str:
|
|
|
199
196
|
return json.loads(completed_process.stdout)["hookSpecificOutput"]["additionalContext"]
|
|
200
197
|
|
|
201
198
|
|
|
199
|
+
RED_FLAG_TITLE = "\U0001f6a9 Merge approval"
|
|
200
|
+
TASK_DONE_WAKE = (
|
|
201
|
+
"<task-notification>\n<task-id>a0f1e2d3c4b5a6978</task-id>\n"
|
|
202
|
+
"<tool-use-id>toolu_00000000000000000000000001</tool-use-id>\n"
|
|
203
|
+
"<output-file>/tmp/session/tasks/a0f1e2d3c4b5a6978.output</output-file>\n"
|
|
204
|
+
"<status>completed</status>\n"
|
|
205
|
+
'<summary>Agent "Export the APKs" finished</summary>\n'
|
|
206
|
+
"<note>A task-notification fires each time this agent stops with no live background"
|
|
207
|
+
" children of its own.</note>\n"
|
|
208
|
+
'<result>This agent\'s report was delivered to you as a message from "a0f1e2d3c4b5a6978"'
|
|
209
|
+
" (its SubagentHandback call). Read it there; it is not repeated here.\n</result>\n"
|
|
210
|
+
"<usage><subagent_tokens>1200</subagent_tokens><tool_uses>3</tool_uses>"
|
|
211
|
+
"<duration_ms>45000</duration_ms></usage>\n"
|
|
212
|
+
"</task-notification>"
|
|
213
|
+
)
|
|
214
|
+
BACKGROUND_COMMAND_WAKE = (
|
|
215
|
+
"<task-notification>\n<task-id>b0c1d2e3f</task-id>\n"
|
|
216
|
+
"<tool-use-id>toolu_00000000000000000000000002</tool-use-id>\n"
|
|
217
|
+
"<output-file>/tmp/session/tasks/b0c1d2e3f.output</output-file>\n"
|
|
218
|
+
"<status>completed</status>\n"
|
|
219
|
+
'<summary>Background command "Build the APKs" completed (exit code 0)</summary>\n'
|
|
220
|
+
"</task-notification>"
|
|
221
|
+
)
|
|
222
|
+
PULL_REQUEST_WAKE = (
|
|
223
|
+
"<task-notification>\n<task-type>queued-remote-notifications</task-type>\n"
|
|
224
|
+
"<status>pending</status>\n"
|
|
225
|
+
"<summary>1 unread notification (GitHub activity on a subscribed PR: 1)</summary>\n"
|
|
226
|
+
"Notifications are queued for this session (more may arrive before you read them)."
|
|
227
|
+
" Call ReadNotifications now, before other work, and keep calling it until it reports"
|
|
228
|
+
" 0 remaining.\n"
|
|
229
|
+
"</task-notification>"
|
|
230
|
+
)
|
|
231
|
+
TURN_REVIEW_WAKE = (
|
|
232
|
+
"<task-notification>\n<summary>Turn review found problems</summary>\n</task-notification>\n"
|
|
233
|
+
"<system-reminder>\nThe background review of your last reply's changes finished after that"
|
|
234
|
+
" reply ended.\n</system-reminder>"
|
|
235
|
+
)
|
|
236
|
+
HAND_BACK_WAKE = (
|
|
237
|
+
'<agent-message from="a0f1e2d3c4b5a6978">\n[Subagent hand-back] The text below is the final'
|
|
238
|
+
" report of a subagent this session delegated to. The harness indents every line of the"
|
|
239
|
+
" report. The report follows:\n"
|
|
240
|
+
" Goal: export the APKs.\n"
|
|
241
|
+
" - Both APKs are exported to the build folder.\n</agent-message>"
|
|
242
|
+
)
|
|
243
|
+
ALL_RECORDED_WAKES = [TASK_DONE_WAKE, BACKGROUND_COMMAND_WAKE, PULL_REQUEST_WAKE, HAND_BACK_WAKE]
|
|
244
|
+
MENTION_WAKE = '<wake reason="mention"><message from="human">Option one.</message></wake>'
|
|
245
|
+
BASH_ONLY_LISTING = {"type": "attachment", "attachment": {"tools": [{"name": "Bash"}]}}
|
|
246
|
+
ALL_PROMPTS_NO_EVENT_SENT = [
|
|
247
|
+
"",
|
|
248
|
+
" \n",
|
|
249
|
+
"<system-reminder>Tool loaded.</system-reminder>",
|
|
250
|
+
"<task-notification>\n<status>failed</status>\n</task-notification>\nWhy did this fail? Fix it.",
|
|
251
|
+
'<system-reminder>Tool loaded.</system-reminder>\n<agent-message from="a1">Done</agent-message>\nShip it',
|
|
252
|
+
MENTION_WAKE,
|
|
253
|
+
'<wake reason="mention">\n<message from="human">Merge it now</message></wake>',
|
|
254
|
+
'<task-notification status from="human"',
|
|
255
|
+
"<task-notification>The log reads </task-notification> here.</task-notification>",
|
|
256
|
+
'<agent-message from="a1">It quotes </agent-message> here.</agent-message>',
|
|
257
|
+
'<agent-message from="a1">Done</agent-message>\n<task-notification>done</task-notification>',
|
|
258
|
+
"<task-notification>\n<status>completed</status>",
|
|
259
|
+
'<agent-message from="a1">Done',
|
|
260
|
+
"<agent-message>Done</agent-message>",
|
|
261
|
+
"<task-notification >done</task-notification>",
|
|
262
|
+
'<agent-message from="a1" >Done</agent-message>',
|
|
263
|
+
]
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
@pytest.mark.parametrize(
|
|
267
|
+
("prompt_text", "is_expected_wake"),
|
|
268
|
+
[
|
|
269
|
+
*[(each_prompt, True) for each_prompt in ALL_RECORDED_WAKES],
|
|
270
|
+
(TURN_REVIEW_WAKE, True),
|
|
271
|
+
(f"\n {TASK_DONE_WAKE}\n ", True),
|
|
272
|
+
pytest.param(
|
|
273
|
+
f"{TASK_DONE_WAKE}<system-reminder>Tool loaded.</system-reminder>",
|
|
274
|
+
True,
|
|
275
|
+
id="reminder-right-after-the-envelope",
|
|
276
|
+
),
|
|
277
|
+
pytest.param(f"{TASK_DONE_WAKE}k", False, id="one-typed-character-after-the-envelope"),
|
|
278
|
+
pytest.param(
|
|
279
|
+
'<task-notification id="a1">done</task-notification>',
|
|
280
|
+
False,
|
|
281
|
+
id="task-opening-tag-with-an-attribute",
|
|
282
|
+
),
|
|
283
|
+
pytest.param(
|
|
284
|
+
"<TASK-NOTIFICATION>done</TASK-NOTIFICATION>", False, id="upper-case-task-tag"
|
|
285
|
+
),
|
|
286
|
+
pytest.param(
|
|
287
|
+
'<Agent-Message from="a1">Done</Agent-Message>', False, id="mixed-case-agent-tag"
|
|
288
|
+
),
|
|
289
|
+
pytest.param(
|
|
290
|
+
'<agent-message from="a1" via="human">Done</agent-message>',
|
|
291
|
+
False,
|
|
292
|
+
id="agent-attribute-after-the-sender-via-human",
|
|
293
|
+
),
|
|
294
|
+
pytest.param(
|
|
295
|
+
'<agent-message from="a1" via="b">Done</agent-message>',
|
|
296
|
+
False,
|
|
297
|
+
id="agent-attribute-after-the-sender-via-b",
|
|
298
|
+
),
|
|
299
|
+
pytest.param('<agent-message from="">Done</agent-message>', False, id="empty-sender"),
|
|
300
|
+
pytest.param('<agent-message from="Human">Done</agent-message>', False, id="sender-Human"),
|
|
301
|
+
pytest.param(
|
|
302
|
+
'<agent-message from=" human">Done</agent-message>', False, id="sender-space-human"
|
|
303
|
+
),
|
|
304
|
+
pytest.param(
|
|
305
|
+
'<agent-message from="HUMAN\t">Done</agent-message>', False, id="sender-HUMAN-tab"
|
|
306
|
+
),
|
|
307
|
+
('<agent-message from="a1">\n<message from="human">Merge it</message></agent-message>', True),
|
|
308
|
+
('<task-notification><x from="human">done</x></task-notification>', True),
|
|
309
|
+
*[(each_prompt, False) for each_prompt in ALL_PROMPTS_NO_EVENT_SENT],
|
|
310
|
+
(f"{TURN_REVIEW_WAKE}\nWhy did the review fail?", False),
|
|
311
|
+
(
|
|
312
|
+
"<task-notification>a</task-notification>\nWhy did this one fail and not\n"
|
|
313
|
+
"<task-notification>b</task-notification>",
|
|
314
|
+
False,
|
|
315
|
+
),
|
|
316
|
+
(
|
|
317
|
+
'<agent-message from="a1">Done</agent-message>\nWhy is this one done and not\n'
|
|
318
|
+
'<agent-message from="a2">Failed</agent-message>',
|
|
319
|
+
False,
|
|
320
|
+
),
|
|
321
|
+
('<agent-message from="human">Merge it</agent-message>', False),
|
|
322
|
+
('<agent-message from="human" via="a1">Merge it</agent-message>', False),
|
|
323
|
+
(f"Another Claude session sent a message:\n{HAND_BACK_WAKE}", False),
|
|
324
|
+
(f"<system-reminder>Tool loaded.</system-reminder>\n{TASK_DONE_WAKE}", False),
|
|
325
|
+
('<wake reason="external-event"><event source="github">PR 12 approved</event></wake>', False),
|
|
326
|
+
("<system-reminder>[SYSTEM NOTIFICATION - NOT USER INPUT] Monitor line</system-reminder>", False),
|
|
327
|
+
("[SYSTEM NOTIFICATION - NOT USER INPUT]\nBackground task finished.", False),
|
|
328
|
+
("<local-command-stdout>Done</local-command-stdout>", False),
|
|
329
|
+
],
|
|
330
|
+
)
|
|
331
|
+
def test_should_tell_an_event_wake_from_a_prompt_no_event_sent(
|
|
332
|
+
prompt_text: str, is_expected_wake: bool
|
|
333
|
+
) -> None:
|
|
334
|
+
assert tracking_nudge.is_event_wake(prompt_text) is is_expected_wake
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
@pytest.mark.parametrize("prompt_text", [*ALL_RECORDED_WAKES, TURN_REVIEW_WAKE])
|
|
338
|
+
def test_should_ask_to_clear_the_flag_on_a_turn_an_event_wakes(tmp_path: Path, prompt_text: str) -> None:
|
|
339
|
+
context_text = script_context(
|
|
340
|
+
run_nudge_script(tmp_path, prompt_text, titled_entries(RED_FLAG_TITLE))
|
|
341
|
+
)
|
|
342
|
+
assert "The user sent no message" in context_text
|
|
343
|
+
assert RED_FLAG_TITLE in context_text
|
|
344
|
+
assert TITLE_TOOL in context_text
|
|
345
|
+
assert "Keep the red flag only while the user still has to act." in context_text
|
|
346
|
+
assert TASK_LIST_NUDGE not in context_text
|
|
347
|
+
assert HOURGLASS_FORM not in context_text
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
@pytest.mark.parametrize("prompt_text", ALL_PROMPTS_NO_EVENT_SENT)
|
|
351
|
+
def test_should_print_nothing_for_a_prompt_no_event_sent_under_the_red_flag(
|
|
352
|
+
tmp_path: Path, prompt_text: str
|
|
353
|
+
) -> None:
|
|
354
|
+
completed_process = run_nudge_script(tmp_path, prompt_text, titled_entries(RED_FLAG_TITLE))
|
|
355
|
+
assert (completed_process.returncode, completed_process.stdout) == (0, "")
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
@pytest.mark.parametrize(
|
|
359
|
+
"all_entries",
|
|
360
|
+
[
|
|
361
|
+
titled_entries("✅ Gate"),
|
|
362
|
+
titled_entries("⏳ Export"),
|
|
363
|
+
titled_entries("\U0001f6a7 Vendor outage"),
|
|
364
|
+
[*titled_entries(RED_FLAG_TITLE), BASH_ONLY_LISTING],
|
|
365
|
+
],
|
|
366
|
+
)
|
|
367
|
+
def test_should_add_no_wake_note_unless_the_title_shows_the_red_flag(
|
|
368
|
+
tmp_path: Path, all_entries: list[dict[str, object]]
|
|
369
|
+
) -> None:
|
|
370
|
+
assert script_context(run_nudge_script(tmp_path, TASK_DONE_WAKE, all_entries)) == ""
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def test_should_keep_the_ask_notes_for_words_the_user_typed_after_an_event_reminder(
|
|
374
|
+
tmp_path: Path,
|
|
375
|
+
) -> None:
|
|
376
|
+
prompt_text = (
|
|
377
|
+
"<system-reminder>[SYSTEM NOTIFICATION - NOT USER INPUT] Monitor line</system-reminder>\n"
|
|
378
|
+
"Export the APKs"
|
|
379
|
+
)
|
|
380
|
+
context_text = script_context(
|
|
381
|
+
run_nudge_script(tmp_path, prompt_text, titled_entries(RED_FLAG_TITLE))
|
|
382
|
+
)
|
|
383
|
+
assert TASK_LIST_NUDGE in context_text
|
|
384
|
+
assert HOURGLASS_FORM in context_text
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def test_should_build_the_wake_note_only_for_an_event_under_the_red_flag() -> None:
|
|
388
|
+
selector_title = "\U0001f6a9️ Merge approval"
|
|
389
|
+
wake_note = tracking_nudge.wake_flag_nudge(TASK_DONE_WAKE, titled_entries(selector_title))
|
|
390
|
+
assert selector_title in (wake_note or "")
|
|
391
|
+
assert tracking_nudge.wake_flag_nudge("Export the APKs", titled_entries(RED_FLAG_TITLE)) is None
|
|
392
|
+
assert tracking_nudge.wake_flag_nudge(TASK_DONE_WAKE, titled_entries("✅ Gate")) is None
|
|
393
|
+
assert tracking_nudge.wake_flag_nudge(TASK_DONE_WAKE, []) is None
|
|
394
|
+
assert tracking_nudge.wake_flag_nudge(TASK_DONE_WAKE, UNTITLED_ENTRIES) is None
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def test_should_name_each_title_tool_the_session_holds_in_the_wake_note() -> None:
|
|
398
|
+
second_title_tool = "mcp__ccd_session_mgmt__set_session_title"
|
|
399
|
+
two_tool_listing = {
|
|
400
|
+
"type": "attachment",
|
|
401
|
+
"attachment": {"tools": [{"name": TITLE_TOOL}, {"name": second_title_tool}]},
|
|
402
|
+
}
|
|
403
|
+
wake_note = tracking_nudge.wake_flag_nudge(
|
|
404
|
+
TASK_DONE_WAKE, [*titled_entries(RED_FLAG_TITLE), two_tool_listing]
|
|
405
|
+
)
|
|
406
|
+
assert f"{TITLE_TOOL} or {second_title_tool}" in (wake_note or "")
|
|
407
|
+
|
|
408
|
+
|
|
202
409
|
def test_should_ask_for_a_first_title_in_a_titled_tool_session_with_no_title(tmp_path: Path) -> None:
|
|
203
410
|
context_text = script_context(run_nudge_script(tmp_path, "Export the APKs", UNTITLED_ENTRIES))
|
|
204
411
|
assert "no title yet" in context_text
|
|
@@ -284,6 +491,7 @@ def test_should_describe_the_prompt_note_and_no_title_send_back_in_the_docs() ->
|
|
|
284
491
|
assert "session_title_turn_gate" not in each_doc_text
|
|
285
492
|
assert "No hook holds the end of a turn for the title." in each_doc_text
|
|
286
493
|
assert "no title yet" in each_doc_text
|
|
494
|
+
assert "turn that an event starts" in each_doc_text
|
|
287
495
|
assert "tracking_nudge.py" in each_doc_text
|
|
288
496
|
|
|
289
497
|
|