@phren/cli 0.3.11 → 0.3.13
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/dist/bridge/account-usage.d.ts +124 -0
- package/dist/bridge/account-usage.js +258 -0
- package/dist/bridge/agent-hook-stores.d.ts +3 -0
- package/dist/bridge/agent-hook-stores.js +5 -0
- package/dist/bridge/agent-hooks.d.ts +162 -5
- package/dist/bridge/agent-hooks.js +682 -49
- package/dist/bridge/approval-summary.d.ts +16 -0
- package/dist/bridge/approval-summary.js +133 -0
- package/dist/bridge/authority-command.d.ts +20 -0
- package/dist/bridge/authority-command.js +120 -0
- package/dist/bridge/authority.d.ts +223 -0
- package/dist/bridge/authority.js +231 -0
- package/dist/bridge/claude-account-setup.d.ts +14 -0
- package/dist/bridge/claude-account-setup.js +69 -0
- package/dist/bridge/claude-accounts.d.ts +49 -0
- package/dist/bridge/claude-accounts.js +195 -0
- package/dist/bridge/code-routes.js +2 -2
- package/dist/bridge/codex-app-server.d.ts +144 -0
- package/dist/bridge/codex-app-server.js +319 -0
- package/dist/bridge/codex-auth-refresh.d.ts +33 -0
- package/dist/bridge/codex-auth-refresh.js +71 -0
- package/dist/bridge/codex-hook-trust.d.ts +27 -0
- package/dist/bridge/codex-hook-trust.js +237 -0
- package/dist/bridge/codex-question-reply.d.ts +16 -0
- package/dist/bridge/codex-question-reply.js +57 -0
- package/dist/bridge/codex-review-mode.d.ts +10 -0
- package/dist/bridge/codex-review-mode.js +74 -0
- package/dist/bridge/codex-servers.d.ts +217 -0
- package/dist/bridge/codex-servers.js +636 -0
- package/dist/bridge/command.js +97 -4
- package/dist/bridge/computer-identity.d.ts +75 -0
- package/dist/bridge/computer-identity.js +166 -0
- package/dist/bridge/conductor-group.d.ts +91 -8
- package/dist/bridge/conductor-group.js +105 -9
- package/dist/bridge/conductor-role.d.ts +94 -0
- package/dist/bridge/conductor-role.js +176 -0
- package/dist/bridge/conductor-sets.d.ts +20 -0
- package/dist/bridge/conductor-sets.js +59 -0
- package/dist/bridge/dispatch-command.d.ts +3 -0
- package/dist/bridge/dispatch-command.js +82 -12
- package/dist/bridge/dispatch-returns.d.ts +128 -19
- package/dist/bridge/dispatch-returns.js +371 -54
- package/dist/bridge/dispatch.d.ts +128 -3
- package/dist/bridge/dispatch.js +303 -42
- package/dist/bridge/fanouts.d.ts +7 -1
- package/dist/bridge/fanouts.js +39 -4
- package/dist/bridge/folder-trust.d.ts +56 -0
- package/dist/bridge/folder-trust.js +195 -0
- package/dist/bridge/grants.d.ts +22 -1
- package/dist/bridge/grants.js +57 -9
- package/dist/bridge/hand-off-queue.d.ts +74 -0
- package/dist/bridge/hand-off-queue.js +235 -0
- package/dist/bridge/hand-off.d.ts +30 -10
- package/dist/bridge/hand-off.js +79 -46
- package/dist/bridge/harness-status.d.ts +11 -0
- package/dist/bridge/harness-status.js +32 -0
- package/dist/bridge/harnesses.d.ts +39 -0
- package/dist/bridge/harnesses.js +65 -0
- package/dist/bridge/health.d.ts +2 -0
- package/dist/bridge/health.js +1 -1
- package/dist/bridge/herdr.d.ts +11 -2
- package/dist/bridge/herdr.js +98 -23
- package/dist/bridge/hook-fast.d.ts +4 -0
- package/dist/bridge/hook-fast.js +68 -0
- package/dist/bridge/install.d.ts +16 -1
- package/dist/bridge/install.js +102 -21
- package/dist/bridge/launch-brief.d.ts +96 -0
- package/dist/bridge/launch-brief.js +164 -0
- package/dist/bridge/model-switch.d.ts +3 -0
- package/dist/bridge/model-switch.js +17 -1
- package/dist/bridge/models.d.ts +8 -4
- package/dist/bridge/models.js +24 -8
- package/dist/bridge/mux-wire.d.ts +9 -0
- package/dist/bridge/mux-wire.js +19 -0
- package/dist/bridge/opencode-pane-server.d.ts +113 -0
- package/dist/bridge/opencode-pane-server.js +332 -0
- package/dist/bridge/opencode-panes.d.ts +111 -0
- package/dist/bridge/opencode-panes.js +295 -0
- package/dist/bridge/pane-accounts.d.ts +8 -0
- package/dist/bridge/pane-accounts.js +46 -0
- package/dist/bridge/pane-status.d.ts +12 -0
- package/dist/bridge/pane-status.js +50 -1
- package/dist/bridge/prompt-startup.d.ts +5 -0
- package/dist/bridge/prompt-startup.js +24 -0
- package/dist/bridge/protocol.d.ts +5 -0
- package/dist/bridge/protocol.js +4 -0
- package/dist/bridge/push.d.ts +11 -4
- package/dist/bridge/push.js +27 -4
- package/dist/bridge/questions.d.ts +37 -2
- package/dist/bridge/questions.js +158 -15
- package/dist/bridge/resources.d.ts +9 -3
- package/dist/bridge/resources.js +24 -8
- package/dist/bridge/schedule-format.d.ts +2 -0
- package/dist/bridge/schedule-format.js +3 -0
- package/dist/bridge/schedule-launch.d.ts +2 -1
- package/dist/bridge/schedule-launch.js +27 -53
- package/dist/bridge/schedule-watch.d.ts +24 -1
- package/dist/bridge/schedule-watch.js +89 -2
- package/dist/bridge/server-launch.d.ts +22 -5
- package/dist/bridge/server-launch.js +238 -32
- package/dist/bridge/server-overview.d.ts +10 -3
- package/dist/bridge/server-overview.js +32 -15
- package/dist/bridge/server-pane-routes.d.ts +3 -0
- package/dist/bridge/server-pane-routes.js +150 -18
- package/dist/bridge/server-routes.d.ts +11 -0
- package/dist/bridge/server-routes.js +214 -36
- package/dist/bridge/server-stream.d.ts +2 -0
- package/dist/bridge/server-stream.js +22 -8
- package/dist/bridge/server.d.ts +6 -1
- package/dist/bridge/server.js +58 -13
- package/dist/bridge/session-activity.d.ts +93 -0
- package/dist/bridge/session-activity.js +139 -0
- package/dist/bridge/session-rename.d.ts +48 -0
- package/dist/bridge/session-rename.js +190 -0
- package/dist/bridge/session-servers.js +2 -2
- package/dist/bridge/settings-switch.d.ts +60 -0
- package/dist/bridge/settings-switch.js +287 -0
- package/dist/bridge/speech-voice.d.ts +55 -0
- package/dist/bridge/speech-voice.js +132 -0
- package/dist/bridge/speech.d.ts +70 -11
- package/dist/bridge/speech.js +169 -41
- package/dist/bridge/stalls.d.ts +22 -0
- package/dist/bridge/stalls.js +57 -0
- package/dist/bridge/sudo.d.ts +209 -0
- package/dist/bridge/sudo.js +501 -0
- package/dist/bridge/terminal-herdr.js +9 -3
- package/dist/bridge/terminal-tmux.d.ts +15 -3
- package/dist/bridge/terminal-tmux.js +103 -13
- package/dist/bridge/terminal.d.ts +27 -4
- package/dist/bridge/terminal.js +8 -1
- package/dist/bridge/transcript-claude.d.ts +4 -0
- package/dist/bridge/transcript-claude.js +186 -16
- package/dist/bridge/transcript-codex.d.ts +0 -2
- package/dist/bridge/transcript-codex.js +29 -4
- package/dist/bridge/transcript-preview.d.ts +1 -0
- package/dist/bridge/transcript-preview.js +24 -4
- package/dist/bridge/transcripts.d.ts +15 -2
- package/dist/bridge/transcripts.js +47 -16
- package/dist/bridge/turn-records.d.ts +85 -0
- package/dist/bridge/turn-records.js +143 -0
- package/dist/bridge/uploads.d.ts +3 -0
- package/dist/bridge/uploads.js +14 -0
- package/dist/bridge/usage.d.ts +56 -10
- package/dist/bridge/usage.js +190 -45
- package/dist/bridge-hook.mjs +27975 -20636
- package/dist/cli/claude-unmanaged.d.ts +12 -0
- package/dist/cli/claude-unmanaged.js +105 -0
- package/dist/cli/schedules.js +2 -1
- package/dist/cli/session-start.js +10 -1
- package/dist/cli/session-stop.js +9 -1
- package/dist/cli-registry.js +31 -6
- package/dist/data/task-receipts.d.ts +19 -0
- package/dist/data/task-receipts.js +68 -0
- package/dist/data/tasks.js +4 -1
- package/dist/generated/memory-ui-graph.browser.js +63 -63
- package/dist/graph-core/model.js +24 -3
- package/dist/graph-core/types.d.ts +4 -1
- package/dist/graph-core/types.js +1 -0
- package/dist/init/init-preset.js +7 -3
- package/dist/init/init-uninstall.js +2 -11
- package/dist/init/teardown.d.ts +3 -0
- package/dist/init/teardown.js +47 -0
- package/dist/link/context.js +21 -9
- package/dist/mcp/plugin-mode.js +1 -1
- package/dist/memory-ui-graph.runtime.js +63 -63
- package/dist/modules/code-package.d.ts +1 -0
- package/dist/modules/code-package.js +36 -7
- package/dist/modules/registry.js +17 -16
- package/dist/profile-store.d.ts +6 -0
- package/dist/profile-store.js +25 -1
- package/dist/shell/graph/glyphs.js +4 -0
- package/dist/shell/graph/graph-view.js +2 -0
- package/dist/status.js +7 -1
- package/dist/sync/task-claim.js +3 -2
- package/dist/task/lifecycle.js +25 -4
- package/dist/test-global-setup.js +5 -0
- package/dist/tools/dispatch.js +52 -4
- package/dist/tools/tasks.js +10 -1
- package/package.json +1 -1
- package/plugins/opencode/phren-transcript.js +87 -4
- package/starter/global/AGENTS.md +4 -0
- package/starter/global/skills/conductor/SKILL.md +51 -4
package/dist/bridge/questions.js
CHANGED
|
@@ -9,6 +9,8 @@ import { paneIdentity, validateTarget } from "./herdr.js";
|
|
|
9
9
|
import { transcriptPath } from "./transcripts.js";
|
|
10
10
|
import { codexExecutable } from "./codex-binary.js";
|
|
11
11
|
import { withTranscriptIndex } from "./transcript-index.js";
|
|
12
|
+
import { formatQuestionReply, parseQuestionReply } from "./codex-question-reply.js";
|
|
13
|
+
import { IMAGE_NAME, sessionUpload } from "./uploads.js";
|
|
12
14
|
const exec = promisify(execFile);
|
|
13
15
|
const text = z.string().trim().min(1).max(4000).refine(t => !/[\x00-\x08\x0b-\x1f\x7f]/.test(t));
|
|
14
16
|
const question = z.object({ title: text, options: z.array(text).max(12).nullable().optional() });
|
|
@@ -48,7 +50,8 @@ export function deliveredQuestion(raw) {
|
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
/** The phone's answer to each question: one option it chose or its typed text. */
|
|
54
|
+
function answerValues(questions, answers) {
|
|
52
55
|
const parsed = z.array(z.object({ optionIndexes: z.array(z.number().int().nonnegative()).max(1), text: z.string().max(4000).optional() })).parse(answers);
|
|
53
56
|
if (parsed.length !== questions.length)
|
|
54
57
|
throw new BridgeError(400, "Answer every question.");
|
|
@@ -59,8 +62,17 @@ export function questionReply(questions, answers) {
|
|
|
59
62
|
const value = typed || options[answer.optionIndexes[0]];
|
|
60
63
|
if (!value || !text.safeParse(value).success)
|
|
61
64
|
throw new BridgeError(400, "Choose an available answer.");
|
|
62
|
-
return
|
|
63
|
-
})
|
|
65
|
+
return value;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export function questionReply(questions, answers) {
|
|
69
|
+
const values = answerValues(questions, answers);
|
|
70
|
+
return questions.map((q, index) => q.title.split("\n").map(line => `> ${line}`).join("\n") + "\n\n" + values[index]).join("\n\n");
|
|
71
|
+
}
|
|
72
|
+
/** The same answers as Codex's own TUI sends them into the running turn. */
|
|
73
|
+
export function asyncQuestionReply(id, questions, answers) {
|
|
74
|
+
const values = answerValues(questions, answers);
|
|
75
|
+
return formatQuestionReply(id, questions.map((q, index) => ({ question: q.title, answer: values[index] })));
|
|
64
76
|
}
|
|
65
77
|
const answersQuestions = (reply, questions) => questions.every(q => {
|
|
66
78
|
const quote = q.title.split("\n").map(line => `> ${line}`).join("\n") + "\n\n";
|
|
@@ -69,7 +81,7 @@ const answersQuestions = (reply, questions) => questions.every(q => {
|
|
|
69
81
|
});
|
|
70
82
|
export async function pendingAsyncQuestions(file, targetID) {
|
|
71
83
|
return withTranscriptIndex(file, async (handle, index) => {
|
|
72
|
-
const replies = [], acknowledged = new Set(), resolved = new Set(), seen = new Set(), pending = [];
|
|
84
|
+
const replies = [], replied = new Set(), acknowledged = new Set(), resolved = new Set(), seen = new Set(), pending = [];
|
|
73
85
|
let bytes = 0;
|
|
74
86
|
for await (const row of index.rows(handle, index.lines, Math.max(0, index.lines - 10_000))) {
|
|
75
87
|
// An incomplete scan is not evidence that no questions remain. Status
|
|
@@ -89,8 +101,14 @@ export async function pendingAsyncQuestions(file, targetID) {
|
|
|
89
101
|
if (raw.type !== "response_item" && !delivered)
|
|
90
102
|
continue;
|
|
91
103
|
const p = object(raw.payload), id = delivered ? delivered.id : typeof p.call_id === "string" ? p.call_id : "";
|
|
92
|
-
if (p.type === "message" && p.role === "user")
|
|
93
|
-
|
|
104
|
+
if (p.type === "message" && p.role === "user") {
|
|
105
|
+
const reply = objects(p.content).map(b => typeof b.text === "string" ? b.text : "").join("\n");
|
|
106
|
+
replies.push(reply);
|
|
107
|
+
// Codex's own answer (its TUI, or the Hook for a pane on its app-server) names the question.
|
|
108
|
+
for (const entry of parseQuestionReply(reply) ?? [])
|
|
109
|
+
if (entry.id)
|
|
110
|
+
replied.add(entry.id);
|
|
111
|
+
}
|
|
94
112
|
if (id && ["function_call_output", "custom_tool_call_output"].includes(String(p.type)) && !resolved.has(id) && !acknowledged.has(id)) {
|
|
95
113
|
try {
|
|
96
114
|
if (object(JSON.parse(String(p.output))).accepted === true)
|
|
@@ -109,7 +127,7 @@ export async function pendingAsyncQuestions(file, targetID) {
|
|
|
109
127
|
const questions = asyncQuestion(raw, id);
|
|
110
128
|
// Codex 0.155 records one question twice under the same id: the
|
|
111
129
|
// request_user_input_async call and the AgentMessage delivered async.
|
|
112
|
-
if (questions && !seen.has(id) && !replies.some(reply => answersQuestions(reply, questions))) {
|
|
130
|
+
if (questions && !seen.has(id) && !replied.has(id) && !replies.some(reply => answersQuestions(reply, questions))) {
|
|
113
131
|
pending.push({ id, questions });
|
|
114
132
|
if (pending.length >= 64)
|
|
115
133
|
throw new BridgeError(413, "Too many pending questions to verify.");
|
|
@@ -130,18 +148,100 @@ export async function pendingAsyncQuestion(file, id) {
|
|
|
130
148
|
throw new BridgeError(409, "This question is no longer pending. Refresh the conversation.");
|
|
131
149
|
return pending.questions;
|
|
132
150
|
}
|
|
151
|
+
/** Files the phone attached to an answer, named the way the phone names them
|
|
152
|
+
* under a chat message it sends with attachments. */
|
|
153
|
+
export const attachedFiles = (paths) => paths.length ? `Attached files on this computer:\n${paths.join("\n")}` : "";
|
|
154
|
+
const withAttachments = (answer, paths) => paths.length ? `${answer}\n\n${attachedFiles(paths)}` : answer;
|
|
155
|
+
/** The phone's attachments for an answer: at most eight of this conversation's uploads. */
|
|
156
|
+
export async function answerAttachments(session, data) {
|
|
157
|
+
const requested = z.array(z.string().max(4096)).max(8).optional().parse(data.attachments) ?? [];
|
|
158
|
+
return Promise.all(requested.map(file => sessionUpload(session, file)));
|
|
159
|
+
}
|
|
160
|
+
const requestKey = (requestId) => `request:${JSON.stringify(requestId)}`;
|
|
161
|
+
const choose = (label, options, typed) => {
|
|
162
|
+
if (!typed && !options.includes(label))
|
|
163
|
+
throw new BridgeError(400, "Choose one of the offered answers.");
|
|
164
|
+
return label;
|
|
165
|
+
};
|
|
166
|
+
/** `item/tool/requestUserInput` (the synchronous tool) and a form MCP
|
|
167
|
+
* elicitation whose fields are all single values. Secret inputs, URL
|
|
168
|
+
* elicitations and multi-select fields stay in the pane. */
|
|
169
|
+
export function serverQuestion(request) {
|
|
170
|
+
const params = request.params;
|
|
171
|
+
if (request.method === "item/tool/requestUserInput") {
|
|
172
|
+
const asked = objects(params.questions);
|
|
173
|
+
if (!asked.length || asked.some(q => q.isSecret === true || typeof q.id !== "string" || typeof q.question !== "string"))
|
|
174
|
+
return undefined;
|
|
175
|
+
const parsed = questionSet.safeParse(asked.map(q => ({ title: q.question,
|
|
176
|
+
options: objects(q.options).map(option => option.label).filter((label) => typeof label === "string") })));
|
|
177
|
+
if (!parsed.success)
|
|
178
|
+
return undefined;
|
|
179
|
+
const questions = parsed.data.map(q => ({ ...q, options: q.options?.length ? q.options : undefined }));
|
|
180
|
+
return { questions, attachments: true, result: values => ({ answers: Object.fromEntries(asked.map((q, index) => [String(q.id),
|
|
181
|
+
{ answers: [choose(values[index], questions[index].options ?? [], q.isOther === true || !questions[index].options)] }])) }) };
|
|
182
|
+
}
|
|
183
|
+
if (request.method !== "mcpServer/elicitation/request" || !["form", "openai/form", "openaiForm"].includes(String(params.mode)))
|
|
184
|
+
return undefined;
|
|
185
|
+
const message = typeof params.message === "string" ? params.message.trim() : "";
|
|
186
|
+
const fields = Object.entries(object(object(params.requestedSchema).properties));
|
|
187
|
+
if (!message || !fields.length || fields.length > 8)
|
|
188
|
+
return undefined;
|
|
189
|
+
const shaped = [];
|
|
190
|
+
for (const [key, raw] of fields) {
|
|
191
|
+
const field = object(raw), label = [field.title, field.description].find((value) => typeof value === "string" && !!value.trim())?.trim() ?? key;
|
|
192
|
+
if (field.type === "boolean") {
|
|
193
|
+
shaped.push({ key, title: label, options: ["Yes", "No"], value: answer => choose(answer, ["Yes", "No"], false) === "Yes" });
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (field.type === "number" || field.type === "integer") {
|
|
197
|
+
shaped.push({ key, title: label, value: answer => {
|
|
198
|
+
const number = Number(answer.trim());
|
|
199
|
+
if (!answer.trim() || !Number.isFinite(number) || (field.type === "integer" && !Number.isInteger(number)))
|
|
200
|
+
throw new BridgeError(400, `Answer "${label}" with a number.`);
|
|
201
|
+
return number;
|
|
202
|
+
} });
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (field.type !== "string")
|
|
206
|
+
return undefined;
|
|
207
|
+
const titled = objects(field.oneOf).filter(option => typeof option.const === "string" && typeof option.title === "string");
|
|
208
|
+
const plain = Array.isArray(field.enum) ? field.enum.filter((value) => typeof value === "string") : [];
|
|
209
|
+
const names = Array.isArray(field.enumNames) ? field.enumNames : [];
|
|
210
|
+
const pairs = titled.length ? titled.map(option => [String(option.title), String(option.const)])
|
|
211
|
+
: plain.map((value, index) => [typeof names[index] === "string" ? String(names[index]) : value, value]);
|
|
212
|
+
if (pairs.length) {
|
|
213
|
+
const options = pairs.map(([title]) => title);
|
|
214
|
+
shaped.push({ key, title: label, options, value: answer => pairs[options.indexOf(choose(answer, options, false))][1] });
|
|
215
|
+
}
|
|
216
|
+
else
|
|
217
|
+
shaped.push({ key, title: label, value: answer => answer });
|
|
218
|
+
}
|
|
219
|
+
// The server's message heads the first question; one field reads as the message itself.
|
|
220
|
+
const titles = shaped.map((field, index) => shaped.length === 1 ? (field.title === field.key ? message : `${message}\n\n${field.title}`)
|
|
221
|
+
: index === 0 ? `${message}\n\n${field.title}` : field.title);
|
|
222
|
+
const parsed = questionSet.safeParse(shaped.map((field, index) => ({ title: titles[index], ...(field.options ? { options: field.options } : {}) })));
|
|
223
|
+
if (!parsed.success)
|
|
224
|
+
return undefined;
|
|
225
|
+
return { questions: parsed.data, attachments: false, result: values => ({ action: "accept", content: Object.fromEntries(shaped.map((field, index) => [field.key, field.value(values[index])])) }) };
|
|
226
|
+
}
|
|
133
227
|
export class CodexQuestions {
|
|
134
228
|
configured;
|
|
229
|
+
served;
|
|
135
230
|
snapshots = new Map();
|
|
136
231
|
failedSnapshots = new Map();
|
|
137
232
|
inboxAvailable = false;
|
|
138
233
|
/** Feature discovery must never delay permission/status frames. */
|
|
139
234
|
get available() { void this.supported(); return this.inboxAvailable; }
|
|
140
235
|
probe;
|
|
141
|
-
/** No executable: the real `codex` on PATH, past phren's session wrapper.
|
|
142
|
-
|
|
236
|
+
/** No executable: the real `codex` on PATH, past phren's session wrapper.
|
|
237
|
+
* `served` answers panes on the Hook's own app-server over that server. */
|
|
238
|
+
constructor(configured, served) {
|
|
143
239
|
this.configured = configured;
|
|
240
|
+
this.served = served;
|
|
144
241
|
}
|
|
242
|
+
/** Whether the phone can answer this pane's questions: a pane on the Hook's
|
|
243
|
+
* own app-server always can; any other needs `codex queue`. */
|
|
244
|
+
availableFor(target) { return target.source === "codex" && (!!this.served?.forTarget(target) || this.available); }
|
|
145
245
|
get executable() { return this.configured ?? codexExecutable(); }
|
|
146
246
|
supported() {
|
|
147
247
|
if (!this.probe || Date.now() - this.probe.at > 300_000)
|
|
@@ -153,6 +253,14 @@ export class CodexQuestions {
|
|
|
153
253
|
async pending(target) {
|
|
154
254
|
if (target.source !== "codex")
|
|
155
255
|
return [];
|
|
256
|
+
const entry = this.served?.forTarget(target);
|
|
257
|
+
const parked = entry ? this.served.questions(entry).flatMap(request => {
|
|
258
|
+
const shown = serverQuestion(request);
|
|
259
|
+
return shown ? [{ toolUseId: requestKey(request.requestId), isAsync: true, submitted: false, questions: asPrompt(shown.questions) }] : [];
|
|
260
|
+
}) : [];
|
|
261
|
+
return [...parked, ...await this.transcriptPending(target)];
|
|
262
|
+
}
|
|
263
|
+
async transcriptPending(target) {
|
|
156
264
|
if (Date.now() - (this.failedSnapshots.get(target.session) ?? 0) < 5000)
|
|
157
265
|
throw new BridgeError(503, "Pending question history is unavailable.");
|
|
158
266
|
const file = await transcriptPath("codex", target.session);
|
|
@@ -174,17 +282,44 @@ export class CodexQuestions {
|
|
|
174
282
|
return Promise.all((pending ?? []).map(async (p) => {
|
|
175
283
|
const key = createHash("sha256").update(JSON.stringify([target.source, target.session, p.id])).digest("hex");
|
|
176
284
|
const submitted = await readFile(path.join(bridgeRoot(), "question-replies", key), "utf8").then(value => value === "submitted").catch(() => false);
|
|
177
|
-
return { toolUseId: p.id, isAsync: true, submitted, questions: p.questions
|
|
178
|
-
options: (q.options ?? []).map(label => ({ label })), ...(!q.options?.length ? { kind: "text" } : {}) })) };
|
|
285
|
+
return { toolUseId: p.id, isAsync: true, submitted, questions: asPrompt(p.questions) };
|
|
179
286
|
})).then(prompts => prompts.filter(p => !p.submitted));
|
|
180
287
|
}
|
|
181
288
|
async answer(target, data) {
|
|
182
|
-
|
|
289
|
+
const id = z.string().min(1).max(512).parse(data.toolUseId);
|
|
290
|
+
const entry = target.source === "codex" ? this.served?.forTarget(target) : undefined;
|
|
291
|
+
if (entry && id.startsWith("request:")) {
|
|
292
|
+
// A question parked on the Hook's own app-server: the answer is the
|
|
293
|
+
// reply to that request, exactly once, from whichever client is first.
|
|
294
|
+
const request = this.served.questions(entry).find(candidate => requestKey(candidate.requestId) === id);
|
|
295
|
+
const shown = request && serverQuestion(request);
|
|
296
|
+
if (!request || !shown)
|
|
297
|
+
throw new BridgeError(409, "This question is no longer pending. Refresh the conversation.");
|
|
298
|
+
const files = await answerAttachments(target.session, data);
|
|
299
|
+
if (files.length && !shown.attachments)
|
|
300
|
+
throw new BridgeError(400, "This question takes no attachments.");
|
|
301
|
+
const result = shown.result(answerValues(shown.questions, data.answers));
|
|
302
|
+
// Files ride on the last answer, the way a chat message carries them.
|
|
303
|
+
const answers = object(result.answers), last = Object.keys(answers).at(-1);
|
|
304
|
+
if (files.length && last) {
|
|
305
|
+
const values = object(answers[last]).answers;
|
|
306
|
+
answers[last] = { answers: [...values.slice(0, -1), withAttachments(values.at(-1) ?? "", files)] };
|
|
307
|
+
}
|
|
308
|
+
if (!this.served.answerQuestion(entry, request.requestId, result))
|
|
309
|
+
throw new BridgeError(409, "This question is no longer pending. Refresh the conversation.");
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (target.source !== "codex" || (!entry && !await this.supported()))
|
|
183
313
|
throw new BridgeError(409, "This connection needs the question answered in the terminal.");
|
|
184
314
|
z.string().uuid().parse(target.session);
|
|
185
|
-
const id = z.string().min(1).max(512).parse(data.toolUseId);
|
|
186
315
|
const questions = await pendingAsyncQuestion(await transcriptPath("codex", target.session), id);
|
|
187
|
-
const
|
|
316
|
+
const files = await answerAttachments(target.session, data);
|
|
317
|
+
// A pane on the Hook's app-server gets the answer in its running turn, as
|
|
318
|
+
// Codex's TUI sends it; `codex queue` would hold it until the turn ends.
|
|
319
|
+
// Attached pictures go in as images, and every file is named below.
|
|
320
|
+
const reply = entry ? asyncQuestionReply(id, questions, data.answers) : withAttachments(questionReply(questions, data.answers), files);
|
|
321
|
+
const extra = entry && files.length ? [{ type: "text", text: attachedFiles(files), text_elements: [] },
|
|
322
|
+
...files.filter(file => IMAGE_NAME.test(file)).map(file => ({ type: "localImage", path: file }))] : [];
|
|
188
323
|
const pane = await validateTarget(target);
|
|
189
324
|
if (await paneIdentity(target.server, pane, true) !== target.session)
|
|
190
325
|
throw new BridgeError(409, "This pane's conversation changed. Reopen the chat.");
|
|
@@ -202,7 +337,10 @@ export class CodexQuestions {
|
|
|
202
337
|
await receipt.close();
|
|
203
338
|
try {
|
|
204
339
|
// Explicit UUID, no session-name lookup, no shell, no terminal keystrokes.
|
|
205
|
-
|
|
340
|
+
if (entry)
|
|
341
|
+
await this.served.steer(entry, reply, extra);
|
|
342
|
+
else
|
|
343
|
+
await exec(this.executable, ["queue", "--thread", target.session, "--message", reply], { timeout: 8000, maxBuffer: 65_536 });
|
|
206
344
|
await writeFile(receiptPath, "submitted", { mode: 0o600 });
|
|
207
345
|
}
|
|
208
346
|
catch {
|
|
@@ -210,3 +348,8 @@ export class CodexQuestions {
|
|
|
210
348
|
}
|
|
211
349
|
}
|
|
212
350
|
}
|
|
351
|
+
/** Questions in the phone's pending-question shape: labelled options, or a
|
|
352
|
+
* typed answer when there are none. */
|
|
353
|
+
function asPrompt(questions) {
|
|
354
|
+
return questions.map(q => ({ question: q.title, options: (q.options ?? []).map(label => ({ label })), ...(!q.options?.length ? { kind: "text" } : {}) }));
|
|
355
|
+
}
|
|
@@ -23,10 +23,12 @@ export interface HeavyProcess {
|
|
|
23
23
|
kind: HeavyKind;
|
|
24
24
|
name: string;
|
|
25
25
|
pid: number;
|
|
26
|
-
/**
|
|
26
|
+
/** OS processes, including helpers; never a count of agents or working sessions. */
|
|
27
27
|
processes: number;
|
|
28
28
|
cpuPercent: number;
|
|
29
29
|
memoryBytes: number;
|
|
30
|
+
/** Why this process group is listed; resource use does not establish session activity. */
|
|
31
|
+
resourceReason?: "cpu" | "memory" | "tracked";
|
|
30
32
|
pane?: PaneRef;
|
|
31
33
|
}
|
|
32
34
|
export interface ComputerResources {
|
|
@@ -86,8 +88,12 @@ export declare function heavyKind(row: ProcessRow): {
|
|
|
86
88
|
* The heavy jobs in a process table. Every process counts toward its nearest
|
|
87
89
|
* heavy ancestor-or-self, so a Codex worker running xcodebuild shows both,
|
|
88
90
|
* each with only its own share. Any other program shows as `busy` when its
|
|
89
|
-
* processes together hold half a core.
|
|
90
|
-
*
|
|
91
|
+
* processes together hold half a core. Known programs below both a core's
|
|
92
|
+
* tenth and 200 MiB are left out, including simulators and emulators.
|
|
93
|
+
* A memory-only row can be an idle session or helper; it is not evidence of
|
|
94
|
+
* agent activity. Counts include OS helpers, not just the named executable.
|
|
95
|
+
* On Linux, ps pcpu is a process lifetime average, so these cutoffs can miss
|
|
96
|
+
* daemons that spike briefly.
|
|
91
97
|
*/
|
|
92
98
|
export declare function heavyProcesses(rows: ProcessRow[], owners?: Map<number, PaneRef>, limit?: number): HeavyProcess[];
|
|
93
99
|
/** `pmset -g batt`: "Now drawing from 'AC Power'" then " -InternalBattery-0 (id=…) 87%; charging; …". */
|
package/dist/bridge/resources.js
CHANGED
|
@@ -47,7 +47,7 @@ export function heavyKind(row) {
|
|
|
47
47
|
if (base === "launchd_sim") {
|
|
48
48
|
return { kind: "simulator", name: /XCTestDevices|Clone \d+ of /.test(args) ? "Simulator test clone" : "Simulator" };
|
|
49
49
|
}
|
|
50
|
-
if (/^qemu-system/.test(base) || base === "emulator" || /^emulator\d*-/.test(base)
|
|
50
|
+
if (/^qemu-system/.test(base) || base === "emulator" || /^emulator\d*-/.test(base))
|
|
51
51
|
return { kind: "emulator", name: "Android emulator" };
|
|
52
52
|
if (base === "xcodebuild")
|
|
53
53
|
return { kind: "xcodebuild", name: "xcodebuild" };
|
|
@@ -58,11 +58,13 @@ export function heavyKind(row) {
|
|
|
58
58
|
return { kind: "gradle", name: "Kotlin daemon" };
|
|
59
59
|
return { kind: "java", name: "Java" };
|
|
60
60
|
}
|
|
61
|
-
if (base === "codex" || base === "node" && /^\S*node\s+\S*\/codex(?:\.js)?(?:\s|$)/.test(args))
|
|
62
|
-
|
|
61
|
+
if (base === "codex" || base === "node" && /^\S*node\s+\S*\/codex(?:\.js)?(?:\s|$)/.test(args)) {
|
|
62
|
+
const service = /^\S+\s+(app-server|mcp-server)(?:\s|$)/.exec(args)?.[1];
|
|
63
|
+
return { kind: "codex", name: service === "app-server" ? "Codex app server" : service === "mcp-server" ? "Codex MCP server" : "Codex" };
|
|
64
|
+
}
|
|
63
65
|
if (base === "opencode" || base === ".opencode")
|
|
64
66
|
return { kind: "opencode", name: "OpenCode" };
|
|
65
|
-
if (base === "claude" ||
|
|
67
|
+
if (base === "claude" || /(?:^|\/)claude\/versions\/\d+\.\d+\.\d+$/.test(row.command))
|
|
66
68
|
return { kind: "claude", name: "Claude Code" };
|
|
67
69
|
return undefined;
|
|
68
70
|
}
|
|
@@ -70,8 +72,12 @@ export function heavyKind(row) {
|
|
|
70
72
|
* The heavy jobs in a process table. Every process counts toward its nearest
|
|
71
73
|
* heavy ancestor-or-self, so a Codex worker running xcodebuild shows both,
|
|
72
74
|
* each with only its own share. Any other program shows as `busy` when its
|
|
73
|
-
* processes together hold half a core.
|
|
74
|
-
*
|
|
75
|
+
* processes together hold half a core. Known programs below both a core's
|
|
76
|
+
* tenth and 200 MiB are left out, including simulators and emulators.
|
|
77
|
+
* A memory-only row can be an idle session or helper; it is not evidence of
|
|
78
|
+
* agent activity. Counts include OS helpers, not just the named executable.
|
|
79
|
+
* On Linux, ps pcpu is a process lifetime average, so these cutoffs can miss
|
|
80
|
+
* daemons that spike briefly.
|
|
75
81
|
*/
|
|
76
82
|
export function heavyProcesses(rows, owners = new Map(), limit = 12) {
|
|
77
83
|
const byPid = new Map(rows.map(row => [row.pid, row]));
|
|
@@ -81,6 +87,15 @@ export function heavyProcesses(rows, owners = new Map(), limit = 12) {
|
|
|
81
87
|
if (kind)
|
|
82
88
|
kinds.set(row.pid, kind);
|
|
83
89
|
}
|
|
90
|
+
// npm's node launcher and its native Codex child are one process group.
|
|
91
|
+
// Keep independently launched/nested Codex workers as separate groups.
|
|
92
|
+
for (const row of rows) {
|
|
93
|
+
const parent = byPid.get(row.ppid);
|
|
94
|
+
if (kinds.get(row.pid)?.kind === "codex" && parent && path.basename(parent.command) === "node" && kinds.get(parent.pid)?.kind === "codex") {
|
|
95
|
+
kinds.set(parent.pid, kinds.get(row.pid));
|
|
96
|
+
kinds.delete(row.pid);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
84
99
|
const totals = new Map();
|
|
85
100
|
const busy = new Map();
|
|
86
101
|
const claim = (row) => {
|
|
@@ -140,8 +155,9 @@ export function heavyProcesses(rows, owners = new Map(), limit = 12) {
|
|
|
140
155
|
totals.set(group.pid, { ...group, ...(pane ? { pane } : {}) });
|
|
141
156
|
}
|
|
142
157
|
return [...totals.values()]
|
|
143
|
-
.filter(item => item.kind === "
|
|
144
|
-
.map(item => ({ ...item, cpuPercent: Math.round(item.cpuPercent * 10) / 10
|
|
158
|
+
.filter(item => item.kind === "busy" || item.cpuPercent >= 10 || item.memoryBytes >= 200 * 1024 ** 2)
|
|
159
|
+
.map(item => ({ ...item, cpuPercent: Math.round(item.cpuPercent * 10) / 10,
|
|
160
|
+
resourceReason: (item.cpuPercent >= 10 ? "cpu" : item.memoryBytes >= 200 * 1024 ** 2 ? "memory" : "tracked") }))
|
|
145
161
|
.sort((a, b) => b.cpuPercent - a.cpuPercent || b.memoryBytes - a.memoryBytes)
|
|
146
162
|
.slice(0, limit);
|
|
147
163
|
}
|
|
@@ -23,6 +23,8 @@ export interface Schedule {
|
|
|
23
23
|
computer: string;
|
|
24
24
|
harness: ScheduleHarness;
|
|
25
25
|
model?: string;
|
|
26
|
+
/** Claude account id (a slug) the run uses; absent means the default account. */
|
|
27
|
+
account?: string;
|
|
26
28
|
notify?: ScheduleNotify[];
|
|
27
29
|
every: ScheduleEvery;
|
|
28
30
|
at?: string;
|
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import * as yaml from "js-yaml";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { atomicInPrivateDir, bridgeRoot, object } from "./protocol.js";
|
|
7
|
+
import { isAccountSlug } from "./claude-accounts.js";
|
|
7
8
|
/** The schedules.yaml store: the schedule and run record shapes, validation,
|
|
8
9
|
* the five timing forms evaluated in local time, and the run history file. */
|
|
9
10
|
export const SCHEDULE_EVERY = ["interval", "daily", "weekly", "once", "cron"];
|
|
@@ -62,6 +63,8 @@ export function parseSchedule(value) {
|
|
|
62
63
|
};
|
|
63
64
|
if (raw.model !== undefined)
|
|
64
65
|
schedule.model = singleLine(200).parse(raw.model);
|
|
66
|
+
if (raw.account !== undefined)
|
|
67
|
+
schedule.account = z.string().refine(isAccountSlug, "Account must be default or a lowercase slug.").parse(raw.account);
|
|
65
68
|
if (raw.notify !== undefined)
|
|
66
69
|
schedule.notify = z.array(z.enum(SCHEDULE_NOTIFY)).max(3).parse(raw.notify)
|
|
67
70
|
.filter((kind, index, kinds) => kinds.indexOf(kind) === index);
|
|
@@ -11,10 +11,11 @@ export declare function createScheduleLauncher(launchHerdr: HerdrLauncher, store
|
|
|
11
11
|
* since an open run blocks its schedule for good.
|
|
12
12
|
*/
|
|
13
13
|
export declare function resumeScheduleRun(run: ScheduleRun, schedule: Schedule, signal: AbortSignal, watch?: typeof watchHerdrRun): Promise<ScheduleRunOutcome>;
|
|
14
|
+
/** The environment a headless run gets: this Hook's, SUDO_ASKPASS, plus the chosen Claude account's config directory. */
|
|
15
|
+
export declare function headlessEnv(schedule: Schedule, env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
14
16
|
export declare function headlessCommand(schedule: Schedule, cwd: string): {
|
|
15
17
|
file: string;
|
|
16
18
|
args: string[];
|
|
17
19
|
cwd: string;
|
|
18
20
|
};
|
|
19
|
-
export declare function ensureCodexDirTrusted(cwd: string): Promise<void>;
|
|
20
21
|
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { createWriteStream } from "node:fs";
|
|
3
|
-
import { mkdir, readFile
|
|
4
|
-
import { codexHome } from "../home-paths.js";
|
|
3
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
5
4
|
import path from "node:path";
|
|
6
5
|
import { finished as streamFinished } from "node:stream/promises";
|
|
6
|
+
import { askpassEnv } from "./sudo.js";
|
|
7
|
+
import { claudeHome, claudeLaunchEnv } from "./claude-accounts.js";
|
|
7
8
|
import { fanoutRoot } from "./fanouts.js";
|
|
9
|
+
import { pretrustFolder } from "./folder-trust.js";
|
|
8
10
|
import { findPane, paneIdentity, servers, snapshot } from "./herdr.js";
|
|
9
11
|
import { agentNotReady, terminalProvider } from "./terminal.js";
|
|
10
|
-
import {
|
|
11
|
-
import { logger } from "../logger.js";
|
|
12
|
+
import { atomicInPrivateDir, BridgeError } from "./protocol.js";
|
|
12
13
|
import { defaultPhrenPath } from "../shared.js";
|
|
13
14
|
import { watchHerdrRun } from "./schedule-watch.js";
|
|
14
15
|
/** Starting a scheduled run: in a Herdr pane when a server is live, otherwise
|
|
@@ -52,9 +53,13 @@ export async function resumeScheduleRun(run, schedule, signal, watch = watchHerd
|
|
|
52
53
|
return { status: "failed", reason: "Phren Hook restarted while this run was going, so its end was not observed." };
|
|
53
54
|
}
|
|
54
55
|
async function launchInHerdr(server, context, launchHerdr, signal) {
|
|
55
|
-
|
|
56
|
+
// The prompt goes with the launch where the harness takes one (Claude,
|
|
57
|
+
// Codex); otherwise it is typed once the agent is ready.
|
|
58
|
+
const brief = context.schedule.prompt.trim() ? { brief: { id: context.runId, text: context.schedule.prompt } } : {};
|
|
59
|
+
const launched = await launchHerdr(server, { cwd: context.cwd, label: context.schedule.name, kind: context.schedule.harness, model: context.schedule.model, ...(context.schedule.account ? { account: context.schedule.account } : {}), ...brief });
|
|
56
60
|
const workspaceId = String(launched.workspaceId), tabId = String(launched.tabId), paneId = String(launched.paneId);
|
|
57
|
-
|
|
61
|
+
if (launched.briefLaunched !== true)
|
|
62
|
+
await promptWhenReady(server, paneId, context.schedule.prompt, signal);
|
|
58
63
|
let sessionId = typeof launched.sessionId === "string" ? launched.sessionId : undefined;
|
|
59
64
|
for (let attempt = 0; attempt < 10 && !sessionId; attempt++) {
|
|
60
65
|
const pane = findPane(await snapshot(server), { workspace: workspaceId, tab: tabId, pane: paneId });
|
|
@@ -86,7 +91,20 @@ async function promptWhenReady(server, paneId, text, signal, waitMs = 60_000) {
|
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
}
|
|
94
|
+
/** The environment a headless run gets: this Hook's, SUDO_ASKPASS, plus the chosen Claude account's config directory. */
|
|
95
|
+
export function headlessEnv(schedule, env = process.env) {
|
|
96
|
+
const askpass = askpassEnv();
|
|
97
|
+
if (askpass.SUDO_ASKPASS)
|
|
98
|
+
env = { ...env, ...askpass };
|
|
99
|
+
if (!schedule.account || schedule.harness !== "claude")
|
|
100
|
+
return env;
|
|
101
|
+
const home = claudeHome(schedule.account, env);
|
|
102
|
+
if (!home)
|
|
103
|
+
throw new Error(`Schedule "${schedule.name}" uses Claude account "${schedule.account}", which is not set up on this computer. Run \`phren bridge accounts\`.`);
|
|
104
|
+
return { ...env, ...claudeLaunchEnv(home) };
|
|
105
|
+
}
|
|
89
106
|
async function launchHeadless(context, store, started) {
|
|
107
|
+
const env = headlessEnv(context.schedule);
|
|
90
108
|
const root = fanoutRoot({ ...process.env, PHREN_PATH: store }), jobDir = path.join(root, context.runId);
|
|
91
109
|
await mkdir(jobDir, { recursive: true, mode: 0o700 });
|
|
92
110
|
const eventLog = "events.jsonl", now = new Date().toISOString();
|
|
@@ -96,11 +114,12 @@ async function launchHeadless(context, store, started) {
|
|
|
96
114
|
await writeManifest(jobDir, manifest);
|
|
97
115
|
const command = headlessCommand(context.schedule, context.cwd);
|
|
98
116
|
// An untrusted directory only costs Codex a prompt; the run still starts, and the log says why.
|
|
117
|
+
// Headless Claude (`-p`) has no trust screen, so only Codex needs it here.
|
|
99
118
|
if (context.schedule.harness === "codex")
|
|
100
|
-
await
|
|
119
|
+
await pretrustFolder("codex", context.cwd, `scheduled run ${context.runId}`);
|
|
101
120
|
let child;
|
|
102
121
|
try {
|
|
103
|
-
child = spawn(command.file, command.args, { cwd: command.cwd, env
|
|
122
|
+
child = spawn(command.file, command.args, { cwd: command.cwd, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
104
123
|
}
|
|
105
124
|
catch (error) {
|
|
106
125
|
await writeManifest(jobDir, { ...manifest, status: "failed", updatedAt: new Date().toISOString(), finishedAt: new Date().toISOString() });
|
|
@@ -145,51 +164,6 @@ export function headlessCommand(schedule, cwd) {
|
|
|
145
164
|
return { file: "opencode", cwd, args: ["run", "--format", "json", "--dir", cwd, ...model] };
|
|
146
165
|
return { file: "claude", cwd, args: ["-p", "--output-format", "stream-json", "--settings", CLAUDE_SCHEDULE_SETTINGS, ...model] };
|
|
147
166
|
}
|
|
148
|
-
function tomlQuote(value) {
|
|
149
|
-
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
150
|
-
}
|
|
151
|
-
export async function ensureCodexDirTrusted(cwd) {
|
|
152
|
-
const directory = codexHome();
|
|
153
|
-
const file = path.join(directory, "config.toml");
|
|
154
|
-
let text = "";
|
|
155
|
-
try {
|
|
156
|
-
text = await readFile(file, "utf8");
|
|
157
|
-
}
|
|
158
|
-
// An unreadable config is left untouched; the caller logs why.
|
|
159
|
-
catch (error) {
|
|
160
|
-
if (error.code !== "ENOENT")
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
163
|
-
const header = `[projects.${tomlQuote(cwd)}]`;
|
|
164
|
-
const trustLine = 'trust_level = "trusted"';
|
|
165
|
-
let next;
|
|
166
|
-
const at = text.indexOf(header);
|
|
167
|
-
if (at >= 0) {
|
|
168
|
-
const bodyStart = at + header.length;
|
|
169
|
-
const rest = text.slice(bodyStart);
|
|
170
|
-
const nextTable = rest.search(/^\s*\[/m);
|
|
171
|
-
const section = nextTable >= 0 ? rest.slice(0, nextTable) : rest;
|
|
172
|
-
if (new RegExp(`trust_level\\s*=\\s*"trusted"`).test(section))
|
|
173
|
-
return;
|
|
174
|
-
const existing = /^[ \t]*trust_level\s*=.*$/m.exec(section);
|
|
175
|
-
if (existing) {
|
|
176
|
-
const replaced = section.replace(existing[0], existing[0].match(/^[ \t]*/)[0] + trustLine);
|
|
177
|
-
next = text.slice(0, bodyStart) + replaced + rest.slice(section.length);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
const newline = section.startsWith("\n") || section.startsWith("\r\n") ? "" : "\n";
|
|
181
|
-
next = text.slice(0, bodyStart) + newline + trustLine + (section.startsWith("\n") || section.startsWith("\r\n") ? section : "\n" + section) + rest.slice(section.length);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
const separator = text && !text.endsWith("\n") ? "\n\n" : text ? "\n" : "";
|
|
186
|
-
next = text + `${separator}${header}\n${trustLine}\n`;
|
|
187
|
-
}
|
|
188
|
-
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
189
|
-
const metadata = await stat(file).catch(() => undefined);
|
|
190
|
-
const mode = metadata ? metadata.mode & 0o777 : 0o600;
|
|
191
|
-
await atomic(file, next, mode);
|
|
192
|
-
}
|
|
193
167
|
async function writeManifest(jobDir, manifest) {
|
|
194
168
|
await atomicInPrivateDir(path.join(jobDir, "manifest.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
195
169
|
}
|
|
@@ -30,14 +30,37 @@ export interface StartupWatchEnv {
|
|
|
30
30
|
panes?: (server: string) => Promise<Json[]>;
|
|
31
31
|
finalTurn?: (source: ScheduleHarness, sessionId: string | undefined) => Promise<FinalTurn | undefined>;
|
|
32
32
|
}
|
|
33
|
-
/** `error`: the harness ended the turn on an error (Codex's usage limit) instead of a reply.
|
|
33
|
+
/** `error`: the harness ended the turn on an error (Codex's usage limit) instead of a reply.
|
|
34
|
+
* `interrupted`: the owner stopped the last turn (Claude's "[Request interrupted by user]",
|
|
35
|
+
* Codex's turn_aborted); the harness sends no Stop for it.
|
|
36
|
+
* `background`: Claude Code background tasks (shells, subagents, monitors) started in
|
|
37
|
+
* the transcript's tail with no task-notification or TaskStop ending them yet.
|
|
38
|
+
* `finishedTasks`: when each Claude background task the tail shows finishing
|
|
39
|
+
* finished (its first final task-notification's timestamp), one per task.
|
|
40
|
+
* `awaited`: those of the running tasks that are shells or monitors started
|
|
41
|
+
* since the owner's last prompt, other than streams that never end (a log
|
|
42
|
+
* tail, a watcher, a dev server). Sub-agents are left to the child tree. */
|
|
34
43
|
export interface FinalTurn {
|
|
35
44
|
completed: boolean;
|
|
36
45
|
lastAssistant?: string;
|
|
37
46
|
error?: string;
|
|
47
|
+
interrupted?: boolean;
|
|
48
|
+
background?: number;
|
|
49
|
+
finishedTasks?: string[];
|
|
50
|
+
awaited?: number;
|
|
38
51
|
}
|
|
39
52
|
/** The public text of one assistant row, without reasoning or tool output. */
|
|
40
53
|
export declare function publicAssistant(raw: Json, source: Provider): string | undefined;
|
|
54
|
+
/** Claude Code background work a transcript line starts or ends, by task id:
|
|
55
|
+
* a backgrounded Bash call, an async subagent or a Monitor start one; a
|
|
56
|
+
* task-notification with a final status, or a TaskStop, ends it. A
|
|
57
|
+
* persistent monitor runs for the whole session and is never waited on.
|
|
58
|
+
* `finished` keeps when each task's first final notification was written.
|
|
59
|
+
* A notification reaching an idle session is written as a queue-operation
|
|
60
|
+
* row, and may stay there with no new turn to deliver it. */
|
|
61
|
+
/** A backgrounded command that runs until killed rather than finishing:
|
|
62
|
+
* following a log, watching files, serving a dev build. Nobody waits on it. */
|
|
63
|
+
export declare const ENDLESS_COMMAND: RegExp;
|
|
41
64
|
/** The last assistant reply in a transcript and whether its turn finished.
|
|
42
65
|
* A person's message after the reply opens a new turn, so it clears both. */
|
|
43
66
|
export declare function finalTurnFromLines(lines: readonly string[], source: ScheduleHarness): FinalTurn;
|