@akagilnc/pi-workflow-roles 0.1.5375 → 0.1.5406
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/README.zh-CN.md +2 -0
- package/dist/acp-host/production-host.js +6381 -5684
- package/dist/archivist-record-pointer.js +38 -0
- package/dist/collector-tool-schemas.js +18 -0
- package/dist/compliance-transport.js +5 -0
- package/dist/diarist-contracts.js +26 -0
- package/dist/doctor-auditor.js +1 -0
- package/dist/engine-detour-usage.js +6 -6
- package/dist/filed-submission.js +28 -0
- package/dist/gatekeeper-role.js +6 -10
- package/dist/gleaner-left-contracts.js +16 -0
- package/dist/headless-host/production-host.js +1644 -947
- package/dist/judge-role.js +21 -16
- package/dist/migrate-book-topology.js +452 -81
- package/dist/navigator-attendance.js +10 -9
- package/dist/navigator-invocation-identity.js +18 -0
- package/dist/package-contracts/reviewer-output.js +16 -0
- package/dist/package-contracts/worker-output.js +18 -2
- package/dist/pi/role-turn-host.js +9 -0
- package/dist/public-cli/cli.js +1 -0
- package/dist/public-cli/instruction-seat-run.js +258 -55
- package/dist/public-cli/main.js +1209 -346
- package/dist/public-cli/post-admission.js +427 -244
- package/dist/public-cli/settlement.js +111 -48
- package/dist/public-cli/terminal.js +12 -1
- package/dist/public-cli/turn-request.js +3 -0
- package/dist/receipt-delivery-policy.js +152 -17
- package/dist/role-submission-declarations.js +131 -0
- package/dist/secretariat-contracts.js +23 -1
- package/dist/submission-errors.js +11 -1
- package/dist/submission-gate.js +32 -12
- package/package.json +1 -1
- package/src/archivist-record-pointer.ts +48 -0
- package/src/auditor-role.ts +2 -8
- package/src/collector-role.ts +5 -28
- package/src/compliance-transport.ts +10 -2
- package/src/countersign-role.ts +2 -7
- package/src/diarist-contracts.ts +37 -0
- package/src/diarist-role.ts +4 -44
- package/src/doctor-auditor.ts +3 -0
- package/src/doctor-role.ts +16 -11
- package/src/engine-detour-usage.ts +7 -6
- package/src/external-host-turn-loop.ts +24 -12
- package/src/filed-submission.ts +44 -0
- package/src/gatekeeper-role.ts +8 -16
- package/src/gleaner-left-contracts.ts +26 -1
- package/src/gleaner-left-role.ts +4 -32
- package/src/host-contracts.ts +7 -0
- package/src/inspector-role.ts +2 -7
- package/src/judge-role.ts +31 -24
- package/src/merger-role.ts +5 -8
- package/src/navigator-attendance.ts +17 -12
- package/src/navigator-invocation-identity.ts +31 -0
- package/src/navigator-role.ts +2 -8
- package/src/notary-role.ts +5 -20
- package/src/package-contracts/reviewer-output.ts +25 -0
- package/src/package-contracts/worker-output.ts +43 -5
- package/src/pi/adapter.ts +33 -8
- package/src/pi/role-turn-host.ts +7 -0
- package/src/public-cli/cli.ts +1 -0
- package/src/public-cli/instruction-seat-run.ts +292 -61
- package/src/public-cli/post-admission.ts +556 -324
- package/src/public-cli/settlement.ts +112 -50
- package/src/public-cli/terminal.ts +16 -4
- package/src/public-cli/turn-request.ts +10 -1
- package/src/receipt-delivery-policy.ts +209 -17
- package/src/reviewer-role.ts +7 -35
- package/src/role-envelope.ts +5 -1
- package/src/role-runtime-dependencies.ts +1 -0
- package/src/role-runtime.ts +72 -56
- package/src/role-submission-declarations.ts +143 -0
- package/src/secretariat-contracts.ts +35 -0
- package/src/secretariat-role.ts +4 -40
- package/src/submission-correctable-error.ts +5 -2
- package/src/submission-errors.ts +12 -1
- package/src/submission-gate.ts +41 -12
- package/src/worker-role.ts +81 -86
- package/src/worker-submission-gates.ts +32 -7
package/dist/public-cli/main.js
CHANGED
|
@@ -8611,11 +8611,26 @@ var init_judge_output = __esm({
|
|
|
8611
8611
|
});
|
|
8612
8612
|
|
|
8613
8613
|
// src/package-contracts/reviewer-output.ts
|
|
8614
|
-
var REVIEWER_OUTPUT_TOOL_NAME;
|
|
8614
|
+
var REVIEWER_OUTPUT_TOOL_NAME, REVIEWER_AMENDMENTS_DESCRIPTION, REVIEWER_STATUS_DESCRIPTION, reviewerOutputObject, reviewerOutputSchema;
|
|
8615
8615
|
var init_reviewer_output = __esm({
|
|
8616
8616
|
"src/package-contracts/reviewer-output.ts"() {
|
|
8617
8617
|
"use strict";
|
|
8618
|
+
init_build();
|
|
8619
|
+
init_open_tool_schema();
|
|
8620
|
+
init_terminating_infrastructure();
|
|
8618
8621
|
REVIEWER_OUTPUT_TOOL_NAME = "ak_reviewer_output";
|
|
8622
|
+
REVIEWER_AMENDMENTS_DESCRIPTION = "\u5DF2\u8FD0\u884C lens \u7684 amendments \u627F\u8F7D candidates\u3001\u9010\u6761\u5904\u7F6E\u4E0E verdict \u7684\u5B8C\u6574\u62A5\u544A\uFF08\u975E\u4EC5 verdict \u884C\uFF09\uFF1B\u663E\u5F0F\u5355\u8F74\u65F6\u53E6\u4E00\u8F74\u53EF\u7701\u7565\uFF08completeness / correctness\uFF09\u3002hard-stop\uFF0Fusage error \u4E3A refused \u65F6\uFF0C\u5DF2\u4EA7\u51FA\u62A5\u544A\u4ECD\u7167\u5F55\u5BF9\u5E94 lens \u5B57\u6BB5\u3002";
|
|
8623
|
+
REVIEWER_STATUS_DESCRIPTION = "completed | refused\u3002\u4E24\u79CD\u6B63\u5E38 lens verdict\uFF08completeness / correctness\uFF09\u5747 completed\uFF1Bhard-stop \u4E0E usage error \u4E3A refused\uFF08\u5DF2\u4EA7\u51FA\u62A5\u544A\u4ECD\u7167\u5F55\u8FDB\u6240\u9009 lens amendments\uFF09\u3002";
|
|
8624
|
+
reviewerOutputObject = typebox_exports.Object({
|
|
8625
|
+
status: typebox_exports.Unknown({ description: REVIEWER_STATUS_DESCRIPTION }),
|
|
8626
|
+
amendments: typebox_exports.Unknown({ description: REVIEWER_AMENDMENTS_DESCRIPTION }),
|
|
8627
|
+
diagnostic: typebox_exports.Unknown({
|
|
8628
|
+
description: "\u62D2\u7EDD\u8BCA\u65AD\u8BF4\u660E\uFF1Bhard-stop\uFF0Fusage error \u539F\u56E0\u8FDB\u6B64\u5B57\u6BB5\uFF0C\u5DF2\u4EA7\u51FA\u62A5\u544A\u53E6\u7167\u5F55 amendments"
|
|
8629
|
+
})
|
|
8630
|
+
});
|
|
8631
|
+
reviewerOutputSchema = withTerminatingOutputDeclarations(
|
|
8632
|
+
openToolObject(reviewerOutputObject)
|
|
8633
|
+
);
|
|
8619
8634
|
}
|
|
8620
8635
|
});
|
|
8621
8636
|
|
|
@@ -14644,14 +14659,28 @@ var init_fixer_packet = __esm({
|
|
|
14644
14659
|
});
|
|
14645
14660
|
|
|
14646
14661
|
// src/package-contracts/worker-output.ts
|
|
14647
|
-
var CODER_OUTPUT_TOOL_NAME;
|
|
14662
|
+
var CODER_OUTPUT_TOOL_NAME, CODER_STATUS_DESCRIPTION, coderOutputObject, coderOutputSchema;
|
|
14648
14663
|
var init_worker_output = __esm({
|
|
14649
14664
|
"src/package-contracts/worker-output.ts"() {
|
|
14650
14665
|
"use strict";
|
|
14666
|
+
init_build();
|
|
14667
|
+
init_open_tool_schema();
|
|
14651
14668
|
init_fixer_output();
|
|
14652
14669
|
init_fixer_packet();
|
|
14653
|
-
|
|
14670
|
+
init_terminating_infrastructure();
|
|
14654
14671
|
CODER_OUTPUT_TOOL_NAME = "ak_coder_output";
|
|
14672
|
+
CODER_STATUS_DESCRIPTION = `planned | completed | refused | partially_completed | unfinished\u3002unfinished\uFF1A\u7F3A\u524D\u7F6E\u6216\u8FDD\u5BAA\u7EA6\u675F\u81F4\u672C\u5C40\u672A\u5B8C\u6210\u3002${PARTIALLY_COMPLETED_DEFINITION}`;
|
|
14673
|
+
coderOutputObject = typebox_exports.Object({
|
|
14674
|
+
status: typebox_exports.Unknown({ description: CODER_STATUS_DESCRIPTION }),
|
|
14675
|
+
report: typebox_exports.Unknown({ description: "\u5982\u5B9E\u7ED3\u679C\u62A5\u544A" }),
|
|
14676
|
+
remainingScope: typebox_exports.Unknown({ description: "\u672C\u5C40\u540E\u5269\u4F59\u5DE5\u4F5C" }),
|
|
14677
|
+
reason: typebox_exports.Unknown({
|
|
14678
|
+
description: "\u963B\u65AD\u539F\u56E0\uFF1A\u7F3A\u524D\u7F6E\u6216\u8FDD\u5BAA\u7EA6\u675F\u3002\u7F3A\u5F85\u51B3 owner \u51B3\u5B9A\u6216\u7B54\u590D\u5C5E\u7F3A\u524D\u7F6E\u3002"
|
|
14679
|
+
})
|
|
14680
|
+
});
|
|
14681
|
+
coderOutputSchema = withTerminatingOutputDeclarations(
|
|
14682
|
+
openToolObject(coderOutputObject)
|
|
14683
|
+
);
|
|
14655
14684
|
}
|
|
14656
14685
|
});
|
|
14657
14686
|
|
|
@@ -14663,7 +14692,7 @@ var init_canonical_json = __esm({
|
|
|
14663
14692
|
});
|
|
14664
14693
|
|
|
14665
14694
|
// src/doctor-contracts.ts
|
|
14666
|
-
var DOCTOR_OUTPUT_TOOL_NAME, DOCTOR_AUDIT_TOOL_NAME, DOCTOR_TARGET_KINDS, DOCTOR_DISPOSITIONS, DOCTOR_PRESCRIPTION_KINDS, biteActual, biteNone, DOCTOR_BITE_KINDS, DOCTOR_STATUS_DESCRIPTION, doctorSubmissionObject, doctorSubmissionSchema, doctorEvidenceReadSchema;
|
|
14695
|
+
var DOCTOR_OUTPUT_TOOL_NAME, DOCTOR_AUDIT_TOOL_NAME, DOCTOR_OUTPUT_TOOL_DESCRIPTION, DOCTOR_TARGET_KINDS, DOCTOR_DISPOSITIONS, DOCTOR_PRESCRIPTION_KINDS, biteActual, biteNone, DOCTOR_BITE_KINDS, DOCTOR_STATUS_DESCRIPTION, doctorSubmissionObject, doctorSubmissionSchema, doctorEvidenceReadSchema;
|
|
14667
14696
|
var init_doctor_contracts = __esm({
|
|
14668
14697
|
"src/doctor-contracts.ts"() {
|
|
14669
14698
|
"use strict";
|
|
@@ -14674,6 +14703,7 @@ var init_doctor_contracts = __esm({
|
|
|
14674
14703
|
init_unknown_value();
|
|
14675
14704
|
DOCTOR_OUTPUT_TOOL_NAME = "ak_doctor_output";
|
|
14676
14705
|
DOCTOR_AUDIT_TOOL_NAME = "ak_doctor_audit_decision";
|
|
14706
|
+
DOCTOR_OUTPUT_TOOL_DESCRIPTION = "\u63D0\u4EA4\u552F\u4E00\u7EC8\u5C40\u5355\u6848\u8BC1\u8BCD\uFF1Bcompleted \u5141\u8BB8\u7A7A findings\u3002";
|
|
14677
14707
|
DOCTOR_TARGET_KINDS = ["law", "gate", "template", "station", "seat"];
|
|
14678
14708
|
DOCTOR_DISPOSITIONS = ["keep", "thin", "delete"];
|
|
14679
14709
|
DOCTOR_PRESCRIPTION_KINDS = ["retain", "delete", "simplify", "patch", "addMechanism"];
|
|
@@ -14811,12 +14841,27 @@ var init_countersign_contracts = __esm({
|
|
|
14811
14841
|
});
|
|
14812
14842
|
|
|
14813
14843
|
// src/gleaner-left-contracts.ts
|
|
14814
|
-
var GLEANER_LEFT_OUTPUT_TOOL_NAME;
|
|
14844
|
+
var GLEANER_LEFT_OUTPUT_TOOL_NAME, gleanerLeftOutputSchema;
|
|
14815
14845
|
var init_gleaner_left_contracts = __esm({
|
|
14816
14846
|
"src/gleaner-left-contracts.ts"() {
|
|
14817
14847
|
"use strict";
|
|
14848
|
+
init_build();
|
|
14849
|
+
init_open_tool_schema();
|
|
14850
|
+
init_terminating_infrastructure();
|
|
14818
14851
|
init_unknown_value();
|
|
14819
14852
|
GLEANER_LEFT_OUTPUT_TOOL_NAME = "ak_gleaner_left_output";
|
|
14853
|
+
gleanerLeftOutputSchema = withTerminatingOutputDeclarations(
|
|
14854
|
+
openToolObject(
|
|
14855
|
+
typebox_exports.Object({
|
|
14856
|
+
status: typebox_exports.Unknown({
|
|
14857
|
+
description: "completed"
|
|
14858
|
+
}),
|
|
14859
|
+
findings: typebox_exports.Unknown({
|
|
14860
|
+
description: "\u5F39\u7AE0\u5217\u8868\uFF1B\u6BCF\u6761\u53EF\u542B pointer\uFF08\u6587\u4EF6/\u884C\u6307\u9488\uFF09\u4E0E statement\uFF08\u7591\u70B9\u9648\u8FF0\uFF09\uFF0C\u539F\u6837\u7559\u5B58\u3002\u7A7A\u5217\u8868\u5408\u6CD5\u5B8C\u5C40\uFF1B\u673A\u5668\u4E0D\u5224\u5F39\u7AE0\u662F\u5426\u6210\u7ACB\u3002"
|
|
14861
|
+
})
|
|
14862
|
+
})
|
|
14863
|
+
)
|
|
14864
|
+
);
|
|
14820
14865
|
}
|
|
14821
14866
|
});
|
|
14822
14867
|
|
|
@@ -14853,23 +14898,69 @@ var init_ticket_provenance_contracts = __esm({
|
|
|
14853
14898
|
});
|
|
14854
14899
|
|
|
14855
14900
|
// src/diarist-contracts.ts
|
|
14856
|
-
var DIARIST_OUTPUT_TOOL_NAME;
|
|
14901
|
+
var DIARIST_OUTPUT_TOOL_NAME, DIARIST_SESSIONS_DESCRIPTION, diaristOutputSchema;
|
|
14857
14902
|
var init_diarist_contracts = __esm({
|
|
14858
14903
|
"src/diarist-contracts.ts"() {
|
|
14859
14904
|
"use strict";
|
|
14905
|
+
init_build();
|
|
14906
|
+
init_open_tool_schema();
|
|
14907
|
+
init_terminating_infrastructure();
|
|
14860
14908
|
init_ticket_provenance_contracts();
|
|
14861
14909
|
init_run_ticket_number();
|
|
14862
14910
|
init_unknown_value();
|
|
14863
14911
|
DIARIST_OUTPUT_TOOL_NAME = "ak_diarist_output";
|
|
14912
|
+
DIARIST_SESSIONS_DESCRIPTION = "\u5BF9\u8BDD\u8FB9\u754C\u3002\u6BCF\u5377\u542B path\uFF08\u4F1A\u8BDD\u5377\u7EDD\u5BF9\u6216\u53EF\u8BFB\u8DEF\u5F84\uFF09\u4E0E ranges\uFF08\u672C\u5377\u672C\u8F6E\u5404\u533A\u95F4\uFF09\u3002\u6BCF\u6BB5\u533A\u95F4\u542B from / to\uFF1B\u8D77\u70B9\u4E0E\u7EC8\u70B9\u5404\u5199 id\uFF08\u539F\u751F id\uFF09\u6216 line\uFF08\u672C\u8F6E\u884C\u53F7\uFF09\uFF0C\u4E8C\u9009\u4E00\u3002\u7A7A\u5217\u8868\uFF1D\u672C\u8F6E\u65E0\u5BF9\u8BDD\u53EF\u5212\u3002\u7AEF\u70B9\u65E0\u6CD5\u6307\u540D\u65F6\u8D70 reask\uFF0C\u4E0D\u4E2D\u6B62\u3002";
|
|
14913
|
+
diaristOutputSchema = withTerminatingOutputDeclarations(
|
|
14914
|
+
openToolObject(
|
|
14915
|
+
typebox_exports.Object({
|
|
14916
|
+
status: typebox_exports.Unknown({
|
|
14917
|
+
description: "completed | escalate"
|
|
14918
|
+
}),
|
|
14919
|
+
ticketNumber: typebox_exports.Optional(
|
|
14920
|
+
typebox_exports.Unknown({
|
|
14921
|
+
description: "\u672C\u5EAD\u5BF9\u8C61\u7968\u53F7\uFF08\u6B63\u6574\u6570\uFF09\u6216 null/\u7701\u7565\uFF1D\u771F\u65E0\u7968\uFF1B\u4E0B\u6E38\u8D70 typed \u952E\uFF1B\u8BA4\u4E0D\u51FA\u7528 status=escalate\uFF0C\u4E0D\u6D17\u6210\u65E0\u5F55\u3002\u673A\u68B0\u5C42\u4E0D\u91CD\u5224\u3002"
|
|
14922
|
+
})
|
|
14923
|
+
),
|
|
14924
|
+
reason: typebox_exports.Unknown({
|
|
14925
|
+
description: "status \u4E3A escalate \u65F6\uFF1A\u8BA4\u4E0D\u51FA\u672C\u5EAD\u5BF9\u8C61\u7684\u539F\u56E0"
|
|
14926
|
+
}),
|
|
14927
|
+
sessions: typebox_exports.Optional(typebox_exports.Unknown({ description: DIARIST_SESSIONS_DESCRIPTION })),
|
|
14928
|
+
ticketSessions: typebox_exports.Unknown({
|
|
14929
|
+
description: `\u591A\u7968\u5EAD\u9010\u7968\u5BF9\u8BDD\u8FB9\u754C\uFF1B\u6BCF\u7968\u542B ticketNumber\uFF08\u672C\u6761\u8FB9\u754C\u6240\u5F52\u7968\u53F7\uFF0C\u6B63\u6574\u6570\uFF09\u4E0E sessions\uFF08${DIARIST_SESSIONS_DESCRIPTION}\uFF09\u3002\u4E00\u6B21\u4EA4\u5377\u5404\u7968\u5404\u81EA\u5206\u5F55\u3002\u4E0E\u5355\u7968 sessions \u4E8C\u9009\u4E00\u3002`
|
|
14930
|
+
})
|
|
14931
|
+
})
|
|
14932
|
+
)
|
|
14933
|
+
);
|
|
14864
14934
|
}
|
|
14865
14935
|
});
|
|
14866
14936
|
|
|
14867
14937
|
// src/secretariat-contracts.ts
|
|
14868
|
-
var SECRETARIAT_OUTPUT_TOOL_NAME, SECRETARIAT_GATE_OFFICER_ENTRY_TYPE, SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY;
|
|
14938
|
+
var SECRETARIAT_OUTPUT_TOOL_NAME, secretariatVerdictSchema, SECRETARIAT_GATE_OFFICER_ENTRY_TYPE, SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY;
|
|
14869
14939
|
var init_secretariat_contracts = __esm({
|
|
14870
14940
|
"src/secretariat-contracts.ts"() {
|
|
14871
14941
|
"use strict";
|
|
14942
|
+
init_build();
|
|
14943
|
+
init_terminating_infrastructure();
|
|
14872
14944
|
SECRETARIAT_OUTPUT_TOOL_NAME = "ak_secretariat_output";
|
|
14945
|
+
secretariatVerdictSchema = withTerminatingOutputDeclarations(
|
|
14946
|
+
typebox_exports.Object(
|
|
14947
|
+
{
|
|
14948
|
+
secretariatStatus: typebox_exports.Unknown({
|
|
14949
|
+
description: "converged | escalate"
|
|
14950
|
+
}),
|
|
14951
|
+
ticketNumber: typebox_exports.Optional(
|
|
14952
|
+
typebox_exports.Unknown({ description: "\u672C\u7968\u53F7\uFF1B\u7F72\u65F6\u6307\u5411\u6700\u7EC8\u6B63\u6587\u6240\u5728\u7968" })
|
|
14953
|
+
),
|
|
14954
|
+
note: typebox_exports.Unknown({ description: "\u9644\u6CE8" }),
|
|
14955
|
+
evidence: typebox_exports.Optional(typebox_exports.Unknown({ description: "\u7559\u5B58\u8BC1\u636E" })),
|
|
14956
|
+
decisionGate: typebox_exports.Unknown({
|
|
14957
|
+
description: "\u9700\u965B\u4E0B\u5904\u7F6E\u7684\u95EE\u9898\u4E0E\u9009\u9879\uFF1B\u53EF\u5199 question \u4E0E options\uFF0C\u539F\u6837\u7559\u5B58\u3002"
|
|
14958
|
+
})
|
|
14959
|
+
},
|
|
14960
|
+
{ additionalProperties: true }
|
|
14961
|
+
)
|
|
14962
|
+
);
|
|
14963
|
+
secretariatVerdictSchema.required = [];
|
|
14873
14964
|
SECRETARIAT_GATE_OFFICER_ENTRY_TYPE = "ak-secretariat-gate-officer";
|
|
14874
14965
|
SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY = "countersignTerminal";
|
|
14875
14966
|
}
|
|
@@ -16866,6 +16957,161 @@ var init_submission_errors = __esm({
|
|
|
16866
16957
|
}
|
|
16867
16958
|
});
|
|
16868
16959
|
|
|
16960
|
+
// src/collector-tool-schemas.ts
|
|
16961
|
+
var collectorOutputBaseSchema, collectorOutputArgsSchema;
|
|
16962
|
+
var init_collector_tool_schemas = __esm({
|
|
16963
|
+
"src/collector-tool-schemas.ts"() {
|
|
16964
|
+
"use strict";
|
|
16965
|
+
init_build();
|
|
16966
|
+
init_open_tool_schema();
|
|
16967
|
+
init_terminating_infrastructure();
|
|
16968
|
+
collectorOutputBaseSchema = openToolObject(
|
|
16969
|
+
typebox_exports.Object({
|
|
16970
|
+
groups: typebox_exports.Unsafe({
|
|
16971
|
+
description: "\u6309\u673A\u5668\u8EAB\u4EFD\u5F52\u7EC4\u7684\u51FA\u5E2D\u3001\u6750\u6599\u4E0E\u9010\u6761 findings\uFF08LLM \u81EA\u884C\u4ECE\u5BBF\u4E3B CLI \u53D6\u8BC1\u6574\u7406\uFF1B\u4EE3\u7801\u4E0D\u4EE3\u6536\u4E0D\u5F52\u5E76\uFF09\u3002"
|
|
16972
|
+
}),
|
|
16973
|
+
unfinishedReasons: typebox_exports.Unknown({
|
|
16974
|
+
description: "\u672A\u5B8C\u6210\u539F\u56E0\uFF1B\u53D6\u8BC1\u53D7\u9650\u65F6\u5982\u5B9E\u62A5\u544A\u3002"
|
|
16975
|
+
})
|
|
16976
|
+
})
|
|
16977
|
+
);
|
|
16978
|
+
collectorOutputArgsSchema = withTerminatingOutputDeclarations(
|
|
16979
|
+
collectorOutputBaseSchema
|
|
16980
|
+
);
|
|
16981
|
+
}
|
|
16982
|
+
});
|
|
16983
|
+
|
|
16984
|
+
// src/role-submission-declarations.ts
|
|
16985
|
+
function roleSubmissionDeclaration(role) {
|
|
16986
|
+
const name = packagedRoleOutputTool(role);
|
|
16987
|
+
if (name === void 0) throw new Error(`${role} output tool is not declared`);
|
|
16988
|
+
const face = SUBMISSION_FACE[role];
|
|
16989
|
+
return {
|
|
16990
|
+
role,
|
|
16991
|
+
name,
|
|
16992
|
+
label: face.label,
|
|
16993
|
+
description: face.description,
|
|
16994
|
+
..."promptSnippet" in face ? { promptSnippet: face.promptSnippet } : {},
|
|
16995
|
+
parameters: face.parameters
|
|
16996
|
+
};
|
|
16997
|
+
}
|
|
16998
|
+
var SUBMISSION_FACE;
|
|
16999
|
+
var init_role_submission_declarations = __esm({
|
|
17000
|
+
"src/role-submission-declarations.ts"() {
|
|
17001
|
+
"use strict";
|
|
17002
|
+
init_packaged_role_registry();
|
|
17003
|
+
init_review_submission();
|
|
17004
|
+
init_collector_tool_schemas();
|
|
17005
|
+
init_diarist_contracts();
|
|
17006
|
+
init_doctor_contracts();
|
|
17007
|
+
init_fixer_output();
|
|
17008
|
+
init_gatekeeper_output();
|
|
17009
|
+
init_gleaner_left_contracts();
|
|
17010
|
+
init_merger_contracts();
|
|
17011
|
+
init_navigator_output();
|
|
17012
|
+
init_reviewer_output();
|
|
17013
|
+
init_secretariat_contracts();
|
|
17014
|
+
init_worker_output();
|
|
17015
|
+
SUBMISSION_FACE = {
|
|
17016
|
+
judge: {
|
|
17017
|
+
label: "\u5927\u7406\u5BFA\u8F93\u51FA",
|
|
17018
|
+
description: "\u63D0\u4EA4\u5927\u7406\u5BFA\u7EC8\u5C40\u5224\u8BCD\uFF1B\u4EA4\u5377\u8C03\u7528\u7ED3\u675F\u540E\uFF0C\u7531\u516C\u5F00\u8C03\u7528\u63A5\u7F1D\u6309\u5224\u8BCD\u72B6\u6001\u6267\u884C\u9002\u7528\u5BA1\u6838\u3002",
|
|
17019
|
+
promptSnippet: "\u63D0\u4EA4\u5927\u7406\u5BFA\u7EC8\u5C40\u5224\u8BCD",
|
|
17020
|
+
parameters: reviewSubmissionSchema
|
|
17021
|
+
},
|
|
17022
|
+
fixer: {
|
|
17023
|
+
label: "\u4FEE\u5185\u53F8\u8F93\u51FA",
|
|
17024
|
+
description: "\u63D0\u4EA4\u4FEE\u5185\u53F8\u7EC8\u5C40\u56DE\u6267\u3002",
|
|
17025
|
+
promptSnippet: "\u63D0\u4EA4\u4FEE\u5185\u53F8\u7EC8\u5C40\u56DE\u6267",
|
|
17026
|
+
parameters: fixerOutputSchema
|
|
17027
|
+
},
|
|
17028
|
+
coder: {
|
|
17029
|
+
label: "\u5C06\u4F5C\u76D1\u8F93\u51FA",
|
|
17030
|
+
description: "\u63D0\u4EA4\u5C06\u4F5C\u76D1\u7EC8\u5C40\u56DE\u6267\u3002",
|
|
17031
|
+
promptSnippet: "\u63D0\u4EA4\u5C06\u4F5C\u76D1\u7EC8\u5C40\u56DE\u6267",
|
|
17032
|
+
parameters: coderOutputSchema
|
|
17033
|
+
},
|
|
17034
|
+
reviewer: {
|
|
17035
|
+
label: "\u5FA1\u53F2\u53F0\u8F93\u51FA",
|
|
17036
|
+
description: "\u63D0\u4EA4\u5FA1\u53F2\u53F0\u7EC8\u5C40\u56DE\u6267\u3002",
|
|
17037
|
+
promptSnippet: "\u63D0\u4EA4\u5FA1\u53F2\u53F0\u7EC8\u5C40\u56DE\u6267",
|
|
17038
|
+
parameters: reviewerOutputSchema
|
|
17039
|
+
},
|
|
17040
|
+
collector: {
|
|
17041
|
+
label: "\u901A\u8FDB\u53F8\u8F93\u51FA",
|
|
17042
|
+
description: "\u63D0\u4EA4\u901A\u8FDB\u53F8\u56DE\u6267\u3002",
|
|
17043
|
+
promptSnippet: "\u63D0\u4EA4\u901A\u8FDB\u53F8\u56DE\u6267",
|
|
17044
|
+
parameters: collectorOutputArgsSchema
|
|
17045
|
+
},
|
|
17046
|
+
doctor: {
|
|
17047
|
+
label: "\u592A\u533B\u7F72\u8F93\u51FA",
|
|
17048
|
+
description: DOCTOR_OUTPUT_TOOL_DESCRIPTION,
|
|
17049
|
+
parameters: doctorSubmissionSchema
|
|
17050
|
+
},
|
|
17051
|
+
merger: {
|
|
17052
|
+
label: "\u5408\u5E76\u8F93\u51FA",
|
|
17053
|
+
description: "\u63D0\u4EA4\u5408\u5E76\u7ED3\u679C\uFF1B\u8F93\u51FA\u5206\u652F\u4E3A completed \u4E0E escalate\u3002",
|
|
17054
|
+
promptSnippet: "\u63D0\u4EA4\u5408\u5E76\u7ED3\u679C",
|
|
17055
|
+
parameters: mergerOutputSchema
|
|
17056
|
+
},
|
|
17057
|
+
notary: {
|
|
17058
|
+
label: "\u7B26\u5B9D\u90CE\u8F93\u51FA",
|
|
17059
|
+
description: "\u63D0\u4EA4\u5F15\u6587\u4FDD\u771F\u4E0E\u7968\u9762\u5BF9\u9F50\u7684 converged/continue/escalate \u51B3\u8BAE\u3002",
|
|
17060
|
+
promptSnippet: "\u63D0\u4EA4\u7B26\u5B9D\u90CE\u51B3\u8BAE",
|
|
17061
|
+
parameters: reviewSubmissionSchema
|
|
17062
|
+
},
|
|
17063
|
+
countersign: {
|
|
17064
|
+
label: "\u7ED9\u4E8B\u4E2D\u8F93\u51FA",
|
|
17065
|
+
description: "\u7ED9\u4E8B\u4E2D\u51B3\u8BAE\u3002",
|
|
17066
|
+
promptSnippet: "\u7ED9\u4E8B\u4E2D\u51B3\u8BAE",
|
|
17067
|
+
parameters: reviewSubmissionSchema
|
|
17068
|
+
},
|
|
17069
|
+
secretariat: {
|
|
17070
|
+
label: "\u4E2D\u4E66\u7701\u8F93\u51FA",
|
|
17071
|
+
description: "\u4E2D\u4E66\u7701\u7EC8\u5C40\u56DE\u6267\u3002",
|
|
17072
|
+
promptSnippet: "\u4E2D\u4E66\u7701\u7EC8\u5C40\u56DE\u6267",
|
|
17073
|
+
parameters: secretariatVerdictSchema
|
|
17074
|
+
},
|
|
17075
|
+
"gleaner-left": {
|
|
17076
|
+
label: "\u5DE6\u62FE\u9057\u8F93\u51FA",
|
|
17077
|
+
description: "\u5DE6\u62FE\u9057\u5F39\u7AE0\u3002",
|
|
17078
|
+
promptSnippet: "\u5DE6\u62FE\u9057\u5F39\u7AE0",
|
|
17079
|
+
parameters: gleanerLeftOutputSchema
|
|
17080
|
+
},
|
|
17081
|
+
inspector: {
|
|
17082
|
+
label: "\u53F0\u9662\u8F93\u51FA",
|
|
17083
|
+
description: "\u53F0\u9662\u7EC8\u5C40\u56DE\u6267\uFF0C\u72B6\u6001\u4E3A converged\u3001continue \u6216 escalate\u3002",
|
|
17084
|
+
promptSnippet: "\u53F0\u9662\u7EC8\u5C40\u56DE\u6267",
|
|
17085
|
+
parameters: reviewSubmissionSchema
|
|
17086
|
+
},
|
|
17087
|
+
gatekeeper: {
|
|
17088
|
+
label: "\u95E8\u4E0B\u7701\u51B3\u8BAE",
|
|
17089
|
+
description: "\u95E8\u4E0B\u7701\u7EC8\u5C40\u51B3\u8BAE\u3002status \u4E3A dispatch \u6216 pass\u3002",
|
|
17090
|
+
promptSnippet: "\u95E8\u4E0B\u7701\u51B3\u8BAE",
|
|
17091
|
+
parameters: gatekeeperOutputSchema
|
|
17092
|
+
},
|
|
17093
|
+
navigator: {
|
|
17094
|
+
label: "\u6E38\u5955\u4F7F\u5EFA\u8BAE",
|
|
17095
|
+
description: "\u6E38\u5955\u4F7F\u7EC8\u5C40\u56DE\u6267\uFF1A\u6563\u6587\u5EFA\u8BAE\uFF0C\u539F\u6837\u5448\u73B0\u3002",
|
|
17096
|
+
promptSnippet: "\u6E38\u5955\u4F7F\u5EFA\u8BAE",
|
|
17097
|
+
parameters: navigatorOutputSchema
|
|
17098
|
+
},
|
|
17099
|
+
auditor: {
|
|
17100
|
+
label: "\u5BA1\u5211\u9662\u8F93\u51FA",
|
|
17101
|
+
description: "\u5BA1\u5211\u9662\u7EC8\u5C40\u56DE\u6267\uFF0Cstatus \u4E3A converged\u3001continue \u6216 escalate\u3002",
|
|
17102
|
+
promptSnippet: "\u5BA1\u5211\u9662\u7EC8\u5C40\u56DE\u6267",
|
|
17103
|
+
parameters: reviewSubmissionSchema
|
|
17104
|
+
},
|
|
17105
|
+
diarist: {
|
|
17106
|
+
label: "\u8D77\u5C45\u90CE\u8F93\u51FA",
|
|
17107
|
+
description: "\u8D77\u5C45\u90CE\u4EA4\u5355\u7968 sessions \u6216\u591A\u7968\u9010\u7968 ticketSessions \u8FB9\u754C\uFF1B\u8BA4\u4E0D\u51FA\u672C\u5EAD\u5BF9\u8C61\u5219 escalate\u3002",
|
|
17108
|
+
promptSnippet: "\u8D77\u5C45\u90CE\u4EA4\u8FB9\u754C",
|
|
17109
|
+
parameters: diaristOutputSchema
|
|
17110
|
+
}
|
|
17111
|
+
};
|
|
17112
|
+
}
|
|
17113
|
+
});
|
|
17114
|
+
|
|
16869
17115
|
// src/run-terminal-artifacts.ts
|
|
16870
17116
|
var run_terminal_artifacts_exports = {};
|
|
16871
17117
|
__export(run_terminal_artifacts_exports, {
|
|
@@ -17052,7 +17298,7 @@ function reviewQueueStatus(status) {
|
|
|
17052
17298
|
function projectOfficerDecision(officer, decision, fallbackStatus) {
|
|
17053
17299
|
const receipt = retainedReceipt(decision);
|
|
17054
17300
|
const record = isRecord(decision) ? decision : void 0;
|
|
17055
|
-
const status =
|
|
17301
|
+
const status = record !== void 0 && Object.hasOwn(record, "status") ? receivedDiscriminator(record, "status") : fallbackStatus;
|
|
17056
17302
|
const queueStatus = typeof status === "string" ? reviewQueueStatus(status) : void 0;
|
|
17057
17303
|
if (queueStatus === "converged") {
|
|
17058
17304
|
return { status: "converged", officer, receipt };
|
|
@@ -17195,7 +17441,7 @@ async function projectGatekeeperRun(options) {
|
|
|
17195
17441
|
summoned
|
|
17196
17442
|
};
|
|
17197
17443
|
}
|
|
17198
|
-
var GATE_OFFICER_BY_SUBJECT;
|
|
17444
|
+
var GATE_OFFICER_BY_SUBJECT, GATEKEEPER_TOOL_SPEC;
|
|
17199
17445
|
var init_gatekeeper_role = __esm({
|
|
17200
17446
|
"src/gatekeeper-role.ts"() {
|
|
17201
17447
|
"use strict";
|
|
@@ -17205,6 +17451,7 @@ var init_gatekeeper_role = __esm({
|
|
|
17205
17451
|
init_inspector_contracts();
|
|
17206
17452
|
init_review_submission();
|
|
17207
17453
|
init_gatekeeper_output();
|
|
17454
|
+
init_role_submission_declarations();
|
|
17208
17455
|
init_run_terminal_artifacts();
|
|
17209
17456
|
init_unknown_value();
|
|
17210
17457
|
init_submission_errors();
|
|
@@ -17215,6 +17462,7 @@ var init_gatekeeper_role = __esm({
|
|
|
17215
17462
|
countersign_verdict: "notary",
|
|
17216
17463
|
secretariat_verdict: "countersign"
|
|
17217
17464
|
};
|
|
17465
|
+
GATEKEEPER_TOOL_SPEC = roleSubmissionDeclaration("gatekeeper");
|
|
17218
17466
|
}
|
|
17219
17467
|
});
|
|
17220
17468
|
|
|
@@ -17252,6 +17500,13 @@ function formatTerminalResult(result) {
|
|
|
17252
17500
|
`diagnostic ${encodeTerminalField(result.roleOutcome.diagnostic)}`
|
|
17253
17501
|
);
|
|
17254
17502
|
}
|
|
17503
|
+
if (result.roleOutcome.kind === "accepted" && result.roleOutcome.decisiveFacts?.directionUnsettled === true) {
|
|
17504
|
+
lines.push("fact directionUnsettled true");
|
|
17505
|
+
const subsequent = result.roleOutcome.decisiveFacts.subsequentAudit;
|
|
17506
|
+
if (typeof subsequent === "string") {
|
|
17507
|
+
lines.push(`fact subsequentAudit ${encodeTerminalField(subsequent)}`);
|
|
17508
|
+
}
|
|
17509
|
+
}
|
|
17255
17510
|
if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation" || result.roleOutcome.decisiveFacts?.failedAttempts !== void 0) {
|
|
17256
17511
|
const facts = result.roleOutcome.kind === "accepted" ? { failedAttempts: result.roleOutcome.decisiveFacts?.failedAttempts } : result.roleOutcome.decisiveFacts ?? {};
|
|
17257
17512
|
for (const [key, value] of Object.entries(facts)) {
|
|
@@ -17310,7 +17565,7 @@ function formatTerminalResult(result) {
|
|
|
17310
17565
|
lines.push(`recorded-submission ${encodeTerminalField(rendered)}`);
|
|
17311
17566
|
}
|
|
17312
17567
|
} else {
|
|
17313
|
-
const payloads = result.roleOutcome.kind === "accepted" || result.roleOutcome.kind === "audit_escalation" ? coalesceSubmissionRows(result.
|
|
17568
|
+
const payloads = result.roleOutcome.kind === "accepted" || result.roleOutcome.kind === "audit_escalation" ? coalesceSubmissionRows(result.submissions, result.roleOutcome.payloads) : result.submissions ?? [];
|
|
17314
17569
|
for (let i = payloads.length - 1; i >= 0; i -= 1) {
|
|
17315
17570
|
const payload = payloads[i];
|
|
17316
17571
|
const rendered = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
@@ -17326,6 +17581,223 @@ var init_terminal = __esm({
|
|
|
17326
17581
|
}
|
|
17327
17582
|
});
|
|
17328
17583
|
|
|
17584
|
+
// src/receipt-delivery-policy.ts
|
|
17585
|
+
function receiptAttemptPointer(runPointer, invocationScopeId) {
|
|
17586
|
+
const scope = invocationScopeId?.trim() ?? "";
|
|
17587
|
+
if (scope.length > 0) return `invocation:${scope}`;
|
|
17588
|
+
return `current:${runPointer}`;
|
|
17589
|
+
}
|
|
17590
|
+
function deliveryLimitFromConfig(value) {
|
|
17591
|
+
return parseAutoResumeLimit(value ?? AUTO_RESUME_LIMIT);
|
|
17592
|
+
}
|
|
17593
|
+
function deliveryTurnsFact(value) {
|
|
17594
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
17595
|
+
throw new TypeError("deliveryTurns must be a non-negative integer");
|
|
17596
|
+
}
|
|
17597
|
+
return value;
|
|
17598
|
+
}
|
|
17599
|
+
function parseNoReceiptLifecycleFacts(input) {
|
|
17600
|
+
if (!isRecord(input) || typeof input.terminalToolCalled !== "boolean" || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord(item) && typeof item.reason === "string")) {
|
|
17601
|
+
throw new TypeError("malformed no-receipt lifecycle facts");
|
|
17602
|
+
}
|
|
17603
|
+
return {
|
|
17604
|
+
terminalToolCalled: input.terminalToolCalled,
|
|
17605
|
+
rejectedReceipts: input.rejectedReceipts.map((item) => ({
|
|
17606
|
+
reason: item.reason,
|
|
17607
|
+
diagnosticAvailable: item.reason.trim() !== ""
|
|
17608
|
+
})),
|
|
17609
|
+
deliveryTurns: deliveryTurnsFact(input.deliveryTurns),
|
|
17610
|
+
sessionCompletion: "settled-without-accepted-receipt",
|
|
17611
|
+
runPointer: input.runPointer,
|
|
17612
|
+
attemptPointer: input.attemptPointer,
|
|
17613
|
+
acceptedReceipt: false
|
|
17614
|
+
};
|
|
17615
|
+
}
|
|
17616
|
+
function noReceiptLifecycleFacts(input) {
|
|
17617
|
+
return {
|
|
17618
|
+
terminalToolCalled: input.terminalToolCalled,
|
|
17619
|
+
rejectedReceipts: input.rejectedReceipts.map(({ reason }) => ({
|
|
17620
|
+
reason,
|
|
17621
|
+
diagnosticAvailable: reason.trim() !== ""
|
|
17622
|
+
})),
|
|
17623
|
+
deliveryTurns: deliveryTurnsFact(input.deliveryTurns),
|
|
17624
|
+
sessionCompletion: "settled-without-accepted-receipt",
|
|
17625
|
+
runPointer: input.runPointer,
|
|
17626
|
+
attemptPointer: input.attemptPointer,
|
|
17627
|
+
acceptedReceipt: false
|
|
17628
|
+
};
|
|
17629
|
+
}
|
|
17630
|
+
function createReceiptDeliveryPolicy(limit) {
|
|
17631
|
+
const deliveryLimit = deliveryLimitFromConfig(limit);
|
|
17632
|
+
let accepted = false;
|
|
17633
|
+
let closed = false;
|
|
17634
|
+
let terminalToolCalled = false;
|
|
17635
|
+
let deliveryTurns = 0;
|
|
17636
|
+
let budgetSpent = 0;
|
|
17637
|
+
const rejectedReceipts = [];
|
|
17638
|
+
const spend = () => {
|
|
17639
|
+
if (budgetSpent < deliveryLimit) budgetSpent += 1;
|
|
17640
|
+
};
|
|
17641
|
+
return {
|
|
17642
|
+
/** The effective ceiling this budget spends (#1132 — never re-read). */
|
|
17643
|
+
limit: deliveryLimit,
|
|
17644
|
+
recordAccepted() {
|
|
17645
|
+
accepted = true;
|
|
17646
|
+
terminalToolCalled = true;
|
|
17647
|
+
},
|
|
17648
|
+
/** Infrastructure owns terminality and must never trigger receipt催交. */
|
|
17649
|
+
stopForInfrastructure() {
|
|
17650
|
+
accepted = true;
|
|
17651
|
+
},
|
|
17652
|
+
/**
|
|
17653
|
+
* Record the rejection this turn already produced.
|
|
17654
|
+
* The fact does not spend a budget. The seam that sends the next prompt
|
|
17655
|
+
* owns that count.
|
|
17656
|
+
*/
|
|
17657
|
+
recordRejected(reason) {
|
|
17658
|
+
terminalToolCalled = true;
|
|
17659
|
+
rejectedReceipts.push({ reason, diagnosticAvailable: reason.trim() !== "" });
|
|
17660
|
+
},
|
|
17661
|
+
recordDeliveryRequest() {
|
|
17662
|
+
deliveryTurns += 1;
|
|
17663
|
+
spend();
|
|
17664
|
+
},
|
|
17665
|
+
/**
|
|
17666
|
+
* Stop asking. The issued count stays whatever was actually sent (#1132 —
|
|
17667
|
+
* do not fill the remainder up to the ceiling).
|
|
17668
|
+
*/
|
|
17669
|
+
closeBudget() {
|
|
17670
|
+
closed = true;
|
|
17671
|
+
},
|
|
17672
|
+
/**
|
|
17673
|
+
* A nested session settled without an accepted receipt. Close so this layer
|
|
17674
|
+
* does not open another prompt on that session. The issued count stays the
|
|
17675
|
+
* larger of the two seams: a nested zero must not wipe prompts this layer
|
|
17676
|
+
* already sent, and adding the two counts would bill one send twice.
|
|
17677
|
+
*/
|
|
17678
|
+
recordNestedNoReceipt(facts) {
|
|
17679
|
+
terminalToolCalled = terminalToolCalled || facts.terminalToolCalled;
|
|
17680
|
+
rejectedReceipts.push(...facts.rejectedReceipts);
|
|
17681
|
+
deliveryTurns = Math.max(deliveryTurns, facts.deliveryTurns);
|
|
17682
|
+
closed = true;
|
|
17683
|
+
},
|
|
17684
|
+
nextAction() {
|
|
17685
|
+
if (accepted) return "accepted";
|
|
17686
|
+
if (closed) return "no-receipt";
|
|
17687
|
+
return budgetSpent < deliveryLimit ? "request-delivery" : "no-receipt";
|
|
17688
|
+
},
|
|
17689
|
+
/** Delivery requests actually issued so far (#1132). */
|
|
17690
|
+
issuedDeliveryRequests() {
|
|
17691
|
+
return deliveryTurns;
|
|
17692
|
+
},
|
|
17693
|
+
/** Current typed delivery facts. No prose. */
|
|
17694
|
+
deliveryState() {
|
|
17695
|
+
return {
|
|
17696
|
+
terminalToolCalled,
|
|
17697
|
+
rejectedReceipts: rejectedReceipts.map((item) => ({ ...item })),
|
|
17698
|
+
deliveryTurns,
|
|
17699
|
+
acceptedReceipt: false
|
|
17700
|
+
};
|
|
17701
|
+
},
|
|
17702
|
+
facts(binding) {
|
|
17703
|
+
return noReceiptLifecycleFacts({ terminalToolCalled, rejectedReceipts: [...rejectedReceipts], deliveryTurns, ...binding });
|
|
17704
|
+
},
|
|
17705
|
+
/**
|
|
17706
|
+
* Continue a public call after the in-memory policy was rebuilt.
|
|
17707
|
+
* Sends already issued spend the same budget; copied rejections keep
|
|
17708
|
+
* the fact and do not spend again.
|
|
17709
|
+
*/
|
|
17710
|
+
continueIssued(prior) {
|
|
17711
|
+
for (const receipt of prior.rejectedReceipts) {
|
|
17712
|
+
this.recordRejected(receipt.reason);
|
|
17713
|
+
}
|
|
17714
|
+
if (prior.terminalToolCalled === true) terminalToolCalled = true;
|
|
17715
|
+
for (let index = 0; index < prior.deliveryTurns; index += 1) {
|
|
17716
|
+
this.recordDeliveryRequest();
|
|
17717
|
+
}
|
|
17718
|
+
}
|
|
17719
|
+
};
|
|
17720
|
+
}
|
|
17721
|
+
function entryRecord(entry) {
|
|
17722
|
+
return isRecord(entry) ? entry : void 0;
|
|
17723
|
+
}
|
|
17724
|
+
function customTypeOf(record, message) {
|
|
17725
|
+
return record.customType ?? message?.customType;
|
|
17726
|
+
}
|
|
17727
|
+
function dataOf(record, message) {
|
|
17728
|
+
return record.data ?? message?.details;
|
|
17729
|
+
}
|
|
17730
|
+
function scopeTag(record) {
|
|
17731
|
+
const message = isRecord(record.message) ? record.message : void 0;
|
|
17732
|
+
const customType = customTypeOf(record, message);
|
|
17733
|
+
const data = dataOf(record, message);
|
|
17734
|
+
if ((customType === RECEIPT_DELIVERY_REQUEST_ENTRY || customType === RECEIPT_REJECTION_ENTRY) && isRecord(data) && typeof data.invocationScopeId === "string" && data.invocationScopeId.trim() !== "") {
|
|
17735
|
+
return data.invocationScopeId;
|
|
17736
|
+
}
|
|
17737
|
+
if (customType !== NO_RECEIPT_LIFECYCLE_ENTRY_TYPE) return void 0;
|
|
17738
|
+
try {
|
|
17739
|
+
const facts = parseNoReceiptLifecycleFacts(data);
|
|
17740
|
+
const prefix = "invocation:";
|
|
17741
|
+
if (!facts.attemptPointer.startsWith(prefix)) return void 0;
|
|
17742
|
+
const scope = facts.attemptPointer.slice(prefix.length);
|
|
17743
|
+
return scope.trim() === "" ? void 0 : scope;
|
|
17744
|
+
} catch {
|
|
17745
|
+
return void 0;
|
|
17746
|
+
}
|
|
17747
|
+
}
|
|
17748
|
+
function priorReceiptContinuation(entries, invocationScopeId) {
|
|
17749
|
+
const pointer = receiptAttemptPointer("", invocationScopeId);
|
|
17750
|
+
let entryTurns = 0;
|
|
17751
|
+
let factTurns = 0;
|
|
17752
|
+
let rejectedReceipts = [];
|
|
17753
|
+
let snapshotTerminal = false;
|
|
17754
|
+
for (const entry of entries) {
|
|
17755
|
+
const record = entryRecord(entry);
|
|
17756
|
+
if (record === void 0) continue;
|
|
17757
|
+
const tagged = scopeTag(record);
|
|
17758
|
+
if (tagged !== void 0) {
|
|
17759
|
+
const message = isRecord(record.message) ? record.message : void 0;
|
|
17760
|
+
const customType = customTypeOf(record, message);
|
|
17761
|
+
if (tagged !== invocationScopeId) continue;
|
|
17762
|
+
if (customType === RECEIPT_DELIVERY_REQUEST_ENTRY) entryTurns += 1;
|
|
17763
|
+
if (customType === RECEIPT_REJECTION_ENTRY) {
|
|
17764
|
+
const data = dataOf(record, message);
|
|
17765
|
+
if (isRecord(data) && typeof data.reason === "string") rejectedReceipts.push({ reason: data.reason });
|
|
17766
|
+
}
|
|
17767
|
+
if (customType !== NO_RECEIPT_LIFECYCLE_ENTRY_TYPE) continue;
|
|
17768
|
+
try {
|
|
17769
|
+
const facts = parseNoReceiptLifecycleFacts(dataOf(record, message));
|
|
17770
|
+
if (facts.attemptPointer !== pointer) continue;
|
|
17771
|
+
factTurns = Math.max(factTurns, facts.deliveryTurns);
|
|
17772
|
+
if (facts.rejectedReceipts.length >= rejectedReceipts.length) {
|
|
17773
|
+
rejectedReceipts = facts.rejectedReceipts.map(({ reason }) => ({ reason }));
|
|
17774
|
+
}
|
|
17775
|
+
snapshotTerminal ||= facts.terminalToolCalled;
|
|
17776
|
+
} catch {
|
|
17777
|
+
}
|
|
17778
|
+
continue;
|
|
17779
|
+
}
|
|
17780
|
+
}
|
|
17781
|
+
return {
|
|
17782
|
+
deliveryTurns: Math.max(entryTurns, factTurns),
|
|
17783
|
+
rejectedReceipts,
|
|
17784
|
+
terminalToolCalled: snapshotTerminal || rejectedReceipts.length > 0
|
|
17785
|
+
};
|
|
17786
|
+
}
|
|
17787
|
+
var NO_RECEIPT_LIFECYCLE_ENTRY_TYPE, RECEIPT_DELIVERY_REQUEST_ENTRY, RECEIPT_REJECTION_ENTRY, RECEIPT_DELIVERY_LIMIT_ENV;
|
|
17788
|
+
var init_receipt_delivery_policy = __esm({
|
|
17789
|
+
"src/receipt-delivery-policy.ts"() {
|
|
17790
|
+
"use strict";
|
|
17791
|
+
init_run_lifecycle();
|
|
17792
|
+
init_config2();
|
|
17793
|
+
init_unknown_value();
|
|
17794
|
+
NO_RECEIPT_LIFECYCLE_ENTRY_TYPE = "ak-no-receipt-lifecycle";
|
|
17795
|
+
RECEIPT_DELIVERY_REQUEST_ENTRY = "ak-receipt-delivery-request";
|
|
17796
|
+
RECEIPT_REJECTION_ENTRY = "ak-receipt-rejection";
|
|
17797
|
+
RECEIPT_DELIVERY_LIMIT_ENV = "AK_ROLE_RECEIPT_DELIVERY_LIMIT";
|
|
17798
|
+
}
|
|
17799
|
+
});
|
|
17800
|
+
|
|
17329
17801
|
// src/session-assistant-usage.ts
|
|
17330
17802
|
var session_assistant_usage_exports = {};
|
|
17331
17803
|
__export(session_assistant_usage_exports, {
|
|
@@ -17335,10 +17807,10 @@ __export(session_assistant_usage_exports, {
|
|
|
17335
17807
|
});
|
|
17336
17808
|
import { join as join14 } from "node:path";
|
|
17337
17809
|
async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
17338
|
-
const { readFile:
|
|
17810
|
+
const { readFile: readFile23 } = await import("node:fs/promises");
|
|
17339
17811
|
let text;
|
|
17340
17812
|
try {
|
|
17341
|
-
text = await
|
|
17813
|
+
text = await readFile23(sessionFile, "utf8");
|
|
17342
17814
|
} catch (error) {
|
|
17343
17815
|
if (error?.code === "ENOENT") return void 0;
|
|
17344
17816
|
throw error;
|
|
@@ -17959,6 +18431,8 @@ function createPiRoleTurnHost(config) {
|
|
|
17959
18431
|
else env.AK_ROLE_INVOCATION_SCOPE = request.invocationScopeId;
|
|
17960
18432
|
if (request.host === void 0 || request.host.trim() === "") delete env.AK_ROLE_HOST;
|
|
17961
18433
|
else env.AK_ROLE_HOST = request.host.trim();
|
|
18434
|
+
if (request.deliveryRequestLimit === void 0) delete env[RECEIPT_DELIVERY_LIMIT_ENV];
|
|
18435
|
+
else env[RECEIPT_DELIVERY_LIMIT_ENV] = String(request.deliveryRequestLimit);
|
|
17962
18436
|
applyEngineChildEnv(env, request.engine);
|
|
17963
18437
|
if (typeof process.env.AK_ROLE_AUDITOR_SOURCE_RUN === "string" && process.env.AK_ROLE_AUDITOR_SOURCE_RUN.trim() !== "") {
|
|
17964
18438
|
env.AK_ROLE_AUDITOR_SOURCE_RUN = process.env.AK_ROLE_AUDITOR_SOURCE_RUN;
|
|
@@ -18018,6 +18492,7 @@ var init_role_turn_host = __esm({
|
|
|
18018
18492
|
init_engine_detour();
|
|
18019
18493
|
init_role_activation_flags();
|
|
18020
18494
|
init_user_dialogue_stdin();
|
|
18495
|
+
init_receipt_delivery_policy();
|
|
18021
18496
|
init_sitian_facade();
|
|
18022
18497
|
INTERNAL_ROLE_ENTRYPOINT_RELATIVE2 = "extensions/role-runtime.ts";
|
|
18023
18498
|
EXPLICIT_INTERNAL_LOAD_PROBE_ARGS = [
|
|
@@ -21838,10 +22313,10 @@ function pairGateRounds(volumes) {
|
|
|
21838
22313
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
21839
22314
|
}
|
|
21840
22315
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
21841
|
-
const { readFile:
|
|
22316
|
+
const { readFile: readFile23 } = await import("node:fs/promises");
|
|
21842
22317
|
let raw;
|
|
21843
22318
|
try {
|
|
21844
|
-
raw = JSON.parse(await
|
|
22319
|
+
raw = JSON.parse(await readFile23(pointerPath, "utf8"));
|
|
21845
22320
|
} catch (error) {
|
|
21846
22321
|
throw new Error(
|
|
21847
22322
|
`direct officer run pointer unreadable in ${pointerPath}: ${errorText(error)}`,
|
|
@@ -22449,9 +22924,7 @@ function runDirectoryFromSessionDirectory(sessionDirectory) {
|
|
|
22449
22924
|
function sessionFileFromSessionDirectory(sessionDirectory) {
|
|
22450
22925
|
return join26(sessionDirectory, "session.jsonl");
|
|
22451
22926
|
}
|
|
22452
|
-
function mintEngineDetourInvocationScope(
|
|
22453
|
-
const engine = input.effectiveEngine?.trim();
|
|
22454
|
-
if (engine === void 0 || engine.length === 0) return void 0;
|
|
22927
|
+
function mintEngineDetourInvocationScope(_input) {
|
|
22455
22928
|
return randomUUID3();
|
|
22456
22929
|
}
|
|
22457
22930
|
function withEngineDetourInvocationScope(request, invocationScopeId) {
|
|
@@ -22654,51 +23127,6 @@ var init_navigator_invocation_identity = __esm({
|
|
|
22654
23127
|
}
|
|
22655
23128
|
});
|
|
22656
23129
|
|
|
22657
|
-
// src/receipt-delivery-policy.ts
|
|
22658
|
-
function parseNoReceiptLifecycleFacts(input) {
|
|
22659
|
-
if (!isRecord(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord(item) && typeof item.reason === "string")) {
|
|
22660
|
-
throw new TypeError("malformed no-receipt lifecycle facts");
|
|
22661
|
-
}
|
|
22662
|
-
return {
|
|
22663
|
-
terminalToolCalled: input.terminalToolCalled,
|
|
22664
|
-
rejectedReceipts: input.rejectedReceipts.map((item) => ({
|
|
22665
|
-
reason: item.reason,
|
|
22666
|
-
diagnosticAvailable: item.reason.trim() !== ""
|
|
22667
|
-
})),
|
|
22668
|
-
deliveryTurns: RECEIPT_DELIVERY_TURN_LIMIT,
|
|
22669
|
-
sessionCompletion: "settled-without-accepted-receipt",
|
|
22670
|
-
runPointer: input.runPointer,
|
|
22671
|
-
attemptPointer: input.attemptPointer,
|
|
22672
|
-
acceptedReceipt: false
|
|
22673
|
-
};
|
|
22674
|
-
}
|
|
22675
|
-
function noReceiptLifecycleFacts(input) {
|
|
22676
|
-
if (input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT) {
|
|
22677
|
-
throw new TypeError("no-receipt lifecycle requires an exhausted delivery budget");
|
|
22678
|
-
}
|
|
22679
|
-
return {
|
|
22680
|
-
terminalToolCalled: input.terminalToolCalled,
|
|
22681
|
-
rejectedReceipts: input.rejectedReceipts.map(({ reason }) => ({
|
|
22682
|
-
reason,
|
|
22683
|
-
diagnosticAvailable: reason.trim() !== ""
|
|
22684
|
-
})),
|
|
22685
|
-
deliveryTurns: RECEIPT_DELIVERY_TURN_LIMIT,
|
|
22686
|
-
sessionCompletion: "settled-without-accepted-receipt",
|
|
22687
|
-
runPointer: input.runPointer,
|
|
22688
|
-
attemptPointer: input.attemptPointer,
|
|
22689
|
-
acceptedReceipt: false
|
|
22690
|
-
};
|
|
22691
|
-
}
|
|
22692
|
-
var RECEIPT_DELIVERY_TURN_LIMIT, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE;
|
|
22693
|
-
var init_receipt_delivery_policy = __esm({
|
|
22694
|
-
"src/receipt-delivery-policy.ts"() {
|
|
22695
|
-
"use strict";
|
|
22696
|
-
init_unknown_value();
|
|
22697
|
-
RECEIPT_DELIVERY_TURN_LIMIT = 2;
|
|
22698
|
-
NO_RECEIPT_LIFECYCLE_ENTRY_TYPE = "ak-no-receipt-lifecycle";
|
|
22699
|
-
}
|
|
22700
|
-
});
|
|
22701
|
-
|
|
22702
23130
|
// src/public-cli/settlement.ts
|
|
22703
23131
|
var settlement_exports = {};
|
|
22704
23132
|
__export(settlement_exports, {
|
|
@@ -22841,13 +23269,76 @@ async function attachRecordedSubmissions(admitted, terminal, scope) {
|
|
|
22841
23269
|
if (errorPath !== void 0) privateFailureErrorPaths.set(result, errorPath);
|
|
22842
23270
|
return result;
|
|
22843
23271
|
}
|
|
22844
|
-
|
|
23272
|
+
function lifecycleFactsFromEntry(entry) {
|
|
23273
|
+
const customType = entry.customType ?? entry.message?.customType;
|
|
23274
|
+
if (customType !== NO_RECEIPT_LIFECYCLE_ENTRY_TYPE) return void 0;
|
|
23275
|
+
return entry.data ?? entry.message?.details;
|
|
23276
|
+
}
|
|
23277
|
+
async function readCurrentAttemptNoReceiptFacts(admitted, authority, scope) {
|
|
23278
|
+
const { sessionFile } = coordinatesFromAdmitted(authority, admitted);
|
|
23279
|
+
const entries = await readBoundSessionEntries(sessionFile).catch(() => void 0);
|
|
23280
|
+
if (entries === void 0) return void 0;
|
|
23281
|
+
const scopeId = scope?.invocationScopeId?.trim() ?? "";
|
|
23282
|
+
if (scopeId.length > 0) {
|
|
23283
|
+
const pointer = receiptAttemptPointer(admitted.runDirectory, scopeId);
|
|
23284
|
+
let selected;
|
|
23285
|
+
for (const entry of entries) {
|
|
23286
|
+
const raw2 = lifecycleFactsFromEntry(entry);
|
|
23287
|
+
if (raw2 === void 0) continue;
|
|
23288
|
+
try {
|
|
23289
|
+
const facts2 = parseNoReceiptLifecycleFacts(raw2);
|
|
23290
|
+
if (facts2.runPointer !== admitted.runDirectory) continue;
|
|
23291
|
+
if (facts2.attemptPointer !== pointer) continue;
|
|
23292
|
+
if (selected === void 0 || facts2.deliveryTurns >= selected.deliveryTurns) {
|
|
23293
|
+
selected = facts2;
|
|
23294
|
+
}
|
|
23295
|
+
} catch {
|
|
23296
|
+
}
|
|
23297
|
+
}
|
|
23298
|
+
return selected;
|
|
23299
|
+
}
|
|
23300
|
+
let attemptStart = 0;
|
|
23301
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
23302
|
+
if (entries[index]?.type === "message" && entries[index]?.message?.role === "user") {
|
|
23303
|
+
attemptStart = index;
|
|
23304
|
+
break;
|
|
23305
|
+
}
|
|
23306
|
+
}
|
|
23307
|
+
const lifecycleEntry = entries.slice(attemptStart).reverse().find((entry) => lifecycleFactsFromEntry(entry) !== void 0);
|
|
23308
|
+
const raw = lifecycleEntry === void 0 ? void 0 : lifecycleFactsFromEntry(lifecycleEntry);
|
|
23309
|
+
if (raw === void 0) return void 0;
|
|
23310
|
+
let facts;
|
|
23311
|
+
try {
|
|
23312
|
+
facts = parseNoReceiptLifecycleFacts(raw);
|
|
23313
|
+
} catch {
|
|
23314
|
+
return void 0;
|
|
23315
|
+
}
|
|
23316
|
+
if (facts.runPointer !== admitted.runDirectory) return void 0;
|
|
23317
|
+
if (facts.attemptPointer !== receiptAttemptPointer(admitted.runDirectory)) return void 0;
|
|
23318
|
+
return facts;
|
|
23319
|
+
}
|
|
23320
|
+
async function settleHostEndedNoReceipt(admitted, authority, scope, issuedDeliveryRequests = 0) {
|
|
23321
|
+
const scopeId = scope?.invocationScopeId?.trim() ?? "";
|
|
23322
|
+
const persisted = scopeId.length > 0 ? void 0 : await readCurrentAttemptNoReceiptFacts(admitted, authority, scope);
|
|
23323
|
+
let terminalToolCalled = persisted?.terminalToolCalled ?? false;
|
|
23324
|
+
let rejectedReceipts = persisted?.rejectedReceipts ?? [];
|
|
23325
|
+
let recordedTurns = persisted?.deliveryTurns ?? 0;
|
|
23326
|
+
if (scopeId.length > 0) {
|
|
23327
|
+
const { sessionFile } = coordinatesFromAdmitted(authority, admitted);
|
|
23328
|
+
const entries = await readBoundSessionEntries(sessionFile).catch(() => void 0);
|
|
23329
|
+
if (entries !== void 0) {
|
|
23330
|
+
const prior = priorReceiptContinuation(entries, scopeId);
|
|
23331
|
+
terminalToolCalled = prior.terminalToolCalled;
|
|
23332
|
+
rejectedReceipts = prior.rejectedReceipts;
|
|
23333
|
+
recordedTurns = prior.deliveryTurns;
|
|
23334
|
+
}
|
|
23335
|
+
}
|
|
22845
23336
|
const facts = noReceiptLifecycleFacts({
|
|
22846
|
-
terminalToolCalled
|
|
22847
|
-
rejectedReceipts
|
|
22848
|
-
deliveryTurns:
|
|
23337
|
+
terminalToolCalled,
|
|
23338
|
+
rejectedReceipts,
|
|
23339
|
+
deliveryTurns: Math.max(issuedDeliveryRequests, recordedTurns),
|
|
22849
23340
|
runPointer: admitted.runDirectory,
|
|
22850
|
-
attemptPointer:
|
|
23341
|
+
attemptPointer: receiptAttemptPointer(admitted.runDirectory, scope?.invocationScopeId)
|
|
22851
23342
|
});
|
|
22852
23343
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
22853
23344
|
await clearOppositeTerminalArtifactFace(admitted.runDirectory);
|
|
@@ -24420,44 +24911,26 @@ async function settleFailureTerminalResult(admitted, failure, authority, options
|
|
|
24420
24911
|
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
24421
24912
|
const { sessionDirectory, sessionFile } = coordinates;
|
|
24422
24913
|
if (failure.cause === "output") {
|
|
24423
|
-
const
|
|
24424
|
-
if (
|
|
24425
|
-
|
|
24426
|
-
|
|
24427
|
-
|
|
24428
|
-
|
|
24429
|
-
|
|
24430
|
-
|
|
24431
|
-
|
|
24432
|
-
|
|
24433
|
-
|
|
24434
|
-
|
|
24435
|
-
|
|
24436
|
-
|
|
24437
|
-
|
|
24438
|
-
|
|
24439
|
-
}
|
|
24440
|
-
|
|
24441
|
-
|
|
24442
|
-
|
|
24443
|
-
return withOptionalGateProjection(
|
|
24444
|
-
{
|
|
24445
|
-
roleOutcome: {
|
|
24446
|
-
kind: "no_receipt",
|
|
24447
|
-
role: admitted.role,
|
|
24448
|
-
status: "no-accepted-receipt",
|
|
24449
|
-
...facts,
|
|
24450
|
-
decisiveFacts: decisiveFacts2
|
|
24451
|
-
},
|
|
24452
|
-
navigator: await extractNavigatorFactFromAdmittedSession(sessionFile),
|
|
24453
|
-
artifacts: [],
|
|
24454
|
-
runId: admitted.runId
|
|
24455
|
-
},
|
|
24456
|
-
sessionDirectory,
|
|
24457
|
-
detourGateContext(admitted, options)
|
|
24458
|
-
);
|
|
24459
|
-
}
|
|
24460
|
-
}
|
|
24914
|
+
const facts = await readCurrentAttemptNoReceiptFacts(admitted, authority, options);
|
|
24915
|
+
if (facts !== void 0) {
|
|
24916
|
+
const decisiveFacts2 = facts;
|
|
24917
|
+
await clearOppositeTerminalArtifactFace(admitted.runDirectory);
|
|
24918
|
+
return withOptionalGateProjection(
|
|
24919
|
+
{
|
|
24920
|
+
roleOutcome: {
|
|
24921
|
+
kind: "no_receipt",
|
|
24922
|
+
role: admitted.role,
|
|
24923
|
+
status: "no-accepted-receipt",
|
|
24924
|
+
...facts,
|
|
24925
|
+
decisiveFacts: decisiveFacts2
|
|
24926
|
+
},
|
|
24927
|
+
navigator: await extractNavigatorFactFromAdmittedSession(sessionFile),
|
|
24928
|
+
artifacts: [],
|
|
24929
|
+
runId: admitted.runId
|
|
24930
|
+
},
|
|
24931
|
+
sessionDirectory,
|
|
24932
|
+
detourGateContext(admitted, options)
|
|
24933
|
+
);
|
|
24461
24934
|
}
|
|
24462
24935
|
}
|
|
24463
24936
|
const navigator = await extractNavigatorFactFromAdmittedSession(sessionFile);
|
|
@@ -24627,16 +25100,19 @@ var init_settlement = __esm({
|
|
|
24627
25100
|
|
|
24628
25101
|
// src/archivist-record-pointer.ts
|
|
24629
25102
|
import { mkdirSync as mkdirSync3, writeFileSync } from "node:fs";
|
|
25103
|
+
import { readFile as readFile16 } from "node:fs/promises";
|
|
24630
25104
|
import { dirname as dirname16, join as join28 } from "node:path";
|
|
24631
25105
|
function bookDirectOfficerRunPointer(options) {
|
|
24632
25106
|
const nest = join28(dirname16(options.parentSessionFile), "auditor-roles");
|
|
24633
25107
|
mkdirSync3(nest, { recursive: true });
|
|
25108
|
+
const submissionToolCallId = options.submissionToolCallId?.trim() ?? "";
|
|
24634
25109
|
const pointer = {
|
|
24635
25110
|
version: 1,
|
|
24636
25111
|
kind: DIRECT_OFFICER_RUN_POINTER_KIND,
|
|
24637
25112
|
officer: options.officer,
|
|
24638
25113
|
sessionFile: options.sessionFile,
|
|
24639
|
-
...options.runDirectory !== void 0 && options.runDirectory.trim() !== "" ? { runDirectory: options.runDirectory } : {}
|
|
25114
|
+
...options.runDirectory !== void 0 && options.runDirectory.trim() !== "" ? { runDirectory: options.runDirectory } : {},
|
|
25115
|
+
...submissionToolCallId === "" ? {} : { submissionToolCallId }
|
|
24640
25116
|
};
|
|
24641
25117
|
writeFileSync(
|
|
24642
25118
|
join28(nest, `${options.officer}.pointer.json`),
|
|
@@ -24646,10 +25122,36 @@ function bookDirectOfficerRunPointer(options) {
|
|
|
24646
25122
|
);
|
|
24647
25123
|
return pointer;
|
|
24648
25124
|
}
|
|
25125
|
+
async function readDirectOfficerRunPointer(parentSessionFile, officer) {
|
|
25126
|
+
try {
|
|
25127
|
+
const raw = JSON.parse(await readFile16(
|
|
25128
|
+
join28(dirname16(parentSessionFile), "auditor-roles", `${officer}.pointer.json`),
|
|
25129
|
+
"utf8"
|
|
25130
|
+
));
|
|
25131
|
+
if (!isRecord(raw) || raw.kind !== DIRECT_OFFICER_RUN_POINTER_KIND || raw.version !== 1) {
|
|
25132
|
+
return void 0;
|
|
25133
|
+
}
|
|
25134
|
+
if (raw.officer !== officer) return void 0;
|
|
25135
|
+
if (typeof raw.sessionFile !== "string" || raw.sessionFile.trim() === "") return void 0;
|
|
25136
|
+
const runDirectory = typeof raw.runDirectory === "string" && raw.runDirectory.trim() !== "" ? raw.runDirectory : void 0;
|
|
25137
|
+
const submissionToolCallId = typeof raw.submissionToolCallId === "string" && raw.submissionToolCallId.trim() !== "" ? raw.submissionToolCallId : void 0;
|
|
25138
|
+
return {
|
|
25139
|
+
version: 1,
|
|
25140
|
+
kind: DIRECT_OFFICER_RUN_POINTER_KIND,
|
|
25141
|
+
officer,
|
|
25142
|
+
sessionFile: raw.sessionFile,
|
|
25143
|
+
...runDirectory === void 0 ? {} : { runDirectory },
|
|
25144
|
+
...submissionToolCallId === void 0 ? {} : { submissionToolCallId }
|
|
25145
|
+
};
|
|
25146
|
+
} catch {
|
|
25147
|
+
return void 0;
|
|
25148
|
+
}
|
|
25149
|
+
}
|
|
24649
25150
|
var DIRECT_OFFICER_RUN_POINTER_KIND;
|
|
24650
25151
|
var init_archivist_record_pointer = __esm({
|
|
24651
25152
|
"src/archivist-record-pointer.ts"() {
|
|
24652
25153
|
"use strict";
|
|
25154
|
+
init_unknown_value();
|
|
24653
25155
|
DIRECT_OFFICER_RUN_POINTER_KIND = "direct-officer-run-pointer";
|
|
24654
25156
|
}
|
|
24655
25157
|
});
|
|
@@ -24667,6 +25169,7 @@ function createPiDoctorAuditor() {
|
|
|
24667
25169
|
submission: options.submission,
|
|
24668
25170
|
...auditorRunDirectory(options.context) === void 0 ? {} : { runDirectory: auditorRunDirectory(options.context) },
|
|
24669
25171
|
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
25172
|
+
...options.autoResumeLimit === void 0 ? {} : { autoResumeLimit: options.autoResumeLimit },
|
|
24670
25173
|
...options.summonAuditor === void 0 ? {} : { summonAuditor: options.summonAuditor }
|
|
24671
25174
|
});
|
|
24672
25175
|
};
|
|
@@ -24681,16 +25184,37 @@ var init_doctor_auditor = __esm({
|
|
|
24681
25184
|
}
|
|
24682
25185
|
});
|
|
24683
25186
|
|
|
25187
|
+
// src/filed-submission.ts
|
|
25188
|
+
var init_filed_submission = __esm({
|
|
25189
|
+
"src/filed-submission.ts"() {
|
|
25190
|
+
"use strict";
|
|
25191
|
+
}
|
|
25192
|
+
});
|
|
25193
|
+
|
|
24684
25194
|
// src/judge-role.ts
|
|
24685
25195
|
async function runJudgeGates(input) {
|
|
24686
25196
|
const passes = [];
|
|
24687
25197
|
for (const subject of JUDGE_GATES) {
|
|
24688
25198
|
if (await input.gateAlreadyConverged(subject)) continue;
|
|
24689
25199
|
const pass = await input.runGate(subject);
|
|
24690
|
-
const
|
|
24691
|
-
if (pass === void 0 ||
|
|
25200
|
+
const received = pass?.status;
|
|
25201
|
+
if (pass === void 0 || (typeof received !== "string" || !REVIEW_QUEUE_STATUSES.has(received) && received !== "needs_reask")) {
|
|
24692
25202
|
throw new Error("judge gate returned no conclusion");
|
|
24693
25203
|
}
|
|
25204
|
+
const status = received;
|
|
25205
|
+
if (status === "needs_reask") {
|
|
25206
|
+
return {
|
|
25207
|
+
status,
|
|
25208
|
+
passes: [{
|
|
25209
|
+
subject,
|
|
25210
|
+
status,
|
|
25211
|
+
receipt: pass.receipt,
|
|
25212
|
+
...pass.runId === void 0 ? {} : { runId: pass.runId },
|
|
25213
|
+
...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
|
|
25214
|
+
...pass.terminal === void 0 ? {} : { terminal: pass.terminal }
|
|
25215
|
+
}]
|
|
25216
|
+
};
|
|
25217
|
+
}
|
|
24694
25218
|
passes.push({
|
|
24695
25219
|
subject,
|
|
24696
25220
|
status,
|
|
@@ -24708,6 +25232,8 @@ var init_judge_role = __esm({
|
|
|
24708
25232
|
"use strict";
|
|
24709
25233
|
init_host_contracts();
|
|
24710
25234
|
init_review_submission();
|
|
25235
|
+
init_filed_submission();
|
|
25236
|
+
init_role_submission_declarations();
|
|
24711
25237
|
init_gatekeeper_role();
|
|
24712
25238
|
init_judge_output();
|
|
24713
25239
|
JUDGE_GATES = [
|
|
@@ -24736,11 +25262,10 @@ function latestQueueStatus(terminal) {
|
|
|
24736
25262
|
if (outcome.kind === "audit_escalation") return "escalate";
|
|
24737
25263
|
if (outcome.kind !== "accepted") return void 0;
|
|
24738
25264
|
const latest = outcome.payloads?.[outcome.payloads.length - 1];
|
|
24739
|
-
if (isRecord(latest)) {
|
|
24740
|
-
|
|
24741
|
-
if (typeof status === "string" && status.trim() !== "") return status;
|
|
25265
|
+
if (isRecord(latest) && Object.hasOwn(latest, "status")) {
|
|
25266
|
+
return receivedDiscriminator(latest, "status");
|
|
24742
25267
|
}
|
|
24743
|
-
return
|
|
25268
|
+
return outcome.status;
|
|
24744
25269
|
}
|
|
24745
25270
|
function latestQueuePayload(terminal) {
|
|
24746
25271
|
const outcome = terminal?.roleOutcome;
|
|
@@ -24768,7 +25293,7 @@ function createDefaultGateOfficerSummon(options) {
|
|
|
24768
25293
|
});
|
|
24769
25294
|
};
|
|
24770
25295
|
}
|
|
24771
|
-
function bookDirectOfficerPointer(context, officer, result, summoned) {
|
|
25296
|
+
function bookDirectOfficerPointer(context, officer, result, summoned, toolCallId) {
|
|
24772
25297
|
if (result.status !== "converged" && result.status !== "continue" && result.status !== "escalate" && result.status !== "needs_reask" && result.status !== "transport_failure") {
|
|
24773
25298
|
return;
|
|
24774
25299
|
}
|
|
@@ -24782,11 +25307,14 @@ function bookDirectOfficerPointer(context, officer, result, summoned) {
|
|
|
24782
25307
|
parentSessionFile: parentFile,
|
|
24783
25308
|
officer,
|
|
24784
25309
|
sessionFile,
|
|
24785
|
-
...typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "" ? { runDirectory: summoned.runDirectory } : {}
|
|
25310
|
+
...typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "" ? { runDirectory: summoned.runDirectory } : {},
|
|
25311
|
+
...toolCallId.trim() === "" ? {} : { submissionToolCallId: toolCallId }
|
|
24786
25312
|
});
|
|
24787
25313
|
}
|
|
24788
25314
|
async function requireSubmissionGate(options) {
|
|
24789
25315
|
let reask;
|
|
25316
|
+
let reasksSpent = 0;
|
|
25317
|
+
const reaskLimit = deliveryLimitFromConfig(options.autoResumeLimit);
|
|
24790
25318
|
const summonOfficer = options.summonOfficer ?? createDefaultGateOfficerSummon({
|
|
24791
25319
|
cwd: options.context.cwd ?? process.cwd()
|
|
24792
25320
|
});
|
|
@@ -24806,7 +25334,8 @@ async function requireSubmissionGate(options) {
|
|
|
24806
25334
|
options.context,
|
|
24807
25335
|
projected.officer,
|
|
24808
25336
|
gatekeeper,
|
|
24809
|
-
projected.summoned
|
|
25337
|
+
projected.summoned,
|
|
25338
|
+
options.toolCallId
|
|
24810
25339
|
);
|
|
24811
25340
|
} catch (error) {
|
|
24812
25341
|
options.hostActions.failInfrastructure(error, options.context, options.toolCallId);
|
|
@@ -24829,6 +25358,17 @@ async function requireSubmissionGate(options) {
|
|
|
24829
25358
|
};
|
|
24830
25359
|
}
|
|
24831
25360
|
if (gatekeeper.status === "needs_reask") {
|
|
25361
|
+
if (reasksSpent >= reaskLimit) {
|
|
25362
|
+
return {
|
|
25363
|
+
status: "needs_reask",
|
|
25364
|
+
officer: projected.officer,
|
|
25365
|
+
receipt: gatekeeper.receipt,
|
|
25366
|
+
...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {},
|
|
25367
|
+
...typeof projected.summoned?.runDirectory === "string" && projected.summoned.runDirectory.trim() !== "" ? { runDirectory: projected.summoned.runDirectory } : {},
|
|
25368
|
+
...projected.summoned?.terminal === void 0 ? {} : { terminal: projected.summoned.terminal }
|
|
25369
|
+
};
|
|
25370
|
+
}
|
|
25371
|
+
reasksSpent += 1;
|
|
24832
25372
|
reask = officerConclusionReask(gatekeeper.receivedStatus);
|
|
24833
25373
|
continue;
|
|
24834
25374
|
}
|
|
@@ -24857,6 +25397,8 @@ var init_submission_gate = __esm({
|
|
|
24857
25397
|
"use strict";
|
|
24858
25398
|
init_archivist_record_pointer();
|
|
24859
25399
|
init_gatekeeper_role();
|
|
25400
|
+
init_submission_errors();
|
|
25401
|
+
init_receipt_delivery_policy();
|
|
24860
25402
|
init_session_assistant_usage();
|
|
24861
25403
|
init_unknown_value();
|
|
24862
25404
|
}
|
|
@@ -24914,7 +25456,8 @@ function projectRoleTurnRequest(admitted, roleDetails, options) {
|
|
|
24914
25456
|
...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs },
|
|
24915
25457
|
...options.courtAttemptId === void 0 || options.courtAttemptId.length === 0 ? {} : { courtAttemptId: options.courtAttemptId },
|
|
24916
25458
|
...options.invocationScopeId === void 0 || options.invocationScopeId.length === 0 ? {} : { invocationScopeId: options.invocationScopeId },
|
|
24917
|
-
...options.stationChild === void 0 ? {} : { stationChild: options.stationChild }
|
|
25459
|
+
...options.stationChild === void 0 ? {} : { stationChild: options.stationChild },
|
|
25460
|
+
...options.deliveryRequestLimit === void 0 ? {} : { deliveryRequestLimit: options.deliveryRequestLimit }
|
|
24918
25461
|
};
|
|
24919
25462
|
}
|
|
24920
25463
|
function packagedSettleSkill(admitted) {
|
|
@@ -25105,15 +25648,70 @@ function unreadablePostSubmissionStatus(admitted, terminal) {
|
|
|
25105
25648
|
const route = POST_SUBMISSION_ROUTING[admitted.role];
|
|
25106
25649
|
if (route === void 0) return void 0;
|
|
25107
25650
|
const payload = terminal.roleOutcome.payloads?.at(-1);
|
|
25108
|
-
const status =
|
|
25109
|
-
return typeof status === "string" && route.statuses.has(status) ? void 0 : route.reask;
|
|
25651
|
+
const status = receivedDiscriminator(payload, "status");
|
|
25652
|
+
return typeof status === "string" && route.statuses.has(status) ? void 0 : route.reask ?? officerConclusionReask(status);
|
|
25653
|
+
}
|
|
25654
|
+
function withUnreadableReask(env) {
|
|
25655
|
+
const spent = env.unreadableReasksSpent ?? 0;
|
|
25656
|
+
if (spent >= deliveryLimitFromConfig(env.autoResumeLimit)) return void 0;
|
|
25657
|
+
return { ...env, unreadableReasksSpent: spent + 1 };
|
|
25658
|
+
}
|
|
25659
|
+
function isUnreadableReaskExhausted(value) {
|
|
25660
|
+
return value === UNREADABLE_REASK_EXHAUSTED;
|
|
25661
|
+
}
|
|
25662
|
+
function presentOriginalVolume(held, terminal, io) {
|
|
25663
|
+
if (terminal?.roleOutcome.decisiveFacts?.directionUnsettled === true) {
|
|
25664
|
+
io.stdout(formatTerminalResult(terminal));
|
|
25665
|
+
return;
|
|
25666
|
+
}
|
|
25667
|
+
if (held.length > 0) {
|
|
25668
|
+
for (const value of held) io.stdout(value);
|
|
25669
|
+
return;
|
|
25670
|
+
}
|
|
25671
|
+
if (terminal !== void 0) io.stdout(formatTerminalResult(terminal));
|
|
25672
|
+
}
|
|
25673
|
+
function withUnsettledDirection(parent, officer) {
|
|
25674
|
+
const outcome = parent.roleOutcome;
|
|
25675
|
+
if (outcome.kind !== "accepted" && outcome.kind !== "audit_escalation") return parent;
|
|
25676
|
+
const officerOutcome = officer?.roleOutcome;
|
|
25677
|
+
const officerPayloads = coalesceSubmissionRows(
|
|
25678
|
+
officer?.submissions,
|
|
25679
|
+
officerOutcome !== void 0 && officerOutcome.kind !== "no_receipt" ? officerOutcome.payloads : void 0
|
|
25680
|
+
);
|
|
25681
|
+
return {
|
|
25682
|
+
...parent,
|
|
25683
|
+
roleOutcome: {
|
|
25684
|
+
...outcome,
|
|
25685
|
+
decisiveFacts: {
|
|
25686
|
+
...outcome.decisiveFacts ?? {},
|
|
25687
|
+
directionUnsettled: true,
|
|
25688
|
+
subsequentAudit: "incomplete",
|
|
25689
|
+
...officerOutcome === void 0 ? {} : { officerRole: officerOutcome.role },
|
|
25690
|
+
...officer?.runId === void 0 ? {} : { officerRunId: officer.runId },
|
|
25691
|
+
...officerPayloads.length === 0 ? {} : { officerPayloads }
|
|
25692
|
+
}
|
|
25693
|
+
}
|
|
25694
|
+
};
|
|
25695
|
+
}
|
|
25696
|
+
function heldUnreadableTerminal(terminal) {
|
|
25697
|
+
if (terminal?.roleOutcome.kind !== "accepted") return false;
|
|
25698
|
+
if (latestPayloadEscalated(terminal.roleOutcome)) return false;
|
|
25699
|
+
const status = latestQueueStatus(terminal);
|
|
25700
|
+
return typeof status !== "string" || !REVIEW_QUEUE_STATUSES.has(status);
|
|
25701
|
+
}
|
|
25702
|
+
function presentUnsettledAudit(parent, officer, io) {
|
|
25703
|
+
const terminal = withUnsettledDirection(parent, officer);
|
|
25704
|
+
io.stdout(formatTerminalResult(terminal));
|
|
25705
|
+
if (officer !== void 0) io.stdout(formatTerminalResult(officer));
|
|
25706
|
+
return terminal;
|
|
25110
25707
|
}
|
|
25111
|
-
async function reaskUnreadablePostSubmissionStatus(admitted, terminal, env, io) {
|
|
25112
|
-
const message = unreadablePostSubmissionStatus(admitted, terminal);
|
|
25708
|
+
async function reaskUnreadablePostSubmissionStatus(admitted, terminal, env, io, message = unreadablePostSubmissionStatus(admitted, terminal)) {
|
|
25113
25709
|
if (message === void 0) return void 0;
|
|
25710
|
+
const next = withUnreadableReask(env);
|
|
25711
|
+
if (next === void 0) return UNREADABLE_REASK_EXHAUSTED;
|
|
25114
25712
|
return runPublicInstructionSeatResume(
|
|
25115
25713
|
{ runId: admitted.runId, message },
|
|
25116
|
-
|
|
25714
|
+
next,
|
|
25117
25715
|
io
|
|
25118
25716
|
);
|
|
25119
25717
|
}
|
|
@@ -25267,6 +25865,11 @@ async function dispatchAdmitted(admitted, env, io) {
|
|
|
25267
25865
|
env,
|
|
25268
25866
|
io
|
|
25269
25867
|
);
|
|
25868
|
+
if (isUnreadableReaskExhausted(unreadableReask)) {
|
|
25869
|
+
const terminal = result.terminal === void 0 ? void 0 : withUnsettledDirection(result.terminal);
|
|
25870
|
+
presentOriginalVolume(held, terminal, io);
|
|
25871
|
+
return terminal === void 0 ? result : { ...result, terminal };
|
|
25872
|
+
}
|
|
25270
25873
|
if (unreadableReask !== void 0) return unreadableReask;
|
|
25271
25874
|
if (AUDITED_ROLES.has(admitted.role) && result.terminal?.roleOutcome.kind === "accepted") {
|
|
25272
25875
|
return auditSubmittedRole(result, env, io);
|
|
@@ -25398,20 +26001,16 @@ async function runCountersignBody(parsed, env, io) {
|
|
|
25398
26001
|
await persistAdmittedSourceRunPath(admitted, gateParentRunPath);
|
|
25399
26002
|
admitted = { ...admitted, sourceRunPath: gateParentRunPath };
|
|
25400
26003
|
}
|
|
25401
|
-
const turnProjection = {
|
|
25402
|
-
|
|
25403
|
-
|
|
25404
|
-
|
|
25405
|
-
|
|
25406
|
-
|
|
25407
|
-
|
|
25408
|
-
|
|
25409
|
-
|
|
25410
|
-
|
|
25411
|
-
})
|
|
25412
|
-
)
|
|
25413
|
-
}
|
|
25414
|
-
};
|
|
26004
|
+
const turnProjection = roleTurnOptions(env, admitted, {
|
|
26005
|
+
kind: "initial",
|
|
26006
|
+
prompt: env.reviewReask ?? env.gateReviewInstruction ?? buildInstructionTransportPrompt(
|
|
26007
|
+
admitted,
|
|
26008
|
+
engineSessionMaterialFromOptions({
|
|
26009
|
+
...pickEngineAxis(env),
|
|
26010
|
+
packageRoot: env.packageRoot
|
|
26011
|
+
})
|
|
26012
|
+
)
|
|
26013
|
+
});
|
|
25415
26014
|
const turnRequest = buildInstructionSeatTurnRequest(admitted, turnProjection);
|
|
25416
26015
|
const result = await runPostAdmissionOneShot({
|
|
25417
26016
|
admitted,
|
|
@@ -25680,7 +26279,23 @@ async function runPublicInstructionSeatResume(request, env, io) {
|
|
|
25680
26279
|
},
|
|
25681
26280
|
afterAdmittedLoad: async (admitted) => {
|
|
25682
26281
|
await warnMissingMethodSkills(env.home, env.host, admitted.role, requiredMethodSkills(admitted), io.stdout);
|
|
25683
|
-
|
|
26282
|
+
const adapters = seatAdapters(admitted, env);
|
|
26283
|
+
if ((env.unreadableReasksSpent ?? 0) === 0 && env.reviewReask === void 0) {
|
|
26284
|
+
return { kind: "continue", adapters };
|
|
26285
|
+
}
|
|
26286
|
+
const original = await adapters.trySettle(
|
|
26287
|
+
admitted,
|
|
26288
|
+
env.principalAuthority,
|
|
26289
|
+
await readCurrentCourt(admitted.runDirectory)
|
|
26290
|
+
);
|
|
26291
|
+
const unsettled = POST_SUBMISSION_ROUTING[admitted.role] === void 0 ? heldUnreadableTerminal(original) : unreadablePostSubmissionStatus(admitted, original) !== void 0;
|
|
26292
|
+
return {
|
|
26293
|
+
kind: "continue",
|
|
26294
|
+
adapters: original === void 0 || !unsettled ? adapters : {
|
|
26295
|
+
...adapters,
|
|
26296
|
+
trySettle: async (seat, authority, scope) => await adapters.trySettle(seat, authority, scope) ?? original
|
|
26297
|
+
}
|
|
26298
|
+
};
|
|
25684
26299
|
},
|
|
25685
26300
|
...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
|
|
25686
26301
|
});
|
|
@@ -25690,6 +26305,11 @@ async function runPublicInstructionSeatResume(request, env, io) {
|
|
|
25690
26305
|
env,
|
|
25691
26306
|
io
|
|
25692
26307
|
);
|
|
26308
|
+
if (isUnreadableReaskExhausted(unreadableReask)) {
|
|
26309
|
+
const terminal = result.terminal === void 0 ? void 0 : withUnsettledDirection(result.terminal);
|
|
26310
|
+
presentOriginalVolume(held, terminal, io);
|
|
26311
|
+
return terminal === void 0 ? result : { ...result, terminal };
|
|
26312
|
+
}
|
|
25693
26313
|
if (unreadableReask !== void 0) return unreadableReask;
|
|
25694
26314
|
if (result.admitted !== void 0 && AUDITED_ROLES.has(result.admitted.role) && result.terminal?.roleOutcome.kind === "accepted") {
|
|
25695
26315
|
return auditSubmittedRole(result, env, io);
|
|
@@ -25715,26 +26335,46 @@ async function runPublicInstructionSeatResume(request, env, io) {
|
|
|
25715
26335
|
}
|
|
25716
26336
|
async function queueConclusionFromChild(child, env, io) {
|
|
25717
26337
|
if (!GATE_CHILD_ROLES.has(child.role)) return void 0;
|
|
26338
|
+
if (child.role === "countersign") {
|
|
26339
|
+
const terminal = await trySettlePublicSeat(
|
|
26340
|
+
child,
|
|
26341
|
+
env.principalAuthority,
|
|
26342
|
+
await readCurrentCourt(child.runDirectory)
|
|
26343
|
+
);
|
|
26344
|
+
const status = latestQueueStatus(terminal);
|
|
26345
|
+
if (terminal !== void 0 && typeof status === "string" && REVIEW_QUEUE_STATUSES.has(status)) {
|
|
26346
|
+
return { admitted: child, terminal, status };
|
|
26347
|
+
}
|
|
26348
|
+
return { stop: { exitCode: 0, ...terminal === void 0 ? {} : { terminal } } };
|
|
26349
|
+
}
|
|
25718
26350
|
let current = child;
|
|
26351
|
+
let budgetEnv = { ...env, unreadableReasksSpent: 0 };
|
|
25719
26352
|
for (; ; ) {
|
|
25720
26353
|
const terminal = await trySettlePublicSeat(
|
|
25721
26354
|
current,
|
|
25722
26355
|
env.principalAuthority,
|
|
25723
|
-
|
|
26356
|
+
await readCurrentCourt(current.runDirectory)
|
|
25724
26357
|
);
|
|
25725
26358
|
const status = latestQueueStatus(terminal);
|
|
25726
|
-
if (terminal !== void 0 && status
|
|
26359
|
+
if (terminal !== void 0 && typeof status === "string" && REVIEW_QUEUE_STATUSES.has(status)) {
|
|
25727
26360
|
return { admitted: current, terminal, status };
|
|
25728
26361
|
}
|
|
25729
|
-
const reasked = await
|
|
25730
|
-
|
|
25731
|
-
|
|
25732
|
-
|
|
25733
|
-
|
|
26362
|
+
const reasked = await reaskUnreadablePostSubmissionStatus(
|
|
26363
|
+
current,
|
|
26364
|
+
terminal,
|
|
26365
|
+
budgetEnv,
|
|
26366
|
+
io,
|
|
26367
|
+
officerConclusionReask(status)
|
|
26368
|
+
);
|
|
26369
|
+
if (reasked === void 0 || isUnreadableReaskExhausted(reasked)) {
|
|
26370
|
+
return { stop: { exitCode: 0, ...terminal === void 0 ? {} : { terminal } } };
|
|
26371
|
+
}
|
|
26372
|
+
budgetEnv = withUnreadableReask(budgetEnv);
|
|
26373
|
+
if (reasked.exitCode !== 0 || reasked.admitted === void 0 || reasked.terminal === void 0 || reasked.terminal.roleOutcome.kind === "no_receipt" || reasked.terminal.roleOutcome.decisiveFacts?.directionUnsettled === true) {
|
|
25734
26374
|
return { stop: reasked };
|
|
25735
26375
|
}
|
|
25736
26376
|
const reaskedStatus = latestQueueStatus(reasked.terminal);
|
|
25737
|
-
if (reaskedStatus
|
|
26377
|
+
if (typeof reaskedStatus === "string" && REVIEW_QUEUE_STATUSES.has(reaskedStatus)) {
|
|
25738
26378
|
return { admitted: reasked.admitted, terminal: reasked.terminal, status: reaskedStatus };
|
|
25739
26379
|
}
|
|
25740
26380
|
if (latestPayloadEscalated(reasked.terminal.roleOutcome)) return { stop: reasked };
|
|
@@ -25748,7 +26388,17 @@ async function continueParentAfterChild(parentRunId, child, env, io) {
|
|
|
25748
26388
|
}
|
|
25749
26389
|
const admitted = loaded.admitted;
|
|
25750
26390
|
const resolved = await queueConclusionFromChild(child, env, io);
|
|
25751
|
-
if (resolved !== void 0 && "stop" in resolved)
|
|
26391
|
+
if (resolved !== void 0 && "stop" in resolved) {
|
|
26392
|
+
const stopped = resolved.stop;
|
|
26393
|
+
if (stopped.exitCode === 0 && heldUnreadableTerminal(stopped.terminal) && stopped.terminal !== void 0) {
|
|
26394
|
+
const parentTerminal = await trySettlePublicSeat(admitted, env.principalAuthority, void 0);
|
|
26395
|
+
if (parentTerminal?.roleOutcome.kind === "accepted" || parentTerminal?.roleOutcome.kind === "audit_escalation") {
|
|
26396
|
+
const terminal = presentUnsettledAudit(parentTerminal, stopped.terminal, io);
|
|
26397
|
+
return { exitCode: 0, admitted, terminal };
|
|
26398
|
+
}
|
|
26399
|
+
}
|
|
26400
|
+
return stopped;
|
|
26401
|
+
}
|
|
25752
26402
|
if (resolved !== void 0 && resolved.status === "escalate") {
|
|
25753
26403
|
return { exitCode: 0, admitted: resolved.admitted, terminal: resolved.terminal };
|
|
25754
26404
|
}
|
|
@@ -25756,37 +26406,67 @@ async function continueParentAfterChild(parentRunId, child, env, io) {
|
|
|
25756
26406
|
if (AUDITED_ROLES.has(admitted.role) && resolved.status === "converged") {
|
|
25757
26407
|
const terminal = await trySettlePublicSeat(admitted, env.principalAuthority, void 0);
|
|
25758
26408
|
if (terminal?.roleOutcome.kind !== "accepted") throw new Error("pending submission is not recorded");
|
|
25759
|
-
return auditSubmittedRole({ exitCode: 0, admitted, terminal }, env, io, resolved.admitted
|
|
26409
|
+
return auditSubmittedRole({ exitCode: 0, admitted, terminal }, env, io, resolved.admitted, latestQueuePayload(resolved.terminal));
|
|
25760
26410
|
}
|
|
25761
26411
|
return runPublicInstructionSeatResume({
|
|
25762
26412
|
runId: parentRunId,
|
|
25763
26413
|
message: readableGateItem(latestQueuePayload(resolved.terminal))
|
|
25764
|
-
}, { ...env,
|
|
26414
|
+
}, { ...env, unreadableReasksSpent: 0 }, io);
|
|
25765
26415
|
}
|
|
25766
26416
|
const result = await dispatchAdmitted(admitted, env, { ...io, omitFailureStderrDiagnostic: true });
|
|
25767
26417
|
showResumeErrorPointer(io, result.exitCode, result.terminal);
|
|
25768
26418
|
return result;
|
|
25769
26419
|
}
|
|
25770
|
-
async function
|
|
26420
|
+
async function officerPassedCurrentSubmission(input) {
|
|
26421
|
+
const { env, officer } = input;
|
|
26422
|
+
const pointer = await readDirectOfficerRunPointer(input.parentSessionFile, officer);
|
|
26423
|
+
if (pointer?.runDirectory === void 0) return false;
|
|
26424
|
+
if (pointer.submissionToolCallId !== input.toolCallId) return false;
|
|
26425
|
+
const officerRunId = runIdFromRunDirectory(pointer.runDirectory);
|
|
26426
|
+
if (officerRunId === void 0) return false;
|
|
26427
|
+
let admitted;
|
|
26428
|
+
try {
|
|
26429
|
+
const loaded = await loadResumablePublicRole(
|
|
26430
|
+
env.home,
|
|
26431
|
+
officerRunId,
|
|
26432
|
+
env.principalAuthority
|
|
26433
|
+
);
|
|
26434
|
+
admitted = loaded.admitted;
|
|
26435
|
+
} catch {
|
|
26436
|
+
return false;
|
|
26437
|
+
}
|
|
26438
|
+
if (admitted.role !== officer) return false;
|
|
26439
|
+
const court = await readCurrentCourt(admitted.runDirectory);
|
|
26440
|
+
const terminal = await trySettlePublicSeat(admitted, env.principalAuthority, court);
|
|
26441
|
+
return latestQueueStatus(terminal) === "converged";
|
|
26442
|
+
}
|
|
26443
|
+
async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt) {
|
|
25771
26444
|
const admitted = turn.admitted;
|
|
25772
26445
|
if (admitted === void 0 || !AUDITED_ROLES.has(admitted.role) || turn.terminal?.roleOutcome.kind !== "accepted") return turn;
|
|
25773
26446
|
const accepted = turn.terminal.roleOutcome.payloads?.at(-1);
|
|
25774
26447
|
if (accepted === void 0) throw new Error("accepted submission has no payload");
|
|
25775
26448
|
const record = isRecord(accepted) ? accepted : void 0;
|
|
25776
26449
|
const status = admitted.role === "secretariat" ? record?.secretariatStatus : record?.status;
|
|
26450
|
+
const gateOwnsStatusReask = typeof env.parentRunPath === "string" && env.parentRunPath.trim() !== "";
|
|
25777
26451
|
if (admitted.role === "secretariat" && status !== "converged" && status !== "escalate") {
|
|
25778
|
-
return
|
|
25779
|
-
|
|
25780
|
-
|
|
25781
|
-
|
|
25782
|
-
|
|
26452
|
+
if (gateOwnsStatusReask) return turn;
|
|
26453
|
+
const next = withUnreadableReask(env);
|
|
26454
|
+
if (next === void 0) {
|
|
26455
|
+
const terminal2 = withUnsettledDirection(turn.terminal);
|
|
26456
|
+
io.stdout(formatTerminalResult(terminal2));
|
|
26457
|
+
return { ...turn, terminal: terminal2 };
|
|
26458
|
+
}
|
|
26459
|
+
return runPublicInstructionSeatResume({ runId: admitted.runId, message: SECRETARIAT_STATUS_REASK }, next, io);
|
|
25783
26460
|
}
|
|
25784
|
-
if (admitted.role === "countersign" && (typeof status !== "string" || !
|
|
25785
|
-
return
|
|
25786
|
-
|
|
25787
|
-
|
|
25788
|
-
|
|
25789
|
-
|
|
26461
|
+
if (admitted.role === "countersign" && (typeof status !== "string" || !REVIEW_QUEUE_STATUSES.has(status))) {
|
|
26462
|
+
if (gateOwnsStatusReask) return turn;
|
|
26463
|
+
const next = withUnreadableReask(env);
|
|
26464
|
+
if (next === void 0) {
|
|
26465
|
+
const terminal2 = withUnsettledDirection(turn.terminal);
|
|
26466
|
+
io.stdout(formatTerminalResult(terminal2));
|
|
26467
|
+
return { ...turn, terminal: terminal2 };
|
|
26468
|
+
}
|
|
26469
|
+
return runPublicInstructionSeatResume({ runId: admitted.runId, message: officerConclusionReask(status) }, next, io);
|
|
25790
26470
|
}
|
|
25791
26471
|
const selfEscalationSkipsAudit = status === "escalate" && (admitted.role === "judge" || admitted.role === "secretariat" || admitted.role === "countersign");
|
|
25792
26472
|
const skipAudit = selfEscalationSkipsAudit || (admitted.role === "fixer" || admitted.role === "coder") && (typeof status !== "string" || !WORKER_DONE_STATUSES.has(status));
|
|
@@ -25816,12 +26496,19 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
|
|
|
25816
26496
|
abort() {
|
|
25817
26497
|
}
|
|
25818
26498
|
};
|
|
26499
|
+
const passedThisSubmission = (officer) => officerPassedCurrentSubmission({
|
|
26500
|
+
env,
|
|
26501
|
+
parentSessionFile: sessionFile,
|
|
26502
|
+
officer,
|
|
26503
|
+
toolCallId
|
|
26504
|
+
});
|
|
25819
26505
|
if (admitted.role === "doctor") {
|
|
25820
|
-
if (
|
|
26506
|
+
if (!await passedThisSubmission("auditor")) {
|
|
25821
26507
|
let lastSummon;
|
|
25822
26508
|
const decision = await createPiDoctorAuditor()({
|
|
25823
26509
|
context,
|
|
25824
26510
|
submission: accepted,
|
|
26511
|
+
...env.autoResumeLimit === void 0 ? {} : { autoResumeLimit: env.autoResumeLimit },
|
|
25825
26512
|
...env.signal === void 0 ? {} : { signal: env.signal },
|
|
25826
26513
|
summonAuditor: async (subject, sourceRunDirectory, signal, reask, submission) => {
|
|
25827
26514
|
const summoned = await summonPublicRole({
|
|
@@ -25850,6 +26537,7 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
|
|
|
25850
26537
|
parentSessionFile: sessionFile,
|
|
25851
26538
|
officer: "auditor",
|
|
25852
26539
|
sessionFile: officerSession,
|
|
26540
|
+
submissionToolCallId: toolCallId,
|
|
25853
26541
|
...summoned.runDirectory === void 0 ? {} : { runDirectory: summoned.runDirectory }
|
|
25854
26542
|
});
|
|
25855
26543
|
}
|
|
@@ -25861,7 +26549,15 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
|
|
|
25861
26549
|
return runPublicInstructionSeatResume({
|
|
25862
26550
|
runId: admitted.runId,
|
|
25863
26551
|
message: readableGateItem(decision.receipt ?? decision.violations)
|
|
25864
|
-
}, { ...env,
|
|
26552
|
+
}, { ...env, unreadableReasksSpent: 0 }, io);
|
|
26553
|
+
}
|
|
26554
|
+
if (decision.status === "received") {
|
|
26555
|
+
if (lastSummon?.terminal === void 0) {
|
|
26556
|
+
throw new Error("doctor audit kept an unreadable reply with no terminal");
|
|
26557
|
+
}
|
|
26558
|
+
if (turn.terminal === void 0) throw new Error("doctor submission has no terminal");
|
|
26559
|
+
const terminal2 = presentUnsettledAudit(turn.terminal, lastSummon.terminal, io);
|
|
26560
|
+
return { exitCode: 0, admitted, terminal: terminal2 };
|
|
25865
26561
|
}
|
|
25866
26562
|
if (decision.status !== "converged") {
|
|
25867
26563
|
if (lastSummon?.terminal !== void 0) {
|
|
@@ -25884,13 +26580,14 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
|
|
|
25884
26580
|
...env.hostAdapters === void 0 ? {} : { hostAdapters: env.hostAdapters }
|
|
25885
26581
|
});
|
|
25886
26582
|
let chain;
|
|
25887
|
-
let officerRunId =
|
|
26583
|
+
let officerRunId = resumedOfficer?.runId;
|
|
25888
26584
|
const runGate = (subject) => requireSubmissionGate({
|
|
25889
26585
|
context,
|
|
25890
26586
|
subject,
|
|
25891
26587
|
toolCallId,
|
|
25892
26588
|
submission: accepted,
|
|
25893
26589
|
summonOfficer,
|
|
26590
|
+
...env.autoResumeLimit === void 0 ? {} : { autoResumeLimit: env.autoResumeLimit },
|
|
25894
26591
|
...env.signal === void 0 ? {} : { signal: env.signal },
|
|
25895
26592
|
hostActions: {
|
|
25896
26593
|
failInfrastructure(error) {
|
|
@@ -25902,13 +26599,13 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
|
|
|
25902
26599
|
});
|
|
25903
26600
|
if (admitted.role === "judge") {
|
|
25904
26601
|
chain = await runJudgeGates({
|
|
25905
|
-
gateAlreadyConverged: async (subject) =>
|
|
26602
|
+
gateAlreadyConverged: async (subject) => passedThisSubmission(gateOfficerForSubject(subject)),
|
|
25906
26603
|
runGate
|
|
25907
26604
|
});
|
|
25908
26605
|
} else {
|
|
25909
26606
|
const subject = admitted.role === "fixer" || admitted.role === "coder" ? { kind: "worker_completion" } : admitted.role === "secretariat" ? { kind: "secretariat_verdict" } : { kind: "countersign_verdict" };
|
|
25910
26607
|
const officer = gateOfficerForSubject(subject);
|
|
25911
|
-
if (
|
|
26608
|
+
if (await passedThisSubmission(officer)) {
|
|
25912
26609
|
chain = { status: "converged", passes: [] };
|
|
25913
26610
|
} else {
|
|
25914
26611
|
const pass = await runGate(subject);
|
|
@@ -25921,17 +26618,29 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
|
|
|
25921
26618
|
status: pass.status,
|
|
25922
26619
|
receipt: pass.receipt,
|
|
25923
26620
|
...pass.runId === void 0 ? {} : { runId: pass.runId },
|
|
25924
|
-
...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory }
|
|
26621
|
+
...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
|
|
26622
|
+
...pass.terminal === void 0 ? {} : { terminal: pass.terminal }
|
|
25925
26623
|
}]
|
|
25926
26624
|
};
|
|
25927
26625
|
}
|
|
25928
26626
|
}
|
|
26627
|
+
if (chain.status === "needs_reask") {
|
|
26628
|
+
const officerTerminal = chain.passes.at(-1)?.terminal;
|
|
26629
|
+
if (officerTerminal === void 0) throw new Error("unreadable audit has no terminal result");
|
|
26630
|
+
if (turn.terminal === void 0) throw new Error("audited submission has no terminal");
|
|
26631
|
+
const terminal2 = presentUnsettledAudit(turn.terminal, officerTerminal, io);
|
|
26632
|
+
return { exitCode: 0, admitted, terminal: terminal2 };
|
|
26633
|
+
}
|
|
25929
26634
|
if (chain.status === "escalate") {
|
|
25930
26635
|
const escalation = chain.passes.at(-1);
|
|
25931
26636
|
const escalatedRunId = escalation?.runId ?? (escalation?.runDirectory === void 0 ? void 0 : runIdFromRunDirectory(escalation.runDirectory));
|
|
25932
26637
|
if (escalatedRunId === void 0) throw new Error("escalated audit has no resumable run identity");
|
|
25933
26638
|
const officer = await loadResumablePublicRole(env.home, escalatedRunId, env.principalAuthority);
|
|
25934
|
-
const terminal2 = await trySettlePublicSeat(
|
|
26639
|
+
const terminal2 = await trySettlePublicSeat(
|
|
26640
|
+
officer.admitted,
|
|
26641
|
+
env.principalAuthority,
|
|
26642
|
+
await readCurrentCourt(officer.admitted.runDirectory)
|
|
26643
|
+
);
|
|
25935
26644
|
if (terminal2 === void 0) throw new Error("escalated audit has no terminal result");
|
|
25936
26645
|
io.stdout(formatTerminalResult(terminal2));
|
|
25937
26646
|
return { exitCode: 0, admitted: officer.admitted, terminal: terminal2 };
|
|
@@ -25940,7 +26649,7 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
|
|
|
25940
26649
|
return runPublicInstructionSeatResume({
|
|
25941
26650
|
runId: admitted.runId,
|
|
25942
26651
|
message: readableGateItem(chain.passes.at(-1)?.receipt)
|
|
25943
|
-
}, { ...env,
|
|
26652
|
+
}, { ...env, unreadableReasksSpent: 0 }, io);
|
|
25944
26653
|
}
|
|
25945
26654
|
if (admitted.role === "secretariat") {
|
|
25946
26655
|
const pass = chain.passes.at(-1);
|
|
@@ -25960,7 +26669,7 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
|
|
|
25960
26669
|
io.stdout(formatTerminalResult(terminal));
|
|
25961
26670
|
return turn;
|
|
25962
26671
|
}
|
|
25963
|
-
var AUDITED_ROLES, SECRETARIAT_STATUS_REASK,
|
|
26672
|
+
var AUDITED_ROLES, SECRETARIAT_STATUS_REASK, WORKER_ROUTING_STATUSES, WORKER_STATUS_REASK, DOCTOR_ROUTING_STATUSES, DOCTOR_STATUS_REASK, POST_SUBMISSION_ROUTING, UNREADABLE_REASK_EXHAUSTED, GATE_CHILD_ROLES;
|
|
25964
26673
|
var init_instruction_seat_run = __esm({
|
|
25965
26674
|
"src/public-cli/instruction-seat-run.ts"() {
|
|
25966
26675
|
"use strict";
|
|
@@ -25969,10 +26678,13 @@ var init_instruction_seat_run = __esm({
|
|
|
25969
26678
|
init_archivist_record_pointer();
|
|
25970
26679
|
init_doctor_auditor();
|
|
25971
26680
|
init_gatekeeper_role();
|
|
26681
|
+
init_submission_errors();
|
|
26682
|
+
init_review_submission();
|
|
25972
26683
|
init_judge_role();
|
|
25973
26684
|
init_worker_submission_contracts();
|
|
25974
26685
|
init_secretariat_contracts();
|
|
25975
26686
|
init_readable_gate_item();
|
|
26687
|
+
init_receipt_delivery_policy();
|
|
25976
26688
|
init_run_terminal_artifacts();
|
|
25977
26689
|
init_submission_gate();
|
|
25978
26690
|
init_submission_ledger();
|
|
@@ -25997,7 +26709,6 @@ var init_instruction_seat_run = __esm({
|
|
|
25997
26709
|
init_unknown_value();
|
|
25998
26710
|
AUDITED_ROLES = /* @__PURE__ */ new Set(["judge", "fixer", "coder", "secretariat", "countersign", "doctor"]);
|
|
25999
26711
|
SECRETARIAT_STATUS_REASK = "secretariatStatus \u4E0D\u662F converged\u3001escalate \u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0CsecretariatStatus \u5199\u660E\u5176\u4E00\u3002";
|
|
26000
|
-
COUNTERSIGN_STATUS_REASK = "status \u4E0D\u662F converged\u3001continue\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
|
|
26001
26712
|
WORKER_ROUTING_STATUSES = /* @__PURE__ */ new Set([
|
|
26002
26713
|
"planned",
|
|
26003
26714
|
"completed",
|
|
@@ -26010,8 +26721,7 @@ var init_instruction_seat_run = __esm({
|
|
|
26010
26721
|
DOCTOR_STATUS_REASK = "status \u4E0D\u662F completed\u3001refused \u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
|
|
26011
26722
|
POST_SUBMISSION_ROUTING = {
|
|
26012
26723
|
judge: {
|
|
26013
|
-
statuses:
|
|
26014
|
-
reask: "status \u4E0D\u662F converged\u3001continue\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002"
|
|
26724
|
+
statuses: REVIEW_QUEUE_STATUSES
|
|
26015
26725
|
},
|
|
26016
26726
|
coder: {
|
|
26017
26727
|
statuses: WORKER_ROUTING_STATUSES,
|
|
@@ -26032,7 +26742,7 @@ var init_instruction_seat_run = __esm({
|
|
|
26032
26742
|
reask: DOCTOR_STATUS_REASK
|
|
26033
26743
|
}
|
|
26034
26744
|
};
|
|
26035
|
-
|
|
26745
|
+
UNREADABLE_REASK_EXHAUSTED = { unreadableReaskExhausted: true };
|
|
26036
26746
|
GATE_CHILD_ROLES = /* @__PURE__ */ new Set(["notary", "auditor", "inspector", "countersign"]);
|
|
26037
26747
|
}
|
|
26038
26748
|
});
|
|
@@ -26653,10 +27363,14 @@ async function runComplianceAudit(options) {
|
|
|
26653
27363
|
});
|
|
26654
27364
|
});
|
|
26655
27365
|
let reask;
|
|
27366
|
+
let reasksSpent = 0;
|
|
27367
|
+
const reaskLimit = deliveryLimitFromConfig(options.autoResumeLimit);
|
|
26656
27368
|
for (; ; ) {
|
|
26657
27369
|
const summoned = await summon(subject, runDirectory, options.signal, reask, submission);
|
|
26658
27370
|
const decision = await projectAuditorTerminal(summoned);
|
|
26659
27371
|
if (decision.status === "received") {
|
|
27372
|
+
if (reasksSpent >= reaskLimit) return decision;
|
|
27373
|
+
reasksSpent += 1;
|
|
26660
27374
|
reask = officerConclusionReask(receivedDiscriminator(decision.reply, "status"));
|
|
26661
27375
|
continue;
|
|
26662
27376
|
}
|
|
@@ -26672,6 +27386,7 @@ var init_compliance_transport = __esm({
|
|
|
26672
27386
|
init_submission_errors();
|
|
26673
27387
|
init_terminal();
|
|
26674
27388
|
init_readable_gate_item();
|
|
27389
|
+
init_receipt_delivery_policy();
|
|
26675
27390
|
init_unknown_value();
|
|
26676
27391
|
AUDITOR_DOSSIER_PROMPT = "\u5377\u5B97\u6307\u9488\uFF1A";
|
|
26677
27392
|
AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
|
|
@@ -26805,7 +27520,7 @@ __export(run_lifecycle_exports, {
|
|
|
26805
27520
|
renderResumeCommand: () => renderResumeCommand,
|
|
26806
27521
|
writeRoleRunState: () => writeRoleRunState
|
|
26807
27522
|
});
|
|
26808
|
-
import { chmod, lstat as lstat5, open, readdir as readdir6, readFile as
|
|
27523
|
+
import { chmod, lstat as lstat5, open, readdir as readdir6, readFile as readFile17, unlink as unlink4, writeFile as writeFile5 } from "node:fs/promises";
|
|
26809
27524
|
import { basename as basename8, join as join31 } from "node:path";
|
|
26810
27525
|
function buildAutoResumeContinuationPrompt(options) {
|
|
26811
27526
|
return appendEngineSessionMaterial(
|
|
@@ -26882,7 +27597,7 @@ function parseCurrentCourtState(raw) {
|
|
|
26882
27597
|
async function readRoleRunStateRaw(runDirectory) {
|
|
26883
27598
|
let raw;
|
|
26884
27599
|
try {
|
|
26885
|
-
raw = JSON.parse(await
|
|
27600
|
+
raw = JSON.parse(await readFile17(join31(runDirectory, RUN_STATE_FILE), "utf8"));
|
|
26886
27601
|
} catch (error) {
|
|
26887
27602
|
if (errorCodeOf(error) === "ENOENT") return void 0;
|
|
26888
27603
|
throw error;
|
|
@@ -27140,7 +27855,7 @@ function isProcessAlive(pid) {
|
|
|
27140
27855
|
async function autopsyWriterLock(lockPath) {
|
|
27141
27856
|
let content;
|
|
27142
27857
|
try {
|
|
27143
|
-
content = await
|
|
27858
|
+
content = await readFile17(lockPath, "utf8");
|
|
27144
27859
|
} catch (error) {
|
|
27145
27860
|
if (errorCodeOf(error) === "ENOENT") return { verdict: "absent" };
|
|
27146
27861
|
return { verdict: "unknown", reason: "unreadable", readFailure: error };
|
|
@@ -27337,7 +28052,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
27337
28052
|
let raw;
|
|
27338
28053
|
try {
|
|
27339
28054
|
raw = JSON.parse(
|
|
27340
|
-
await
|
|
28055
|
+
await readFile17(join31(runDirectory, "admitted-request.json"), "utf8")
|
|
27341
28056
|
);
|
|
27342
28057
|
} catch (error) {
|
|
27343
28058
|
if (errorCodeOf(error) === "ENOENT") return void 0;
|
|
@@ -27452,7 +28167,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
27452
28167
|
let sourceRun;
|
|
27453
28168
|
try {
|
|
27454
28169
|
const raw = JSON.parse(
|
|
27455
|
-
await
|
|
28170
|
+
await readFile17(run.admittedRequestPath, "utf8")
|
|
27456
28171
|
);
|
|
27457
28172
|
if (isRecord(raw)) {
|
|
27458
28173
|
const record = raw;
|
|
@@ -27574,7 +28289,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
27574
28289
|
let model;
|
|
27575
28290
|
try {
|
|
27576
28291
|
const invocationRaw = JSON.parse(
|
|
27577
|
-
await
|
|
28292
|
+
await readFile17(join31(run.runDirectory, "invocation.json"), "utf8")
|
|
27578
28293
|
);
|
|
27579
28294
|
if (isRecord(invocationRaw)) {
|
|
27580
28295
|
const rec = invocationRaw;
|
|
@@ -27939,7 +28654,7 @@ var init_run_lifecycle = __esm({
|
|
|
27939
28654
|
});
|
|
27940
28655
|
|
|
27941
28656
|
// src/session-identity.ts
|
|
27942
|
-
import { mkdir as mkdir3, readFile as
|
|
28657
|
+
import { mkdir as mkdir3, readFile as readFile18, rename as rename2, writeFile as writeFile6 } from "node:fs/promises";
|
|
27943
28658
|
import { dirname as dirname18, join as join32 } from "node:path";
|
|
27944
28659
|
function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
27945
28660
|
const bindingPath = (principal) => join32(authority.decode(principal).sessionDirectory, sessionBindingFile);
|
|
@@ -27949,7 +28664,7 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
|
27949
28664
|
},
|
|
27950
28665
|
async load(principal) {
|
|
27951
28666
|
try {
|
|
27952
|
-
const value = JSON.parse(await
|
|
28667
|
+
const value = JSON.parse(await readFile18(bindingPath(principal), "utf8"));
|
|
27953
28668
|
if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
|
|
27954
28669
|
throw new Error("durable session binding is invalid");
|
|
27955
28670
|
}
|
|
@@ -28593,15 +29308,213 @@ async function settleDeferredPersist(admitted, authority, adapters, io, result)
|
|
|
28593
29308
|
io,
|
|
28594
29309
|
true
|
|
28595
29310
|
);
|
|
28596
|
-
return {
|
|
29311
|
+
return {
|
|
29312
|
+
...failed,
|
|
29313
|
+
turnDispatched: true,
|
|
29314
|
+
skipAutoResume: true
|
|
29315
|
+
};
|
|
28597
29316
|
}
|
|
28598
29317
|
}
|
|
29318
|
+
function settlementScopeForTurn(request) {
|
|
29319
|
+
const hasCourt = request.courtAttemptId !== void 0 && request.courtAttemptId.length > 0;
|
|
29320
|
+
const hasScope = request.invocationScopeId !== void 0 && request.invocationScopeId.length > 0;
|
|
29321
|
+
if (!hasCourt && !hasScope) return void 0;
|
|
29322
|
+
return {
|
|
29323
|
+
...hasCourt ? { courtAttemptId: request.courtAttemptId } : {},
|
|
29324
|
+
...hasScope ? { invocationScopeId: request.invocationScopeId } : {}
|
|
29325
|
+
};
|
|
29326
|
+
}
|
|
29327
|
+
async function buildReceiptDeliveryRequest(input) {
|
|
29328
|
+
const { admitted, env, request, receiptDelivery } = input;
|
|
29329
|
+
const hostSessionId = await readStoredHostSessionId(
|
|
29330
|
+
env.host,
|
|
29331
|
+
env.principalAuthority,
|
|
29332
|
+
admitted.principal
|
|
29333
|
+
);
|
|
29334
|
+
return {
|
|
29335
|
+
...request,
|
|
29336
|
+
continuation: {
|
|
29337
|
+
kind: "resume",
|
|
29338
|
+
prompt: JSON.stringify({
|
|
29339
|
+
...receiptDelivery.deliveryState(),
|
|
29340
|
+
deliveryTurns: receiptDelivery.issuedDeliveryRequests() + 1
|
|
29341
|
+
}),
|
|
29342
|
+
...hostSessionId === void 0 ? {} : { hostSessionId }
|
|
29343
|
+
},
|
|
29344
|
+
deliveryRequestLimit: receiptDelivery.limit
|
|
29345
|
+
};
|
|
29346
|
+
}
|
|
29347
|
+
async function settleCompletedHostTurn(input) {
|
|
29348
|
+
const { admitted, env, io, adapters, shouldPresent, request, result, persistRunState, deferredPersist } = input;
|
|
29349
|
+
const finishAfterTurn = input.finishAfterTurn;
|
|
29350
|
+
let stderrLogWriteFailure;
|
|
29351
|
+
try {
|
|
29352
|
+
await writeFile7(
|
|
29353
|
+
join35(admitted.runDirectory, "stderr.log"),
|
|
29354
|
+
result.stderr,
|
|
29355
|
+
"utf8"
|
|
29356
|
+
);
|
|
29357
|
+
} catch (error) {
|
|
29358
|
+
stderrLogWriteFailure = error;
|
|
29359
|
+
await recordBestEffortPostDispatchDiagnostic(
|
|
29360
|
+
admitted,
|
|
29361
|
+
env,
|
|
29362
|
+
`stderr.log write failed (best-effort continue): ${describeErrorIdentity(error)}`,
|
|
29363
|
+
io
|
|
29364
|
+
);
|
|
29365
|
+
}
|
|
29366
|
+
const courtScope = settlementScopeForTurn(request);
|
|
29367
|
+
let settled;
|
|
29368
|
+
let settledOutcome;
|
|
29369
|
+
let hostSignalFailed = false;
|
|
29370
|
+
let resolution;
|
|
29371
|
+
try {
|
|
29372
|
+
const sessionFile = admitted.principal !== void 0 ? env.principalAuthority.decode(admitted.principal).sessionFile : "";
|
|
29373
|
+
const runnerKnownFailure = adapters.resolveRunnerKnownFailure !== void 0 && sessionFile !== "" ? await adapters.resolveRunnerKnownFailure({ result, sessionFile }) : result.knownFailure;
|
|
29374
|
+
resolution = await resolveAuditedRunnerFailureResolution({
|
|
29375
|
+
runner: runnerKnownFailure,
|
|
29376
|
+
sessionFile,
|
|
29377
|
+
credential: void 0,
|
|
29378
|
+
runDirectory: admitted.runDirectory
|
|
29379
|
+
});
|
|
29380
|
+
const processCancelName = processCancelSignalName(env.signal);
|
|
29381
|
+
const directHostFailureSignal = result.timedOut || result.knownFailure !== void 0 || runnerKnownFailure !== void 0 || processCancelName !== void 0;
|
|
29382
|
+
hostSignalFailed = directHostFailureSignal || result.code !== null && result.code !== 0 || resolution.knownFailure !== void 0;
|
|
29383
|
+
settled = await adapters.trySettle(admitted, env.principalAuthority, courtScope);
|
|
29384
|
+
if (settled !== void 0) {
|
|
29385
|
+
settled = await attachRecordedSubmissions(admitted, settled, courtScope);
|
|
29386
|
+
}
|
|
29387
|
+
const settledIsFreshThisAttempt = settled === void 0 || settled.roleOutcome.kind !== "accepted" && settled.roleOutcome.kind !== "audit_escalation" ? true : await attemptProducedFreshSubmission(admitted, courtScope);
|
|
29388
|
+
const staleAcceptanceOutranksRealFailure = !settledIsFreshThisAttempt && hostSignalFailed;
|
|
29389
|
+
const cancelAfterSettle = processCancelSignalName(env.signal);
|
|
29390
|
+
if (settled !== void 0 && shouldPresent(settled) && !directHostFailureSignal && !staleAcceptanceOutranksRealFailure && stderrLogWriteFailure === void 0 && cancelAfterSettle === void 0) {
|
|
29391
|
+
if (settled.roleOutcome.kind === "accepted" && request.courtAttemptId !== void 0 && request.courtAttemptId.length > 0) {
|
|
29392
|
+
try {
|
|
29393
|
+
await clearCurrentCourt(admitted.runDirectory, request.courtAttemptId);
|
|
29394
|
+
} catch (error) {
|
|
29395
|
+
await recordBestEffortPostDispatchDiagnostic(
|
|
29396
|
+
admitted,
|
|
29397
|
+
env,
|
|
29398
|
+
`current-court cleanup failed after accepted settlement (best-effort continue): ${describeErrorIdentity(error)}`,
|
|
29399
|
+
io
|
|
29400
|
+
);
|
|
29401
|
+
}
|
|
29402
|
+
}
|
|
29403
|
+
settledOutcome = {
|
|
29404
|
+
exitCode: exitCodeForTerminalOutcome(settled.roleOutcome),
|
|
29405
|
+
admitted,
|
|
29406
|
+
terminal: settled,
|
|
29407
|
+
turnDispatched: true
|
|
29408
|
+
};
|
|
29409
|
+
}
|
|
29410
|
+
} catch (error) {
|
|
29411
|
+
const settledFailure = await settleAfterTurnStarted(
|
|
29412
|
+
admitted,
|
|
29413
|
+
withEngineDetourInvocationScope({
|
|
29414
|
+
timedOut: false,
|
|
29415
|
+
code: result.code,
|
|
29416
|
+
stderr: result.stderr,
|
|
29417
|
+
thrown: error
|
|
29418
|
+
}, request.invocationScopeId),
|
|
29419
|
+
adapters,
|
|
29420
|
+
env.principalAuthority,
|
|
29421
|
+
io,
|
|
29422
|
+
persistRunState
|
|
29423
|
+
);
|
|
29424
|
+
return { kind: "settled", outcome: await finishAfterTurn({ ...settledFailure, turnDispatched: true, ...deferredPersist }) };
|
|
29425
|
+
}
|
|
29426
|
+
if (settledOutcome !== void 0) {
|
|
29427
|
+
const lateCancel = processCancelSignalName(env.signal);
|
|
29428
|
+
if (lateCancel !== void 0) {
|
|
29429
|
+
return { kind: "settled", outcome: await finishAfterTurn(
|
|
29430
|
+
await settleProcessCancelAfterTurn({
|
|
29431
|
+
admitted,
|
|
29432
|
+
cancelName: lateCancel,
|
|
29433
|
+
result,
|
|
29434
|
+
adapters,
|
|
29435
|
+
env,
|
|
29436
|
+
io,
|
|
29437
|
+
persistRunState,
|
|
29438
|
+
deferredPersist,
|
|
29439
|
+
invocationScopeId: request.invocationScopeId
|
|
29440
|
+
})
|
|
29441
|
+
) };
|
|
29442
|
+
}
|
|
29443
|
+
if (persistRunState) {
|
|
29444
|
+
try {
|
|
29445
|
+
await persistReturnedRunState(admitted, { lawful: true });
|
|
29446
|
+
} catch (error) {
|
|
29447
|
+
await recordBestEffortPostDispatchDiagnostic(
|
|
29448
|
+
admitted,
|
|
29449
|
+
env,
|
|
29450
|
+
`run-state persistence failed beside host terminal (best-effort continue): ${describeErrorIdentity(error)}`,
|
|
29451
|
+
io
|
|
29452
|
+
);
|
|
29453
|
+
}
|
|
29454
|
+
}
|
|
29455
|
+
return { kind: "settled", outcome: await finishAfterTurn({ ...settledOutcome, ...deferredPersist }) };
|
|
29456
|
+
}
|
|
29457
|
+
if (hostSignalFailed) {
|
|
29458
|
+
const resolutionInput = controlledFailureInputFromResolution(resolution);
|
|
29459
|
+
const processCancelName = processCancelSignalName(env.signal);
|
|
29460
|
+
const stderrLogWriteDetails = stderrLogWriteFailure === void 0 ? void 0 : { stderrLogWriteFailure: describeCaughtError(stderrLogWriteFailure) };
|
|
29461
|
+
const failed = await settleAfterTurnStarted(
|
|
29462
|
+
admitted,
|
|
29463
|
+
withEngineDetourInvocationScope({
|
|
29464
|
+
timedOut: result.timedOut,
|
|
29465
|
+
code: result.code,
|
|
29466
|
+
stderr: result.stderr,
|
|
29467
|
+
...resolutionInput,
|
|
29468
|
+
...processCancelName === void 0 ? {} : { knownDiagnostic: processCancelDiagnostic(processCancelName) },
|
|
29469
|
+
// Secondary fact only — never the cause. Rides on whichever channel
|
|
29470
|
+
// classification actually reads (knownFailure.details owns it when
|
|
29471
|
+
// a knownFailure exists; the top-level knownDetails otherwise).
|
|
29472
|
+
...stderrLogWriteDetails === void 0 ? {} : resolutionInput.knownFailure !== void 0 ? {
|
|
29473
|
+
knownFailure: {
|
|
29474
|
+
...resolutionInput.knownFailure,
|
|
29475
|
+
details: { ...resolutionInput.knownFailure.details ?? {}, ...stderrLogWriteDetails }
|
|
29476
|
+
}
|
|
29477
|
+
} : { knownDetails: stderrLogWriteDetails }
|
|
29478
|
+
}, request.invocationScopeId),
|
|
29479
|
+
adapters,
|
|
29480
|
+
env.principalAuthority,
|
|
29481
|
+
io,
|
|
29482
|
+
persistRunState
|
|
29483
|
+
);
|
|
29484
|
+
return { kind: "settled", outcome: await finishAfterTurn(
|
|
29485
|
+
withProcessCancelSkipAutoResume(
|
|
29486
|
+
{ ...failed, turnDispatched: true, ...deferredPersist },
|
|
29487
|
+
env.signal
|
|
29488
|
+
)
|
|
29489
|
+
) };
|
|
29490
|
+
}
|
|
29491
|
+
if (stderrLogWriteFailure !== void 0) {
|
|
29492
|
+
const failed = await settleAfterTurnStarted(
|
|
29493
|
+
admitted,
|
|
29494
|
+
withEngineDetourInvocationScope({
|
|
29495
|
+
timedOut: false,
|
|
29496
|
+
code: result.code,
|
|
29497
|
+
stderr: result.stderr,
|
|
29498
|
+
thrown: stderrLogWriteFailure
|
|
29499
|
+
}, request.invocationScopeId),
|
|
29500
|
+
adapters,
|
|
29501
|
+
env.principalAuthority,
|
|
29502
|
+
io,
|
|
29503
|
+
persistRunState
|
|
29504
|
+
);
|
|
29505
|
+
return { kind: "settled", outcome: await finishAfterTurn({ ...failed, turnDispatched: true, ...deferredPersist }) };
|
|
29506
|
+
}
|
|
29507
|
+
return { kind: "still-missing" };
|
|
29508
|
+
}
|
|
28599
29509
|
async function dispatchPostAdmissionTurn(input) {
|
|
28600
29510
|
const { admitted, env, io, request, lease, adapters, effectiveEngine } = input;
|
|
28601
29511
|
const persistRunState = input.persistRunState !== false;
|
|
28602
29512
|
const deferredPersist = persistRunState ? {} : { needsPersist: true };
|
|
28603
29513
|
const shouldPresent = adapters.shouldPresentSettled ?? ((terminal) => isLawfulTypedTerminalOutcome(terminal.roleOutcome));
|
|
28604
29514
|
let afterDispatchApplied = false;
|
|
29515
|
+
const receiptDelivery = input.receiptDelivery ?? createReceiptDeliveryPolicy(env.autoResumeLimit);
|
|
29516
|
+
let turnDispatched = false;
|
|
29517
|
+
const akSeamDeliversReceipt = env.host !== void 0 && env.host !== "" && env.host !== DEFAULT_ROLE_TURN_HOST;
|
|
28605
29518
|
const finishAfterTurn = async (result) => {
|
|
28606
29519
|
if (afterDispatchApplied) return result;
|
|
28607
29520
|
afterDispatchApplied = true;
|
|
@@ -28699,7 +29612,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28699
29612
|
return { exitCode: 0, admitted, terminal: paused, skipAutoResume: true };
|
|
28700
29613
|
}
|
|
28701
29614
|
} catch (error) {
|
|
28702
|
-
const
|
|
29615
|
+
const settled = await presentControlledFailure2(
|
|
28703
29616
|
admitted,
|
|
28704
29617
|
withEngineDetourInvocationScope({
|
|
28705
29618
|
timedOut: false,
|
|
@@ -28712,7 +29625,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28712
29625
|
io,
|
|
28713
29626
|
persistRunState
|
|
28714
29627
|
);
|
|
28715
|
-
return { ...
|
|
29628
|
+
return { ...settled, ...deferredPersist };
|
|
28716
29629
|
}
|
|
28717
29630
|
}
|
|
28718
29631
|
let turnRequest = {
|
|
@@ -28736,10 +29649,11 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28736
29649
|
let result;
|
|
28737
29650
|
try {
|
|
28738
29651
|
recordRunStart(admitted.runDirectory);
|
|
29652
|
+
turnDispatched = true;
|
|
28739
29653
|
result = await env.roleTurnHost.executeTurn(turnRequest);
|
|
28740
29654
|
} catch (error) {
|
|
28741
29655
|
const processCancelName = processCancelSignalName(env.signal);
|
|
28742
|
-
const
|
|
29656
|
+
const settled = await settleAfterTurnStarted(
|
|
28743
29657
|
admitted,
|
|
28744
29658
|
withEngineDetourInvocationScope({
|
|
28745
29659
|
timedOut: false,
|
|
@@ -28754,175 +29668,111 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28754
29668
|
);
|
|
28755
29669
|
return await finishAfterTurn(
|
|
28756
29670
|
withProcessCancelSkipAutoResume(
|
|
28757
|
-
{ ...
|
|
29671
|
+
{ ...settled, turnDispatched: true, ...deferredPersist },
|
|
28758
29672
|
env.signal
|
|
28759
29673
|
)
|
|
28760
29674
|
);
|
|
28761
29675
|
}
|
|
28762
|
-
|
|
28763
|
-
|
|
28764
|
-
|
|
28765
|
-
|
|
28766
|
-
|
|
28767
|
-
|
|
28768
|
-
|
|
28769
|
-
|
|
28770
|
-
|
|
28771
|
-
|
|
29676
|
+
const settledTurn = await settleCompletedHostTurn({
|
|
29677
|
+
admitted,
|
|
29678
|
+
env,
|
|
29679
|
+
io,
|
|
29680
|
+
adapters,
|
|
29681
|
+
shouldPresent,
|
|
29682
|
+
request,
|
|
29683
|
+
result,
|
|
29684
|
+
persistRunState,
|
|
29685
|
+
deferredPersist,
|
|
29686
|
+
finishAfterTurn
|
|
29687
|
+
});
|
|
29688
|
+
if (settledTurn.kind === "settled") return settledTurn.outcome;
|
|
29689
|
+
while (akSeamDeliversReceipt && receiptDelivery.nextAction() === "request-delivery") {
|
|
29690
|
+
let deliveryResult;
|
|
29691
|
+
let deliveryTurnRequest;
|
|
29692
|
+
try {
|
|
29693
|
+
const deliveryRequest = await buildReceiptDeliveryRequest({
|
|
29694
|
+
admitted,
|
|
29695
|
+
env,
|
|
29696
|
+
// Host and the other axes already selected on this turn ride the
|
|
29697
|
+
// shared projection. The pre-projection request does not have them.
|
|
29698
|
+
request: turnRequest,
|
|
29699
|
+
receiptDelivery
|
|
29700
|
+
});
|
|
29701
|
+
deliveryTurnRequest = {
|
|
29702
|
+
...deliveryRequest,
|
|
29703
|
+
principal: admitted.principal,
|
|
29704
|
+
runDirectory: admitted.runDirectory,
|
|
29705
|
+
...env.signal === void 0 ? {} : { signal: env.signal }
|
|
29706
|
+
};
|
|
29707
|
+
receiptDelivery.recordDeliveryRequest();
|
|
29708
|
+
deliveryResult = await env.roleTurnHost.executeTurn(deliveryTurnRequest);
|
|
29709
|
+
} catch (error) {
|
|
29710
|
+
const settled = await settleAfterTurnStarted(
|
|
29711
|
+
admitted,
|
|
29712
|
+
withEngineDetourInvocationScope(
|
|
29713
|
+
{ timedOut: false, code: null, stderr: "", thrown: error },
|
|
29714
|
+
request.invocationScopeId
|
|
29715
|
+
),
|
|
29716
|
+
adapters,
|
|
29717
|
+
env.principalAuthority,
|
|
29718
|
+
io,
|
|
29719
|
+
persistRunState
|
|
29720
|
+
);
|
|
29721
|
+
return await finishAfterTurn(
|
|
29722
|
+
withProcessCancelSkipAutoResume(
|
|
29723
|
+
{
|
|
29724
|
+
...settled,
|
|
29725
|
+
turnDispatched: true,
|
|
29726
|
+
...deferredPersist
|
|
29727
|
+
},
|
|
29728
|
+
env.signal
|
|
29729
|
+
)
|
|
29730
|
+
);
|
|
29731
|
+
}
|
|
29732
|
+
const deliveryTurn = await settleCompletedHostTurn({
|
|
28772
29733
|
admitted,
|
|
28773
29734
|
env,
|
|
28774
|
-
|
|
28775
|
-
io
|
|
28776
|
-
|
|
28777
|
-
|
|
28778
|
-
|
|
28779
|
-
|
|
28780
|
-
|
|
28781
|
-
|
|
28782
|
-
|
|
28783
|
-
|
|
28784
|
-
|
|
28785
|
-
|
|
28786
|
-
try {
|
|
28787
|
-
const sessionFile = admitted.principal !== void 0 ? env.principalAuthority.decode(admitted.principal).sessionFile : "";
|
|
28788
|
-
const runnerKnownFailure = adapters.resolveRunnerKnownFailure !== void 0 && sessionFile !== "" ? await adapters.resolveRunnerKnownFailure({ result, sessionFile }) : result.knownFailure;
|
|
28789
|
-
resolution = await resolveAuditedRunnerFailureResolution({
|
|
28790
|
-
runner: runnerKnownFailure,
|
|
28791
|
-
sessionFile,
|
|
28792
|
-
credential: void 0,
|
|
28793
|
-
runDirectory: admitted.runDirectory
|
|
29735
|
+
// Only the final Terminal presents; intermediate delivery attempts stay quiet.
|
|
29736
|
+
io: { ...io, stdout: () => {
|
|
29737
|
+
} },
|
|
29738
|
+
adapters,
|
|
29739
|
+
shouldPresent,
|
|
29740
|
+
request: deliveryTurnRequest,
|
|
29741
|
+
result: deliveryResult,
|
|
29742
|
+
// Run-state terminal write belongs to the OUTERMOST turn only, so a
|
|
29743
|
+
// still-silent delivery attempt never makes the run look lawfully terminal.
|
|
29744
|
+
persistRunState: false,
|
|
29745
|
+
deferredPersist,
|
|
29746
|
+
finishAfterTurn
|
|
28794
29747
|
});
|
|
28795
|
-
|
|
28796
|
-
|
|
28797
|
-
hostSignalFailed = directHostFailureSignal || result.code !== null && result.code !== 0 || resolution.knownFailure !== void 0;
|
|
28798
|
-
settled = await adapters.trySettle(admitted, env.principalAuthority, courtScope);
|
|
28799
|
-
if (settled !== void 0) {
|
|
28800
|
-
settled = await attachRecordedSubmissions(admitted, settled, courtScope);
|
|
28801
|
-
}
|
|
28802
|
-
const settledIsFreshThisAttempt = settled === void 0 || settled.roleOutcome.kind !== "accepted" && settled.roleOutcome.kind !== "audit_escalation" ? true : await attemptProducedFreshSubmission(admitted, courtScope);
|
|
28803
|
-
const staleAcceptanceOutranksRealFailure = !settledIsFreshThisAttempt && hostSignalFailed;
|
|
28804
|
-
const cancelAfterSettle = processCancelSignalName(env.signal);
|
|
28805
|
-
if (settled !== void 0 && shouldPresent(settled) && !directHostFailureSignal && !staleAcceptanceOutranksRealFailure && stderrLogWriteFailure === void 0 && cancelAfterSettle === void 0) {
|
|
28806
|
-
if (settled.roleOutcome.kind === "accepted" && request.courtAttemptId !== void 0 && request.courtAttemptId.length > 0) {
|
|
29748
|
+
if (deliveryTurn.kind === "settled") {
|
|
29749
|
+
if (persistRunState && deliveryTurn.outcome.terminal !== void 0) {
|
|
28807
29750
|
try {
|
|
28808
|
-
await
|
|
29751
|
+
await persistReturnedRunState(admitted, {
|
|
29752
|
+
lawful: isLawfulTypedTerminalOutcome(deliveryTurn.outcome.terminal.roleOutcome)
|
|
29753
|
+
});
|
|
28809
29754
|
} catch (error) {
|
|
28810
29755
|
await recordBestEffortPostDispatchDiagnostic(
|
|
28811
29756
|
admitted,
|
|
28812
29757
|
env,
|
|
28813
|
-
`
|
|
29758
|
+
`run-state persistence failed beside\u50AC\u4EA4 terminal (best-effort continue): ${describeErrorIdentity(error)}`,
|
|
28814
29759
|
io
|
|
28815
29760
|
);
|
|
28816
29761
|
}
|
|
28817
29762
|
}
|
|
28818
|
-
|
|
28819
|
-
exitCode: exitCodeForTerminalOutcome(settled.roleOutcome),
|
|
28820
|
-
admitted,
|
|
28821
|
-
terminal: settled,
|
|
28822
|
-
turnDispatched: true
|
|
28823
|
-
};
|
|
29763
|
+
return await finishAfterTurn(deliveryTurn.outcome);
|
|
28824
29764
|
}
|
|
28825
|
-
} catch (error) {
|
|
28826
|
-
const settledFailure = await settleAfterTurnStarted(
|
|
28827
|
-
admitted,
|
|
28828
|
-
withEngineDetourInvocationScope({
|
|
28829
|
-
timedOut: false,
|
|
28830
|
-
code: result.code,
|
|
28831
|
-
stderr: result.stderr,
|
|
28832
|
-
thrown: error
|
|
28833
|
-
}, request.invocationScopeId),
|
|
28834
|
-
adapters,
|
|
28835
|
-
env.principalAuthority,
|
|
28836
|
-
io,
|
|
28837
|
-
persistRunState
|
|
28838
|
-
);
|
|
28839
|
-
return await finishAfterTurn({ ...settledFailure, turnDispatched: true, ...deferredPersist });
|
|
28840
|
-
}
|
|
28841
|
-
if (settledOutcome !== void 0) {
|
|
28842
|
-
const lateCancel = processCancelSignalName(env.signal);
|
|
28843
|
-
if (lateCancel !== void 0) {
|
|
28844
|
-
return await finishAfterTurn(
|
|
28845
|
-
await settleProcessCancelAfterTurn({
|
|
28846
|
-
admitted,
|
|
28847
|
-
cancelName: lateCancel,
|
|
28848
|
-
result,
|
|
28849
|
-
adapters,
|
|
28850
|
-
env,
|
|
28851
|
-
io,
|
|
28852
|
-
persistRunState,
|
|
28853
|
-
deferredPersist,
|
|
28854
|
-
invocationScopeId: request.invocationScopeId
|
|
28855
|
-
})
|
|
28856
|
-
);
|
|
28857
|
-
}
|
|
28858
|
-
if (persistRunState) {
|
|
28859
|
-
try {
|
|
28860
|
-
await persistReturnedRunState(admitted, { lawful: true });
|
|
28861
|
-
} catch (error) {
|
|
28862
|
-
await recordBestEffortPostDispatchDiagnostic(
|
|
28863
|
-
admitted,
|
|
28864
|
-
env,
|
|
28865
|
-
`run-state persistence failed beside host terminal (best-effort continue): ${describeErrorIdentity(error)}`,
|
|
28866
|
-
io
|
|
28867
|
-
);
|
|
28868
|
-
}
|
|
28869
|
-
}
|
|
28870
|
-
return await finishAfterTurn({ ...settledOutcome, ...deferredPersist });
|
|
28871
|
-
}
|
|
28872
|
-
if (hostSignalFailed) {
|
|
28873
|
-
const resolutionInput = controlledFailureInputFromResolution(resolution);
|
|
28874
|
-
const processCancelName = processCancelSignalName(env.signal);
|
|
28875
|
-
const stderrLogWriteDetails = stderrLogWriteFailure === void 0 ? void 0 : { stderrLogWriteFailure: describeCaughtError(stderrLogWriteFailure) };
|
|
28876
|
-
const failed = await settleAfterTurnStarted(
|
|
28877
|
-
admitted,
|
|
28878
|
-
withEngineDetourInvocationScope({
|
|
28879
|
-
timedOut: result.timedOut,
|
|
28880
|
-
code: result.code,
|
|
28881
|
-
stderr: result.stderr,
|
|
28882
|
-
...resolutionInput,
|
|
28883
|
-
...processCancelName === void 0 ? {} : { knownDiagnostic: processCancelDiagnostic(processCancelName) },
|
|
28884
|
-
// Secondary fact only — never the cause. Rides on whichever channel
|
|
28885
|
-
// classification actually reads (knownFailure.details owns it when
|
|
28886
|
-
// a knownFailure exists; the top-level knownDetails otherwise).
|
|
28887
|
-
...stderrLogWriteDetails === void 0 ? {} : resolutionInput.knownFailure !== void 0 ? {
|
|
28888
|
-
knownFailure: {
|
|
28889
|
-
...resolutionInput.knownFailure,
|
|
28890
|
-
details: { ...resolutionInput.knownFailure.details ?? {}, ...stderrLogWriteDetails }
|
|
28891
|
-
}
|
|
28892
|
-
} : { knownDetails: stderrLogWriteDetails }
|
|
28893
|
-
}, request.invocationScopeId),
|
|
28894
|
-
adapters,
|
|
28895
|
-
env.principalAuthority,
|
|
28896
|
-
io,
|
|
28897
|
-
persistRunState
|
|
28898
|
-
);
|
|
28899
|
-
return await finishAfterTurn(
|
|
28900
|
-
withProcessCancelSkipAutoResume(
|
|
28901
|
-
{ ...failed, turnDispatched: true, ...deferredPersist },
|
|
28902
|
-
env.signal
|
|
28903
|
-
)
|
|
28904
|
-
);
|
|
28905
|
-
}
|
|
28906
|
-
if (stderrLogWriteFailure !== void 0) {
|
|
28907
|
-
const failed = await settleAfterTurnStarted(
|
|
28908
|
-
admitted,
|
|
28909
|
-
withEngineDetourInvocationScope({
|
|
28910
|
-
timedOut: false,
|
|
28911
|
-
code: result.code,
|
|
28912
|
-
stderr: result.stderr,
|
|
28913
|
-
thrown: stderrLogWriteFailure
|
|
28914
|
-
}, request.invocationScopeId),
|
|
28915
|
-
adapters,
|
|
28916
|
-
env.principalAuthority,
|
|
28917
|
-
io,
|
|
28918
|
-
persistRunState
|
|
28919
|
-
);
|
|
28920
|
-
return await finishAfterTurn({ ...failed, turnDispatched: true, ...deferredPersist });
|
|
28921
29765
|
}
|
|
29766
|
+
const noReceiptScope = settlementScopeForTurn(request);
|
|
28922
29767
|
const noReceipt = await attachRecordedSubmissions(
|
|
28923
29768
|
admitted,
|
|
28924
|
-
await settleHostEndedNoReceipt(
|
|
28925
|
-
|
|
29769
|
+
await settleHostEndedNoReceipt(
|
|
29770
|
+
admitted,
|
|
29771
|
+
env.principalAuthority,
|
|
29772
|
+
noReceiptScope,
|
|
29773
|
+
receiptDelivery.issuedDeliveryRequests()
|
|
29774
|
+
),
|
|
29775
|
+
noReceiptScope
|
|
28926
29776
|
);
|
|
28927
29777
|
const noReceiptCancel = processCancelSignalName(env.signal);
|
|
28928
29778
|
if (noReceiptCancel !== void 0) {
|
|
@@ -28959,6 +29809,11 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
28959
29809
|
turnDispatched: true,
|
|
28960
29810
|
...deferredPersist
|
|
28961
29811
|
});
|
|
29812
|
+
} catch (error) {
|
|
29813
|
+
if (turnDispatched && !(error instanceof TurnDispatchedFailure)) {
|
|
29814
|
+
throw new TurnDispatchedFailure(error);
|
|
29815
|
+
}
|
|
29816
|
+
throw error;
|
|
28962
29817
|
} finally {
|
|
28963
29818
|
if (lease !== void 0) {
|
|
28964
29819
|
try {
|
|
@@ -29004,7 +29859,9 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
|
|
|
29004
29859
|
prompt
|
|
29005
29860
|
},
|
|
29006
29861
|
...request.message === void 0 ? {} : { courtAttemptId: randomUUID6() },
|
|
29007
|
-
...env.stationChild === void 0 ? {} : { stationChild: env.stationChild }
|
|
29862
|
+
...env.stationChild === void 0 ? {} : { stationChild: env.stationChild },
|
|
29863
|
+
// #1132: one configured ceiling, already resolved by the caller (#422).
|
|
29864
|
+
deliveryRequestLimit: deliveryLimitFromConfig(env.autoResumeLimit)
|
|
29008
29865
|
};
|
|
29009
29866
|
}
|
|
29010
29867
|
function roleTurnOptions(env, admitted, continuation) {
|
|
@@ -29014,7 +29871,9 @@ function roleTurnOptions(env, admitted, continuation) {
|
|
|
29014
29871
|
...env.host === void 0 ? {} : { host: env.host },
|
|
29015
29872
|
...correlationId === void 0 || correlationId.trim() === "" ? {} : { correlationId },
|
|
29016
29873
|
continuation,
|
|
29017
|
-
...env.stationChild === void 0 ? {} : { stationChild: env.stationChild }
|
|
29874
|
+
...env.stationChild === void 0 ? {} : { stationChild: env.stationChild },
|
|
29875
|
+
// #1132: one configured ceiling, already resolved by the caller (#422).
|
|
29876
|
+
deliveryRequestLimit: deliveryLimitFromConfig(env.autoResumeLimit)
|
|
29018
29877
|
};
|
|
29019
29878
|
}
|
|
29020
29879
|
async function dispatchAfterWriterLease(input) {
|
|
@@ -29032,6 +29891,7 @@ async function dispatchAfterWriterLease(input) {
|
|
|
29032
29891
|
async function runSettledAutoResumeLoop(input) {
|
|
29033
29892
|
const adapters = withOnceSuccessfulBeforeDispatch(input.adapters);
|
|
29034
29893
|
const dispatchEnv = input.dispatchEnv ?? input.env;
|
|
29894
|
+
const receiptDelivery = createReceiptDeliveryPolicy(input.env.autoResumeLimit);
|
|
29035
29895
|
return runWithAutoResumeLoop({
|
|
29036
29896
|
admitted: input.admitted,
|
|
29037
29897
|
principalAuthority: input.env.principalAuthority,
|
|
@@ -29053,6 +29913,7 @@ async function runSettledAutoResumeLoop(input) {
|
|
|
29053
29913
|
...lease === void 0 ? {} : { lease },
|
|
29054
29914
|
adapters,
|
|
29055
29915
|
persistRunState: false,
|
|
29916
|
+
receiptDelivery,
|
|
29056
29917
|
...input.effectiveEngine === void 0 ? {} : { effectiveEngine: input.effectiveEngine }
|
|
29057
29918
|
});
|
|
29058
29919
|
return settleDeferredPersist(
|
|
@@ -29415,12 +30276,14 @@ var init_post_admission = __esm({
|
|
|
29415
30276
|
init_activation_ledger_topology();
|
|
29416
30277
|
init_engine_material();
|
|
29417
30278
|
init_session_identity();
|
|
30279
|
+
init_receipt_delivery_policy();
|
|
29418
30280
|
init_role_run_relocation();
|
|
29419
30281
|
init_packaged_role_registry();
|
|
29420
30282
|
init_engine_detour_usage();
|
|
29421
30283
|
init_run_lifecycle();
|
|
29422
30284
|
init_process_cancel();
|
|
29423
30285
|
init_activation_ledger_topology();
|
|
30286
|
+
init_host_descriptions();
|
|
29424
30287
|
init_host_session_record();
|
|
29425
30288
|
init_settlement();
|
|
29426
30289
|
init_terminal();
|
|
@@ -29486,7 +30349,7 @@ var init_atomic_write = __esm({
|
|
|
29486
30349
|
});
|
|
29487
30350
|
|
|
29488
30351
|
// src/analyst-index.ts
|
|
29489
|
-
import { open as open3, readFile as
|
|
30352
|
+
import { open as open3, readFile as readFile19, unlink as unlink5 } from "node:fs/promises";
|
|
29490
30353
|
import { dirname as dirname21, join as join37 } from "node:path";
|
|
29491
30354
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
29492
30355
|
async function withAnalystLibraryIndexLock(ledgerHome, fn) {
|
|
@@ -29610,7 +30473,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
|
|
|
29610
30473
|
const path = analystLibraryIndexPath(ledgerHome);
|
|
29611
30474
|
let raw;
|
|
29612
30475
|
try {
|
|
29613
|
-
raw = await
|
|
30476
|
+
raw = await readFile19(path, "utf8");
|
|
29614
30477
|
} catch (error) {
|
|
29615
30478
|
if (isMissingPathError(error)) return void 0;
|
|
29616
30479
|
throw error;
|
|
@@ -29813,7 +30676,7 @@ var init_analyst_cohort = __esm({
|
|
|
29813
30676
|
});
|
|
29814
30677
|
|
|
29815
30678
|
// src/analyst-ledger.ts
|
|
29816
|
-
import { readdir as readdir7, readFile as
|
|
30679
|
+
import { readdir as readdir7, readFile as readFile20 } from "node:fs/promises";
|
|
29817
30680
|
import { basename as basename9, join as join38 } from "node:path";
|
|
29818
30681
|
async function readExistingRunLifecycleState(runDirectory) {
|
|
29819
30682
|
return (await readRoleRunIdentity(runDirectory))?.state;
|
|
@@ -29863,7 +30726,7 @@ async function listLedgerBookNames(booksRoot) {
|
|
|
29863
30726
|
async function readInvocationScopeFields(runDirectory) {
|
|
29864
30727
|
let raw;
|
|
29865
30728
|
try {
|
|
29866
|
-
raw = await
|
|
30729
|
+
raw = await readFile20(join38(runDirectory, "invocation.json"), "utf8");
|
|
29867
30730
|
} catch (error) {
|
|
29868
30731
|
if (isMissingPathError(error)) return void 0;
|
|
29869
30732
|
throw error;
|
|
@@ -29896,7 +30759,7 @@ function decideIssueScope(input) {
|
|
|
29896
30759
|
}
|
|
29897
30760
|
async function resolveSessionFile(runDirectory) {
|
|
29898
30761
|
try {
|
|
29899
|
-
const raw = await
|
|
30762
|
+
const raw = await readFile20(join38(runDirectory, "invocation.json"), "utf8");
|
|
29900
30763
|
const parsed = JSON.parse(raw);
|
|
29901
30764
|
if (isRecord(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
|
|
29902
30765
|
return parsed.sessionFile;
|
|
@@ -31156,7 +32019,7 @@ var init_analyst_model_groups = __esm({
|
|
|
31156
32019
|
});
|
|
31157
32020
|
|
|
31158
32021
|
// src/analyst-entry.ts
|
|
31159
|
-
import { readFile as
|
|
32022
|
+
import { readFile as readFile21 } from "node:fs/promises";
|
|
31160
32023
|
function cachedPageMatchesRequestedScope(page, input) {
|
|
31161
32024
|
if (page.bookKey !== input.bookKey) return false;
|
|
31162
32025
|
const requestedTicket = input.ticketNumber ?? input.issueNumber;
|
|
@@ -31183,7 +32046,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
|
|
|
31183
32046
|
...issueNumber === void 0 && input.bookKey === void 0 ? { scopeRootIdentity: projectRoot } : {}
|
|
31184
32047
|
});
|
|
31185
32048
|
try {
|
|
31186
|
-
const raw = await
|
|
32049
|
+
const raw = await readFile21(pagePath, "utf8");
|
|
31187
32050
|
const page = JSON.parse(raw);
|
|
31188
32051
|
if (cachedPageMatchesRequestedScope(page, { bookKey, ...input })) {
|
|
31189
32052
|
const ghostScan = await scanAnalystIssueRuns({
|
|
@@ -31284,7 +32147,7 @@ async function runAnalystModelGroupsMode(input, home) {
|
|
|
31284
32147
|
scopeRootIdentity: projectRoot
|
|
31285
32148
|
});
|
|
31286
32149
|
try {
|
|
31287
|
-
const raw = await
|
|
32150
|
+
const raw = await readFile21(pagePath, "utf8");
|
|
31288
32151
|
JSON.parse(raw);
|
|
31289
32152
|
} catch (error) {
|
|
31290
32153
|
if (!isMissingPathError(error)) {
|
|
@@ -31382,7 +32245,7 @@ var init_analyst_entry = __esm({
|
|
|
31382
32245
|
});
|
|
31383
32246
|
|
|
31384
32247
|
// src/public-cli/analyst-run.ts
|
|
31385
|
-
import { readFile as
|
|
32248
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
31386
32249
|
import { isAbsolute as isAbsolute10, resolve as resolve13 } from "node:path";
|
|
31387
32250
|
function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
|
|
31388
32251
|
try {
|
|
@@ -31435,7 +32298,7 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
|
|
|
31435
32298
|
const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve13(sourcePath);
|
|
31436
32299
|
let bytes;
|
|
31437
32300
|
try {
|
|
31438
|
-
bytes = await
|
|
32301
|
+
bytes = await readFile22(absolute);
|
|
31439
32302
|
} catch (error) {
|
|
31440
32303
|
throw new CliUsageError(
|
|
31441
32304
|
`analyst sweep attachment is not a readable regular file: ${sourcePath}`,
|
|
@@ -32324,7 +33187,7 @@ async function runAkRole(argv2, env) {
|
|
|
32324
33187
|
io
|
|
32325
33188
|
);
|
|
32326
33189
|
let current = result;
|
|
32327
|
-
while (current.exitCode === 0 && current.admitted?.correlationId !== void 0 && current.terminal?.roleOutcome.kind === "accepted" && !latestPayloadEscalated(current.terminal.roleOutcome)) {
|
|
33190
|
+
while (current.exitCode === 0 && current.admitted?.correlationId !== void 0 && current.terminal?.roleOutcome.kind === "accepted" && current.terminal.roleOutcome.decisiveFacts?.directionUnsettled !== true && !latestPayloadEscalated(current.terminal.roleOutcome)) {
|
|
32328
33191
|
const parentRunId = current.admitted.correlationId;
|
|
32329
33192
|
resumeFailureContext = {
|
|
32330
33193
|
home,
|