@akagilnc/pi-workflow-roles 0.1.5775 → 0.1.5805

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.
Files changed (49) hide show
  1. package/dist/acp-host/production-host.js +630 -258
  2. package/dist/engine-detour-tool.js +51 -37
  3. package/dist/engine-detour.js +22 -11
  4. package/dist/external-host-turn-loop.js +3 -0
  5. package/dist/headless-host/production-host.js +603 -231
  6. package/dist/migrate-book-topology.js +63 -23
  7. package/dist/pi/role-turn-host.js +6 -1
  8. package/dist/public-cli/instruction-seat-run.js +10 -7
  9. package/dist/public-cli/invocation.js +95 -39
  10. package/dist/public-cli/main.js +357 -147
  11. package/dist/public-cli/post-admission.js +2 -0
  12. package/dist/public-cli/run-lifecycle.js +10 -4
  13. package/dist/public-cli/turn-request.js +3 -0
  14. package/dist/report-ticket-tool.js +3 -3
  15. package/dist/role-run-placement.js +14 -2
  16. package/dist/role-run-relocation.js +2 -2
  17. package/dist/run-dossier.js +5 -4
  18. package/dist/session-identity.js +3 -2
  19. package/dist/sitian-appender.js +12 -3
  20. package/dist/submission-ledger.js +24 -0
  21. package/dist/ticket-progress.js +306 -0
  22. package/dist/user-dialogue-stdin.js +23 -17
  23. package/package.json +1 -1
  24. package/resources/engine-dispatch.md +6 -6
  25. package/resources/engines/agy.md +1 -1
  26. package/src/engine-detour-tool.ts +88 -57
  27. package/src/engine-detour.ts +31 -14
  28. package/src/external-host-turn-loop.ts +7 -1
  29. package/src/host-contracts.ts +8 -1
  30. package/src/pi/adapter.ts +57 -45
  31. package/src/pi/role-turn-host.ts +6 -1
  32. package/src/prepared-role-turn.ts +6 -0
  33. package/src/public-cli/instruction-seat-run.ts +10 -7
  34. package/src/public-cli/invocation.ts +116 -38
  35. package/src/public-cli/post-admission.ts +3 -1
  36. package/src/public-cli/run-lifecycle.ts +10 -8
  37. package/src/public-cli/turn-request.ts +3 -0
  38. package/src/report-ticket-tool.ts +7 -3
  39. package/src/role-envelope.ts +8 -1
  40. package/src/role-run-placement.ts +19 -2
  41. package/src/role-run-relocation.ts +2 -2
  42. package/src/role-runtime.ts +15 -4
  43. package/src/run-dossier.ts +5 -3
  44. package/src/run-terminal-artifacts.ts +0 -1
  45. package/src/session-identity.ts +3 -2
  46. package/src/sitian-appender.ts +14 -3
  47. package/src/submission-ledger.ts +27 -0
  48. package/src/ticket-progress.ts +383 -0
  49. package/src/user-dialogue-stdin.ts +21 -14
@@ -1,7 +1,7 @@
1
1
  import { Type } from "typebox";
