@koda-sl/baker-bridge 0.194.0-dev.8f5bcdb0e → 0.195.0-dev.a2270c74d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -28
- package/dist/hono/agent.d.ts.map +1 -1
- package/dist/hono/agent.js +4 -1
- package/dist/hono/agent.js.map +1 -1
- package/dist/hono/bridge-job.d.ts +27 -0
- package/dist/hono/bridge-job.d.ts.map +1 -1
- package/dist/hono/bridge-job.js +93 -19
- package/dist/hono/bridge-job.js.map +1 -1
- package/dist/hono/bridge-job.test.js +99 -226
- package/dist/hono/bridge-job.test.js.map +1 -1
- package/dist/hono/chat-language.d.ts +34 -0
- package/dist/hono/chat-language.d.ts.map +1 -0
- package/dist/hono/chat-language.js +152 -0
- package/dist/hono/chat-language.js.map +1 -0
- package/dist/hono/chat-language.test.d.ts +2 -0
- package/dist/hono/chat-language.test.d.ts.map +1 -0
- package/dist/hono/chat-language.test.js +136 -0
- package/dist/hono/chat-language.test.js.map +1 -0
- package/dist/hono/jev.d.ts +16 -0
- package/dist/hono/jev.d.ts.map +1 -1
- package/dist/hono/jev.js +44 -21
- package/dist/hono/jev.js.map +1 -1
- package/dist/hono/model-capabilities.js +3 -3
- package/dist/hono/model-capabilities.js.map +1 -1
- package/dist/hono/progress-note.d.ts +0 -3
- package/dist/hono/progress-note.d.ts.map +1 -1
- package/dist/hono/progress-note.js +0 -8
- package/dist/hono/progress-note.js.map +1 -1
- package/dist/hono/publish-handoff.d.ts +6 -17
- package/dist/hono/publish-handoff.d.ts.map +1 -1
- package/dist/hono/publish-handoff.js +17 -67
- package/dist/hono/publish-handoff.js.map +1 -1
- package/dist/hono/publish-handoff.test.js +34 -63
- package/dist/hono/publish-handoff.test.js.map +1 -1
- package/dist/hono/scripted-publish.d.ts +19 -0
- package/dist/hono/scripted-publish.d.ts.map +1 -0
- package/dist/hono/scripted-publish.js +219 -0
- package/dist/hono/scripted-publish.js.map +1 -0
- package/dist/hono/scripted-publish.test.d.ts +2 -0
- package/dist/hono/scripted-publish.test.d.ts.map +1 -0
- package/dist/hono/scripted-publish.test.js +212 -0
- package/dist/hono/scripted-publish.test.js.map +1 -0
- package/dist/hono/skill-language.d.ts +16 -40
- package/dist/hono/skill-language.d.ts.map +1 -1
- package/dist/hono/skill-language.js +39 -168
- package/dist/hono/skill-language.js.map +1 -1
- package/dist/hono/skill-language.test.js +48 -50
- package/dist/hono/skill-language.test.js.map +1 -1
- package/dist/hono/subagent-route.test.js +29 -5
- package/dist/hono/subagent-route.test.js.map +1 -1
- package/dist/hono/types.d.ts +9 -0
- package/dist/hono/types.d.ts.map +1 -1
- package/dist/review/digest.d.ts +6 -5
- package/dist/review/digest.d.ts.map +1 -1
- package/dist/review/digest.js +34 -28
- package/dist/review/digest.js.map +1 -1
- package/dist/review/digest.test.js +42 -177
- package/dist/review/digest.test.js.map +1 -1
- package/dist/review/evidence-block.js +2 -2
- package/dist/review/evidence-block.js.map +1 -1
- package/dist/review/reply-language.d.ts +12 -30
- package/dist/review/reply-language.d.ts.map +1 -1
- package/dist/review/reply-language.js +97 -162
- package/dist/review/reply-language.js.map +1 -1
- package/dist/review/reply-language.test.js +67 -75
- package/dist/review/reply-language.test.js.map +1 -1
- package/package.json +1 -2
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
7
|
+
import { runScriptedPublish } from "./scripted-publish.js";
|
|
8
|
+
const SCRIPTS = ".claude/skills/publish/scripts";
|
|
9
|
+
const RECOVERY = "__tooling__/checks/base/recover-stalled-publish/recover-stalled-publish.mjs";
|
|
10
|
+
const STATE = ".cache/publish-state.json";
|
|
11
|
+
const LOG = "steps.log";
|
|
12
|
+
const PUBLISH_STATE_MODULES = "__tooling__/checks/sdk";
|
|
13
|
+
/** The scaffold's own publish-state reader, which decides what a state on disk means. */
|
|
14
|
+
const SCAFFOLD_SDK = join(dirname(fileURLToPath(import.meta.url)), "../../../../apps/scaffold-template", PUBLISH_STATE_MODULES);
|
|
15
|
+
const workspaces = [];
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
for (const workspace of workspaces.splice(0))
|
|
18
|
+
rmSync(workspace, { recursive: true, force: true });
|
|
19
|
+
});
|
|
20
|
+
function git(cwd, ...args) {
|
|
21
|
+
return execFileSync("git", args, { cwd, encoding: "utf8", stdio: "pipe" }).trim();
|
|
22
|
+
}
|
|
23
|
+
/** A stub step: logs its name, then runs `body` (plain Node). Exit code and output are the body's. */
|
|
24
|
+
function stub(cwd, file, body = "") {
|
|
25
|
+
const path = join(cwd, file);
|
|
26
|
+
mkdirSync(join(path, ".."), { recursive: true });
|
|
27
|
+
writeFileSync(path, [
|
|
28
|
+
'import { appendFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";',
|
|
29
|
+
`appendFileSync(${JSON.stringify(LOG)}, ${JSON.stringify(`${file.split("/").pop()}\n`)});`,
|
|
30
|
+
body,
|
|
31
|
+
].join("\n"));
|
|
32
|
+
}
|
|
33
|
+
/** A publish state as step 1 writes it, with `fields` over it (`phase: undefined` drops the phase). */
|
|
34
|
+
const WRITES_STATE = (fields) => `mkdirSync(".cache", { recursive: true }); writeFileSync(${JSON.stringify(STATE)}, JSON.stringify(${JSON.stringify({
|
|
35
|
+
version: 1,
|
|
36
|
+
chatId: "chat_1",
|
|
37
|
+
baseUrl: "http://127.0.0.1:9",
|
|
38
|
+
apiKey: "key",
|
|
39
|
+
...fields,
|
|
40
|
+
})}));`;
|
|
41
|
+
/**
|
|
42
|
+
* A chat workspace on `chat`, a commit ahead of `main`, with the publish skill's
|
|
43
|
+
* steps stubbed. Step 1 records the publish as Baker does and names the branch.
|
|
44
|
+
*/
|
|
45
|
+
function workspace(overrides = {}) {
|
|
46
|
+
const cwd = mkdtempSync(join(tmpdir(), "scripted-publish-"));
|
|
47
|
+
workspaces.push(cwd);
|
|
48
|
+
git(cwd, "init", "--quiet", "--initial-branch=main");
|
|
49
|
+
git(cwd, "config", "user.email", "test@example.com");
|
|
50
|
+
git(cwd, "config", "user.name", "Test");
|
|
51
|
+
writeFileSync(join(cwd, ".gitignore"), `.cache/\n${LOG}\n.claude/\n__tooling__/\n`);
|
|
52
|
+
writeFileSync(join(cwd, "hero.txt"), "Old headline\n");
|
|
53
|
+
git(cwd, "add", "-A");
|
|
54
|
+
git(cwd, "commit", "--quiet", "-m", "base");
|
|
55
|
+
git(cwd, "checkout", "--quiet", "-b", "chat");
|
|
56
|
+
writeFileSync(join(cwd, "hero.txt"), "Chat headline\n");
|
|
57
|
+
git(cwd, "commit", "--quiet", "-am", "publish: chat");
|
|
58
|
+
stub(cwd, `${SCRIPTS}/prepare-publish.mjs`, overrides.prepare ?? `${WRITES_STATE({ phase: "publishing" })} process.stdout.write("chat");`);
|
|
59
|
+
stub(cwd, `${SCRIPTS}/build-and-amend.mjs`, overrides.build);
|
|
60
|
+
stub(cwd, `${SCRIPTS}/run-verify.mjs`, overrides.verify);
|
|
61
|
+
stub(cwd, `${SCRIPTS}/finalize-publish.mjs`, overrides.finalize ?? 'import { rmSync } from "node:fs"; rmSync(".cache", { recursive: true, force: true });');
|
|
62
|
+
stub(cwd, RECOVERY, overrides.recovery);
|
|
63
|
+
cpSync(SCAFFOLD_SDK, join(cwd, PUBLISH_STATE_MODULES), { recursive: true });
|
|
64
|
+
return cwd;
|
|
65
|
+
}
|
|
66
|
+
function stepsRun(cwd) {
|
|
67
|
+
return existsSync(join(cwd, LOG)) ? readFileSync(join(cwd, LOG), "utf8").trim().split("\n") : [];
|
|
68
|
+
}
|
|
69
|
+
function isRunning(pid) {
|
|
70
|
+
try {
|
|
71
|
+
process.kill(pid, 0);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function publish(cwd, signal = new AbortController().signal) {
|
|
79
|
+
return runScriptedPublish({
|
|
80
|
+
cwd,
|
|
81
|
+
env: { PATH: process.env.PATH, BAKER_THREAD_ID: "thread_1", BAKER_TURN_ID: "turn_1" },
|
|
82
|
+
signal,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
describe("runScriptedPublish", () => {
|
|
86
|
+
it("runs every step of the publish skill in order and finishes", async () => {
|
|
87
|
+
const cwd = workspace();
|
|
88
|
+
const result = await publish(cwd);
|
|
89
|
+
expect({ result, steps: stepsRun(cwd) }).toEqual({
|
|
90
|
+
result: { kind: "finished" },
|
|
91
|
+
steps: ["prepare-publish.mjs", "build-and-amend.mjs", "run-verify.mjs", "finalize-publish.mjs"],
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
it("finishes at step 1 when Baker took a publish with nothing to merge", async () => {
|
|
95
|
+
const cwd = workspace({
|
|
96
|
+
prepare: 'process.stderr.write("✓ NOTHING_TO_PUBLISH — no file changes to merge; Baker has completed this chat.\\n"); process.exit(1);',
|
|
97
|
+
});
|
|
98
|
+
const result = await publish(cwd);
|
|
99
|
+
expect({ result, steps: stepsRun(cwd) }).toEqual({ result: { kind: "finished" }, steps: ["prepare-publish.mjs"] });
|
|
100
|
+
});
|
|
101
|
+
it("hands a publish whose rebase conflicts to the agent, with the rebase undone and step 1 free to start again", async () => {
|
|
102
|
+
const cwd = workspace();
|
|
103
|
+
git(cwd, "checkout", "--quiet", "main");
|
|
104
|
+
writeFileSync(join(cwd, "hero.txt"), "Another chat's headline\n");
|
|
105
|
+
git(cwd, "commit", "--quiet", "-am", "another chat");
|
|
106
|
+
git(cwd, "checkout", "--quiet", "chat");
|
|
107
|
+
const result = await publish(cwd);
|
|
108
|
+
expect({
|
|
109
|
+
result,
|
|
110
|
+
steps: stepsRun(cwd),
|
|
111
|
+
rebasing: existsSync(join(cwd, ".git", "rebase-merge")) || existsSync(join(cwd, ".git", "rebase-apply")),
|
|
112
|
+
branch: git(cwd, "branch", "--show-current"),
|
|
113
|
+
state: existsSync(join(cwd, STATE)),
|
|
114
|
+
}).toEqual({
|
|
115
|
+
result: { kind: "handOff", step: "rebase" },
|
|
116
|
+
steps: ["prepare-publish.mjs"],
|
|
117
|
+
rebasing: false,
|
|
118
|
+
branch: "chat",
|
|
119
|
+
state: false,
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
it("hands a publish whose verify failed, once Baker was told, to the agent", async () => {
|
|
123
|
+
const cwd = workspace({
|
|
124
|
+
verify: 'import { rmSync } from "node:fs"; rmSync(".cache", { recursive: true, force: true }); process.exit(1);',
|
|
125
|
+
});
|
|
126
|
+
const result = await publish(cwd);
|
|
127
|
+
expect({ result, steps: stepsRun(cwd) }).toEqual({
|
|
128
|
+
result: { kind: "handOff", step: "verify" },
|
|
129
|
+
steps: ["prepare-publish.mjs", "build-and-amend.mjs", "run-verify.mjs"],
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
// run-verify tells Baker of its failure; when that call cannot reach Baker the
|
|
133
|
+
// failure stays on disk as `push_failed`, and nothing was pushed.
|
|
134
|
+
it("hands a publish whose verify failed to the agent once the recovery delivered the failure Baker missed", async () => {
|
|
135
|
+
const cwd = workspace({
|
|
136
|
+
verify: `${WRITES_STATE({ phase: "push_failed", failureReason: "verify failed" })} process.exit(1);`,
|
|
137
|
+
recovery: 'import { rmSync } from "node:fs"; rmSync(".cache", { recursive: true, force: true });',
|
|
138
|
+
});
|
|
139
|
+
const result = await publish(cwd);
|
|
140
|
+
expect({ result, steps: stepsRun(cwd) }).toEqual({
|
|
141
|
+
result: { kind: "handOff", step: "verify" },
|
|
142
|
+
steps: ["prepare-publish.mjs", "build-and-amend.mjs", "run-verify.mjs", "recover-stalled-publish.mjs"],
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
// An older scaffold recorded a landed push as `terminalStatus: "completed"`
|
|
146
|
+
// with no phase; Baker is still owed that completion.
|
|
147
|
+
it("leaves a completed publish from an older scaffold to the recovery, never to a fresh publish", async () => {
|
|
148
|
+
const cwd = workspace({
|
|
149
|
+
prepare: 'process.stderr.write("A publish is already recorded.\\n"); process.exit(1);',
|
|
150
|
+
recovery: `appendFileSync(${JSON.stringify(LOG)}, existsSync(${JSON.stringify(STATE)}) ? "state kept\\n" : "state lost\\n");`,
|
|
151
|
+
});
|
|
152
|
+
const legacyState = WRITES_STATE({ phase: undefined, terminalStatus: "completed", commitSha: "a".repeat(40) });
|
|
153
|
+
execFileSync("node", ["--input-type=module", "-e", `import { mkdirSync, writeFileSync } from "node:fs"; ${legacyState}`], { cwd });
|
|
154
|
+
const result = await publish(cwd);
|
|
155
|
+
expect({ result, steps: stepsRun(cwd) }).toEqual({
|
|
156
|
+
result: { kind: "finished" },
|
|
157
|
+
steps: ["prepare-publish.mjs", "recover-stalled-publish.mjs", "state kept"],
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
it("leaves a push Baker never heard about to the recovery, never to a second publish", async () => {
|
|
161
|
+
const cwd = workspace({ finalize: `${WRITES_STATE({ phase: "pushed" })} process.exit(1);` });
|
|
162
|
+
const result = await publish(cwd);
|
|
163
|
+
expect({ result, steps: stepsRun(cwd) }).toEqual({
|
|
164
|
+
result: { kind: "finished" },
|
|
165
|
+
steps: [
|
|
166
|
+
"prepare-publish.mjs",
|
|
167
|
+
"build-and-amend.mjs",
|
|
168
|
+
"run-verify.mjs",
|
|
169
|
+
"finalize-publish.mjs",
|
|
170
|
+
"recover-stalled-publish.mjs",
|
|
171
|
+
],
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
it("leaves a publish whose turn was stopped to the recovery, never to the agent", async () => {
|
|
175
|
+
const cwd = workspace();
|
|
176
|
+
const stop = new AbortController();
|
|
177
|
+
stop.abort();
|
|
178
|
+
const result = await publish(cwd, stop.signal);
|
|
179
|
+
expect({ result, steps: stepsRun(cwd) }).toEqual({
|
|
180
|
+
result: { kind: "finished" },
|
|
181
|
+
steps: ["recover-stalled-publish.mjs"],
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
// A step's real work runs in its own children (pnpm verify, shadowdog, git
|
|
185
|
+
// push): stopping only the step would leave them writing past the recovery.
|
|
186
|
+
it("stops everything a step started before the recovery runs", async () => {
|
|
187
|
+
const cwd = workspace({
|
|
188
|
+
verify: [
|
|
189
|
+
'import { spawnSync } from "node:child_process";',
|
|
190
|
+
'spawnSync(process.execPath, ["-e", "require(\'fs\').writeFileSync(\'verify.pid\', String(process.pid)); setTimeout(() => {}, 60000);"], { stdio: "inherit" });',
|
|
191
|
+
].join("\n"),
|
|
192
|
+
});
|
|
193
|
+
const stop = new AbortController();
|
|
194
|
+
const running = publish(cwd, stop.signal);
|
|
195
|
+
while (!existsSync(join(cwd, "verify.pid")))
|
|
196
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
197
|
+
const verifyPid = Number(readFileSync(join(cwd, "verify.pid"), "utf8"));
|
|
198
|
+
stop.abort();
|
|
199
|
+
const result = await running;
|
|
200
|
+
expect({ result, verifyRunning: isRunning(verifyPid) }).toEqual({
|
|
201
|
+
result: { kind: "finished" },
|
|
202
|
+
verifyRunning: false,
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
it("hands the publish to the agent in a workspace without the publish scripts", async () => {
|
|
206
|
+
const cwd = workspace();
|
|
207
|
+
rmSync(join(cwd, SCRIPTS, "run-verify.mjs"));
|
|
208
|
+
const result = await publish(cwd);
|
|
209
|
+
expect({ result, steps: stepsRun(cwd) }).toEqual({ result: { kind: "handOff", step: "prepare" }, steps: [] });
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
//# sourceMappingURL=scripted-publish.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripted-publish.test.js","sourceRoot":"","sources":["../../src/hono/sc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k";
|
|
2
|
+
import { type ChatLanguage } from "./chat-language.ts";
|
|
2
3
|
import type { DispatchHistorySnapshot, DispatchSender } from "./types.ts";
|
|
3
4
|
/**
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The marketer's language, restated once a turn, the first time a skill loads. A skill's English
|
|
6
|
+
* body arrives in the user's seat, and the line after it went out in English to a Spanish chat
|
|
7
|
+
* (BAKER-3462). A skill loads two ways: the model calls `Skill` (PostToolUse), or the marketer
|
|
8
|
+
* types `/name …` and the CLI expands it with no tool call (UserPromptExpansion). The CLI sends
|
|
9
|
+
* either hook's context after the skill body, so this is the last thing the model reads before it
|
|
10
|
+
* writes again.
|
|
8
11
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
export declare class RelayedLines {
|
|
14
|
-
private lines;
|
|
15
|
-
private readonly calls;
|
|
16
|
-
private readonly agentCalls;
|
|
17
|
-
private reported;
|
|
18
|
-
private readonly waiting;
|
|
19
|
-
private streaming;
|
|
20
|
-
open(): void;
|
|
21
|
-
close(): void;
|
|
22
|
-
observe(msg: SDKMessage): void;
|
|
23
|
-
private called;
|
|
24
|
-
takeThrough(toolUseId: string): Promise<{
|
|
25
|
-
lines: string[];
|
|
26
|
-
reported: boolean;
|
|
27
|
-
}>;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* The marketer's language, restated the moment a skill loads. A skill's English
|
|
31
|
-
* body arrives in the user's seat, and the line after it went out in English to
|
|
32
|
-
* a Spanish chat (BAKER-3462). A skill loads two ways: the model calls `Skill`
|
|
33
|
-
* (PostToolUse), or the marketer types `/name …` and the CLI expands it with no
|
|
34
|
-
* tool call (UserPromptExpansion). The CLI sends either hook's context after the
|
|
35
|
-
* skill body, so this is the last thing the model reads before it writes again.
|
|
36
|
-
* Nothing is added to a chat the marketer writes in English, and a language is
|
|
37
|
-
* named only when it is read for sure: otherwise the note says theirs. A
|
|
38
|
-
* publish run never sees the conversation, and read a quoted message as
|
|
39
|
-
* feedback still owed (BAKER-3389), so there the note names the language only.
|
|
12
|
+
* Everything else is the scaffold's own rule ("Write in their language, in every line"): a note
|
|
13
|
+
* after every subagent report and a drift check on every line repeated it many times a turn, and
|
|
14
|
+
* the drift check, wrong, told a Spanish chat's agent it had slipped out of Catalan seven times
|
|
15
|
+
* (BAKER-4943).
|
|
40
16
|
*
|
|
41
|
-
* The
|
|
42
|
-
*
|
|
43
|
-
*
|
|
17
|
+
* The language is `answerLanguage`'s, named only when Jev is sure; otherwise the note names none
|
|
18
|
+
* and the scaffold's rule decides. Nobody's words are quoted, so nothing reads as feedback still owed
|
|
19
|
+
* (BAKER-3389). A chat answered in English gets no note. A nudge, never a block; it fails silent.
|
|
44
20
|
*/
|
|
45
21
|
export declare function skillLanguageHooks(job: {
|
|
46
22
|
history?: DispatchHistorySnapshot;
|
|
47
23
|
prompt: string;
|
|
48
24
|
currentSender?: DispatchSender;
|
|
49
|
-
},
|
|
25
|
+
}, language: ChatLanguage): Partial<Record<HookEvent, HookCallbackMatcher[]>>;
|
|
50
26
|
//# sourceMappingURL=skill-language.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skill-language.d.ts","sourceRoot":"","sources":["../../src/hono/skill-language.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"skill-language.d.ts","sourceRoot":"","sources":["../../src/hono/skill-language.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAErF,OAAO,EAAkB,KAAK,YAAY,EAAwB,MAAM,oBAAoB,CAAC;AAG7F,OAAO,KAAK,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK1E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE;IACH,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,cAAc,CAAC;CAChC,EACD,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,mBAAmB,EAAE,CAAC,CAAC,CA4CnD"}
|
|
@@ -1,184 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { lastTypedMessages } from "./publish-handoff.js";
|
|
1
|
+
import { marketerWords, runReportLanguage } from "../review/reply-language.js";
|
|
2
|
+
import { answerLanguage, languageConversation } from "./chat-language.js";
|
|
4
3
|
import { applyCurrentSenderAttribution } from "./session-continuity.js";
|
|
5
|
-
import {
|
|
6
|
-
const
|
|
4
|
+
import { bridgeSlashCommandNames } from "./slash-commands.js";
|
|
5
|
+
const SKILL = "The skill you just loaded is written in English for you. The user never reads it, and it does not change the language you write to them in.";
|
|
7
6
|
/**
|
|
8
|
-
* The
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* The marketer's language, restated once a turn, the first time a skill loads. A skill's English
|
|
8
|
+
* body arrives in the user's seat, and the line after it went out in English to a Spanish chat
|
|
9
|
+
* (BAKER-3462). A skill loads two ways: the model calls `Skill` (PostToolUse), or the marketer
|
|
10
|
+
* types `/name …` and the CLI expands it with no tool call (UserPromptExpansion). The CLI sends
|
|
11
|
+
* either hook's context after the skill body, so this is the last thing the model reads before it
|
|
12
|
+
* writes again.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
export class RelayedLines {
|
|
18
|
-
lines = [];
|
|
19
|
-
calls = new Set();
|
|
20
|
-
agentCalls = new Set();
|
|
21
|
-
reported = false;
|
|
22
|
-
waiting = new Map();
|
|
23
|
-
streaming = false;
|
|
24
|
-
open() {
|
|
25
|
-
this.streaming = true;
|
|
26
|
-
}
|
|
27
|
-
close() {
|
|
28
|
-
this.streaming = false;
|
|
29
|
-
for (const release of this.waiting.values())
|
|
30
|
-
release();
|
|
31
|
-
this.waiting.clear();
|
|
32
|
-
}
|
|
33
|
-
observe(msg) {
|
|
34
|
-
// A background subagent's report reaches the model as a task notification, not as its tool result.
|
|
35
|
-
if (msg.type === "system" && msg.subtype === "task_notification") {
|
|
36
|
-
if (msg.tool_use_id !== undefined && this.agentCalls.has(msg.tool_use_id))
|
|
37
|
-
this.reported = true;
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (msg.type !== "assistant" || msg.parent_tool_use_id)
|
|
41
|
-
return;
|
|
42
|
-
const content = msg.message?.content;
|
|
43
|
-
if (!Array.isArray(content))
|
|
44
|
-
return;
|
|
45
|
-
for (const block of content) {
|
|
46
|
-
const line = relayedLine(block, msg.message?.model);
|
|
47
|
-
if (line)
|
|
48
|
-
this.lines.push(line);
|
|
49
|
-
if (block?.type === "tool_use" && typeof block.id === "string")
|
|
50
|
-
this.called(block.id, block.name);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
called(toolUseId, toolName) {
|
|
54
|
-
this.calls.add(toolUseId);
|
|
55
|
-
if (typeof toolName === "string" && AGENT_TOOLS.has(toolName))
|
|
56
|
-
this.agentCalls.add(toolUseId);
|
|
57
|
-
this.waiting.get(toolUseId)?.();
|
|
58
|
-
this.waiting.delete(toolUseId);
|
|
59
|
-
}
|
|
60
|
-
async takeThrough(toolUseId) {
|
|
61
|
-
if (this.streaming && !this.calls.has(toolUseId)) {
|
|
62
|
-
await new Promise((resolve) => {
|
|
63
|
-
const timer = setTimeout(release, 2000);
|
|
64
|
-
function release() {
|
|
65
|
-
clearTimeout(timer);
|
|
66
|
-
resolve();
|
|
67
|
-
}
|
|
68
|
-
this.waiting.set(toolUseId, release);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const taken = { lines: this.lines, reported: this.reported };
|
|
72
|
-
this.lines = [];
|
|
73
|
-
this.reported = false;
|
|
74
|
-
return taken;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function startsInBackground(toolInput) {
|
|
78
|
-
return typeof toolInput === "object" && toolInput !== null && "run_in_background" in toolInput
|
|
79
|
-
? toolInput.run_in_background === true
|
|
80
|
-
: false;
|
|
81
|
-
}
|
|
82
|
-
/** What the marketer reads from one block of the agent's message: its text, or a progress note. */
|
|
83
|
-
function relayedLine(block, model) {
|
|
84
|
-
if (block?.type === "text")
|
|
85
|
-
return typeof block.text === "string" ? block.text : null;
|
|
86
|
-
return block?.type === "thinking" ? progressNoteText(block, model) : null;
|
|
87
|
-
}
|
|
88
|
-
/** Whether a line the marketer read is, for sure, in another language than theirs. Never throws. */
|
|
89
|
-
function drifted(lines, language) {
|
|
90
|
-
try {
|
|
91
|
-
return lines.some((line) => {
|
|
92
|
-
const written = identifiedLanguage(line);
|
|
93
|
-
return written !== undefined && written !== language;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* The marketer's language, restated the moment a skill loads. A skill's English
|
|
102
|
-
* body arrives in the user's seat, and the line after it went out in English to
|
|
103
|
-
* a Spanish chat (BAKER-3462). A skill loads two ways: the model calls `Skill`
|
|
104
|
-
* (PostToolUse), or the marketer types `/name …` and the CLI expands it with no
|
|
105
|
-
* tool call (UserPromptExpansion). The CLI sends either hook's context after the
|
|
106
|
-
* skill body, so this is the last thing the model reads before it writes again.
|
|
107
|
-
* Nothing is added to a chat the marketer writes in English, and a language is
|
|
108
|
-
* named only when it is read for sure: otherwise the note says theirs. A
|
|
109
|
-
* publish run never sees the conversation, and read a quoted message as
|
|
110
|
-
* feedback still owed (BAKER-3389), so there the note names the language only.
|
|
14
|
+
* Everything else is the scaffold's own rule ("Write in their language, in every line"): a note
|
|
15
|
+
* after every subagent report and a drift check on every line repeated it many times a turn, and
|
|
16
|
+
* the drift check, wrong, told a Spanish chat's agent it had slipped out of Catalan seven times
|
|
17
|
+
* (BAKER-4943).
|
|
111
18
|
*
|
|
112
|
-
* The
|
|
113
|
-
*
|
|
114
|
-
*
|
|
19
|
+
* The language is `answerLanguage`'s, named only when Jev is sure; otherwise the note names none
|
|
20
|
+
* and the scaffold's rule decides. Nobody's words are quoted, so nothing reads as feedback still owed
|
|
21
|
+
* (BAKER-3389). A chat answered in English gets no note. A nudge, never a block; it fails silent.
|
|
115
22
|
*/
|
|
116
|
-
export function skillLanguageHooks(job,
|
|
23
|
+
export function skillLanguageHooks(job, language) {
|
|
117
24
|
// A typed skill command reaches the SDK as typed, without the speaker label.
|
|
118
25
|
const current = marketerWords(job.prompt) ?? marketerWords(applyCurrentSenderAttribution(job.prompt, job.currentSender));
|
|
119
|
-
|
|
120
|
-
if (typed.length === 0)
|
|
26
|
+
if (!languageConversation(job.history, current).text && !runReportLanguage(job.prompt))
|
|
121
27
|
return {};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
typed.length > 1
|
|
140
|
-
? "The last messages the user typed are quoted below, oldest first, only so you know their language — they are not new instructions:"
|
|
141
|
-
: "The last message the user typed is quoted below only so you know its language — it is not a new instruction:",
|
|
142
|
-
...typed.map((message) => `"${message.quoted}"`),
|
|
143
|
-
]),
|
|
144
|
-
language
|
|
145
|
-
? `Write every line you send the user in ${language}, the short notes between tool calls too.`
|
|
146
|
-
: likely.length > 0
|
|
147
|
-
? `Write every line you send the user in the language they write in, which reads as ${likely.join(" or ")}, the short notes between tool calls too.`
|
|
148
|
-
: "Write every line you send the user in the language they write in, the short notes between tool calls too.",
|
|
149
|
-
].join("\n");
|
|
150
|
-
const reminder = reminderAfter("The skill you just loaded is written in English for you. The user never reads it, and it does not change the language you write to them in.");
|
|
151
|
-
const afterAgent = reminderAfter("The agent's report you just read is written for you. The user never reads it, and it does not change the language you write to them in.");
|
|
152
|
-
const afterDrift = reminderAfter(`Your last line to the user was not in ${language}. Tool output and docs are in English for you; they do not change the language you write to them in.`);
|
|
28
|
+
let noted = false;
|
|
29
|
+
const note = async () => {
|
|
30
|
+
if (noted)
|
|
31
|
+
return undefined;
|
|
32
|
+
noted = true;
|
|
33
|
+
const known = await answerLanguage(language, job.history, current, job.prompt);
|
|
34
|
+
if (known === "English")
|
|
35
|
+
return undefined;
|
|
36
|
+
// No `<system-reminder>` of its own: the CLI wraps a hook's context in one and escapes a `<` inside it.
|
|
37
|
+
// Unsure, it points at no language: "the language they write in" pushed English on a chat asked for Spanish (BAKER-3729).
|
|
38
|
+
return [
|
|
39
|
+
// A fixed first line: session review's hook ledger names the note by it.
|
|
40
|
+
"Baker: the language of this chat.",
|
|
41
|
+
SKILL,
|
|
42
|
+
...(known ? [`Write every line you send the user in ${known}, the short notes between tool calls too.`] : []),
|
|
43
|
+
].join("\n");
|
|
44
|
+
};
|
|
153
45
|
// `/publish` carries its own note (`publishLanguageReminder`), and `/compact` loads no skill.
|
|
154
46
|
const bridgeCommands = bridgeSlashCommandNames();
|
|
47
|
+
const posted = (event, context) => context ? { hookSpecificOutput: { hookEventName: event, additionalContext: context } } : {};
|
|
155
48
|
return {
|
|
156
49
|
PostToolUse: [
|
|
157
50
|
{
|
|
158
51
|
matcher: "Skill",
|
|
159
|
-
hooks: [
|
|
160
|
-
async (input) => input.hook_event_name === "PostToolUse"
|
|
161
|
-
? { hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: reminder } }
|
|
162
|
-
: {},
|
|
163
|
-
],
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
hooks: [
|
|
167
|
-
async (input) => {
|
|
168
|
-
// A subagent's own tool calls: its lines never reach the marketer.
|
|
169
|
-
if (input.hook_event_name !== "PostToolUse" || input.agent_id !== undefined)
|
|
170
|
-
return {};
|
|
171
|
-
const { lines, reported: backgroundReport } = await relayed.takeThrough(input.tool_use_id);
|
|
172
|
-
// A background subagent's launch returns at once, with no report yet.
|
|
173
|
-
const foregroundReport = AGENT_TOOLS.has(input.tool_name) && !startsInBackground(input.tool_input);
|
|
174
|
-
const note = foregroundReport || backgroundReport
|
|
175
|
-
? afterAgent
|
|
176
|
-
: input.tool_name !== "Skill" && language !== undefined && drifted(lines, language)
|
|
177
|
-
? afterDrift
|
|
178
|
-
: undefined;
|
|
179
|
-
return note ? { hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: note } } : {};
|
|
180
|
-
},
|
|
181
|
-
],
|
|
52
|
+
hooks: [async (input) => (input.hook_event_name === "PostToolUse" ? posted("PostToolUse", await note()) : {})],
|
|
182
53
|
},
|
|
183
54
|
],
|
|
184
55
|
UserPromptExpansion: [
|
|
@@ -187,7 +58,7 @@ export function skillLanguageHooks(job, relayed) {
|
|
|
187
58
|
async (input) => input.hook_event_name === "UserPromptExpansion" &&
|
|
188
59
|
input.expansion_type === "slash_command" &&
|
|
189
60
|
!bridgeCommands.includes(input.command_name)
|
|
190
|
-
?
|
|
61
|
+
? posted("UserPromptExpansion", await note())
|
|
191
62
|
: {},
|
|
192
63
|
],
|
|
193
64
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skill-language.js","sourceRoot":"","sources":["../../src/hono/skill-language.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"skill-language.js","sourceRoot":"","sources":["../../src/hono/skill-language.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAqB,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,uBAAuB,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