ai_co_discuss 0.5.19 → 0.5.21
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/.agents/skills/discuss-participant/SKILL.md +2 -1
- package/.agents/skills/share-card/SKILL.md +15 -0
- package/.agents/skills/share-card/references/share-card.md +43 -0
- package/.agents/skills/workflow-creator/SKILL.md +3 -0
- package/backend/execution_diagnostics.py +149 -0
- package/backend/free_room.py +133 -40
- package/backend/message_queue.py +6 -4
- package/backend/room_trace.py +219 -0
- package/backend/schema.sql +7 -1
- package/backend/server.py +113 -8
- package/docs/en/guide/cli.md +20 -0
- package/docs/en/guide/faq.md +1 -0
- package/docs/en/guide/members.md +3 -1
- package/docs/en/guide/rooms.md +7 -3
- package/docs/en/guide/workflows.md +2 -0
- package/docs/en/guide/working.md +9 -4
- package/docs/guide/cli.md +20 -0
- package/docs/guide/faq.md +1 -0
- package/docs/guide/members.md +3 -1
- package/docs/guide/rooms.md +7 -3
- package/docs/guide/workflows.md +2 -0
- package/docs/guide/working.md +9 -4
- package/frontend/locales/en/app.json +8 -0
- package/frontend/locales/en/backend.json +5 -0
- package/frontend/locales/en/discussion.json +10 -3
- package/frontend/locales/en/execution-diagnostics.json +32 -0
- package/frontend/locales/en/room.json +1 -0
- package/frontend/locales/en/settings.json +5 -0
- package/package.json +3 -2
- package/runner/adapters/antigravity_cli.mjs +15 -1
- package/runner/adapters/api.mjs +27 -3
- package/runner/adapters/api_images.mjs +1 -1
- package/runner/adapters/api_pi.mjs +30 -1
- package/runner/adapters/cli.mjs +15 -6
- package/runner/adapters/codex_bridge.mjs +20 -6
- package/runner/adapters/codex_cli.mjs +2 -1
- package/runner/codiscuss.mjs +7 -0
- package/runner/discuss.py +24 -2
- package/runner/discussion_launch.mjs +1 -1
- package/runner/discussion_setup.mjs +1 -1
- package/runner/discussion_skills.mjs +1 -1
- package/runner/expert_prompts.mjs +4 -3
- package/runner/free_runner.mjs +102 -24
- package/runner/i18n_en.mjs +45 -2
- package/runner/remote_launch.mjs +2 -2
- package/runner/share_card.mjs +1314 -0
- package/runner/share_service.mjs +25 -7
- package/runner/share_shared.mjs +28 -7
- package/runner/site_deploy.mjs +125 -4
- package/runner/timeline_metrics.mjs +185 -0
- package/runner/workflows.mjs +38 -9
- package/web/app.js +303 -81
- package/web/i18n.js +3 -3
- package/web/modern.css +1 -1
- package/web/modern.js +98 -67
- package/workflows/decision-council/SKILL.md +2 -1
- package/workflows/decision-council/flow.json +15 -15
- package/workflows/story-serial/agents/writer.md +1 -1
- package/workflows/story-serial/flow.json +456 -123
- package/workflows/story-serial/workflows/aigc-reduce/flow.json +134 -13
- package/workflows/story-serial/workflows/character-play/flow.json +212 -25
- package/workflows/story-serial/workflows/jack-sparrow/flow.json +67 -23
- package/workflows/story-serial/workflows/luke-nichols/flow.json +67 -23
- package/workflows/story-serial/workflows/revise-episodes/flow.json +184 -23
- package/workflows/story-serial/workflows/tidy-docs/flow.json +256 -19
- package/workflows/tri-model-dev/SKILL.md +72 -0
- package/workflows/tri-model-dev/agents/advisor.md +22 -0
- package/workflows/tri-model-dev/agents/backend.md +25 -0
- package/workflows/tri-model-dev/agents/reviewer.md +38 -0
- package/workflows/tri-model-dev/flow.json +397 -0
- package/workflows/tri-model-dev/workflows/browser-verify/SKILL.md +22 -0
- package/workflows/tri-model-dev/workflows/browser-verify/agents/browser_ops.md +18 -0
- package/workflows/tri-model-dev/workflows/browser-verify/flow.json +136 -0
- package/workflows/trpg-classic/flow.json +17 -17
package/runner/adapters/cli.mjs
CHANGED
|
@@ -53,9 +53,17 @@ function monitor_cli(adapter, child, binding, task, restart) {
|
|
|
53
53
|
const lines = createInterface({ input: child.stdout, crlfDelay: Infinity });
|
|
54
54
|
const max_run_ms = cli_max_run_ms();
|
|
55
55
|
track_edits(adapter, task);
|
|
56
|
-
|
|
56
|
+
task.on_diagnostic?.({ timeout_limits: { total_ms: max_run_ms } });
|
|
57
|
+
state.limit_timer = setTimeout(() => {
|
|
58
|
+
task.on_diagnostic?.({ timeout_kind: 'total' });
|
|
59
|
+
state.error = cli_timeout_reason(max_run_ms);
|
|
60
|
+
child.kill();
|
|
61
|
+
}, max_run_ms);
|
|
57
62
|
child.stdout.on('data', chunk => task.on_output(log_path, chunk));
|
|
58
63
|
child.stderr.setEncoding('utf8');
|
|
64
|
+
if (adapter.stderr_line) {
|
|
65
|
+
createInterface({ input: child.stderr, crlfDelay: Infinity }).on('line', line => adapter.stderr_line(state, line));
|
|
66
|
+
}
|
|
59
67
|
// Stops the process without marking it stopped by the runner, so a restart is still allowed.
|
|
60
68
|
const own_kill = child.kill.bind(child);
|
|
61
69
|
// Plain text output (stderr, and stdout lines that are not JSON) goes to the adapter's `on_stderr`.
|
|
@@ -73,7 +81,7 @@ function monitor_cli(adapter, child, binding, task, restart) {
|
|
|
73
81
|
if (!line.trim()) return;
|
|
74
82
|
let event;
|
|
75
83
|
try { event = JSON.parse(line); }
|
|
76
|
-
catch { state.diagnostic = 'CLI 输出中存在无效 JSON,详情见本机日志'; watch_text(line); return; }
|
|
84
|
+
catch { state.diagnostic = 'CLI 输出中存在无效 JSON,详情见本机日志'; adapter.stderr_line?.(state, line); watch_text(line); return; }
|
|
77
85
|
trace_cli_event(event, task);
|
|
78
86
|
const phase = adapter.events.phase(event);
|
|
79
87
|
if (phase) task.on_activity?.(phase, adapter.events.tool(event), adapter.events.call?.(event));
|
|
@@ -96,7 +104,7 @@ function monitor_cli(adapter, child, binding, task, restart) {
|
|
|
96
104
|
if (error && state.not_started && !state.stopped && (!failure.failure_class || restartable) && restart?.()) return;
|
|
97
105
|
// `not_started`: the adapter saw the CLI fail before any turn ran, so the runner may deliver the same task again.
|
|
98
106
|
if (error) task.on_failure(error, { not_started: Boolean(state.not_started) && !failure.failure_class,
|
|
99
|
-
...(failure.failure_class ? { retryable: false
|
|
107
|
+
...(failure.failure_class ? { retryable: false } : {}), ...failure });
|
|
100
108
|
else task.on_exit?.(state.denial);
|
|
101
109
|
});
|
|
102
110
|
return state;
|
|
@@ -133,6 +141,7 @@ export async function cli_delivery(adapter, config, binding, task, spawn_process
|
|
|
133
141
|
if (restarts >= CLI_START_RETRIES) return false;
|
|
134
142
|
restarts += 1;
|
|
135
143
|
task.on_trace?.('cli_restart', { attempt: restarts });
|
|
144
|
+
task.on_diagnostic?.({ retry: { layer: 'adapter', state: 'started', attempt: restarts } });
|
|
136
145
|
let launched;
|
|
137
146
|
try { launched = launch(); }
|
|
138
147
|
catch (error) { task.on_failure(error.message, { not_started: true }); return true; }
|
|
@@ -169,7 +178,7 @@ export async function cli_delivery(adapter, config, binding, task, spawn_process
|
|
|
169
178
|
child.once('error', error => state.spawned ? task.on_failure(error.message) : reject(not_sent(error)));
|
|
170
179
|
});
|
|
171
180
|
first.send();
|
|
172
|
-
const steer = invocation.steer && (text => steer_cli(current, invocation, task, text));
|
|
181
|
+
const steer = invocation.steer && ((text, id) => steer_cli(current, invocation, task, text, id));
|
|
173
182
|
return { session_id: state.session_id, status: 'accepted', capabilities: adapter_capabilities(adapter.id).delivery, ...(steer ? { steer } : {}) };
|
|
174
183
|
}
|
|
175
184
|
|
|
@@ -177,9 +186,9 @@ export async function cli_delivery(adapter, config, binding, task, spawn_process
|
|
|
177
186
|
* Pass one interjection into a running CLI turn as the adapter's stdin line, and mark it in the log so the execution's
|
|
178
187
|
* details show it where it happened. False when the turn already ended or the process is gone.
|
|
179
188
|
*/
|
|
180
|
-
function steer_cli({ child, state }, invocation, task, text) {
|
|
189
|
+
function steer_cli({ child, state }, invocation, task, text, id) {
|
|
181
190
|
if (state.completed || state.stopped || state.error || child.exitCode !== null || child.stdin.destroyed || child.stdin.writableEnded) return false;
|
|
182
|
-
child.stdin.write(invocation.steer(text));
|
|
191
|
+
child.stdin.write(invocation.steer(text, id));
|
|
183
192
|
task.on_output(state.log_path, `${JSON.stringify({ type: 'codiscuss.interjection', text })}\n`);
|
|
184
193
|
return true;
|
|
185
194
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* usage: node codex_bridge.mjs <codex executable> [codex app-server options...]
|
|
6
6
|
* stdin: first line `{prompt, thread_id?, cwd, model?, effort?, full?, images?, developer_instructions?}` (`images`: local
|
|
7
|
-
* image paths sent with the prompt; `developer_instructions`: system-level rules of a new thread);
|
|
7
|
+
* image paths sent with the prompt; `developer_instructions`: system-level rules of a new thread); later lines carry `{steer: text, interjection_id?}`.
|
|
8
8
|
* stdout: `thread.started`, `turn.started`, `item.started|completed`, `turn.completed|failed`, `error` events in the
|
|
9
9
|
* shape `codex exec --json` prints. The process exits when the turn ends; exit 1 with the reason on stderr otherwise.
|
|
10
10
|
* One process per execution: an app-server keeps the thread it loaded as its writer until it exits.
|
|
@@ -27,6 +27,8 @@ let thread_id = '';
|
|
|
27
27
|
let turn_id = '';
|
|
28
28
|
let finished = false;
|
|
29
29
|
const queued_steers = [];
|
|
30
|
+
const pending_steers = new Map();
|
|
31
|
+
const completed_user_items = new Set();
|
|
30
32
|
|
|
31
33
|
const server = spawn(executable, ['app-server', ...CONTEXT_OVERRIDES, ...server_args], { windowsHide: true, shell: false, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
32
34
|
tree_killable(server);
|
|
@@ -84,6 +86,7 @@ function notification({ method, params = {} }) {
|
|
|
84
86
|
if (params.threadId && params.threadId !== thread_id) return;
|
|
85
87
|
if (method === 'turn/started') emit({ type: 'turn.started' });
|
|
86
88
|
else if (method === 'item/started' || method === 'item/completed') {
|
|
89
|
+
if (method === 'item/completed' && params.threadId === thread_id && params.turnId === turn_id) confirm_steer(params.item);
|
|
87
90
|
const item = exec_item(params.item || {});
|
|
88
91
|
if (item) emit({ type: method === 'item/started' ? 'item.started' : 'item.completed', item });
|
|
89
92
|
} else if (method === 'error') emit({ type: 'error', message: params.error?.message || params.message || 'Codex 返回错误', ...error_details(params.error) });
|
|
@@ -97,6 +100,16 @@ function notification({ method, params = {} }) {
|
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
|
|
103
|
+
/** Match a completed user message to one pending interjection without emitting the message text. */
|
|
104
|
+
function confirm_steer(item) {
|
|
105
|
+
if (item?.type !== 'userMessage' || !item.id || completed_user_items.has(item.id)
|
|
106
|
+
|| item.content?.length !== 1 || item.content[0].type !== 'text') return;
|
|
107
|
+
completed_user_items.add(item.id);
|
|
108
|
+
const matches = [...pending_steers].filter(([, text]) => text === item.content[0].text);
|
|
109
|
+
for (const [id] of matches) pending_steers.delete(id);
|
|
110
|
+
if (matches.length === 1) emit({ type: 'codiscuss.interjection_confirmed', interjection_id: matches[0][0] });
|
|
111
|
+
}
|
|
112
|
+
|
|
100
113
|
createInterface({ input: server.stdout, crlfDelay: Infinity }).on('line', line => {
|
|
101
114
|
let message;
|
|
102
115
|
try { message = JSON.parse(line); } catch { return; }
|
|
@@ -108,11 +121,12 @@ createInterface({ input: server.stdout, crlfDelay: Infinity }).on('line', line =
|
|
|
108
121
|
});
|
|
109
122
|
|
|
110
123
|
/** Pass an interjection into the running turn; before the turn exists it waits, after the turn it is refused. */
|
|
111
|
-
async function steer(text) {
|
|
124
|
+
async function steer(text, id) {
|
|
112
125
|
if (finished) return;
|
|
113
|
-
if (!turn_id) { queued_steers.push(text); return; }
|
|
126
|
+
if (!turn_id) { queued_steers.push({ text, id }); return; }
|
|
127
|
+
if (Number.isSafeInteger(id) && id > 0) pending_steers.set(id, text);
|
|
114
128
|
try { await request('turn/steer', { threadId: thread_id, expectedTurnId: turn_id, input: [{ type: 'text', text }] }); }
|
|
115
|
-
catch (error) { process.stderr.write(`插话未送达:${error.message}\n`); }
|
|
129
|
+
catch (error) { pending_steers.delete(id); process.stderr.write(`插话未送达:${error.message}\n`); }
|
|
116
130
|
}
|
|
117
131
|
|
|
118
132
|
/** Open or resume the thread, then start the turn with the prompt. */
|
|
@@ -132,7 +146,7 @@ async function start(task) {
|
|
|
132
146
|
...(task.model ? { model: task.model } : {}), ...(task.effort ? { effort: task.effort } : {}) });
|
|
133
147
|
turn_id = started.turn.id;
|
|
134
148
|
emit({ type: 'codiscuss.turn', thread_id, turn_id, rollout_path: opened.thread.path || '' });
|
|
135
|
-
for (const text of queued_steers.splice(0)) await steer(text);
|
|
149
|
+
for (const { text, id } of queued_steers.splice(0)) await steer(text, id);
|
|
136
150
|
}
|
|
137
151
|
|
|
138
152
|
let first = true;
|
|
@@ -140,5 +154,5 @@ createInterface({ input: process.stdin, crlfDelay: Infinity }).on('line', line =
|
|
|
140
154
|
let input;
|
|
141
155
|
try { input = JSON.parse(line); } catch { return; }
|
|
142
156
|
if (first) { first = false; start(input).catch(error => fail(error.message)); }
|
|
143
|
-
else if (typeof input.steer === 'string') steer(input.steer);
|
|
157
|
+
else if (typeof input.steer === 'string') steer(input.steer, input.interjection_id);
|
|
144
158
|
});
|
|
@@ -179,7 +179,7 @@ function invocation(config, binding, task) {
|
|
|
179
179
|
model: config.model || '', effort: config.effort || '', full, ...(developer_instructions ? { developer_instructions } : {}),
|
|
180
180
|
...(task.images?.length ? { images: task.images.map(image => image.path) } : {}) })}\n`;
|
|
181
181
|
return { executable: process.execPath, args: [CODEX_BRIDGE, config.executable, ...(full ? [] : permissions.args)], input,
|
|
182
|
-
steer: text => `${JSON.stringify({ steer: text })}\n`,
|
|
182
|
+
steer: (text, interjection_id) => `${JSON.stringify({ steer: text, interjection_id })}\n`,
|
|
183
183
|
...(permissions.name ? { check: spawn_process => check_codex_permissions(config, task, permissions, spawn_process) } : {}) };
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -190,6 +190,7 @@ function remember_writer_conflict(state, diagnostic) {
|
|
|
190
190
|
|
|
191
191
|
/** Consume only documented lifecycle events, not text produced by agent tools. */
|
|
192
192
|
function lifecycle(state, event, task, bind) {
|
|
193
|
+
if (event.type === 'codiscuss.interjection_confirmed') task.on_diagnostic?.({ interjection_confirmed: event.interjection_id });
|
|
193
194
|
if (event.type === 'thread.started') bind(event.thread_id);
|
|
194
195
|
if (event.type === 'codiscuss.turn') task.on_recovery?.({ kind: 'codex_turn',
|
|
195
196
|
thread_id: event.thread_id, turn_id: event.turn_id, rollout_path: event.rollout_path });
|
package/runner/codiscuss.mjs
CHANGED
|
@@ -38,6 +38,7 @@ const HELP = t(`AI CoDiscuss CLI
|
|
|
38
38
|
invited COMMAND 查看外部房间,调整信任等级、同意或拒绝唤醒、退出
|
|
39
39
|
repo COMMAND 外部成员只读查看对方电脑开放的项目
|
|
40
40
|
site COMMAND 预检、发布、续期、回滚或撤销房间静态网站(公开发布须经用户明确授权)
|
|
41
|
+
share-card COMMAND 读取房间可分享协作指标与素材,或将本地静态 HTML 封面导出为 PNG
|
|
41
42
|
|
|
42
43
|
codiscuss service --help
|
|
43
44
|
codiscuss room --help
|
|
@@ -45,6 +46,11 @@ const HELP = t(`AI CoDiscuss CLI
|
|
|
45
46
|
|
|
46
47
|
网站操作使用 --site、DISCUSS_URL 或 --access-file 中的站点,并需要 Python 3.10+。
|
|
47
48
|
原有 start、status、stop、add 等服务命令继续兼容。
|
|
49
|
+
`) + '\n' + t(`排障速查
|
|
50
|
+
按标题找房间 codiscuss room list --query "标题片段"
|
|
51
|
+
追踪消息的处理 codiscuss room trace ROOM --message MESSAGE_ID
|
|
52
|
+
查看执行详情 codiscuss execution view ROOM EXECUTION_ID
|
|
53
|
+
核对站点版本 codiscuss site diagnose SITE_ID
|
|
48
54
|
`);
|
|
49
55
|
const SERVICE_HELP = t(`AI CoDiscuss 讨论服务
|
|
50
56
|
|
|
@@ -144,6 +150,7 @@ async function main(args = process.argv.slice(2)) {
|
|
|
144
150
|
// Rooms on other computers this one was invited to, and the AI's entry to them (runner/external_client.mjs).
|
|
145
151
|
if (['join', 'invited', 'repo', 'external-proxy'].includes(command)) return (await import('./external_client.mjs')).external_main(command, args.slice(1));
|
|
146
152
|
if (command === 'site') return (await import('./site_deploy.mjs')).site_cli(args.slice(1));
|
|
153
|
+
if (command === 'share-card') return (await import('./share_card.mjs')).share_card_cli(args.slice(1));
|
|
147
154
|
if (!command || (command === 'run' && args.length === 1)) return service_cli([]);
|
|
148
155
|
if (SERVICE_COMMANDS.has(command) || command === '--json') return service_cli(args);
|
|
149
156
|
return website_cli(args);
|
package/runner/discuss.py
CHANGED
|
@@ -121,6 +121,7 @@ class RequestPlan:
|
|
|
121
121
|
params: dict | None = None
|
|
122
122
|
upload_file: str | None = None
|
|
123
123
|
download_file: str | None = None
|
|
124
|
+
title_query: str | None = None
|
|
124
125
|
|
|
125
126
|
|
|
126
127
|
class JoinPreviousStep(argparse.Action):
|
|
@@ -324,6 +325,7 @@ def room_commands(subcommands, registry):
|
|
|
324
325
|
("protocol", "按需读取当前服务的参与协议")):
|
|
325
326
|
parser = add_leaf(subcommands, registry, f"room {action}", description, action != "list")
|
|
326
327
|
if action == "list":
|
|
328
|
+
parser.add_argument("--query", help="按房间标题片段搜索 / Search by part of the room title")
|
|
327
329
|
parser.add_argument("--submission-id", type=submission_id, help="按建房提交编号精确查询")
|
|
328
330
|
elif action in ("view", "brief"):
|
|
329
331
|
parser.add_argument("--request", type=positive_int, help="手动成员:按自己的有效请求限制可读原文")
|
|
@@ -332,6 +334,12 @@ def room_commands(subcommands, registry):
|
|
|
332
334
|
paging = events.add_mutually_exclusive_group()
|
|
333
335
|
paging.add_argument("--after", type=non_negative_int, help="只读此事件编号之后的记录")
|
|
334
336
|
paging.add_argument("--before", type=non_negative_int, help="读此事件编号之前的一页;按返回的 more 继续向前")
|
|
337
|
+
trace = add_leaf(subcommands, registry, "room trace",
|
|
338
|
+
"按消息编号追踪请求、执行、重试、失败唤醒、交回、插话和卡片位置 / Trace a message through room work and card layout",
|
|
339
|
+
True)
|
|
340
|
+
trace.add_argument("--message", type=positive_int, required=True, help="要追踪的房间消息编号 / Room message ID to trace")
|
|
341
|
+
trace.add_argument("--page", type=positive_int, default=1, help="按 next_page 续读 / Continue at next_page")
|
|
342
|
+
trace.add_argument("--request", type=positive_int, help="手动成员的有效请求编号 / Active request ID for manual members")
|
|
335
343
|
limits = add_leaf(subcommands, registry, "room limits", "查看上限;--check 检查并执行到限处理;--done 通知程序目标已完成", True)
|
|
336
344
|
limits.add_argument("--check", action="store_true")
|
|
337
345
|
limits.add_argument("--done", action="store_true", help="主持人宣告目标已完成:结束讨论,房间照常协作;须带 --conclusion")
|
|
@@ -775,7 +783,13 @@ def topic_payload(args):
|
|
|
775
783
|
def read_context_params(args):
|
|
776
784
|
"""Select an explicit manual request or the execution bound to this access file."""
|
|
777
785
|
request_id = getattr(args, "request", None)
|
|
778
|
-
|
|
786
|
+
access = load_access(args)
|
|
787
|
+
if access.get("room") and args.room != access["room"]:
|
|
788
|
+
# A bound execution is only valid in its own room. An explicit request must not silently become an unscoped read.
|
|
789
|
+
if request_id is not None:
|
|
790
|
+
raise CliError("--request 须属于凭据绑定的房间 / --request requires the room bound to the credential")
|
|
791
|
+
return {}
|
|
792
|
+
execution_value = access.get("execution_id")
|
|
779
793
|
if request_id is not None and execution_value is not None:
|
|
780
794
|
raise CliError("读取时 --request 不能与凭据文件中的 execution_id 同用")
|
|
781
795
|
if request_id is not None:
|
|
@@ -793,7 +807,7 @@ def plan_room(args):
|
|
|
793
807
|
"""Translate room operations to one existing HTTP endpoint."""
|
|
794
808
|
if args.action == "list":
|
|
795
809
|
params = {"submission_id": args.submission_id} if args.submission_id else None
|
|
796
|
-
return RequestPlan("/api/rooms", view="room_list", params=params)
|
|
810
|
+
return RequestPlan("/api/rooms", view="room_list", params=params, title_query=args.query)
|
|
797
811
|
if args.action == "create":
|
|
798
812
|
payload = topic_payload(args)
|
|
799
813
|
payload.setdefault("host", require_actor(args))
|
|
@@ -821,6 +835,9 @@ def plan_room(args):
|
|
|
821
835
|
if args.action == "events":
|
|
822
836
|
params = {"after": args.after, "before": args.before}
|
|
823
837
|
return RequestPlan(base + "/events", params={key: value for key, value in params.items() if value})
|
|
838
|
+
if args.action == "trace":
|
|
839
|
+
return RequestPlan(base + "/trace",
|
|
840
|
+
params={"message_id": args.message, "page": args.page, **read_context_params(args)})
|
|
824
841
|
return RequestPlan(base, view="brief" if args.action == "brief" else "overview", params=read_context_params(args))
|
|
825
842
|
|
|
826
843
|
|
|
@@ -1438,6 +1455,11 @@ def select_fields(value, names):
|
|
|
1438
1455
|
def project_result(value, plan, site):
|
|
1439
1456
|
"""Keep summaries, briefing material, host state, and original text separate."""
|
|
1440
1457
|
if plan.view == "room_list":
|
|
1458
|
+
if plan.title_query is not None:
|
|
1459
|
+
query = plan.title_query.strip().casefold()
|
|
1460
|
+
folders = {folder["id"]: folder["name"] for folder in value.get("folders", [])}
|
|
1461
|
+
return {"rooms": [{"id": room["id"], "title": room["title"], "folder": folders.get(room.get("folder_id"))}
|
|
1462
|
+
for room in value["rooms"] if query in room["title"].casefold()]}
|
|
1441
1463
|
return {"rooms": [select_fields(room, ROOM_LIST_FIELDS) for room in value["rooms"]]}
|
|
1442
1464
|
if plan.view in ("overview", "brief", "state"):
|
|
1443
1465
|
fields = {"overview": OVERVIEW_FIELDS, "brief": BRIEF_FIELDS,
|
|
@@ -3324,7 +3324,7 @@ export async function launch_main(args = process.argv.slice(2), input_text) {
|
|
|
3324
3324
|
else if (positionals[0] === 'room-config' && input) result = await room_configuration(home, input, { local_guard: values['configuration-locked'] });
|
|
3325
3325
|
// Rooms on other computers this one was invited to (runner/external_client.mjs, CONTRACT of 子Task4).
|
|
3326
3326
|
else if (positionals[0].startsWith('invited-')) result = await (await import('./external_client.mjs')).invited_command(home, positionals[0], input || {});
|
|
3327
|
-
else if (['site-stage', 'site-publish', 'site-list', 'site-renew', 'site-rollback', 'site-revoke'].includes(positionals[0])) {
|
|
3327
|
+
else if (['site-stage', 'site-publish', 'site-list', 'site-diagnose', 'site-renew', 'site-rollback', 'site-revoke'].includes(positionals[0])) {
|
|
3328
3328
|
result = await (await import('./site_deploy.mjs')).site_command(home, positionals[0], input || {});
|
|
3329
3329
|
}
|
|
3330
3330
|
else throw new Error(HELP);
|
|
@@ -550,7 +550,7 @@ function report_styled(result, options) {
|
|
|
550
550
|
for (const permission of result.permissions) {
|
|
551
551
|
if (permission.status === 'removed') rows.push([permission.client, t('已移除旧版全局放行规则'), short_path(permission.path)]);
|
|
552
552
|
}
|
|
553
|
-
if (result.skills.length) rows.push([t('技能'), result.skills.map(group => `${group.client} ${group.results.filter(skill => skill.status !== 'conflict').length}/${group.results.length}`).join(' · '), '
|
|
553
|
+
if (result.skills.length) rows.push([t('技能'), result.skills.map(group => `${group.client} ${group.results.filter(skill => skill.status !== 'conflict').length}/${group.results.length}`).join(' · '), SKILLS.join(' · ')]);
|
|
554
554
|
if (result.workflows.length) rows.push([t('工作流'), workflow_summary(result.workflows), '']);
|
|
555
555
|
if (result.launcher) rows.push([t('快捷方式'), t('双击“共议”启动'), short_path(result.launcher)]);
|
|
556
556
|
if (result.hosting) rows.push([t('托管管理'), t('已打开'), t('在管理面板中可用')]);
|
|
@@ -11,7 +11,7 @@ import { atomic_json } from './files.mjs';
|
|
|
11
11
|
import { WORKFLOW_ID_PATTERN, install_workflow_folder, parse_markdown, workflow_directory } from './workflows.mjs';
|
|
12
12
|
|
|
13
13
|
const SOURCE = fileURLToPath(new URL('../.agents/skills/', import.meta.url));
|
|
14
|
-
export const SKILLS = ['discuss-host', 'discuss-participant', 'discuss-goal', 'discuss-session', 'discuss-report', 'workflow-creator', 'local-tts-setup', 'local-stt-setup'];
|
|
14
|
+
export const SKILLS = ['discuss-host', 'discuss-participant', 'discuss-goal', 'discuss-session', 'discuss-report', 'share-card', 'workflow-creator', 'local-tts-setup', 'local-stt-setup'];
|
|
15
15
|
const LEGACY_MANIFEST = '.codiscuss-skills.json';
|
|
16
16
|
|
|
17
17
|
/** Hash names and contents, rejecting links instead of following them outside a skill. */
|
|
@@ -79,7 +79,7 @@ export function access_label(level) { return level === 'own' ? '自行决定' :
|
|
|
79
79
|
* Subcommands an automatic task may run; service, run, api, setup and the rest of launch stay unapproved.
|
|
80
80
|
* `launch workflow-adopt`, `launch workflow-join`, `launch workflow-leave` and `launch host-control` check themselves that the caller is the room's host (adopt and host-control also need the owner's grant).
|
|
81
81
|
*/
|
|
82
|
-
export const TASK_SUBCOMMANDS = ['room', 'message', 'turn', 'state', 'goal', 'mode', 'review', 'sequence', 'question', 'execution', 'health', 'schema', 'launch workflow-adopt', 'launch workflow-join', 'launch workflow-leave', 'launch host-control', 'attachment', 'launch image', 'repo', 'site'];
|
|
82
|
+
export const TASK_SUBCOMMANDS = ['room', 'message', 'turn', 'state', 'goal', 'mode', 'review', 'sequence', 'question', 'execution', 'health', 'schema', 'launch workflow-adopt', 'launch workflow-join', 'launch workflow-leave', 'launch host-control', 'attachment', 'launch image', 'repo', 'site', 'share-card'];
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* The limit on a quick answer given inline with --body: a run allowed only codiscuss commands refuses a command line
|
|
@@ -100,8 +100,9 @@ export const correctable_refusals = denials => (denials || []).filter(item => it
|
|
|
100
100
|
* What a member hears when the program resumes its session after this computer's room service restarted (an update,
|
|
101
101
|
* a crash) and ended its turn midway: the same execution goes on, checking the workspace before redoing anything.
|
|
102
102
|
*/
|
|
103
|
-
export function restart_resume_prompt(execution_id) {
|
|
104
|
-
|
|
103
|
+
export function restart_resume_prompt(execution_id, cause = 'restart') {
|
|
104
|
+
const cause_text = cause === 'network' ? '网络中断' : '本机服务重启';
|
|
105
|
+
return `你正在做的这次房间任务(执行 #${execution_id},仍在进行)被${cause_text}打断,上一轮在中途结束,回答还没有提交。`
|
|
105
106
|
+ '先核对工作区与上一轮最后在做的操作(中途被打断的命令可能只执行了一部分),已经做完的部分不必重做,接着完成原任务,最后照常提交这次执行的回答。';
|
|
106
107
|
}
|
|
107
108
|
|
package/runner/free_runner.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import { image_settings } from './image_service.mjs';
|
|
|
14
14
|
import { outside_directory, room_directories } from './project_files.mjs';
|
|
15
15
|
import { SessionDriver } from './session_driver.mjs';
|
|
16
16
|
import { slash_names } from './slash_names.mjs';
|
|
17
|
-
import { effective_profile, load_room_workflow, member_knowledge, workflow_directory, workflow_in_use, workflow_task_field } from './workflows.mjs';
|
|
17
|
+
import { effective_profile, load_room_workflow, member_knowledge, workflow_directory, workflow_execution_binding, workflow_in_use, workflow_task_field } from './workflows.mjs';
|
|
18
18
|
import { GOAL_CONFIDENCE, GOAL_PROMPT_VERSION, decide_goal_wake, decide_sequence_checkpoint, REVIEW_CONFIDENCE, REVIEW_PROMPT_VERSION, SEQUENCE_CONFIDENCE, SEQUENCE_PROMPT_VERSION, ROUTE_CONFIDENCE, ROUTE_CONTEXT_MESSAGES, ROUTE_GUIDED_PROMPT_VERSION, ROUTE_WIDE_CONFIDENCE, SCHEDULER_MODE, decide_review_completion, route_free_message, some_members } from './scheduler.mjs';
|
|
19
19
|
import { room_text, room_payload } from './room_text.mjs';
|
|
20
20
|
import { question_notice } from './question_weixin.mjs';
|
|
@@ -42,7 +42,9 @@ const NOTICE_RETRY_MS = 60_000;
|
|
|
42
42
|
const NOTICE_EXCERPT = 300;
|
|
43
43
|
// A manual member's session that refuses a delivery is retried in the same execution, after a wait the owner can cut short.
|
|
44
44
|
const MAX_DELIVERY_RETRIES = 3;
|
|
45
|
+
const MAX_DIAGNOSTIC_RETRIES = 30;
|
|
45
46
|
const RETRY_DELAY_SECONDS = 60;
|
|
47
|
+
const NETWORK_RETRY_SECONDS = [10, 30, 60];
|
|
46
48
|
// How long a voided turn the runner cannot stop is still watched for its end: a little past the site's 600-second hold.
|
|
47
49
|
const UNSTOPPABLE_FOLLOW_MS = 15 * 60_000;
|
|
48
50
|
// The failure classes an adapter may report (adapter contract `on_failure(reason, {failure_class, ...})`).
|
|
@@ -541,6 +543,7 @@ export class FreeRoomRunner {
|
|
|
541
543
|
this.snapshots = new Map();
|
|
542
544
|
// Execution id -> { phase, at, sent_phase, sent_at }: what the member's software last showed it doing.
|
|
543
545
|
this.activity = new Map();
|
|
546
|
+
this.diagnostics = new Map();
|
|
544
547
|
// Execution id -> until when its completed software may still record its receipt (0: stop it now), see `closing`.
|
|
545
548
|
this.closed_at = new Map();
|
|
546
549
|
this.segments = new SegmentLog();
|
|
@@ -1065,7 +1068,7 @@ export class FreeRoomRunner {
|
|
|
1065
1068
|
await this.invoke(member, execution);
|
|
1066
1069
|
}
|
|
1067
1070
|
/** Hand the execution to the member's software; only proven non-delivery is released for retry. */
|
|
1068
|
-
async invoke(member, execution, { resume = '' } = {}) {
|
|
1071
|
+
async invoke(member, execution, { resume = '', network_binding = '' } = {}) {
|
|
1069
1072
|
const adapter = this.config.participants[member.name];
|
|
1070
1073
|
const review_request = execution.requests?.find(request => request.review?.phase === 'review');
|
|
1071
1074
|
if (review_request) {
|
|
@@ -1126,9 +1129,16 @@ export class FreeRoomRunner {
|
|
|
1126
1129
|
this.store.db.prepare('DELETE FROM metadata WHERE key IN (?,?)').run(`recovery:${execution.id}`, `recovery-denied:${execution.id}`);
|
|
1127
1130
|
invoked = true;
|
|
1128
1131
|
this.segments.start(execution.id);
|
|
1132
|
+
this.record_diagnostics(execution.id, { workflow: workflow_execution_binding(workflow, member, Boolean(task.workflow)) });
|
|
1129
1133
|
if (warning) this.note(execution.id, warning);
|
|
1130
1134
|
const result = await this.deliver(review_request ? structuredClone(task.profile) : task.profile, binding, { ...task, ...(resume ? { prompt: resume, images: [] } : {}), room_title: this.room_title,
|
|
1131
|
-
...(review_request ? { before_model_start: () =>
|
|
1135
|
+
...(review_request || network_binding ? { before_model_start: async () => {
|
|
1136
|
+
if (review_request) await this.check_review_delivery(member, review_request);
|
|
1137
|
+
if (network_binding) {
|
|
1138
|
+
const latest = await api(this.config, `/executions/${execution.id}`);
|
|
1139
|
+
if (!['dispatched', 'started'].includes(latest.status) || latest.retry?.stopped) throw new Error(room_text("送达前本次执行已结束"));
|
|
1140
|
+
}
|
|
1141
|
+
} } : {}),
|
|
1132
1142
|
api_context: { site: this.config.site, room: this.config.room, token: this.config.members[member.name].token,
|
|
1133
1143
|
home: this.config.api_home, mode: 'free', role: member.role || 'member', execution_id: execution.id,
|
|
1134
1144
|
// An API member reads its knowledge through the file tools; writing it waits for per-directory write access.
|
|
@@ -1149,7 +1159,17 @@ export class FreeRoomRunner {
|
|
|
1149
1159
|
on_binding: session => this.store.bind(member.name, session),
|
|
1150
1160
|
on_process: child => this.track(member.name, child, live()),
|
|
1151
1161
|
on_output: (path, chunk) => { appendFileSync(path, chunk, { mode: 0o600 }); this.touch(live()); this.segments.mark(live()); },
|
|
1152
|
-
on_activity: (phase, tool, call
|
|
1162
|
+
on_activity: (phase, tool, call, { synthetic = false } = {}) => {
|
|
1163
|
+
if (!current()) return;
|
|
1164
|
+
worked = true;
|
|
1165
|
+
this.touch(live(), phase);
|
|
1166
|
+
this.segments.mark(live(), phase, tool, call);
|
|
1167
|
+
if (!synthetic && phase !== 'waiting') this.record_diagnostics(live(), { last_activity_at: Date.now() });
|
|
1168
|
+
},
|
|
1169
|
+
on_diagnostic: facts => {
|
|
1170
|
+
if (facts.interjection_confirmed) return this.confirm_interjection(facts.interjection_confirmed);
|
|
1171
|
+
if (current()) this.record_diagnostics(live(), facts);
|
|
1172
|
+
},
|
|
1153
1173
|
on_note: text => {
|
|
1154
1174
|
this.note(live(), text);
|
|
1155
1175
|
if (worked && current()) this.replies.set(live(), text);
|
|
@@ -1161,7 +1181,7 @@ export class FreeRoomRunner {
|
|
|
1161
1181
|
if (snapshot && !paths.length) snapshot.edited ||= new Set();
|
|
1162
1182
|
},
|
|
1163
1183
|
// A stopped process may report after the next execution started; only its own execution takes the result.
|
|
1164
|
-
on_failure: (error, { not_started = false, retryable = true, failure_class = '', resets = '', reset_at = 0 } = {}) => {
|
|
1184
|
+
on_failure: (error, { not_started = false, retryable = true, failure_class = '', resets = '', reset_at = 0, resume_session = '' } = {}) => {
|
|
1165
1185
|
if (!current()) return;
|
|
1166
1186
|
if (not_started) this.not_started.add(live());
|
|
1167
1187
|
if (!retryable) this.not_retryable.add(live());
|
|
@@ -1169,7 +1189,12 @@ export class FreeRoomRunner {
|
|
|
1169
1189
|
// `auth` asks for signing in again, `output_truncated` states where the model's reply was cut.
|
|
1170
1190
|
if (FAILURE_CLASSES.includes(failure_class)) this.failure_classes.set(live(), { failure_class, ...(resets ? { resets: String(resets) } : {}),
|
|
1171
1191
|
...(Number.isSafeInteger(reset_at) && reset_at > 0 ? { reset_at } : {}) });
|
|
1172
|
-
try {
|
|
1192
|
+
try {
|
|
1193
|
+
if (this.row(member.name)?.execution_id !== live()) return;
|
|
1194
|
+
const retry_binding = resume_session ? `network:${adapter.adapter}:${resume_session}` : not_started && network_binding;
|
|
1195
|
+
if (retry_binding) this.store.db.prepare('INSERT OR REPLACE INTO metadata VALUES (?,?)').run(`retry-reason:${live()}`, retry_binding);
|
|
1196
|
+
this.save(member.name, { error });
|
|
1197
|
+
} catch { /* Store may already be closed at shutdown. */ }
|
|
1173
1198
|
},
|
|
1174
1199
|
// The turn was seen to end in a window or App the runner cannot stop; unlike on_exit it says nothing about an answer.
|
|
1175
1200
|
on_turn_end: () => { if (current()) this.turn_ended.add(live()); },
|
|
@@ -1206,6 +1231,7 @@ export class FreeRoomRunner {
|
|
|
1206
1231
|
}
|
|
1207
1232
|
} catch (error) {
|
|
1208
1233
|
if (review_request && error.delivery_status === 'not_sent') return this.reject_review(member, execution, error.message);
|
|
1234
|
+
if (network_binding) return this.fail(member.name, execution.id, room_text("投递失败:{value1}", { value1: error.message }));
|
|
1209
1235
|
if (adapter.project_access === 'own') return this.retry_or_fail(member.name, execution, `投递失败:${error.message}`);
|
|
1210
1236
|
const attempts = (this.row(member.name)?.attempts || 0) + 1;
|
|
1211
1237
|
if ((invoked && error.delivery_status !== 'not_sent') || attempts >= MAX_DELIVERY_ATTEMPTS) {
|
|
@@ -1324,11 +1350,19 @@ export class FreeRoomRunner {
|
|
|
1324
1350
|
if (reason_code === RESTART_REASON_CODE) return this.recover_orphan(member, row, execution);
|
|
1325
1351
|
const retry = execution.retry;
|
|
1326
1352
|
if (retry?.stopped) return this.fail(member.name, execution.id, room_text("{value1}(已停止自动重试)", { value1: retry.reason }));
|
|
1327
|
-
|
|
1328
|
-
|
|
1353
|
+
// retry_at is already zero if the site received retry_start but its response was lost.
|
|
1354
|
+
// The local retry_wait row proves this runner has not begun the next delivery.
|
|
1355
|
+
if (!execution.paused_at && retry && Date.now() >= retry.retry_at * 1000) {
|
|
1356
|
+
const network_binding = reason_code?.startsWith('network:') ? reason_code : '';
|
|
1357
|
+
const latest = await api(this.config, `/executions/${execution.id}`, { action: 'retry_start',
|
|
1358
|
+
diagnostics: { retry: { layer: 'runner', state: 'started', attempt: retry.attempt, mode: network_binding ? 'resume' : 'redeliver' } } });
|
|
1359
|
+
if (latest.retry?.stopped) return this.fail(member.name, execution.id, room_text("{value1}(已停止自动重试)", { value1: retry.reason }));
|
|
1360
|
+
if (network_binding && network_binding !== `network:${this.config.participants[member.name]?.adapter}:${this.store.binding(member.name).session_id}`) {
|
|
1361
|
+
return this.fail(member.name, execution.id, room_text("原会话绑定已改变,无法继续本次执行"));
|
|
1362
|
+
}
|
|
1329
1363
|
this.save(member.name, { status: 'delivering' });
|
|
1330
1364
|
this.store.db.prepare('DELETE FROM metadata WHERE key=?').run(`retry-reason:${execution.id}`);
|
|
1331
|
-
return this.invoke(member,
|
|
1365
|
+
return this.invoke(member, latest, { network_binding, resume: network_binding ? restart_resume_prompt(execution.id, 'network') : '' });
|
|
1332
1366
|
}
|
|
1333
1367
|
}
|
|
1334
1368
|
// A restart between persisting and invoking cannot prove non-delivery, so it never resends.
|
|
@@ -1376,6 +1410,7 @@ export class FreeRoomRunner {
|
|
|
1376
1410
|
const elapsed = Date.now() - row.last_renew;
|
|
1377
1411
|
if (elapsed >= RENEW_MS || (changed && elapsed >= ACTIVITY_REPORT_MS)) {
|
|
1378
1412
|
const renew = phase => api(this.config, `/executions/${execution.id}`, { action: 'renew',
|
|
1413
|
+
diagnostics: this.diagnostics.get(execution.id),
|
|
1379
1414
|
...(activity ? { activity: phase, activity_at: Math.floor(activity.at / 1000) } : {}) });
|
|
1380
1415
|
try { await renew(activity?.phase); }
|
|
1381
1416
|
catch (error) {
|
|
@@ -1416,7 +1451,9 @@ export class FreeRoomRunner {
|
|
|
1416
1451
|
this.store.db.prepare('INSERT OR REPLACE INTO metadata VALUES (?,?)').run(`${prefix}:${id}`, value);
|
|
1417
1452
|
this.store.db.prepare('DELETE FROM metadata WHERE key=?').run(`${prefix}:${old}`);
|
|
1418
1453
|
}
|
|
1454
|
+
const workflow = this.diagnostics.get(old)?.workflow;
|
|
1419
1455
|
await this.report_segments(old, true);
|
|
1456
|
+
if (workflow) this.record_diagnostics(id, { workflow });
|
|
1420
1457
|
this.segments.start(id);
|
|
1421
1458
|
this.save(name, { execution_id: id, last_renew: 0 });
|
|
1422
1459
|
}
|
|
@@ -1442,7 +1479,8 @@ export class FreeRoomRunner {
|
|
|
1442
1479
|
if (this.row(member.name)?.status !== 'running') return true;
|
|
1443
1480
|
for (const interjection of execution.interjections) {
|
|
1444
1481
|
this.interjecting.set(interjection.id, { status: 'delivered' });
|
|
1445
|
-
await api(this.config, `/executions/${execution.id}`, { action: 'interjection', interjection_id: interjection.id, status: 'delivered'
|
|
1482
|
+
await api(this.config, `/executions/${execution.id}`, { action: 'interjection', interjection_id: interjection.id, status: 'delivered',
|
|
1483
|
+
diagnostics: { transport: 'resumed_turn', confirmed_at: null } })
|
|
1446
1484
|
.catch(error => this.log(`插话 #${interjection.id} 的结果未能上报:${error.message}`));
|
|
1447
1485
|
}
|
|
1448
1486
|
return true;
|
|
@@ -1455,7 +1493,8 @@ export class FreeRoomRunner {
|
|
|
1455
1493
|
async report_delivery(execution_id, { stoppable, progress, ends = false, steer = false, resume = false }, member) {
|
|
1456
1494
|
// `ends`: the adapter cannot stop or follow this turn but reports when it ends (`on_turn_end`); kept locally only.
|
|
1457
1495
|
this.store.db.prepare('INSERT OR REPLACE INTO metadata VALUES (?,?)').run(`delivery:${execution_id}`, JSON.stringify({ stoppable, progress, ends, member }));
|
|
1458
|
-
await api(this.config, `/executions/${execution_id}`, { action: 'delivery', stoppable, progress, steer, resume
|
|
1496
|
+
await api(this.config, `/executions/${execution_id}`, { action: 'delivery', stoppable, progress, steer, resume,
|
|
1497
|
+
diagnostics: this.diagnostics.get(execution_id) })
|
|
1459
1498
|
.catch(error => this.log(`执行 #${execution_id} 的投递能力未能上报:${error.message}`));
|
|
1460
1499
|
}
|
|
1461
1500
|
/** Tell the site which model and effort an execution ran with, for its card; a lost report only leaves the card without it. */
|
|
@@ -1553,7 +1592,7 @@ export class FreeRoomRunner {
|
|
|
1553
1592
|
}
|
|
1554
1593
|
/** Drop the records an ended execution leaves: its process owners and whether a restart already resumed it. */
|
|
1555
1594
|
forget_owner(execution_id) {
|
|
1556
|
-
this.store.db.prepare('DELETE FROM metadata WHERE key IN (
|
|
1595
|
+
this.store.db.prepare('DELETE FROM metadata WHERE key IN (?,?,?)').run(`owner:${execution_id}`, `restart-resumed:${execution_id}`, `retry-reason:${execution_id}`);
|
|
1557
1596
|
}
|
|
1558
1597
|
/** Once a new task received the stop reminders, retire acknowledged unconfirmed reports for its old turns. */
|
|
1559
1598
|
clear_stopped(name) {
|
|
@@ -1571,9 +1610,30 @@ export class FreeRoomRunner {
|
|
|
1571
1610
|
return JSON.parse(this.store.db.prepare('SELECT value FROM metadata WHERE key=?').get(`stopped:${name}`)?.value || '[]');
|
|
1572
1611
|
}
|
|
1573
1612
|
/** Send the execution's recorded segments and progress notes; `final` sends the rest once it has ended. */
|
|
1574
|
-
report_segments(execution_id, final = false) {
|
|
1575
|
-
|
|
1576
|
-
|
|
1613
|
+
async report_segments(execution_id, final = false) {
|
|
1614
|
+
const diagnostics = this.diagnostics.get(execution_id);
|
|
1615
|
+
await this.segments.report(execution_id, final, ({ segments, notes }) =>
|
|
1616
|
+
api(this.config, `/executions/${execution_id}`, { action: 'segments', diagnostics, segments, ...(notes.length ? { notes } : {}) }));
|
|
1617
|
+
if (final) {
|
|
1618
|
+
const snapshot = this.snapshots.get(execution_id);
|
|
1619
|
+
if (snapshot) snapshot.diagnostics = this.diagnostics.get(execution_id);
|
|
1620
|
+
this.diagnostics.delete(execution_id);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
/** Record adapter evidence without carrying output text, tool arguments, or session credentials. */
|
|
1624
|
+
record_diagnostics(execution_id, { retry, ...facts }) {
|
|
1625
|
+
const previous = this.diagnostics.get(execution_id);
|
|
1626
|
+
const retries = retry ? [...(previous?.retries || []), { ...retry, at: Date.now() }].slice(-MAX_DIAGNOSTIC_RETRIES) : null;
|
|
1627
|
+
this.diagnostics.set(execution_id, { ...previous, ...facts, ...(retries ? { retries } : {}) });
|
|
1628
|
+
}
|
|
1629
|
+
/** Keep software confirmation bound to the original interjection even if the turn has continued onto another execution. */
|
|
1630
|
+
confirm_interjection(interjection_id) {
|
|
1631
|
+
const report = this.interjecting.get(interjection_id);
|
|
1632
|
+
if (report?.status !== 'delivered' || !report.execution_id) return;
|
|
1633
|
+
const execution_id = report.execution_id;
|
|
1634
|
+
report.confirmed_at ||= Date.now();
|
|
1635
|
+
return this.report_interjection(execution_id, interjection_id, report)
|
|
1636
|
+
.catch(error => this.log(`插话 #${interjection_id} 的确认未能上报:${error.message}`));
|
|
1577
1637
|
}
|
|
1578
1638
|
/** Note that the software produced output now, and its phase when the output names one. */
|
|
1579
1639
|
touch(execution_id, phase) {
|
|
@@ -1631,18 +1691,25 @@ export class FreeRoomRunner {
|
|
|
1631
1691
|
if (profile) this.report_model(execution_id, session_settings(profile.adapter, this.store.binding(snapshot.member).session_id));
|
|
1632
1692
|
}
|
|
1633
1693
|
const after = snapshot.before ? workspace_snapshot(snapshot.directory) : null;
|
|
1694
|
+
let workspace_observed = Boolean(after);
|
|
1634
1695
|
const extra = (snapshot.extras || []).flatMap(item => {
|
|
1635
1696
|
const current = workspace_snapshot(item.directory);
|
|
1697
|
+
if (current) workspace_observed = true;
|
|
1636
1698
|
return current ? changed_between(item.before, current).map(path => extra_change(item.directory, path)) : [];
|
|
1637
1699
|
});
|
|
1700
|
+
if (!workspace_observed) continue;
|
|
1638
1701
|
const own = after ? changed_between(snapshot.before, after) : [];
|
|
1639
1702
|
const changes = [...own, ...extra].slice(0, 200);
|
|
1640
1703
|
// `edited` is sent only when the adapter tracked edits; without it the site cannot tell who wrote a shared file.
|
|
1641
1704
|
const edited = snapshot.edited ? { edited: edited_changes(changes, snapshot.edited) } : {};
|
|
1705
|
+
const diagnostics = { ...(this.diagnostics.get(execution_id) || snapshot.diagnostics),
|
|
1706
|
+
file_attribution: { tracked: Boolean(snapshot.edited), provisional: running,
|
|
1707
|
+
omitted: Math.max(0, own.length + extra.length - changes.length) } };
|
|
1642
1708
|
// Line counts and patches of the files in the member's own working tree, for the card's "edited N files".
|
|
1643
1709
|
let diffs = [];
|
|
1644
1710
|
if (own.length) try { diffs = file_diffs(snapshot.directory, own.slice(0, 200), snapshot.base); } catch { /* The card then lists names only. */ }
|
|
1645
|
-
try { await api(this.config, `/executions/${execution_id}`, { action: 'report', ...(running ? { provisional: true } : {}),
|
|
1711
|
+
try { await api(this.config, `/executions/${execution_id}`, { action: 'report', ...(running ? { provisional: true } : {}),
|
|
1712
|
+
changes, ...edited, ...(diffs.length ? { diffs } : {}), diagnostics }); }
|
|
1646
1713
|
catch (error) { if (!/HTTP (404|409)/.test(error.message)) throw error; }
|
|
1647
1714
|
}
|
|
1648
1715
|
}
|
|
@@ -1691,21 +1758,25 @@ export class FreeRoomRunner {
|
|
|
1691
1758
|
await this.invoke(member, execution, { resume: restart_resume_prompt(execution.id) });
|
|
1692
1759
|
return true;
|
|
1693
1760
|
}
|
|
1694
|
-
/**
|
|
1761
|
+
/** Redeliver an unstarted or manual task, or resume the session named by a transient network failure. */
|
|
1695
1762
|
async retry_or_fail(name, execution, reason) {
|
|
1763
|
+
// Recover a retry_wait acknowledged by the site before the local row was saved.
|
|
1764
|
+
if (execution.retry?.retry_at) return this.save(name, { status: 'retry_wait', error: '' });
|
|
1696
1765
|
const attempt = (execution.retry?.attempt || 0) + 1;
|
|
1697
1766
|
const not_started = this.not_started.delete(execution.id);
|
|
1698
1767
|
if (this.not_retryable.delete(execution.id)) return this.fail(name, execution.id, reason);
|
|
1699
|
-
|
|
1768
|
+
const retry_reason = this.store.db.prepare('SELECT value FROM metadata WHERE key=?').get(`retry-reason:${execution.id}`)?.value;
|
|
1769
|
+
const network = retry_reason?.startsWith('network:');
|
|
1770
|
+
if (!network && this.config.participants[name]?.project_access !== 'own' && !not_started) return this.fail(name, execution.id, reason);
|
|
1700
1771
|
if (attempt > MAX_DELIVERY_RETRIES) return this.fail(name, execution.id, room_text("{value1}(已自动重试 {value2} 次)", { value1: reason, value2: MAX_DELIVERY_RETRIES }));
|
|
1701
1772
|
this.stop_member(name);
|
|
1702
1773
|
this.exited.delete(execution.id);
|
|
1703
1774
|
this.replies.delete(execution.id);
|
|
1704
1775
|
this.denied.delete(execution.id);
|
|
1705
|
-
|
|
1706
|
-
.run(`retry-reason:${execution.id}`, 'delivery_failed');
|
|
1776
|
+
const delay = network ? NETWORK_RETRY_SECONDS[attempt - 1] : RETRY_DELAY_SECONDS;
|
|
1707
1777
|
await api(this.config, `/executions/${execution.id}`, { action: 'retry_wait', attempt,
|
|
1708
|
-
retry_at: Math.floor(Date.now() / 1000) +
|
|
1778
|
+
retry_at: Math.floor(Date.now() / 1000) + delay, reason: reason.slice(0, MAX_RETRY_REASON),
|
|
1779
|
+
diagnostics: { retry: { layer: 'runner', state: 'waiting', attempt, mode: network ? 'resume' : 'redeliver' } } });
|
|
1709
1780
|
this.save(name, { status: 'retry_wait', error: '' });
|
|
1710
1781
|
}
|
|
1711
1782
|
/**
|
|
@@ -1730,6 +1801,7 @@ export class FreeRoomRunner {
|
|
|
1730
1801
|
this.save(name, { status: 'idle', error: '' });
|
|
1731
1802
|
}
|
|
1732
1803
|
async fail(name, execution_id, reason) {
|
|
1804
|
+
const diagnostics = this.diagnostics.get(execution_id);
|
|
1733
1805
|
this.activity.delete(execution_id);
|
|
1734
1806
|
this.not_started.delete(execution_id);
|
|
1735
1807
|
this.not_retryable.delete(execution_id);
|
|
@@ -1737,7 +1809,7 @@ export class FreeRoomRunner {
|
|
|
1737
1809
|
this.failure_classes.delete(execution_id);
|
|
1738
1810
|
await this.report_segments(execution_id, true);
|
|
1739
1811
|
let recorded = true;
|
|
1740
|
-
try { await api(this.config, `/executions/${execution_id}`, { action: 'fail', reason, ...failure_class }); }
|
|
1812
|
+
try { await api(this.config, `/executions/${execution_id}`, { action: 'fail', reason, ...failure_class, diagnostics }); }
|
|
1741
1813
|
catch (error) { if (!/HTTP 409/.test(error.message)) throw error; recorded = false; }
|
|
1742
1814
|
if (recorded && this.on_failed) {
|
|
1743
1815
|
try { this.on_failed({ member: name, execution_id, reason, room: this.config.room, title: this.room_title || '' }); }
|
|
@@ -1793,16 +1865,22 @@ export class FreeRoomRunner {
|
|
|
1793
1865
|
const steer = this.steers.get(execution.id);
|
|
1794
1866
|
report = { status: 'failed', reason: room_text("本次投递不支持执行中插话") };
|
|
1795
1867
|
if (steer) {
|
|
1796
|
-
try { report = await steer(interjection_text(interjection)) ? { status: 'delivered' } : { status: 'failed', reason: room_text("它已结束本轮,插话未送达") }; }
|
|
1868
|
+
try { report = await steer(interjection_text(interjection), interjection.id) ? { status: 'delivered' } : { status: 'failed', reason: room_text("它已结束本轮,插话未送达") }; }
|
|
1797
1869
|
catch (error) { report = { status: 'failed', reason: String(error.message).slice(0, 400) }; }
|
|
1798
1870
|
}
|
|
1871
|
+
Object.assign(report, { execution_id: execution.id, confirmed_at: null });
|
|
1799
1872
|
this.interjecting.set(interjection.id, report);
|
|
1800
1873
|
}
|
|
1801
|
-
try { await
|
|
1874
|
+
try { await this.report_interjection(execution.id, interjection.id, report); }
|
|
1802
1875
|
catch (error) { this.log(`插话 #${interjection.id} 的结果未能上报:${error.message}`); }
|
|
1803
1876
|
}
|
|
1804
1877
|
}
|
|
1805
1878
|
}
|
|
1879
|
+
/** Report transport status and the optional matching software receipt as independent facts. */
|
|
1880
|
+
report_interjection(execution_id, interjection_id, { status, reason, confirmed_at = null }) {
|
|
1881
|
+
return api(this.config, `/executions/${execution_id}`, { action: 'interjection', interjection_id, status, reason,
|
|
1882
|
+
diagnostics: { transport: 'steer', confirmed_at } });
|
|
1883
|
+
}
|
|
1806
1884
|
/**
|
|
1807
1885
|
* The owner's private chat lines (backend/private_chat.py), each run as a turn of its member's own session once the
|
|
1808
1886
|
* member is idle, the reply taken from the software's last remark. A line sent while a chat turn runs goes into it
|