2
2
  import {
3
3
  ENGINE_DETOUR_TOOL_NAME,
4
- engineDetourFailureDiagnostic,
4
+ engineDetourFailureSeatText,
5
5
  isEngineDetourFailure,
6
6
  resolveEngineModel,
7
7
  resolveEngineName,
@@ -12,6 +12,7 @@ import {
12
12
  reportEngineDetourCall
13
13
  } from "./engine-detour-usage.js";
14
14
  import { runIdFromRunDirectory } from "./run-terminal-artifacts.js";
15
+ import { serializeThrownValue } from "./serialize-thrown-value.js";
15
16
  const engineDetourArgsSchema = Type.Object(
16
17
  {
17
18
  argv: Type.Array(Type.String({ minLength: 1 }), {
@@ -31,6 +32,27 @@ function isCallerCancellation(error, signal) {
31
32
  function asError(error, fallback) {
32
33
  return error instanceof Error ? error : new Error(String(error).trim() || fallback);
33
34
  }
35
+ function engineFailureResult(input) {
36
+ const details = {
37
+ tool: ENGINE_DETOUR_TOOL_NAME,
38
+ ...input.code === void 0 ? {} : { code: input.code },
39
+ ...input.stdout === void 0 ? {} : { stdout: input.stdout },
40
+ ...input.stderr === void 0 ? {} : { stderr: input.stderr },
41
+ ...input.errorCode === void 0 ? {} : { errorCode: input.errorCode },
42
+ ...input.ledgerError === void 0 ? {} : { ledgerError: input.ledgerError }
43
+ };
44
+ let text = input.text;
45
+ if (input.ledgerError !== void 0 && input.ledgerError.length > 0) {
46
+ if (text.length > 0 && !text.endsWith("\n")) text += "\n";
47
+ text += input.ledgerError;
48
+ }
49
+ return {
50
+ content: [{ type: "text", text }],
51
+ details,
52
+ // Identified detour failure is a tool error, not a seat-run death (#1213).
53
+ isError: true
54
+ };
55
+ }
34
56
  function createEngineDetourToolDefinition(input) {
35
57
  const engineName = input.engineName;
36
58
  const engineModel = input.engineModel;
@@ -44,13 +66,6 @@ function createEngineDetourToolDefinition(input) {
44
66
  async execute(toolCallId, params, signal, _onUpdate, ctx) {
45
67
  const args = params;
46
68
  const argv = Array.isArray(args.argv) ? args.argv : [];
47
- if (argv.length === 0 || argv.some((part) => typeof part !== "string" || part.length === 0)) {
48
- input.fail(
49
- new Error("\u52B3\u52A1\u5F15\u64CE argv \u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\u6570\u7EC4"),
50
- toolCallId,
51
- ctx
52
- );
53
- }
54
69
  const sessionParent = ctx.sessionManager?.getSessionFile?.();
55
70
  const startedAt = Date.now();
56
71
  const runDirectory = typeof ctx.runDirectory === "string" && ctx.runDirectory.length > 0 ? ctx.runDirectory : void 0;
@@ -71,25 +86,21 @@ function createEngineDetourToolDefinition(input) {
71
86
  ...observed2.stdoutByteLength === void 0 ? {} : { stdoutByteLength: observed2.stdoutByteLength }
72
87
  });
73
88
  };
74
- const failAfterLedger = (engineCause, observed2, aggregateMessage) => {
89
+ const recordCallOrLedgerError = (observed2) => {
75
90
  try {
76
91
  recordCall(observed2);
92
+ return void 0;
77
93
  } catch (recordError) {
78
- input.fail(
79
- new AggregateError(
80
- [
81
- engineCause,
82
- asError(recordError, "engine detour usage ledger write failed")
83
- ],
84
- aggregateMessage,
85
- { cause: engineCause }
86
- ),
87
- toolCallId,
88
- ctx
89
- );
94
+ return serializeThrownValue(recordError);
90
95
  }
91
- input.fail(engineCause, toolCallId, ctx);
92
96
  };
97
+ if (argv.length === 0 || argv.some((part) => typeof part !== "string" || part.length === 0)) {
98
+ const ledgerError = recordCallOrLedgerError({});
99
+ return engineFailureResult({
100
+ text: "\u52B3\u52A1\u5F15\u64CE argv \u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\u6570\u7EC4",
101
+ ...ledgerError === void 0 ? {} : { ledgerError }
102
+ });
103
+ }
93
104
  let result;
94
105
  try {
95
106
  result = await runEngineDetourOnce({
@@ -99,20 +110,26 @@ function createEngineDetourToolDefinition(input) {
99
110
  });
100
111
  } catch (error) {
101
112
  if (isCallerCancellation(error, signal)) throw error;
102
- return failAfterLedger(
103
- asError(error, "\u52B3\u52A1\u5F15\u64CE spawn \u5931\u8D25"),
104
- {},
105
- "engine detour spawn and usage ledger both failed"
106
- );
113
+ const engineError = asError(error, "\u52B3\u52A1\u5F15\u64CE spawn \u5931\u8D25");
114
+ const ledgerError = recordCallOrLedgerError({});
115
+ const errno = typeof engineError.code === "string" ? engineError.code : void 0;
116
+ return engineFailureResult({
117
+ text: engineError.message,
118
+ ...errno === void 0 ? {} : { errorCode: errno },
119
+ ...ledgerError === void 0 ? {} : { ledgerError }
120
+ });
107
121
  }
108
122
  const stdoutByteLength = engineDetourStdoutByteLength(result.stdout);
109
123
  const observed = { code: result.code, stdoutByteLength };
110
124
  if (isEngineDetourFailure(result)) {
111
- return failAfterLedger(
112
- new Error(engineDetourFailureDiagnostic(result)),
113
- observed,
114
- "engine detour child-close and usage ledger both failed"
115
- );
125
+ const ledgerError = recordCallOrLedgerError(observed);
126
+ return engineFailureResult({
127
+ text: engineDetourFailureSeatText(result),
128
+ code: result.code,
129
+ stdout: result.stdout,
130
+ stderr: result.stderr,
131
+ ...ledgerError === void 0 ? {} : { ledgerError }
132
+ });
116
133
  }
117
134
  recordCall(observed);
118
135
  return {
@@ -126,7 +143,7 @@ function createEngineDetourToolDefinition(input) {
126
143
  }
127
144
  };
128
145
  }
129
- function registerEngineDetourTool(roleHost, hostActions) {
146
+ function registerEngineDetourTool(roleHost) {
130
147
  const getFlag = (name) => roleHost.getFlag(name);
131
148
  const engineName = resolveEngineName(getFlag);
132
149
  if (engineName === void 0) {
@@ -135,10 +152,7 @@ function registerEngineDetourTool(roleHost, hostActions) {
135
152
  const engineModel = resolveEngineModel(getFlag);
136
153
  const definition = createEngineDetourToolDefinition({
137
154
  engineName,
138
- ...engineModel === void 0 ? {} : { engineModel },
139
- fail(error, toolCallId, ctx) {
140
- hostActions.failInfrastructure(error, ctx, toolCallId);
141
- }
155
+ ...engineModel === void 0 ? {} : { engineModel }
142
156
  });
143
157
  roleHost.registerTool(definition);
144
158
  return true;
@@ -89,18 +89,29 @@ async function runEngineDetourOnce(input) {
89
89
  function isEngineDetourFailure(result) {
90
90
  return result.code !== 0 || result.stdout.trim() === "";
91
91
  }
92
- function engineDetourFailureDiagnostic(result) {
93
- if (result.stderr.trim().length > 0) return result.stderr;
94
- if (result.stdout.trim() === "") return ENGINE_DETOUR_EMPTY_STDOUT_DIAGNOSTIC;
95
- const rows = result.stdout.split("\n");
96
- let lastRow = "";
97
- for (let index = rows.length - 1; index >= 0; index -= 1) {
98
- if (rows[index].trim() !== "") {
99
- lastRow = rows[index];
100
- break;
92
+ function engineDetourFailureSeatText(result) {
93
+ const parts = [];
94
+ if (result.stdout.length > 0) parts.push(result.stdout);
95
+ if (result.stderr.length > 0) parts.push(result.stderr);
96
+ let text = "";
97
+ if (parts.length > 0) {
98
+ text = parts[0];
99
+ for (let index = 1; index < parts.length; index += 1) {
100
+ if (!text.endsWith("\n")) text += "\n";
101
+ text += parts[index];
101
102
  }
102
103
  }
103
- return `\u52B3\u52A1\u5F15\u64CE\u4EE5 code ${result.code} \u9000\u51FA\uFF1A${lastRow}`;
104
+ const append = (line) => {
105
+ if (text.length > 0 && !text.endsWith("\n")) text += "\n";
106
+ text += line;
107
+ };
108
+ if (result.code !== 0) {
109
+ append(`\u52B3\u52A1\u5F15\u64CE\u4EE5 code ${result.code} \u9000\u51FA`);
110
+ }
111
+ if (result.stdout.trim() === "") {
112
+ append(ENGINE_DETOUR_EMPTY_STDOUT_DIAGNOSTIC);
113
+ }
114
+ return text.length > 0 ? text : ENGINE_DETOUR_EMPTY_STDOUT_DIAGNOSTIC;
104
115
  }
105
116
  function engineNameFromEnv() {
106
117
  return normalizeEngineName(
@@ -127,7 +138,7 @@ export {
127
138
  ENGINE_FLAG_NAME,
128
139
  ENGINE_MODEL_FLAG_NAME,
129
140
  applyEngineChildEnv,
130
- engineDetourFailureDiagnostic,
141
+ engineDetourFailureSeatText,
131
142
  engineNameFromEnv,
132
143
  isEngineDetourFailure,
133
144
  normalizeEngineName,
@@ -252,6 +252,9 @@ export async function driveExternalRoleTurnRounds(prepared, request, driver) {
252
252
  }
253
253
  }
254
254
  prompt = closure.retry.message;
255
+ // #1199: same-envelope 催交 / correctable retry — progress instruction is
256
+ // the bytes actually sent this round, not the first-mint summons.
257
+ prepared.recordSentInstruction?.(prompt);
255
258
  driver.afterRetry?.();
256
259
  }
257
260
  }