@amaster.ai/employee-runtime-connector 0.1.1 → 0.1.3
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.
|
@@ -4285,6 +4285,8 @@ var ISSUE_THREAD_INTERACTION_KINDS = [
|
|
|
4285
4285
|
"request_confirmation",
|
|
4286
4286
|
"request_checkbox_confirmation"
|
|
4287
4287
|
];
|
|
4288
|
+
var ASK_USER_QUESTIONS_FIELD_VALUE_MAX_LENGTH = 2e3;
|
|
4289
|
+
var ASK_USER_QUESTIONS_OTHER_TEXT_MAX_LENGTH = 4e3;
|
|
4288
4290
|
var ISSUE_THREAD_INTERACTION_SETTLEMENT_PURPOSE_CODES = [
|
|
4289
4291
|
"request_required_inputs",
|
|
4290
4292
|
"clarify_required_scope",
|
|
@@ -4932,6 +4934,7 @@ var AMASTER_RUNTIME_CONNECTOR_CAPABILITIES = [
|
|
|
4932
4934
|
"run_exit_live_path_closure_v1",
|
|
4933
4935
|
"browser_credential_ref_fill_v1",
|
|
4934
4936
|
"browser_credential_auth_transaction_v1",
|
|
4937
|
+
"browser_credential_env_read_v1",
|
|
4935
4938
|
"execution_lanes_v1",
|
|
4936
4939
|
"mirrorx_initialization_context_v1",
|
|
4937
4940
|
"mirrorx_initialization_completion_v1",
|
|
@@ -6790,6 +6793,11 @@ var goalGapCausalSourceSchema = external_exports.discriminatedUnion("kind", [
|
|
|
6790
6793
|
external_exports.object({ kind: external_exports.literal("work_family"), workFamilyKey: sha256Schema }).strict(),
|
|
6791
6794
|
external_exports.object({
|
|
6792
6795
|
kind: external_exports.literal("board_direct"),
|
|
6796
|
+
decisionStateId: external_exports.string().uuid(),
|
|
6797
|
+
decisionResolutionRevision: external_exports.number().int().positive()
|
|
6798
|
+
}).strict(),
|
|
6799
|
+
external_exports.object({
|
|
6800
|
+
kind: external_exports.literal("legacy_task_attribution"),
|
|
6793
6801
|
interactionId: external_exports.string().uuid(),
|
|
6794
6802
|
resolutionRevision: external_exports.number().int().positive()
|
|
6795
6803
|
}).strict()
|
|
@@ -6848,26 +6856,38 @@ var boardResolveGoalGapAuthoritySchema = external_exports.discriminatedUnion("de
|
|
|
6848
6856
|
remindAt: external_exports.string().datetime({ offset: true }).optional()
|
|
6849
6857
|
}).strict()
|
|
6850
6858
|
]);
|
|
6851
|
-
var
|
|
6859
|
+
var DEFAULT_ATTRIBUTE_LEGACY_OUTCOME_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u6839\u636E\u539F\u4EFB\u52A1\u4E0E\u9A8C\u6536\u8BC1\u636E\u786E\u8BA4\u8BE5\u5386\u53F2\u4EA4\u4ED8\u5F52\u5C5E\u4E8E\u6240\u9009\u8FBE\u6210\u6807\u51C6\u3002";
|
|
6860
|
+
var DEFAULT_NOT_GOAL_EFFECT_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u6839\u636E\u539F\u4EFB\u52A1\u4E0E\u9A8C\u6536\u8BC1\u636E\u786E\u8BA4\u8BE5\u5386\u53F2\u4EA4\u4ED8\u4E0D\u5F71\u54CD\u5F53\u524D\u76EE\u6807\u3002";
|
|
6861
|
+
var DEFAULT_DEFER_LEGACY_OUTCOME_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u8BBE\u7F6E\u4E86\u5386\u53F2\u4EA4\u4ED8\u5F52\u5C5E\u7684\u4E0B\u6B21\u786E\u8BA4\u65F6\u95F4\u3002";
|
|
6862
|
+
var DEFAULT_CORRECT_FACTS_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u786E\u8BA4\u5F53\u524D\u8BB0\u5F55\u9700\u8981\u6309\u6700\u65B0\u4E8B\u5B9E\u66F4\u6B63\u3002";
|
|
6863
|
+
var boardResolveLegacyOutcomeGapCommonSchema = external_exports.object({
|
|
6852
6864
|
expectedAuthorityRevision: external_exports.number().int().min(0),
|
|
6853
6865
|
expectedContractId: external_exports.string().uuid().nullable(),
|
|
6854
6866
|
readinessStateId: external_exports.string().uuid(),
|
|
6855
6867
|
expectedReadinessRevision: external_exports.number().int().positive(),
|
|
6856
6868
|
interactionId: external_exports.string().uuid(),
|
|
6857
6869
|
resolutionRevision: external_exports.number().int().positive(),
|
|
6858
|
-
rationale: external_exports.string().trim().min(1).max(2e3),
|
|
6859
6870
|
observedAt: external_exports.string().datetime({ offset: true }),
|
|
6860
6871
|
idempotencyKey: external_exports.string().trim().min(1).max(200)
|
|
6861
6872
|
});
|
|
6873
|
+
var optionalLegacyOutcomeRationaleSchema = (defaultValue) => external_exports.string().trim().max(2e3).optional().transform((value) => value || defaultValue);
|
|
6862
6874
|
var boardResolveLegacyOutcomeGapSchema = external_exports.discriminatedUnion("decision", [
|
|
6863
|
-
|
|
6875
|
+
boardResolveLegacyOutcomeGapCommonSchema.extend({
|
|
6864
6876
|
decision: external_exports.literal("attribute_to_criterion"),
|
|
6865
|
-
criterionIndex: external_exports.number().int().min(0).max(9)
|
|
6877
|
+
criterionIndex: external_exports.number().int().min(0).max(9),
|
|
6878
|
+
rationale: optionalLegacyOutcomeRationaleSchema(DEFAULT_ATTRIBUTE_LEGACY_OUTCOME_RATIONALE)
|
|
6879
|
+
}).strict(),
|
|
6880
|
+
boardResolveLegacyOutcomeGapCommonSchema.extend({
|
|
6881
|
+
decision: external_exports.literal("not_goal_effect"),
|
|
6882
|
+
rationale: optionalLegacyOutcomeRationaleSchema(DEFAULT_NOT_GOAL_EFFECT_RATIONALE)
|
|
6883
|
+
}).strict(),
|
|
6884
|
+
boardResolveLegacyOutcomeGapCommonSchema.extend({
|
|
6885
|
+
decision: external_exports.literal("correct_facts"),
|
|
6886
|
+
rationale: optionalLegacyOutcomeRationaleSchema(DEFAULT_CORRECT_FACTS_RATIONALE)
|
|
6866
6887
|
}).strict(),
|
|
6867
|
-
|
|
6868
|
-
boardResolveLegacyOutcomeGapBaseSchema.extend({ decision: external_exports.literal("correct_facts") }).strict(),
|
|
6869
|
-
boardResolveLegacyOutcomeGapBaseSchema.extend({
|
|
6888
|
+
boardResolveLegacyOutcomeGapCommonSchema.extend({
|
|
6870
6889
|
decision: external_exports.literal("defer"),
|
|
6890
|
+
rationale: optionalLegacyOutcomeRationaleSchema(DEFAULT_DEFER_LEGACY_OUTCOME_RATIONALE),
|
|
6871
6891
|
remindAt: external_exports.string().datetime({ offset: true }).optional()
|
|
6872
6892
|
}).strict()
|
|
6873
6893
|
]);
|
|
@@ -7027,13 +7047,6 @@ var goalCriterionProgressReadModelSchema = external_exports.object({
|
|
|
7027
7047
|
status: external_exports.enum(GOAL_CRITERION_PROGRESS_STATUSES),
|
|
7028
7048
|
statusLabel: external_exports.string().min(1),
|
|
7029
7049
|
decisionKind: external_exports.enum(GOAL_CRITERION_DECISION_KINDS).nullable(),
|
|
7030
|
-
decisionContext: external_exports.discriminatedUnion("kind", [
|
|
7031
|
-
external_exports.object({
|
|
7032
|
-
kind: external_exports.literal("legacy_outcome_attribution"),
|
|
7033
|
-
sourceIssueId: external_exports.string().uuid(),
|
|
7034
|
-
sourceIssueTitle: external_exports.string().min(1)
|
|
7035
|
-
}).strict()
|
|
7036
|
-
]).nullable().optional(),
|
|
7037
7050
|
question: external_exports.string().min(1).nullable(),
|
|
7038
7051
|
factInput: external_exports.object({
|
|
7039
7052
|
kind: external_exports.enum(["boolean", "count", "amount", "ratio"]),
|
|
@@ -7059,10 +7072,17 @@ var goalCriterionProgressReadModelSchema = external_exports.object({
|
|
|
7059
7072
|
unknownSummary: external_exports.string().min(1).nullable(),
|
|
7060
7073
|
sourceSummary: external_exports.array(external_exports.string().min(1)).max(20),
|
|
7061
7074
|
lastCheckedAt: external_exports.string().datetime().nullable(),
|
|
7075
|
+
latestDecision: external_exports.object({
|
|
7076
|
+
action: external_exports.enum(GOAL_CRITERION_DECISION_ACTIONS),
|
|
7077
|
+
rationale: external_exports.string().min(1),
|
|
7078
|
+
actorType: external_exports.enum(["user", "agent", "system"]),
|
|
7079
|
+
decidedAt: external_exports.string().datetime()
|
|
7080
|
+
}).strict().nullable(),
|
|
7062
7081
|
decisionImpact: external_exports.string().min(1),
|
|
7063
7082
|
allowedActions: external_exports.array(external_exports.enum(GOAL_CRITERION_DECISION_ACTIONS)),
|
|
7064
7083
|
relatedDemands: external_exports.array(goalCriterionRelatedWorkSchema).max(20),
|
|
7065
7084
|
relatedTasks: external_exports.array(goalCriterionRelatedWorkSchema).max(20),
|
|
7085
|
+
decisionStateId: external_exports.string().uuid().nullable(),
|
|
7066
7086
|
decisionRevision: external_exports.number().int().nonnegative().nullable(),
|
|
7067
7087
|
attentionItemKey: external_exports.string().min(1).nullable().optional(),
|
|
7068
7088
|
expectedDecisionToken: sha256Schema.nullable(),
|
|
@@ -7093,10 +7113,10 @@ var goalCriteriaProgressReadModelSchema = external_exports.object({
|
|
|
7093
7113
|
var DEFAULT_CONTINUE_PROGRESS_RATIONALE = "\u516C\u53F8\u7BA1\u7406\u5458\u786E\u8BA4\u5F53\u524D\u4E1A\u52A1\u7ED3\u679C\u5C1A\u672A\u8FBE\u5230\uFF0C\u7EE7\u7EED\u63A8\u8FDB\u3002";
|
|
7094
7114
|
var DEFAULT_KEEP_IN_GOAL_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u786E\u8BA4\u8FD9\u6761\u8FBE\u6210\u6807\u51C6\u4ECD\u9002\u7528\u4E8E\u5F53\u524D\u76EE\u6807\u3002";
|
|
7095
7115
|
var DEFAULT_DEFER_GOAL_CRITERION_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u8BBE\u7F6E\u4E86\u4E0B\u6B21\u786E\u8BA4\u65F6\u95F4\u3002";
|
|
7096
|
-
var
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7116
|
+
var DEFAULT_MARK_NOT_APPLICABLE_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u786E\u8BA4\u8FD9\u6761\u8FBE\u6210\u6807\u51C6\u5F53\u524D\u4E0D\u518D\u9002\u7528\u4E8E\u76EE\u6807\u3002";
|
|
7117
|
+
var DEFAULT_CONFIRM_ACHIEVED_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u6839\u636E\u5F53\u524D\u7ECF\u8425\u4E8B\u5B9E\u786E\u8BA4\u8FD9\u6761\u8FBE\u6210\u6807\u51C6\u5DF2\u7ECF\u8FBE\u5230\u3002";
|
|
7118
|
+
var DEFAULT_SUBMIT_CORRECTED_FACT_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u63D0\u4EA4\u4E86\u7ECF\u6838\u5B9E\u7684\u6B63\u786E\u4E8B\u5B9E\u3002";
|
|
7119
|
+
var DEFAULT_WAIT_FOR_EXTERNAL_FACT_RATIONALE = "\u516C\u53F8\u8D1F\u8D23\u4EBA\u786E\u8BA4\u9700\u8981\u7B49\u5F85\u5916\u90E8\u6743\u5A01\u6570\u636E\u66F4\u65B0\u3002";
|
|
7100
7120
|
var continueProgressRationaleSchema = external_exports.string().trim().max(2e3).optional().transform((value) => value || DEFAULT_CONTINUE_PROGRESS_RATIONALE);
|
|
7101
7121
|
var optionalGoalCriterionRationaleSchema = (defaultValue) => external_exports.string().trim().max(2e3).optional().transform((value) => value || defaultValue);
|
|
7102
7122
|
var correctedFactSourceSchema = external_exports.object({
|
|
@@ -7113,12 +7133,20 @@ var correctedGoalCriterionFactSchema = external_exports.object({
|
|
|
7113
7133
|
source: correctedFactSourceSchema
|
|
7114
7134
|
}).strict();
|
|
7115
7135
|
var boardDecideGoalCriterionSchema = external_exports.discriminatedUnion("action", [
|
|
7116
|
-
|
|
7117
|
-
action: external_exports.
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7136
|
+
external_exports.object({
|
|
7137
|
+
action: external_exports.literal("mark_not_applicable"),
|
|
7138
|
+
rationale: optionalGoalCriterionRationaleSchema(DEFAULT_MARK_NOT_APPLICABLE_RATIONALE),
|
|
7139
|
+
expectedDecisionToken: sha256Schema
|
|
7140
|
+
}).strict(),
|
|
7141
|
+
external_exports.object({
|
|
7142
|
+
action: external_exports.literal("confirm_achieved"),
|
|
7143
|
+
rationale: optionalGoalCriterionRationaleSchema(DEFAULT_CONFIRM_ACHIEVED_RATIONALE),
|
|
7144
|
+
expectedDecisionToken: sha256Schema
|
|
7145
|
+
}).strict(),
|
|
7146
|
+
external_exports.object({
|
|
7147
|
+
action: external_exports.literal("correct_facts"),
|
|
7148
|
+
rationale: optionalGoalCriterionRationaleSchema(DEFAULT_CORRECT_FACTS_RATIONALE),
|
|
7149
|
+
expectedDecisionToken: sha256Schema
|
|
7122
7150
|
}).strict(),
|
|
7123
7151
|
external_exports.object({
|
|
7124
7152
|
action: external_exports.literal("keep_in_goal"),
|
|
@@ -7136,12 +7164,16 @@ var boardDecideGoalCriterionSchema = external_exports.discriminatedUnion("action
|
|
|
7136
7164
|
expectedDecisionToken: sha256Schema,
|
|
7137
7165
|
remindAt: external_exports.string().datetime({ offset: true })
|
|
7138
7166
|
}).strict(),
|
|
7139
|
-
|
|
7167
|
+
external_exports.object({
|
|
7140
7168
|
action: external_exports.literal("submit_corrected_fact"),
|
|
7169
|
+
rationale: optionalGoalCriterionRationaleSchema(DEFAULT_SUBMIT_CORRECTED_FACT_RATIONALE),
|
|
7170
|
+
expectedDecisionToken: sha256Schema,
|
|
7141
7171
|
correction: correctedGoalCriterionFactSchema
|
|
7142
7172
|
}).strict(),
|
|
7143
|
-
|
|
7173
|
+
external_exports.object({
|
|
7144
7174
|
action: external_exports.literal("wait_for_external_fact"),
|
|
7175
|
+
rationale: optionalGoalCriterionRationaleSchema(DEFAULT_WAIT_FOR_EXTERNAL_FACT_RATIONALE),
|
|
7176
|
+
expectedDecisionToken: sha256Schema,
|
|
7145
7177
|
awaitedFactKind: goalGapIndependentObservationSourceKindSchema,
|
|
7146
7178
|
expectedAt: external_exports.string().datetime({ offset: true }).optional()
|
|
7147
7179
|
}).strict()
|
|
@@ -7178,7 +7210,7 @@ var goalGapContractReadResponseSchema = external_exports.object({
|
|
|
7178
7210
|
pendingDecisions: external_exports.array(external_exports.discriminatedUnion("kind", [
|
|
7179
7211
|
external_exports.object({
|
|
7180
7212
|
kind: external_exports.literal("observed_effect"),
|
|
7181
|
-
|
|
7213
|
+
decisionStateId: external_exports.string().uuid(),
|
|
7182
7214
|
gapKey: external_exports.string(),
|
|
7183
7215
|
criterionId: external_exports.string().uuid(),
|
|
7184
7216
|
title: external_exports.string(),
|
|
@@ -7191,7 +7223,7 @@ var goalGapContractReadResponseSchema = external_exports.object({
|
|
|
7191
7223
|
}).strict(),
|
|
7192
7224
|
external_exports.object({
|
|
7193
7225
|
kind: external_exports.literal("gap_authority"),
|
|
7194
|
-
|
|
7226
|
+
decisionStateId: external_exports.string().uuid(),
|
|
7195
7227
|
gapKey: external_exports.string(),
|
|
7196
7228
|
criterionId: external_exports.string().uuid(),
|
|
7197
7229
|
criterionIndex: external_exports.number().int().min(0).max(9),
|
|
@@ -7203,7 +7235,7 @@ var goalGapContractReadResponseSchema = external_exports.object({
|
|
|
7203
7235
|
}).strict(),
|
|
7204
7236
|
external_exports.object({
|
|
7205
7237
|
kind: external_exports.literal("fact_correction"),
|
|
7206
|
-
|
|
7238
|
+
decisionStateId: external_exports.string().uuid(),
|
|
7207
7239
|
criterionId: external_exports.string().uuid(),
|
|
7208
7240
|
title: external_exports.string(),
|
|
7209
7241
|
summary: external_exports.string(),
|
|
@@ -9839,7 +9871,8 @@ var secureInteractionFormFieldTypeSchema = external_exports.enum([
|
|
|
9839
9871
|
"email",
|
|
9840
9872
|
"tel",
|
|
9841
9873
|
"textarea",
|
|
9842
|
-
"secret"
|
|
9874
|
+
"secret",
|
|
9875
|
+
"file"
|
|
9843
9876
|
]);
|
|
9844
9877
|
var secureInteractionFormFieldSchema = external_exports.object({
|
|
9845
9878
|
id: external_exports.string().trim().min(1).max(120),
|
|
@@ -11716,14 +11749,20 @@ var askUserQuestionsSecretRefSchema = secureInteractionSecretRefSchema;
|
|
|
11716
11749
|
var askUserQuestionsAnswerSchema = external_exports.object({
|
|
11717
11750
|
questionId: external_exports.string().trim().min(1).max(120),
|
|
11718
11751
|
optionIds: external_exports.array(external_exports.string().trim().min(1).max(120)).max(20),
|
|
11719
|
-
otherText: multilineTextSchema.pipe(external_exports.string().trim().max(
|
|
11752
|
+
otherText: multilineTextSchema.pipe(external_exports.string().trim().max(ASK_USER_QUESTIONS_OTHER_TEXT_MAX_LENGTH)).nullable().optional(),
|
|
11720
11753
|
optionInputs: external_exports.record(
|
|
11721
11754
|
external_exports.string().trim().min(1).max(120),
|
|
11722
|
-
external_exports.record(external_exports.string().trim().min(1).max(120), external_exports.string().max(
|
|
11755
|
+
external_exports.record(external_exports.string().trim().min(1).max(120), external_exports.string().max(ASK_USER_QUESTIONS_FIELD_VALUE_MAX_LENGTH))
|
|
11723
11756
|
).optional(),
|
|
11724
11757
|
fieldValues: external_exports.record(
|
|
11725
11758
|
external_exports.string().trim().min(1).max(120),
|
|
11726
|
-
external_exports.string().max(
|
|
11759
|
+
external_exports.string().max(ASK_USER_QUESTIONS_FIELD_VALUE_MAX_LENGTH)
|
|
11760
|
+
).optional(),
|
|
11761
|
+
// Keys follow the secretRefs convention: fieldId for form fields,
|
|
11762
|
+
// `${optionId}.${inputId}` for option inputs → 120 + 1 + 120 = 241.
|
|
11763
|
+
fieldAttachments: external_exports.record(
|
|
11764
|
+
external_exports.string().trim().min(1).max(241),
|
|
11765
|
+
external_exports.array(external_exports.string().uuid()).min(1).max(5)
|
|
11727
11766
|
).optional(),
|
|
11728
11767
|
// Option-input scope keys are `${optionId}.${inputId}` → 120 + 1 + 120 = 241.
|
|
11729
11768
|
secretRefs: external_exports.record(
|
|
@@ -13698,9 +13737,6 @@ var goalWorkProgressSummarySchema = external_exports.discriminatedUnion("state",
|
|
|
13698
13737
|
|
|
13699
13738
|
// ../shared/src/goal-action-semantics.ts
|
|
13700
13739
|
var GOAL_ACTION_INTERACTION_PURPOSE_CODES = [
|
|
13701
|
-
"goal_gap_authority_exception",
|
|
13702
|
-
"goal_gap_observed_effect",
|
|
13703
|
-
"goal_gap_fact_correction",
|
|
13704
13740
|
"goal_gap_legacy_outcome_attribution",
|
|
13705
13741
|
"goal_gap_work_purpose_catalog_candidate"
|
|
13706
13742
|
];
|
|
@@ -16846,12 +16882,14 @@ var companyArtifactsQuerySchema = external_exports.object({
|
|
|
16846
16882
|
cursor: external_exports.string().min(1).optional()
|
|
16847
16883
|
});
|
|
16848
16884
|
var companyArtifactSchema = external_exports.object({
|
|
16885
|
+
wikiRevisionId: external_exports.string().uuid().nullable().optional(),
|
|
16849
16886
|
id: external_exports.string().min(1),
|
|
16850
16887
|
source: companyArtifactSourceSchema,
|
|
16851
16888
|
mediaKind: companyArtifactMediaKindSchema,
|
|
16852
16889
|
title: external_exports.string(),
|
|
16853
16890
|
previewText: external_exports.string().nullable(),
|
|
16854
16891
|
contentType: external_exports.string().nullable(),
|
|
16892
|
+
originalFilename: external_exports.string().nullable(),
|
|
16855
16893
|
contentPath: external_exports.string().nullable(),
|
|
16856
16894
|
openPath: external_exports.string().nullable(),
|
|
16857
16895
|
downloadPath: external_exports.string().nullable(),
|
|
@@ -18044,6 +18082,18 @@ var API = {
|
|
|
18044
18082
|
admin: `${API_PREFIX}/admin`
|
|
18045
18083
|
};
|
|
18046
18084
|
|
|
18085
|
+
// ../shared/src/mention-context.ts
|
|
18086
|
+
var MENTION_CONTEXT_SCHEMA_VERSION = "mirrorx.mention-context.v1";
|
|
18087
|
+
var HELIGE_APPLICATION_PROVIDERS = /* @__PURE__ */ new Set(["helige", "helige-app-builder"]);
|
|
18088
|
+
var APPLICATION_MENTION_PROVIDERS = /* @__PURE__ */ new Set([
|
|
18089
|
+
...HELIGE_APPLICATION_PROVIDERS,
|
|
18090
|
+
"amaster-app-builder"
|
|
18091
|
+
]);
|
|
18092
|
+
var MENTIONED_APPLICATION_SKILL_HINTS = {
|
|
18093
|
+
"helige-app-builder": "application changes/publication",
|
|
18094
|
+
"helige-runtime-cli": "data/entities/files/workflows"
|
|
18095
|
+
};
|
|
18096
|
+
|
|
18047
18097
|
// ../shared/src/config-schema.ts
|
|
18048
18098
|
var configMetaSchema = external_exports.object({
|
|
18049
18099
|
version: external_exports.literal(1),
|
|
@@ -18480,10 +18530,71 @@ var prerequisiteOperationsSchema = external_exports.object({
|
|
|
18480
18530
|
}))
|
|
18481
18531
|
});
|
|
18482
18532
|
|
|
18533
|
+
// ../shared/src/mirrorx-message-preferences.ts
|
|
18534
|
+
var time = external_exports.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "\u8BF7\u8F93\u5165\u6709\u6548\u65F6\u95F4");
|
|
18535
|
+
var messagePreferencesSchema = external_exports.object({
|
|
18536
|
+
smsEnabled: external_exports.boolean().default(false),
|
|
18537
|
+
// Historical wire names retained; these rules apply to all channels.
|
|
18538
|
+
smsImmediateAttention: external_exports.boolean().default(false),
|
|
18539
|
+
smsFrequencyHours: external_exports.union([external_exports.literal(24), external_exports.literal(12), external_exports.literal(6), external_exports.literal(1), external_exports.literal(0)]).default(24),
|
|
18540
|
+
phone: external_exports.string().trim().max(24).regex(/^(?:\+?[1-9]\d{5,14})?$/, "\u8BF7\u8F93\u5165\u6709\u6548\u624B\u673A\u53F7\uFF08\u53EF\u5305\u542B\u56FD\u9645\u533A\u53F7\uFF09").default(""),
|
|
18541
|
+
events: external_exports.object({
|
|
18542
|
+
action: external_exports.boolean().default(true),
|
|
18543
|
+
review: external_exports.boolean().default(true),
|
|
18544
|
+
interrupted: external_exports.boolean().default(true),
|
|
18545
|
+
completed: external_exports.boolean().default(true),
|
|
18546
|
+
milestone: external_exports.boolean().default(true),
|
|
18547
|
+
progress: external_exports.boolean().default(true),
|
|
18548
|
+
started: external_exports.boolean().default(false),
|
|
18549
|
+
daily: external_exports.boolean().default(true)
|
|
18550
|
+
}).strict().default({}),
|
|
18551
|
+
// Deprecated: accepted for stored preferences/older clients, no scheduling effect.
|
|
18552
|
+
frequencyMinutes: external_exports.union([external_exports.literal(30), external_exports.literal(60), external_exports.literal(120)]).default(60),
|
|
18553
|
+
dailyTime: time.default("18:00"),
|
|
18554
|
+
timezone: external_exports.string().max(80).refine((value) => {
|
|
18555
|
+
try {
|
|
18556
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
18557
|
+
return true;
|
|
18558
|
+
} catch {
|
|
18559
|
+
return false;
|
|
18560
|
+
}
|
|
18561
|
+
}, "\u65F6\u533A\u65E0\u6548").default("Asia/Shanghai"),
|
|
18562
|
+
quiet: external_exports.boolean().default(true),
|
|
18563
|
+
quietStart: time.default("22:00"),
|
|
18564
|
+
quietEnd: time.default("08:00"),
|
|
18565
|
+
urgentDuringQuiet: external_exports.boolean().default(false)
|
|
18566
|
+
}).strict().refine((value) => !value.smsEnabled || /^(?:\+86)?1[3-9]\d{9}$/.test(value.phone), {
|
|
18567
|
+
message: "\u542F\u7528\u77ED\u4FE1\u524D\u8BF7\u586B\u5199\u6709\u6548\u7684\u4E2D\u56FD\u5927\u9646\u624B\u673A\u53F7",
|
|
18568
|
+
path: ["phone"]
|
|
18569
|
+
}).refine((value) => !value.quiet || value.quietStart !== value.quietEnd, {
|
|
18570
|
+
message: "\u514D\u6253\u6270\u5F00\u59CB\u548C\u7ED3\u675F\u65F6\u95F4\u4E0D\u80FD\u76F8\u540C",
|
|
18571
|
+
path: ["quietEnd"]
|
|
18572
|
+
});
|
|
18573
|
+
|
|
18574
|
+
// ../shared/src/wiki-mentions.ts
|
|
18575
|
+
var wikiMentionQuerySchema = external_exports.object({
|
|
18576
|
+
q: external_exports.string().trim().max(200).optional(),
|
|
18577
|
+
cursor: external_exports.string().max(1e3).optional(),
|
|
18578
|
+
limit: external_exports.coerce.number().int().min(1).max(100).optional()
|
|
18579
|
+
}).strict();
|
|
18580
|
+
var wikiMentionPageSchema = external_exports.object({
|
|
18581
|
+
pageId: external_exports.string().uuid(),
|
|
18582
|
+
revisionId: external_exports.string().uuid(),
|
|
18583
|
+
title: external_exports.string(),
|
|
18584
|
+
path: external_exports.string(),
|
|
18585
|
+
updatedAt: external_exports.string(),
|
|
18586
|
+
contentHash: external_exports.string().regex(/^[a-f0-9]{64}$/),
|
|
18587
|
+
byteSize: external_exports.number().int().nonnegative()
|
|
18588
|
+
});
|
|
18589
|
+
var wikiMentionListSchema = external_exports.object({
|
|
18590
|
+
pages: external_exports.array(wikiMentionPageSchema),
|
|
18591
|
+
nextCursor: external_exports.string().nullable()
|
|
18592
|
+
});
|
|
18593
|
+
|
|
18483
18594
|
// src/amaster-runtime-daemon.mjs
|
|
18484
|
-
import { chmodSync as
|
|
18485
|
-
import { arch as arch4, homedir as
|
|
18486
|
-
import { basename as basename8, delimiter as delimiter3, dirname as dirname11, extname as extname3, isAbsolute as isAbsolute12, join as
|
|
18595
|
+
import { chmodSync as chmodSync7, copyFileSync as copyFileSync2, existsSync as existsSync18, lstatSync as lstatSync13, mkdirSync as mkdirSync12, mkdtempSync as mkdtempSync5, readFileSync as readFileSync19, readdirSync as readdirSync12, realpathSync as realpathSync12, renameSync as renameSync10, rmSync as rmSync11, statSync as statSync12, symlinkSync as symlinkSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync13 } from "node:fs";
|
|
18596
|
+
import { arch as arch4, homedir as homedir6, hostname as hostname2, platform as platform4, tmpdir } from "node:os";
|
|
18597
|
+
import { basename as basename8, delimiter as delimiter3, dirname as dirname11, extname as extname3, isAbsolute as isAbsolute12, join as join23, relative as relative9, resolve as resolve19 } from "node:path";
|
|
18487
18598
|
import { spawn, spawnSync as spawnSync5 } from "node:child_process";
|
|
18488
18599
|
|
|
18489
18600
|
// src/amaster-runtime-daemon/common.mjs
|
|
@@ -18992,7 +19103,7 @@ async function postRuntimeConnectorJsonWithRetry(config, path, payload, options
|
|
|
18992
19103
|
} catch (error) {
|
|
18993
19104
|
lastError = error;
|
|
18994
19105
|
if (attempt >= maxAttempts || !retryableRuntimeConnectorPost(error)) throw error;
|
|
18995
|
-
if (delayMs > 0) await new Promise((
|
|
19106
|
+
if (delayMs > 0) await new Promise((resolve20) => setTimeout(resolve20, delayMs));
|
|
18996
19107
|
}
|
|
18997
19108
|
}
|
|
18998
19109
|
throw lastError;
|
|
@@ -19128,7 +19239,7 @@ var MAX_BYTES = 20 * 1024 * 1024;
|
|
|
19128
19239
|
var digest = (bytes) => createHash3("sha256").update(bytes).digest("hex");
|
|
19129
19240
|
function buildCheckpointUpload(checkpointDir, manifest, nativeSession) {
|
|
19130
19241
|
if (!Array.isArray(manifest?.files) || manifest.files.length > 20) throw new Error("Invalid checkpoint inventory");
|
|
19131
|
-
const root = realpathSync2(join3(checkpointDir, "files"));
|
|
19242
|
+
const root = manifest.files.length > 0 ? realpathSync2(join3(checkpointDir, "files")) : null;
|
|
19132
19243
|
const paths = /* @__PURE__ */ new Set();
|
|
19133
19244
|
let total = 0;
|
|
19134
19245
|
const files = manifest.files.map((file) => {
|
|
@@ -19246,6 +19357,7 @@ function installCheckpoint(target, bytes, expected, kind) {
|
|
|
19246
19357
|
if (existsSync(target) && (!lstatSync2(target).isDirectory() || lstatSync2(target).isSymbolicLink())) throw new Error("Checkpoint target must be a private directory");
|
|
19247
19358
|
mkdirSync2(dirname(target), { recursive: true });
|
|
19248
19359
|
const staging = mkdtempSync2(`${target}.restore-`);
|
|
19360
|
+
mkdirSync2(join4(staging, "files"), { recursive: true, mode: 448 });
|
|
19249
19361
|
const backup = `${target}.previous-${randomUUID()}`;
|
|
19250
19362
|
let moved = false;
|
|
19251
19363
|
try {
|
|
@@ -21337,48 +21449,48 @@ var FULL_DIRECT_TYPED_V1_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
21337
21449
|
function record5(value) {
|
|
21338
21450
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21339
21451
|
}
|
|
21340
|
-
function requiredString(value, label,
|
|
21341
|
-
if (typeof value !== "string" || value.trim() === "")
|
|
21452
|
+
function requiredString(value, label, fail3) {
|
|
21453
|
+
if (typeof value !== "string" || value.trim() === "") fail3(`${label} is required`);
|
|
21342
21454
|
return value.trim();
|
|
21343
21455
|
}
|
|
21344
21456
|
function validateDirectTypedMcpCatalog(catalogValue, options = {}) {
|
|
21345
21457
|
const errorPrefix = typeof options.errorPrefix === "string" && options.errorPrefix ? options.errorPrefix : "direct_typed_mcp_invalid";
|
|
21346
|
-
const
|
|
21458
|
+
const fail3 = (detail) => {
|
|
21347
21459
|
throw new Error(`${errorPrefix}: ${detail}`);
|
|
21348
21460
|
};
|
|
21349
21461
|
const admittedToolNames = options.admittedToolNames instanceof Set ? options.admittedToolNames : options.admittedToolNames == null ? null : new Set(options.admittedToolNames);
|
|
21350
21462
|
const catalog = record5(catalogValue);
|
|
21351
21463
|
if (catalog.schemaVersion !== DIRECT_TYPED_MCP_CATALOG_SCHEMA_VERSION) {
|
|
21352
|
-
|
|
21464
|
+
fail3("direct tool catalog schema mismatch");
|
|
21353
21465
|
}
|
|
21354
21466
|
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(record5) : [];
|
|
21355
21467
|
const names = /* @__PURE__ */ new Set();
|
|
21356
21468
|
const exposedNames = /* @__PURE__ */ new Set();
|
|
21357
21469
|
const tools = rawTools.map((tool) => {
|
|
21358
|
-
const name = requiredString(tool.name, "toolCatalog.tools.name",
|
|
21470
|
+
const name = requiredString(tool.name, "toolCatalog.tools.name", fail3);
|
|
21359
21471
|
if (admittedToolNames && !admittedToolNames.has(name) || names.has(name)) {
|
|
21360
|
-
|
|
21472
|
+
fail3("direct tool catalog name mismatch");
|
|
21361
21473
|
}
|
|
21362
21474
|
names.add(name);
|
|
21363
|
-
const exposedName = requiredString(tool.exposedName, `toolCatalog.tools.exposedName:${name}`,
|
|
21475
|
+
const exposedName = requiredString(tool.exposedName, `toolCatalog.tools.exposedName:${name}`, fail3);
|
|
21364
21476
|
if (!PROVIDER_SAFE_DIRECT_TOOL_NAME.test(exposedName)) {
|
|
21365
|
-
|
|
21477
|
+
fail3(`direct tool exposed name is unsafe for ${name}`);
|
|
21366
21478
|
}
|
|
21367
21479
|
if (exposedNames.has(exposedName)) {
|
|
21368
|
-
|
|
21480
|
+
fail3(`direct tool exposed name collision for ${exposedName}`);
|
|
21369
21481
|
}
|
|
21370
21482
|
exposedNames.add(exposedName);
|
|
21371
21483
|
const inputSchema = record5(tool.inputSchema);
|
|
21372
21484
|
if (inputSchema.type !== "object" || inputSchema.additionalProperties !== false) {
|
|
21373
|
-
|
|
21485
|
+
fail3(`direct tool schema is not strict for ${name}`);
|
|
21374
21486
|
}
|
|
21375
21487
|
const schemaHash = stablePiToolSchemaHash(inputSchema);
|
|
21376
21488
|
if (tool.schemaHash !== schemaHash) {
|
|
21377
|
-
|
|
21489
|
+
fail3(`direct tool schema hash mismatch for ${name}`);
|
|
21378
21490
|
}
|
|
21379
|
-
const riskLevel = requiredString(tool.riskLevel, `toolCatalog.tools.riskLevel:${name}`,
|
|
21491
|
+
const riskLevel = requiredString(tool.riskLevel, `toolCatalog.tools.riskLevel:${name}`, fail3);
|
|
21380
21492
|
if (!(/* @__PURE__ */ new Set(["read", "write", "destructive"])).has(riskLevel)) {
|
|
21381
|
-
|
|
21493
|
+
fail3(`direct tool risk level mismatch for ${name}`);
|
|
21382
21494
|
}
|
|
21383
21495
|
return {
|
|
21384
21496
|
name,
|
|
@@ -21396,7 +21508,7 @@ function validateDirectTypedMcpCatalog(catalogValue, options = {}) {
|
|
|
21396
21508
|
schemaHash: tool.schemaHash,
|
|
21397
21509
|
riskLevel: tool.riskLevel
|
|
21398
21510
|
})));
|
|
21399
|
-
if (catalog.setHash !== setHash)
|
|
21511
|
+
if (catalog.setHash !== setHash) fail3("direct tool catalog set hash mismatch");
|
|
21400
21512
|
return {
|
|
21401
21513
|
setHash,
|
|
21402
21514
|
tools: tools.sort((left, right) => left.name.localeCompare(right.name))
|
|
@@ -22639,14 +22751,14 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22639
22751
|
const receipts = [];
|
|
22640
22752
|
let stage = "upload";
|
|
22641
22753
|
let callId;
|
|
22642
|
-
const
|
|
22754
|
+
const fail3 = (code, detail) => {
|
|
22643
22755
|
throw Object.assign(new Error(code), { detail });
|
|
22644
22756
|
};
|
|
22645
22757
|
async function invoke(name, args) {
|
|
22646
|
-
if (now() >= deadline)
|
|
22758
|
+
if (now() >= deadline) fail3("initialization_completion_deadline");
|
|
22647
22759
|
let envelope;
|
|
22648
22760
|
for (let transportFailures = 0; ; ) {
|
|
22649
|
-
if (now() >= deadline)
|
|
22761
|
+
if (now() >= deadline) fail3("initialization_completion_deadline");
|
|
22650
22762
|
try {
|
|
22651
22763
|
envelope = await call(name, args, Math.min(45e3, deadline - now()));
|
|
22652
22764
|
break;
|
|
@@ -22659,12 +22771,11 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22659
22771
|
}
|
|
22660
22772
|
}
|
|
22661
22773
|
const content = envelope?.content;
|
|
22662
|
-
|
|
22663
|
-
|
|
22664
|
-
fail2("initialization_completion_receipt_mismatch");
|
|
22774
|
+
if (!envelope?.invocationId || !content || typeof content !== "object" || content?.toolName !== name.replace("runtime_action_", "runtime_action.")) {
|
|
22775
|
+
fail3("initialization_completion_receipt_mismatch");
|
|
22665
22776
|
}
|
|
22666
22777
|
if (envelope.status !== "succeeded" || !["accepted", "pending_reconcile"].includes(content.status)) {
|
|
22667
|
-
|
|
22778
|
+
fail3("initialization_completion_action_not_accepted", content.error ?? { status: envelope.status });
|
|
22668
22779
|
}
|
|
22669
22780
|
const result2 = content.result;
|
|
22670
22781
|
await onReceipt(envelope);
|
|
@@ -22675,19 +22786,19 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22675
22786
|
planId: result2?.planId,
|
|
22676
22787
|
status: result2?.status
|
|
22677
22788
|
});
|
|
22678
|
-
if (!result2 || result2.error)
|
|
22789
|
+
if (!result2 || result2.error) fail3("initialization_completion_action_failed", result2?.error);
|
|
22679
22790
|
return result2;
|
|
22680
22791
|
}
|
|
22681
22792
|
async function settleCall(value, actionType) {
|
|
22682
22793
|
callId = value.callId;
|
|
22683
|
-
if (!callId || value.actionType !== actionType)
|
|
22794
|
+
if (!callId || value.actionType !== actionType) fail3("initialization_completion_call_mismatch");
|
|
22684
22795
|
for (let attempt = 0; ; attempt++) {
|
|
22685
|
-
if (value.callId !== callId || value.actionType !== actionType)
|
|
22796
|
+
if (value.callId !== callId || value.actionType !== actionType) fail3("initialization_completion_call_mismatch");
|
|
22686
22797
|
if (value.status === "succeeded") return value;
|
|
22687
22798
|
if (!["pending_reconcile", "claimed", "executing"].includes(value.status)) {
|
|
22688
|
-
|
|
22799
|
+
fail3("initialization_completion_action_incomplete", { status: value.status, error: value.error });
|
|
22689
22800
|
}
|
|
22690
|
-
if (now() >= deadline)
|
|
22801
|
+
if (now() >= deadline) fail3("initialization_completion_deadline");
|
|
22691
22802
|
await sleep(Math.min(1e3 * (attempt + 1), 5e3));
|
|
22692
22803
|
value = await invoke("runtime_action_status", { callId });
|
|
22693
22804
|
}
|
|
@@ -22696,7 +22807,7 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22696
22807
|
const doc = plan.initializationDocument;
|
|
22697
22808
|
const materialized = plan.initializationDocumentMaterialization;
|
|
22698
22809
|
if (!plan.planId || !plan.revision || !["planned", "committing", "pending_reconcile", "completed"].includes(plan.status) || materialized?.status !== "materialized" || materialized.planId !== plan.planId || materialized.revision !== plan.revision || materialized.sha256 !== doc?.sha256 || materialized.byteSize !== doc?.byteSize || materialized.path !== doc?.path) {
|
|
22699
|
-
|
|
22810
|
+
fail3("initialization_completion_invalid_plan");
|
|
22700
22811
|
}
|
|
22701
22812
|
const prefix = "initialization-complete:" + plan.planId;
|
|
22702
22813
|
const { createHash: createHash20 } = await import("node:crypto");
|
|
@@ -22717,13 +22828,13 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22717
22828
|
}
|
|
22718
22829
|
}), "upload_artifact");
|
|
22719
22830
|
if (upload.postcondition?.artifactFinalized !== true || upload.postcondition?.attachmentReadback !== true || upload.postcondition?.workProductReadback !== true || upload.effectResult?.sha256 !== doc.sha256 || upload.effectResult?.byteSize !== doc.byteSize || !upload.effectResult?.attachmentId || !upload.effectResult?.workProductId) {
|
|
22720
|
-
|
|
22831
|
+
fail3("initialization_completion_artifact_mismatch");
|
|
22721
22832
|
}
|
|
22722
22833
|
stage = "commit";
|
|
22723
22834
|
callId = void 0;
|
|
22724
22835
|
const committed = await invoke("runtime_action_commit", { planId: plan.planId, revision: plan.revision });
|
|
22725
22836
|
if (committed.planId !== plan.planId || committed.revision !== plan.revision || committed.status !== "completed" || committed.failure || committed.nextActionIndex !== committed.actionCount) {
|
|
22726
|
-
|
|
22837
|
+
fail3("initialization_completion_plan_incomplete", { status: committed.status, failure: committed.failure });
|
|
22727
22838
|
}
|
|
22728
22839
|
stage = "ready";
|
|
22729
22840
|
const completed = await settleCall(await invoke("runtime_action_submit", {
|
|
@@ -22731,7 +22842,7 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22731
22842
|
action: { type: "update_parent", status: "done" }
|
|
22732
22843
|
}), "update_parent");
|
|
22733
22844
|
if (completed.effectResult?.issueId !== authority.issueId || completed.effectResult?.status !== "done" || completed.postcondition?.issuePersisted !== true || completed.postcondition?.status !== "done" || completed.postcondition?.issueTerminalizationDeferred === true) {
|
|
22734
|
-
|
|
22845
|
+
fail3("initialization_completion_ready_not_confirmed");
|
|
22735
22846
|
}
|
|
22736
22847
|
return {
|
|
22737
22848
|
status: "completed",
|
|
@@ -22817,8 +22928,7 @@ export default function(pi) {
|
|
|
22817
22928
|
const result = call?.result;
|
|
22818
22929
|
const doc = result?.initializationDocument;
|
|
22819
22930
|
if (envelope?.status !== "succeeded" || call?.status !== "accepted"
|
|
22820
|
-
|| call?.
|
|
22821
|
-
|| !["runtime_action.plan", "runtime_action.status"].includes(call?.toolName) || !doc) return;
|
|
22931
|
+
|| call?.toolName !== event.toolName.replace("runtime_action_", "runtime_action.") || !doc) return;
|
|
22822
22932
|
let root, parent, file, temp;
|
|
22823
22933
|
const canonicalName = "organization-plan-" + result.planId + ".md";
|
|
22824
22934
|
let targetName = canonicalName;
|
|
@@ -22968,12 +23078,10 @@ export default function(pi) {
|
|
|
22968
23078
|
if (root !== undefined) fs.closeSync(root);
|
|
22969
23079
|
}
|
|
22970
23080
|
// Only an explicitly negotiated planning call starts effects. Status/document reads stay reads.
|
|
22971
|
-
|
|
23081
|
+
// The session token in the run config binds every call to this run's
|
|
23082
|
+
// authority, so receipt authority is established by transport.
|
|
22972
23083
|
if (completionAuthority && event.toolName === "runtime_action_plan"
|
|
22973
|
-
&& result.initializationDocumentMaterialization?.status === "materialized"
|
|
22974
|
-
&& provider?.provider === "amaster_actions" && provider.invocationId === envelope.invocationId
|
|
22975
|
-
&& provider.planId === result.planId
|
|
22976
|
-
&& ["runId", "commandId", "issueId"].every((key) => completionAuthority[key] && provider[key] === completionAuthority[key])) {
|
|
23084
|
+
&& result.initializationDocumentMaterialization?.status === "materialized") {
|
|
22977
23085
|
result.initializationCompletion = await runInitializationCompletion({ plan: result, authority: completionAuthority,
|
|
22978
23086
|
call: initializationCompletionCall, sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)), now: Date.now,
|
|
22979
23087
|
// Pi redirects extension stdout.write to stderr. This is an explicit
|
|
@@ -23530,25 +23638,20 @@ const terminalActionDispositions = new Map([
|
|
|
23530
23638
|
["schedule_monitor", new Set(["scheduled_monitor"])],
|
|
23531
23639
|
["continue_task", new Set(["continuation_scheduled"])],
|
|
23532
23640
|
]);
|
|
23533
|
-
const terminalToolNames = new Set(["
|
|
23534
|
-
|
|
23535
|
-
function shouldStopFromReceipt(rawResult) {
|
|
23536
|
-
const expectedRunId = readString(process.env.AMASTER_RUNTIME_RUN_ID);
|
|
23537
|
-
const expectedCommandId = readString(process.env.AMASTER_RUNTIME_COMMAND_ID);
|
|
23538
|
-
const expectedIssueId = readString(process.env.AMASTER_RUNTIME_ISSUE_ID);
|
|
23539
|
-
if (!expectedRunId || !expectedCommandId || !expectedIssueId) return false;
|
|
23641
|
+
const terminalToolNames = new Set(["runtime_action_submit", "runtime_action_status"]);
|
|
23540
23642
|
|
|
23643
|
+
// Receipt authority fields never travel in the executor-facing envelope: within
|
|
23644
|
+
// a session every receipt is bound to that session's run/command/issue, so this
|
|
23645
|
+
// in-process check trusts the slim receipt by shape and event identity.
|
|
23646
|
+
function shouldStopFromReceipt(rawResult, eventToolName) {
|
|
23541
23647
|
const result = asRecord(rawResult);
|
|
23542
23648
|
const structured = asRecord(result.structuredContent);
|
|
23543
23649
|
const providerContent = asRecord(structured.content);
|
|
23544
23650
|
const providerResult = asRecord(providerContent.result);
|
|
23545
23651
|
const effectResult = asRecord(providerResult.effectResult);
|
|
23546
|
-
const providerReceipt = asRecord(structured.providerReceipt);
|
|
23547
23652
|
const invocationId = readString(structured.invocationId);
|
|
23548
23653
|
const callId = readString(providerResult.callId);
|
|
23549
|
-
const
|
|
23550
|
-
const receiptCallId = readString(providerReceipt.callId);
|
|
23551
|
-
const actionType = readString(providerReceipt.actionType);
|
|
23654
|
+
const actionType = readString(providerResult.actionType);
|
|
23552
23655
|
const disposition = readString(effectResult.runDisposition);
|
|
23553
23656
|
const existingOwner = asRecord(effectResult.existingOwner);
|
|
23554
23657
|
const existingOwnerEpoch = Number(existingOwner.executionEpoch);
|
|
@@ -23564,7 +23667,7 @@ function shouldStopFromReceipt(rawResult) {
|
|
|
23564
23667
|
&& continuationCount > 0
|
|
23565
23668
|
&& Number.isSafeInteger(maxContinuations)
|
|
23566
23669
|
&& continuationCount <= maxContinuations;
|
|
23567
|
-
if (!invocationId || !
|
|
23670
|
+
if (!invocationId || !callId) return false;
|
|
23568
23671
|
|
|
23569
23672
|
const exactQueuedWakeHandoff = disposition === "handoff_existing_live_path"
|
|
23570
23673
|
&& readString(existingOwner.kind) === "queued_wake"
|
|
@@ -23577,16 +23680,9 @@ function shouldStopFromReceipt(rawResult) {
|
|
|
23577
23680
|
return readString(structured.status) === "succeeded"
|
|
23578
23681
|
&& readString(providerContent.status) === "accepted"
|
|
23579
23682
|
&& ["succeeded", "completed"].includes(readString(providerResult.status) ?? "")
|
|
23580
|
-
&& terminalToolNames.has(readString(
|
|
23683
|
+
&& terminalToolNames.has(readString(eventToolName) ?? "")
|
|
23581
23684
|
&& effectResult.mustEndRun === true
|
|
23582
23685
|
&& Boolean(terminalActionDispositions.get(actionType ?? "")?.has(disposition ?? ""))
|
|
23583
|
-
&& readString(providerReceipt.provider) === "amaster_actions"
|
|
23584
|
-
&& readString(providerReceipt.status) === "accepted"
|
|
23585
|
-
&& receiptInvocationId === invocationId
|
|
23586
|
-
&& readString(providerReceipt.runId) === expectedRunId
|
|
23587
|
-
&& readString(providerReceipt.commandId) === expectedCommandId
|
|
23588
|
-
&& readString(providerReceipt.issueId) === expectedIssueId
|
|
23589
|
-
&& receiptCallId === callId
|
|
23590
23686
|
&& (disposition !== "waiting_human"
|
|
23591
23687
|
|| Boolean(readString(effectResult.interactionId) && readString(effectResult.epochKey)))
|
|
23592
23688
|
&& (disposition !== "handoff_existing_live_path"
|
|
@@ -23598,7 +23694,7 @@ export default function mirrorxRunTermination(pi) {
|
|
|
23598
23694
|
pi.on("tool_result", (event) => {
|
|
23599
23695
|
if (event.isError === true) return undefined;
|
|
23600
23696
|
const rawResult = asRecord(event.details).mcpResult;
|
|
23601
|
-
return shouldStopFromReceipt(rawResult) ? { stopAfterTurn: true } : undefined;
|
|
23697
|
+
return shouldStopFromReceipt(rawResult, event.toolName) ? { stopAfterTurn: true } : undefined;
|
|
23602
23698
|
});
|
|
23603
23699
|
}
|
|
23604
23700
|
`;
|
|
@@ -23760,6 +23856,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23760
23856
|
const SESSION_ROLLOUT_MARKER3 = ".amaster-pi-session-rollout.json";
|
|
23761
23857
|
const DEFAULT_SESSION_ROLLOUT_TTL_MS3 = 24 * 60 * 60 * 1e3;
|
|
23762
23858
|
const PI_VERSION_ATTESTATION_TIMEOUT_MS = 3e4;
|
|
23859
|
+
const MANAGED_PI_GOVERNED_MCP_REQUEST_TIMEOUT_MS = 66e4;
|
|
23763
23860
|
const PI_ATTESTATION_MAX_ATTEMPTS = 2;
|
|
23764
23861
|
const livePiVersionProbes = /* @__PURE__ */ new Map();
|
|
23765
23862
|
function record11(value) {
|
|
@@ -24562,7 +24659,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24562
24659
|
schema: tool.inputSchema
|
|
24563
24660
|
})))
|
|
24564
24661
|
);
|
|
24565
|
-
const
|
|
24662
|
+
const cache2 = {
|
|
24566
24663
|
version: 1,
|
|
24567
24664
|
servers: {
|
|
24568
24665
|
[SUPPORTED_SERVER_NAME3]: {
|
|
@@ -24577,7 +24674,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24577
24674
|
}
|
|
24578
24675
|
}
|
|
24579
24676
|
};
|
|
24580
|
-
const cacheBytes = Buffer.from(`${JSON.stringify(
|
|
24677
|
+
const cacheBytes = Buffer.from(`${JSON.stringify(cache2, null, 2)}
|
|
24581
24678
|
`);
|
|
24582
24679
|
writeOwnedFileAtomic(cachePath, cacheBytes);
|
|
24583
24680
|
const toolSchemaBytes = input.directCatalog.tools.reduce((total, tool) => total + Buffer.byteLength(JSON.stringify({
|
|
@@ -24680,6 +24777,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24680
24777
|
url: gatewayUrl,
|
|
24681
24778
|
headers: { Authorization: `Bearer ${sessionToken}`, ...headers },
|
|
24682
24779
|
lifecycle: directCatalog ? "lazy" : "eager",
|
|
24780
|
+
requestTimeoutMs: MANAGED_PI_GOVERNED_MCP_REQUEST_TIMEOUT_MS,
|
|
24683
24781
|
...directCatalog ? { exposeResources: false, directTools: directToolNames } : {}
|
|
24684
24782
|
};
|
|
24685
24783
|
const config = {
|
|
@@ -24987,6 +25085,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24987
25085
|
url: gatewayUrl,
|
|
24988
25086
|
headers: { Authorization: `Bearer ${sessionToken}`, ...headers },
|
|
24989
25087
|
lifecycle: directCatalog ? "lazy" : "eager",
|
|
25088
|
+
requestTimeoutMs: MANAGED_PI_GOVERNED_MCP_REQUEST_TIMEOUT_MS,
|
|
24990
25089
|
...directCatalog ? { exposeResources: false, directTools: directToolNames } : {}
|
|
24991
25090
|
};
|
|
24992
25091
|
const config = {
|
|
@@ -26564,7 +26663,6 @@ function governedMcpToolResult(structuredContent) {
|
|
|
26564
26663
|
if (!status) return null;
|
|
26565
26664
|
const invocationId = readString(structuredContent.invocationId);
|
|
26566
26665
|
const providerContent = asRecord(structuredContent.content);
|
|
26567
|
-
const providerReceipt = asRecord(structuredContent.providerReceipt);
|
|
26568
26666
|
const providerStatus = readString(providerContent.status);
|
|
26569
26667
|
const providerResult = asRecord(providerContent.result);
|
|
26570
26668
|
const effectResult = asRecord(providerResult.effectResult);
|
|
@@ -26598,13 +26696,9 @@ function governedMcpToolResult(structuredContent) {
|
|
|
26598
26696
|
...runtimeActionResultStatus ? { resultStatus: runtimeActionResultStatus } : {},
|
|
26599
26697
|
...readString(providerResult.errorCode) ?? readString(runtimeActionError.code) ? { errorCode: readString(providerResult.errorCode) ?? readString(runtimeActionError.code) } : {}
|
|
26600
26698
|
} : null;
|
|
26601
|
-
const
|
|
26699
|
+
const actionType = readString(providerResult.actionType);
|
|
26602
26700
|
const runDisposition = readString(effectResult.runDisposition);
|
|
26603
|
-
const expectedDispositions = PI_TERMINATING_RUNTIME_ACTION_TO_DISPOSITION.get(
|
|
26604
|
-
const receiptRunId = readString(providerReceipt.runId);
|
|
26605
|
-
const receiptCommandId = readString(providerReceipt.commandId);
|
|
26606
|
-
const receiptIssueId = readString(providerReceipt.issueId);
|
|
26607
|
-
const receiptCallId = readString(providerReceipt.callId);
|
|
26701
|
+
const expectedDispositions = PI_TERMINATING_RUNTIME_ACTION_TO_DISPOSITION.get(actionType ?? "");
|
|
26608
26702
|
const interactionId = readString(effectResult.interactionId);
|
|
26609
26703
|
const epochKey = readString(effectResult.epochKey);
|
|
26610
26704
|
const existingOwner = asRecord(effectResult.existingOwner);
|
|
@@ -26620,15 +26714,12 @@ function governedMcpToolResult(structuredContent) {
|
|
|
26620
26714
|
const exactQueuedWakeHandoff = runDisposition === "handoff_existing_live_path" && readString(existingOwner.kind) === "queued_wake" && Boolean(readString(existingOwner.id)) && ["pending_dispatch", "queued", "deferred_issue_execution"].includes(
|
|
26621
26715
|
readString(existingOwner.status) ?? ""
|
|
26622
26716
|
) && Number.isSafeInteger(existingOwnerEpoch) && existingOwnerEpoch > 0 && readString(existingOwner.nextAction) === "end_current_run";
|
|
26623
|
-
const terminalRunDisposition = status === "succeeded" && providerStatus === "accepted" && PI_TERMINAL_RUNTIME_ACTION_STATUSES.has(runtimeActionResultStatus ?? "") && PI_TERMINATING_RUNTIME_ACTION_TOOLS.has(runtimeActionToolName ?? "") && effectResult.mustEndRun === true && Boolean(expectedDispositions?.has(runDisposition ?? "")) && invocationId &&
|
|
26717
|
+
const terminalRunDisposition = status === "succeeded" && providerStatus === "accepted" && PI_TERMINAL_RUNTIME_ACTION_STATUSES.has(runtimeActionResultStatus ?? "") && PI_TERMINATING_RUNTIME_ACTION_TOOLS.has(runtimeActionToolName ?? "") && effectResult.mustEndRun === true && Boolean(expectedDispositions?.has(runDisposition ?? "")) && invocationId && runtimeActionCallId && (runDisposition !== "waiting_human" || Boolean(interactionId && epochKey)) && (runDisposition !== "handoff_existing_live_path" || Boolean(epochKey && exactQueuedWakeHandoff)) && (runDisposition !== "continuation_scheduled" || Boolean(exactContinuation)) ? {
|
|
26624
26718
|
disposition: runDisposition,
|
|
26625
|
-
actionType
|
|
26719
|
+
actionType,
|
|
26626
26720
|
toolName: runtimeActionToolName,
|
|
26627
26721
|
invocationId,
|
|
26628
26722
|
callId: runtimeActionCallId,
|
|
26629
|
-
runId: receiptRunId,
|
|
26630
|
-
commandId: receiptCommandId,
|
|
26631
|
-
issueId: receiptIssueId,
|
|
26632
26723
|
...interactionId ? { interactionId } : {},
|
|
26633
26724
|
...epochKey ? { epochKey } : {},
|
|
26634
26725
|
...exactContinuation ? {
|
|
@@ -26703,10 +26794,7 @@ function terminatingRunDispositionEvidence(results, expected = {}) {
|
|
|
26703
26794
|
const expectedCommandId = readString(expected.commandId);
|
|
26704
26795
|
const expectedIssueId = readString(expected.issueId);
|
|
26705
26796
|
if (!expectedRunId || !expectedCommandId || !expectedIssueId) return null;
|
|
26706
|
-
const result2 = (Array.isArray(results) ? results : []).map(asRecord).find((entry) =>
|
|
26707
|
-
const disposition2 = asRecord(entry.terminalRunDisposition);
|
|
26708
|
-
return readString(entry.status) === "succeeded" && readString(disposition2.runId) === expectedRunId && readString(disposition2.commandId) === expectedCommandId && readString(disposition2.issueId) === expectedIssueId;
|
|
26709
|
-
});
|
|
26797
|
+
const result2 = (Array.isArray(results) ? results : []).map(asRecord).find((entry) => readString(entry.status) === "succeeded" && Object.keys(asRecord(entry.terminalRunDisposition)).length > 0);
|
|
26710
26798
|
if (!result2) return null;
|
|
26711
26799
|
const disposition = asRecord(result2.terminalRunDisposition);
|
|
26712
26800
|
const existingOwner = asRecord(disposition.existingOwner);
|
|
@@ -28228,7 +28316,7 @@ function maybeCapturePiMessage(event, messages, usage) {
|
|
|
28228
28316
|
}
|
|
28229
28317
|
return capturedAssistantOutput;
|
|
28230
28318
|
}
|
|
28231
|
-
function piMcpToolResults(event
|
|
28319
|
+
function piMcpToolResults(event) {
|
|
28232
28320
|
const results = [];
|
|
28233
28321
|
const seen = /* @__PURE__ */ new Set();
|
|
28234
28322
|
const retain = (parsed) => {
|
|
@@ -28257,15 +28345,7 @@ function piMcpToolResults(event, expectedAuthority = null) {
|
|
|
28257
28345
|
const invocationId = readString(directStructuredContent.invocationId);
|
|
28258
28346
|
const status = readString(directStructuredContent.status);
|
|
28259
28347
|
if (!invocationId || !status) continue;
|
|
28260
|
-
|
|
28261
|
-
const trustedProviderReceipt = readString(providerReceipt.provider) === "amaster_actions" && readString(providerReceipt.invocationId) === invocationId && Boolean(readString(providerReceipt.status));
|
|
28262
|
-
retain(governedMcpToolResult(trustedProviderReceipt ? directStructuredContent : {
|
|
28263
|
-
invocationId,
|
|
28264
|
-
status,
|
|
28265
|
-
// Never let a receipt-free success satisfy approved-action
|
|
28266
|
-
// completion; non-success states remain useful for control flow.
|
|
28267
|
-
...status === "succeeded" ? { content: { status: "blocked" } } : {}
|
|
28268
|
-
}));
|
|
28348
|
+
retain(governedMcpToolResult(directStructuredContent));
|
|
28269
28349
|
} catch {
|
|
28270
28350
|
}
|
|
28271
28351
|
}
|
|
@@ -28283,11 +28363,10 @@ function piMcpToolResults(event, expectedAuthority = null) {
|
|
|
28283
28363
|
if (readString(event?.type) === "tool_execution_end") {
|
|
28284
28364
|
retainMcpResult(event?.result);
|
|
28285
28365
|
}
|
|
28286
|
-
if (readString(event?.type) === "mirrorx_initialization_action_receipt"
|
|
28366
|
+
if (readString(event?.type) === "mirrorx_initialization_action_receipt") {
|
|
28287
28367
|
const receipt = asRecord(event.receipt);
|
|
28288
|
-
const provider = asRecord(receipt.providerReceipt);
|
|
28289
28368
|
const content = asRecord(receipt.content);
|
|
28290
|
-
if (
|
|
28369
|
+
if (readString(receipt.invocationId) && readString(receipt.status) && readString(content.status)) {
|
|
28291
28370
|
retainMcpResult({ details: { server: "amaster" }, content: [{ type: "text", text: JSON.stringify(receipt) }] });
|
|
28292
28371
|
}
|
|
28293
28372
|
}
|
|
@@ -28618,9 +28697,9 @@ function parseOpenCodeJsonl(stdout) {
|
|
|
28618
28697
|
if (event.type === "step_finish") {
|
|
28619
28698
|
const part = asRecord(event.part);
|
|
28620
28699
|
const tokens = asRecord(part.tokens);
|
|
28621
|
-
const
|
|
28700
|
+
const cache2 = asRecord(tokens.cache);
|
|
28622
28701
|
usage.inputTokens += readNumber(tokens.input, 0);
|
|
28623
|
-
usage.cachedInputTokens += readNumber(
|
|
28702
|
+
usage.cachedInputTokens += readNumber(cache2.read, 0);
|
|
28624
28703
|
usage.outputTokens += readNumber(tokens.output, 0) + readNumber(tokens.reasoning, 0);
|
|
28625
28704
|
continue;
|
|
28626
28705
|
}
|
|
@@ -29019,7 +29098,7 @@ function createRunCompletionRuntimePorts(input) {
|
|
|
29019
29098
|
outbox,
|
|
29020
29099
|
limits,
|
|
29021
29100
|
now = () => (/* @__PURE__ */ new Date()).toISOString(),
|
|
29022
|
-
sleep = (delayMs) => new Promise((
|
|
29101
|
+
sleep = (delayMs) => new Promise((resolve20) => setTimeout(resolve20, delayMs)),
|
|
29023
29102
|
diagnostic = (message) => process.stderr.write(`${message}
|
|
29024
29103
|
`)
|
|
29025
29104
|
} = input;
|
|
@@ -30247,6 +30326,30 @@ function fixedRules(input, includeIssueLine, runContract = "producer") {
|
|
|
30247
30326
|
"- A URL mentioned only in an Issue document, comment, assistant message, or provider tool output is not a collected work product. Persist the typed work product and use its returned workProductId as the durable receipt before marking the task done."
|
|
30248
30327
|
].filter(Boolean).join("\n");
|
|
30249
30328
|
}
|
|
30329
|
+
function conversationAgentRosterText(context) {
|
|
30330
|
+
const roster = asRecord(context.paperclipCompanyAgentRoster);
|
|
30331
|
+
const agents = Array.isArray(roster.agents) ? roster.agents : [];
|
|
30332
|
+
if (agents.length === 0) return "";
|
|
30333
|
+
const lines = agents.map((agent) => {
|
|
30334
|
+
const record11 = asRecord(agent);
|
|
30335
|
+
const name = readString(record11.name) ?? "unknown";
|
|
30336
|
+
const id = readString(record11.id) ?? "unknown";
|
|
30337
|
+
const role = readString(record11.role);
|
|
30338
|
+
const title = readString(record11.title);
|
|
30339
|
+
const details = [
|
|
30340
|
+
role ? `role: ${role}` : "",
|
|
30341
|
+
title ? `title: ${title}` : ""
|
|
30342
|
+
].filter(Boolean).join(", ");
|
|
30343
|
+
const status = readString(record11.status);
|
|
30344
|
+
return `- ${name} (agentId: ${id})${details ? ` \u2014 ${details}` : ""}${status && status !== "active" ? ` [${status}]` : ""}`;
|
|
30345
|
+
});
|
|
30346
|
+
return [
|
|
30347
|
+
"Company agent roster:",
|
|
30348
|
+
'When the user refers to a Company employee by name, role, or pronoun (e.g. @-mention or "\u95EE\u4ED6"), resolve them from this roster and invoke them with the invoke_employee runtime action using their exact agentId. Never substitute a local subagent for a Company employee.',
|
|
30349
|
+
...lines,
|
|
30350
|
+
...roster.truncated === true ? ["(roster truncated; use the governed member-list read for the full roster)"] : []
|
|
30351
|
+
].join("\n");
|
|
30352
|
+
}
|
|
30250
30353
|
function compileConversationPrompt(input, context, maxChars) {
|
|
30251
30354
|
const mode = promptContextMode(input);
|
|
30252
30355
|
const taskText = readString(input.taskMarkdown) ?? "";
|
|
@@ -30267,9 +30370,12 @@ function compileConversationPrompt(input, context, maxChars) {
|
|
|
30267
30370
|
if (!userPrompt) throw new Error("conversation_user_message_missing");
|
|
30268
30371
|
const rawSections = [
|
|
30269
30372
|
{ name: "task", title: "Conversation History", priority: 90, sourceRef: "conversation", originalContent: taskText, content: mode === "cold" ? taskText : "", truncationReason: mode === "cold" ? null : "mode_selection" },
|
|
30373
|
+
...readString(input.browserCredentialEnv) ? [{ name: "browser_credential_env", title: "Browser Credential Access", priority: 100, sourceRef: `command:${input.commandId}:browser-credentials`, content: readString(input.browserCredentialEnv) }] : [],
|
|
30270
30374
|
{ name: "runtime_safety", title: "Runtime Safety", priority: 100, sourceRef: `command:${input.commandId}`, content: runtimeSafety },
|
|
30271
30375
|
...piGovernedTools ? [{ name: "pi_governed_tools", title: "Pi Governed Tools", priority: 96, sourceRef: "amaster_governed_mcp_direct_typed_contract", content: piGovernedTools }] : [],
|
|
30272
30376
|
{ name: "agent_instructions", title: "Agent Instructions", priority: 100, sourceRef: "agent_instructions_bundle", content: readString(input.agentInstructions) ?? "" },
|
|
30377
|
+
{ name: "agent_roster", title: "Company Agent Roster", priority: 86, sourceRef: "company_agent_roster", content: conversationAgentRosterText(context) },
|
|
30378
|
+
{ name: "mention_context", title: "Mentioned Context", priority: 85, sourceRef: "paperclip_mention_context", content: readString(input.mentionContextText) ?? "" },
|
|
30273
30379
|
{ name: "attachments", title: "Materialized Inputs", priority: 80, sourceRef: "materialized_attachments", content: readString(input.attachmentsText) ?? "" },
|
|
30274
30380
|
{ name: "raw_snapshot", title: "Raw Context Snapshot", priority: 0, sourceRef: `run:${input.runId ?? "unknown"}`, originalChars: jsonCharLength(context), content: "", truncationReason: "on_demand_large_object" }
|
|
30275
30381
|
];
|
|
@@ -30959,9 +31065,12 @@ var COMPANY_INITIALIZATION_PRE_AUTHORITY_SECTIONS = /* @__PURE__ */ new Set([
|
|
|
30959
31065
|
"verified_company_context",
|
|
30960
31066
|
"governed_reads",
|
|
30961
31067
|
"optional_task_wiki_context",
|
|
31068
|
+
"mention_context",
|
|
31069
|
+
"agent_roster",
|
|
30962
31070
|
"attachments"
|
|
30963
31071
|
]);
|
|
30964
31072
|
var COMPANY_INITIALIZATION_POST_AUTHORITY_SECTIONS = /* @__PURE__ */ new Set([
|
|
31073
|
+
"browser_credential_env",
|
|
30965
31074
|
"runtime_rules",
|
|
30966
31075
|
"runtime_authorization",
|
|
30967
31076
|
"runtime_decomposition_requirement",
|
|
@@ -31135,6 +31244,8 @@ var CONTEXT_AVAILABILITY_SECTION_TITLES = Object.freeze({
|
|
|
31135
31244
|
governed_reads: "Governed External Reads",
|
|
31136
31245
|
optional_task_wiki_context: "Optional Company Wiki Context",
|
|
31137
31246
|
agent_instructions: "Agent Instructions",
|
|
31247
|
+
mention_context: "Mentioned Context",
|
|
31248
|
+
agent_roster: "Company Agent Roster",
|
|
31138
31249
|
attachments: "Materialized Inputs",
|
|
31139
31250
|
on_demand_refs: "On-demand Context References",
|
|
31140
31251
|
raw_snapshot: "Raw Context Snapshot"
|
|
@@ -31390,6 +31501,7 @@ ${resolvedDependencies.details.content}` : resolvedDependencies.details.content
|
|
|
31390
31501
|
} : fallbackTemplateCatalog;
|
|
31391
31502
|
const rawSections = [
|
|
31392
31503
|
{ name: "recovery_instruction", title: "Recovery Instruction", priority: 100, sourceRef: `run:${input.runId ?? "unknown"}`, content: completeRecoveryInstruction, truncationReason: completeRecoveryInstruction ? null : "mode_selection" },
|
|
31504
|
+
...readString(input.browserCredentialEnv) ? [{ name: "browser_credential_env", title: "Browser Credential Access", priority: 100, sourceRef: `command:${input.commandId}:browser-credentials`, content: readString(input.browserCredentialEnv) }] : [],
|
|
31393
31505
|
{ name: "approval_continuation", title: "Approved Runtime Action Continuation", priority: 100, sourceRef: `run:${input.runId ?? "unknown"}`, content: approvalContinuationText(input), truncationReason: mode === "continuation" ? null : "mode_selection" },
|
|
31394
31506
|
...continuationNextAction ? [{ name: "continuation_next_action", title: "Authoritative Continuation Next Action", priority: 100, ...continuationNextAction }] : [],
|
|
31395
31507
|
{ name: "wake_comments", title: wakeDeltaTitle, priority: interactionResolution ? 99 : 95, sourceRef: wakeDeltaSourceRefs, originalContent: wakeDeltaOriginal, content: wakeDeltaContent, truncationReason: commentsSelected ? null : "duplicate_task_context" },
|
|
@@ -31431,6 +31543,7 @@ ${resolvedDependencies.details.content}` : resolvedDependencies.details.content
|
|
|
31431
31543
|
...optionalTaskWikiContext ? [optionalTaskWikiContext] : [],
|
|
31432
31544
|
...runtimeTemplateCatalog ? [{ name: "runtime_template_catalog", title: "Runtime Template Catalog", priority: 100, ...runtimeTemplateCatalog }] : [],
|
|
31433
31545
|
{ name: "agent_instructions", title: "Agent Instructions", priority: 100, sourceRef: "agent_instructions_bundle", content: readString(input.agentInstructions) ?? "" },
|
|
31546
|
+
{ name: "mention_context", title: "Mentioned Context", priority: 85, sourceRef: "paperclip_mention_context", content: readString(input.mentionContextText) ?? "" },
|
|
31434
31547
|
{ name: "attachments", title: "Materialized Inputs", priority: 80, sourceRef: "materialized_attachments", content: readString(input.attachmentsText) ?? "" },
|
|
31435
31548
|
{
|
|
31436
31549
|
name: "on_demand_refs",
|
|
@@ -31927,12 +32040,17 @@ var BUILD_SUPPORTED_CAPABILITIES = Object.freeze([
|
|
|
31927
32040
|
"run_terminate",
|
|
31928
32041
|
"logs_cost_workspace_status",
|
|
31929
32042
|
"browser_credential_auth_transaction_v1",
|
|
32043
|
+
"browser_credential_env_read_v1",
|
|
31930
32044
|
"execution_lanes_v1",
|
|
31931
32045
|
"mirrorx_initialization_context_v1",
|
|
31932
32046
|
"mirrorx_initialization_completion_v1",
|
|
31933
32047
|
"native_session_checkpoint_v1"
|
|
31934
32048
|
]);
|
|
31935
32049
|
var DYNAMIC_READINESS = Object.freeze({
|
|
32050
|
+
browser_credential_env_read_v1: {
|
|
32051
|
+
reasonCode: "browser_credential_env_runtime_incomplete",
|
|
32052
|
+
ready: (input) => input.executors.some((executor) => executor.kind === "pi") && input.browserCredentialEnv?.extension === true && input.runnerKind === "cloud_managed" && Number.isSafeInteger(input.piExecutorUid) && Number.isSafeInteger(input.piExecutorGid) && input.piExecutorUid > 0 && input.piExecutorGid > 0 && Number.isSafeInteger(input.connectorUid) && input.piExecutorUid !== input.connectorUid
|
|
32053
|
+
},
|
|
31936
32054
|
browser_credential_auth_transaction_v1: {
|
|
31937
32055
|
reasonCode: "browser_credential_auth_runtime_incomplete",
|
|
31938
32056
|
ready: (input) => {
|
|
@@ -32593,10 +32711,150 @@ function sameCredentialBrowserTcb(value) {
|
|
|
32593
32711
|
return value && typeof value === "object" && Object.entries(CREDENTIAL_BROWSER_TCB).every(([key, expected]) => value[key] === expected) && Object.keys(value).length === Object.keys(CREDENTIAL_BROWSER_TCB).length;
|
|
32594
32712
|
}
|
|
32595
32713
|
|
|
32714
|
+
// src/amaster-runtime-daemon/browser-credential-env-readiness.mjs
|
|
32715
|
+
import { lstatSync as lstatSync9, readFileSync as readFileSync13 } from "node:fs";
|
|
32716
|
+
import { homedir as homedir5 } from "node:os";
|
|
32717
|
+
import { join as join16 } from "node:path";
|
|
32718
|
+
var CACHE_TTL_MS = 5e3;
|
|
32719
|
+
var cache = /* @__PURE__ */ new Map();
|
|
32720
|
+
function inspectBrowserCredentialEnvReadiness(env = process.env) {
|
|
32721
|
+
const home = String(env.PI_CODING_AGENT_DIR ?? env.PI_AGENT_HOME ?? join16(homedir5(), ".pi", "agent")).trim();
|
|
32722
|
+
const now = Date.now();
|
|
32723
|
+
const cached = cache.get(home);
|
|
32724
|
+
if (cached && cached.expiresAt > now) return { ...cached.readiness };
|
|
32725
|
+
const extensionPath = join16(home, "extensions", "browser-credential-env.mjs");
|
|
32726
|
+
let extension = false;
|
|
32727
|
+
try {
|
|
32728
|
+
const stat = lstatSync9(extensionPath);
|
|
32729
|
+
const source = stat.isFile() && !stat.isSymbolicLink() ? readFileSync13(extensionPath, "utf8") : "";
|
|
32730
|
+
extension = /\bname\s*:\s*["']browser_read_credential["']/u.test(source) && /\bPI_AGENT_BROWSER_CREDENTIAL_ENV_FILE\b/u.test(source);
|
|
32731
|
+
} catch {
|
|
32732
|
+
extension = false;
|
|
32733
|
+
}
|
|
32734
|
+
const readiness = { extension };
|
|
32735
|
+
cache.set(home, { readiness, expiresAt: now + CACHE_TTL_MS });
|
|
32736
|
+
return { ...readiness };
|
|
32737
|
+
}
|
|
32738
|
+
|
|
32739
|
+
// src/amaster-runtime-daemon/browser-credential-env.mjs
|
|
32740
|
+
import { chmodSync as chmodSync5, mkdtempSync as mkdtempSync3, renameSync as renameSync8, rmSync as rmSync9, writeFileSync as writeFileSync11 } from "node:fs";
|
|
32741
|
+
import { join as join17, resolve as resolve11 } from "node:path";
|
|
32742
|
+
var BROWSER_CREDENTIAL_ENV_CAPABILITY = "browser_credential_env_read_v1";
|
|
32743
|
+
var BROWSER_CREDENTIAL_PRIVATE_CAPABILITY = "browser_credential_auth_transaction_v1";
|
|
32744
|
+
var BROWSER_CREDENTIAL_ENV_FILE = "PI_AGENT_BROWSER_CREDENTIAL_ENV_FILE";
|
|
32745
|
+
var BROWSER_CREDENTIAL_USERNAME_KEY = "BROWSER_USERNAME";
|
|
32746
|
+
var BROWSER_CREDENTIAL_PASSWORD_KEY = "BROWSER_PASSWORD";
|
|
32747
|
+
function exactOrigin2(value) {
|
|
32748
|
+
try {
|
|
32749
|
+
const url = new URL(value);
|
|
32750
|
+
return url.protocol === "https:" && !url.username && !url.password && url.pathname === "/" && !url.search && !url.hash && value === url.origin ? url.origin : null;
|
|
32751
|
+
} catch {
|
|
32752
|
+
return null;
|
|
32753
|
+
}
|
|
32754
|
+
}
|
|
32755
|
+
function fail2(code) {
|
|
32756
|
+
const error = new Error(code);
|
|
32757
|
+
error.code = code;
|
|
32758
|
+
throw error;
|
|
32759
|
+
}
|
|
32760
|
+
function browserCredentialPresentation(command) {
|
|
32761
|
+
const refs = Array.isArray(command?.payload?.browserCredentialRefs) ? command.payload.browserCredentialRefs : [];
|
|
32762
|
+
if (refs.length === 0) return null;
|
|
32763
|
+
const capabilities = new Set(Array.isArray(command?.requiredCapabilities) ? command.requiredCapabilities : []);
|
|
32764
|
+
const envRequested = capabilities.has(BROWSER_CREDENTIAL_ENV_CAPABILITY);
|
|
32765
|
+
const privateRequested = capabilities.has(BROWSER_CREDENTIAL_PRIVATE_CAPABILITY);
|
|
32766
|
+
if (envRequested && privateRequested) fail2("browser_credential_capability_conflict");
|
|
32767
|
+
if (envRequested) return "model_visible_env";
|
|
32768
|
+
if (privateRequested) return "private_channel";
|
|
32769
|
+
fail2("browser_credential_capability_required");
|
|
32770
|
+
}
|
|
32771
|
+
function browserCredentialEnvPlan(command, presentation = browserCredentialPresentation(command)) {
|
|
32772
|
+
if (presentation !== "model_visible_env") return null;
|
|
32773
|
+
const refs = command.payload.browserCredentialRefs;
|
|
32774
|
+
const passwordRefs = refs.filter((ref2) => ref2?.credentialRole === "password");
|
|
32775
|
+
const usernameRefs = refs.filter((ref2) => ref2?.credentialRole === "username");
|
|
32776
|
+
if (passwordRefs.length !== 1 || usernameRefs.length > 1 || passwordRefs.length + usernameRefs.length !== refs.length) {
|
|
32777
|
+
fail2("browser_credential_env_ref_set_invalid");
|
|
32778
|
+
}
|
|
32779
|
+
const origin = exactOrigin2(passwordRefs[0]?.authenticationOrigin);
|
|
32780
|
+
if (!origin || refs.some((ref2) => ref2?.commandId !== command?.commandId || ref2?.authenticationOrigin !== origin || ref2?.targetOrigin !== origin)) {
|
|
32781
|
+
fail2("browser_credential_env_origin_mismatch");
|
|
32782
|
+
}
|
|
32783
|
+
const entries = [
|
|
32784
|
+
...usernameRefs.map((ref2) => ({ ref: ref2, key: BROWSER_CREDENTIAL_USERNAME_KEY, controlSemantic: "username" })),
|
|
32785
|
+
{ ref: passwordRefs[0], key: BROWSER_CREDENTIAL_PASSWORD_KEY, controlSemantic: "password" }
|
|
32786
|
+
];
|
|
32787
|
+
const availableKeys = entries.map((entry) => entry.key);
|
|
32788
|
+
return Object.freeze({
|
|
32789
|
+
origin,
|
|
32790
|
+
entries: Object.freeze(entries),
|
|
32791
|
+
promptText: [
|
|
32792
|
+
`Credentials saved for ${origin} are available only for this command.`,
|
|
32793
|
+
`Call browser_read_credential with key ${BROWSER_CREDENTIAL_PASSWORD_KEY}${usernameRefs.length > 0 ? ` and ${BROWSER_CREDENTIAL_USERNAME_KEY}` : ""}, then use the ordinary browser fill and click tools.`,
|
|
32794
|
+
"The returned values are intentionally model-visible under the approved runner .env design. Do not echo them in comments, documents, artifacts, or the final response.",
|
|
32795
|
+
"Use these credentials only at the exact origin above. If the login redirects to another origin or the expected controls are absent, stop and request human assistance rather than reusing the values elsewhere."
|
|
32796
|
+
].join("\n"),
|
|
32797
|
+
availableKeys: Object.freeze(availableKeys)
|
|
32798
|
+
});
|
|
32799
|
+
}
|
|
32800
|
+
function dotenvQuotedValue(value) {
|
|
32801
|
+
if (value.includes("\0")) fail2("browser_credential_env_value_invalid");
|
|
32802
|
+
return `"${value.replace(/[\\"\n\r\t$`]/gu, (char) => ({
|
|
32803
|
+
"\\": "\\\\",
|
|
32804
|
+
'"': '\\"',
|
|
32805
|
+
"\n": "\\n",
|
|
32806
|
+
"\r": "\\r",
|
|
32807
|
+
" ": "\\t",
|
|
32808
|
+
"$": "\\$",
|
|
32809
|
+
"`": "\\`"
|
|
32810
|
+
})[char])}"`;
|
|
32811
|
+
}
|
|
32812
|
+
async function materializeBrowserCredentialEnv(plan, options) {
|
|
32813
|
+
if (!plan || typeof options?.consume !== "function") fail2("browser_credential_env_plan_required");
|
|
32814
|
+
const rawRunDir = String(options.runDir ?? "").trim();
|
|
32815
|
+
if (!rawRunDir) fail2("browser_credential_env_run_dir_invalid");
|
|
32816
|
+
const runDir = resolve11(rawRunDir);
|
|
32817
|
+
const credentialDir = mkdtempSync3(join17(runDir, ".browser-credentials-"));
|
|
32818
|
+
chmodSync5(credentialDir, 448);
|
|
32819
|
+
const targetPath = join17(credentialDir, "credentials.env");
|
|
32820
|
+
const temporaryPath = join17(credentialDir, ".credentials.env.tmp");
|
|
32821
|
+
const buffers = [];
|
|
32822
|
+
const protectedValues = [];
|
|
32823
|
+
try {
|
|
32824
|
+
const lines = [];
|
|
32825
|
+
for (const entry of plan.entries) {
|
|
32826
|
+
const consumed = await options.consume(entry.ref, entry.controlSemantic);
|
|
32827
|
+
const valueBuffer = Buffer.isBuffer(consumed) ? consumed : Buffer.from(String(consumed), "utf8");
|
|
32828
|
+
buffers.push(valueBuffer);
|
|
32829
|
+
if (valueBuffer.length === 0 || valueBuffer.length > 16 * 1024) fail2("browser_credential_env_value_invalid");
|
|
32830
|
+
const value = valueBuffer.toString("utf8");
|
|
32831
|
+
if (!protectedValues.includes(value)) protectedValues.push(value);
|
|
32832
|
+
lines.push(`${entry.key}=${dotenvQuotedValue(value)}`);
|
|
32833
|
+
}
|
|
32834
|
+
writeFileSync11(temporaryPath, `${lines.join("\n")}
|
|
32835
|
+
`, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
32836
|
+
renameSync8(temporaryPath, targetPath);
|
|
32837
|
+
chmodSync5(targetPath, 384);
|
|
32838
|
+
return {
|
|
32839
|
+
dirPath: credentialDir,
|
|
32840
|
+
filePath: targetPath,
|
|
32841
|
+
protectedValues,
|
|
32842
|
+
cleanup() {
|
|
32843
|
+
rmSync9(credentialDir, { recursive: true, force: true });
|
|
32844
|
+
}
|
|
32845
|
+
};
|
|
32846
|
+
} catch (error) {
|
|
32847
|
+
rmSync9(credentialDir, { recursive: true, force: true });
|
|
32848
|
+
throw error;
|
|
32849
|
+
} finally {
|
|
32850
|
+
for (const buffer of buffers) buffer.fill(0);
|
|
32851
|
+
}
|
|
32852
|
+
}
|
|
32853
|
+
|
|
32596
32854
|
// src/amaster-runtime-daemon/runtime-artifact-upload.mjs
|
|
32597
32855
|
import { createHash as createHash14 } from "node:crypto";
|
|
32598
|
-
import { closeSync as closeSync4, constants as constants3, fstatSync as fstatSync4, lstatSync as
|
|
32599
|
-
import { isAbsolute as isAbsolute8, relative as relative6, resolve as
|
|
32856
|
+
import { closeSync as closeSync4, constants as constants3, fstatSync as fstatSync4, lstatSync as lstatSync10, openSync as openSync4, readFileSync as readFileSync14, realpathSync as realpathSync10 } from "node:fs";
|
|
32857
|
+
import { isAbsolute as isAbsolute8, relative as relative6, resolve as resolve12 } from "node:path";
|
|
32600
32858
|
var SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
32601
32859
|
function requiredString2(value, name) {
|
|
32602
32860
|
if (typeof value !== "string" || !value.trim()) throw new Error(`Runtime Artifact ${name} is required`);
|
|
@@ -32615,10 +32873,10 @@ function sameFileSnapshot(left, right) {
|
|
|
32615
32873
|
return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
32616
32874
|
}
|
|
32617
32875
|
function readOwnedWorkspaceFile(rootPath, sourceRelativePath, label = "Runtime workspace file", options = {}) {
|
|
32618
|
-
const root = realpathSync10(
|
|
32876
|
+
const root = realpathSync10(resolve12(rootPath));
|
|
32619
32877
|
const relativePath = ownedRelativePath(sourceRelativePath);
|
|
32620
|
-
const sourcePath =
|
|
32621
|
-
const pathStat =
|
|
32878
|
+
const sourcePath = resolve12(root, relativePath);
|
|
32879
|
+
const pathStat = lstatSync10(sourcePath);
|
|
32622
32880
|
if (!pathStat.isFile() || pathStat.isSymbolicLink() || !pathWithin2(realpathSync10(sourcePath), root)) {
|
|
32623
32881
|
throw new Error(`${label} source is not an owned regular file`);
|
|
32624
32882
|
}
|
|
@@ -32647,10 +32905,10 @@ function readOwnedWorkspaceFile(rootPath, sourceRelativePath, label = "Runtime w
|
|
|
32647
32905
|
);
|
|
32648
32906
|
}
|
|
32649
32907
|
}
|
|
32650
|
-
const body =
|
|
32908
|
+
const body = readFileSync14(descriptor);
|
|
32651
32909
|
options.afterRead?.({ sourcePath, descriptor });
|
|
32652
32910
|
const after = fstatSync4(descriptor);
|
|
32653
|
-
const pathAfter =
|
|
32911
|
+
const pathAfter = lstatSync10(sourcePath);
|
|
32654
32912
|
if (!sameFileSnapshot(before, after) || !sameFileSnapshot(pathAfter, after) || !pathAfter.isFile() || pathAfter.isSymbolicLink() || !pathWithin2(realpathSync10(sourcePath), root) || body.length !== after.size) {
|
|
32655
32913
|
throw new Error(`${label} source changed during the governed read`);
|
|
32656
32914
|
}
|
|
@@ -32975,7 +33233,7 @@ function createRuntimeArtifactIngestQueue({ ingest, onError }) {
|
|
|
32975
33233
|
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
32976
33234
|
import { createHash as createHash16 } from "node:crypto";
|
|
32977
33235
|
import { existsSync as existsSync13, mkdirSync as mkdirSync10, realpathSync as realpathSync11, statSync as statSync7 } from "node:fs";
|
|
32978
|
-
import { basename as basename6, join as
|
|
33236
|
+
import { basename as basename6, join as join18, isAbsolute as isAbsolute9, relative as relative7, resolve as resolve13 } from "node:path";
|
|
32979
33237
|
function pathWithin3(candidate, root) {
|
|
32980
33238
|
const rel = relative7(root, candidate);
|
|
32981
33239
|
return rel === "" || !rel.startsWith("..") && !isAbsolute9(rel);
|
|
@@ -32984,10 +33242,10 @@ function resolveWorkspaceCwd(config, command) {
|
|
|
32984
33242
|
const payload = asRecord(command.payload);
|
|
32985
33243
|
const requested = readString(payload.workspacePath);
|
|
32986
33244
|
const fallback = config.workspaceBindings[0] ?? process.cwd();
|
|
32987
|
-
const cwd = realpathSync11(
|
|
33245
|
+
const cwd = realpathSync11(resolve13(expandHomePath(requested ?? fallback)));
|
|
32988
33246
|
const allowlist = config.workspaceBindings.flatMap((entry) => {
|
|
32989
33247
|
try {
|
|
32990
|
-
return [realpathSync11(
|
|
33248
|
+
return [realpathSync11(resolve13(expandHomePath(entry)))];
|
|
32991
33249
|
} catch {
|
|
32992
33250
|
return [];
|
|
32993
33251
|
}
|
|
@@ -33030,7 +33288,7 @@ function workspaceLabel(sourceWorkspacePath, payload) {
|
|
|
33030
33288
|
return readString(payload.workspaceName) ?? readString(payload.projectName) ?? readString(context.projectName) ?? basename6(sourceWorkspacePath) ?? "workspace";
|
|
33031
33289
|
}
|
|
33032
33290
|
function workspacesRoot(config) {
|
|
33033
|
-
const root =
|
|
33291
|
+
const root = resolve13(expandHomePath(config.runtimeWorkspacesRoot ?? "~/.amaster-employee/workspaces"));
|
|
33034
33292
|
mkdirSync10(root, { recursive: true });
|
|
33035
33293
|
return realpathSync11(root);
|
|
33036
33294
|
}
|
|
@@ -33044,9 +33302,9 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
|
33044
33302
|
const workspaceKey = `${safeSegment(workspaceLabel(sourceWorkspacePath, payload), "workspace")}-${shortHash(sourceWorkspacePath)}`;
|
|
33045
33303
|
const issueKey = `${safeSegment(issueLabel(command, payload), "issue")}-${shortHash(issueId, 8)}`;
|
|
33046
33304
|
const runKey = `${safeSegment(runId, "run")}-${shortHash(runId, 8)}`;
|
|
33047
|
-
const runDir =
|
|
33048
|
-
const cwd =
|
|
33049
|
-
const executorHome =
|
|
33305
|
+
const runDir = join18(root, workspaceKey, issueKey, runKey);
|
|
33306
|
+
const cwd = join18(runDir, "workdir");
|
|
33307
|
+
const executorHome = join18(runDir, "executors", safeSegment(executorKind, "executor"));
|
|
33050
33308
|
mkdirSync10(cwd, { recursive: true });
|
|
33051
33309
|
mkdirSync10(executorHome, { recursive: true });
|
|
33052
33310
|
const workspace = {
|
|
@@ -33071,11 +33329,11 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
|
33071
33329
|
|
|
33072
33330
|
// src/amaster-runtime-daemon/workspace-gc.mjs
|
|
33073
33331
|
import { existsSync as existsSync14, readdirSync as readdirSync8, statSync as statSync8 } from "node:fs";
|
|
33074
|
-
import { join as
|
|
33332
|
+
import { join as join19, resolve as resolve14 } from "node:path";
|
|
33075
33333
|
function readIsoTime(value) {
|
|
33076
33334
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
33077
|
-
const
|
|
33078
|
-
return Number.isFinite(
|
|
33335
|
+
const time2 = new Date(value).getTime();
|
|
33336
|
+
return Number.isFinite(time2) ? time2 : null;
|
|
33079
33337
|
}
|
|
33080
33338
|
function safeManifestString(value) {
|
|
33081
33339
|
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
@@ -33094,7 +33352,7 @@ function walkWorkdirs(root) {
|
|
|
33094
33352
|
}
|
|
33095
33353
|
for (const entry of entries) {
|
|
33096
33354
|
if (!entry.isDirectory()) continue;
|
|
33097
|
-
const fullPath =
|
|
33355
|
+
const fullPath = join19(current, entry.name);
|
|
33098
33356
|
if (entry.name === "workdir" && existsSync14(workspaceManifestPath(fullPath))) {
|
|
33099
33357
|
workdirs.push(fullPath);
|
|
33100
33358
|
continue;
|
|
@@ -33126,7 +33384,7 @@ function directorySizeBytes(path) {
|
|
|
33126
33384
|
continue;
|
|
33127
33385
|
}
|
|
33128
33386
|
for (const entry of entries) {
|
|
33129
|
-
stack.push(
|
|
33387
|
+
stack.push(join19(current, entry.name));
|
|
33130
33388
|
}
|
|
33131
33389
|
continue;
|
|
33132
33390
|
}
|
|
@@ -33153,7 +33411,7 @@ function summarizeWorkdir(path, manifest, nowMs) {
|
|
|
33153
33411
|
};
|
|
33154
33412
|
}
|
|
33155
33413
|
function planManagedWorkspaceGcDryRun(input) {
|
|
33156
|
-
const root =
|
|
33414
|
+
const root = resolve14(String(input.root ?? ""));
|
|
33157
33415
|
const now = input.now instanceof Date ? input.now : /* @__PURE__ */ new Date();
|
|
33158
33416
|
const nowMs = now.getTime();
|
|
33159
33417
|
const ttlHours = Math.max(1, Number(input.ttlHours ?? 72));
|
|
@@ -33201,21 +33459,21 @@ function planManagedWorkspaceGcDryRun(input) {
|
|
|
33201
33459
|
import { createHash as createHash17 } from "node:crypto";
|
|
33202
33460
|
import {
|
|
33203
33461
|
accessSync,
|
|
33204
|
-
chmodSync as
|
|
33462
|
+
chmodSync as chmodSync6,
|
|
33205
33463
|
constants as constants4,
|
|
33206
33464
|
existsSync as existsSync15,
|
|
33207
|
-
lstatSync as
|
|
33465
|
+
lstatSync as lstatSync11,
|
|
33208
33466
|
mkdirSync as mkdirSync11,
|
|
33209
|
-
mkdtempSync as
|
|
33210
|
-
readFileSync as
|
|
33467
|
+
mkdtempSync as mkdtempSync4,
|
|
33468
|
+
readFileSync as readFileSync15,
|
|
33211
33469
|
readdirSync as readdirSync9,
|
|
33212
|
-
renameSync as
|
|
33213
|
-
rmSync as
|
|
33470
|
+
renameSync as renameSync9,
|
|
33471
|
+
rmSync as rmSync10,
|
|
33214
33472
|
statSync as statSync9,
|
|
33215
33473
|
unlinkSync as unlinkSync2,
|
|
33216
|
-
writeFileSync as
|
|
33474
|
+
writeFileSync as writeFileSync12
|
|
33217
33475
|
} from "node:fs";
|
|
33218
|
-
import { dirname as dirname9, extname, isAbsolute as isAbsolute10, join as
|
|
33476
|
+
import { dirname as dirname9, extname, isAbsolute as isAbsolute10, join as join20, parse as parse4, resolve as resolve15, sep as sep4 } from "node:path";
|
|
33219
33477
|
import { fileURLToPath } from "node:url";
|
|
33220
33478
|
var PRESET_TEMPLATE_MANIFEST_FILE = ".mirrorx-preset-templates.json";
|
|
33221
33479
|
var MAX_PRESET_TEMPLATE_FILES = 256;
|
|
@@ -33226,7 +33484,7 @@ function sha2562(value) {
|
|
|
33226
33484
|
}
|
|
33227
33485
|
function lstatIfExists(path) {
|
|
33228
33486
|
try {
|
|
33229
|
-
return
|
|
33487
|
+
return lstatSync11(path);
|
|
33230
33488
|
} catch (error) {
|
|
33231
33489
|
if (error?.code === "ENOENT") return null;
|
|
33232
33490
|
throw error;
|
|
@@ -33241,7 +33499,7 @@ function modeAllows(stat, identity, ownerBit, groupBit, otherBit) {
|
|
|
33241
33499
|
function assertCatalogReadableByExecutor(targetDir, fileNames, identity) {
|
|
33242
33500
|
if (!identity) {
|
|
33243
33501
|
accessSync(targetDir, constants4.R_OK | constants4.X_OK);
|
|
33244
|
-
for (const name of fileNames) accessSync(
|
|
33502
|
+
for (const name of fileNames) accessSync(join20(targetDir, name), constants4.R_OK);
|
|
33245
33503
|
return;
|
|
33246
33504
|
}
|
|
33247
33505
|
let current = targetDir;
|
|
@@ -33259,7 +33517,7 @@ function assertCatalogReadableByExecutor(targetDir, fileNames, identity) {
|
|
|
33259
33517
|
throw new Error(`preset_template_executor_catalog_unreadable: ${targetDir}`);
|
|
33260
33518
|
}
|
|
33261
33519
|
for (const name of fileNames) {
|
|
33262
|
-
const path =
|
|
33520
|
+
const path = join20(targetDir, name);
|
|
33263
33521
|
const stat = statSync9(path);
|
|
33264
33522
|
if (!stat.isFile() || !modeAllows(stat, identity, 256, 32, 4)) {
|
|
33265
33523
|
throw new Error(`preset_template_executor_file_unreadable: ${name}`);
|
|
@@ -33275,7 +33533,7 @@ function validTemplateName(value) {
|
|
|
33275
33533
|
}
|
|
33276
33534
|
function readManifest(manifestPath, { strict }) {
|
|
33277
33535
|
try {
|
|
33278
|
-
const parsed = JSON.parse(
|
|
33536
|
+
const parsed = JSON.parse(readFileSync15(manifestPath, "utf8"));
|
|
33279
33537
|
if (parsed?.schemaVersion !== 1 || !Array.isArray(parsed.files)) {
|
|
33280
33538
|
throw new Error("preset_template_bundle_manifest_invalid");
|
|
33281
33539
|
}
|
|
@@ -33303,12 +33561,12 @@ function readManifest(manifestPath, { strict }) {
|
|
|
33303
33561
|
}
|
|
33304
33562
|
function verifiedBundleFiles(sourceDir, manifest) {
|
|
33305
33563
|
return manifest.files.map((entry) => {
|
|
33306
|
-
const sourcePath =
|
|
33307
|
-
const stat =
|
|
33564
|
+
const sourcePath = join20(sourceDir, entry.name);
|
|
33565
|
+
const stat = lstatSync11(sourcePath);
|
|
33308
33566
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
33309
33567
|
throw new Error(`preset_template_bundle_file_unsafe: ${entry.name}`);
|
|
33310
33568
|
}
|
|
33311
|
-
const body =
|
|
33569
|
+
const body = readFileSync15(sourcePath);
|
|
33312
33570
|
if (body.byteLength !== entry.bytes || sha2562(body) !== entry.sha256) {
|
|
33313
33571
|
throw new Error(`preset_template_bundle_digest_mismatch: ${entry.name}`);
|
|
33314
33572
|
}
|
|
@@ -33318,9 +33576,9 @@ function verifiedBundleFiles(sourceDir, manifest) {
|
|
|
33318
33576
|
function removeRetiredPresetFiles(targetDir, previousManifest, nextNames) {
|
|
33319
33577
|
for (const entry of previousManifest.files) {
|
|
33320
33578
|
if (nextNames.has(entry.name)) continue;
|
|
33321
|
-
const targetPath =
|
|
33579
|
+
const targetPath = join20(targetDir, entry.name);
|
|
33322
33580
|
if (!existsSync15(targetPath)) continue;
|
|
33323
|
-
const stat =
|
|
33581
|
+
const stat = lstatSync11(targetPath);
|
|
33324
33582
|
if (stat.isDirectory()) {
|
|
33325
33583
|
throw new Error(`preset_template_target_conflict: ${entry.name}`);
|
|
33326
33584
|
}
|
|
@@ -33328,12 +33586,12 @@ function removeRetiredPresetFiles(targetDir, previousManifest, nextNames) {
|
|
|
33328
33586
|
}
|
|
33329
33587
|
}
|
|
33330
33588
|
function materializeBundledPresetTemplates(input) {
|
|
33331
|
-
const sourceDir =
|
|
33332
|
-
const targetDir =
|
|
33589
|
+
const sourceDir = resolve15(input.sourceDir);
|
|
33590
|
+
const targetDir = resolve15(input.targetDir);
|
|
33333
33591
|
if (sourceDir === targetDir || sourceDir.startsWith(`${targetDir}${sep4}`) || targetDir.startsWith(`${sourceDir}${sep4}`)) {
|
|
33334
33592
|
throw new Error("preset_template_source_target_overlap");
|
|
33335
33593
|
}
|
|
33336
|
-
const manifest = readManifest(
|
|
33594
|
+
const manifest = readManifest(join20(sourceDir, PRESET_TEMPLATE_MANIFEST_FILE), { strict: true });
|
|
33337
33595
|
const verifiedFiles = verifiedBundleFiles(sourceDir, manifest);
|
|
33338
33596
|
mkdirSync11(dirname9(targetDir), { recursive: true, mode: 493 });
|
|
33339
33597
|
const targetStat = lstatIfExists(targetDir);
|
|
@@ -33341,28 +33599,28 @@ function materializeBundledPresetTemplates(input) {
|
|
|
33341
33599
|
throw new Error("preset_template_target_root_unsafe");
|
|
33342
33600
|
}
|
|
33343
33601
|
mkdirSync11(targetDir, { recursive: true, mode: 493 });
|
|
33344
|
-
const previousManifest = readManifest(
|
|
33345
|
-
const stageDir =
|
|
33602
|
+
const previousManifest = readManifest(join20(targetDir, PRESET_TEMPLATE_MANIFEST_FILE), { strict: false });
|
|
33603
|
+
const stageDir = mkdtempSync4(join20(dirname9(targetDir), ".mirrorx-preset-templates-"));
|
|
33346
33604
|
try {
|
|
33347
33605
|
for (const file of verifiedFiles) {
|
|
33348
|
-
const stagedPath =
|
|
33349
|
-
|
|
33350
|
-
|
|
33351
|
-
|
|
33606
|
+
const stagedPath = join20(stageDir, file.name);
|
|
33607
|
+
writeFileSync12(stagedPath, file.body, { mode: 292 });
|
|
33608
|
+
chmodSync6(stagedPath, 292);
|
|
33609
|
+
renameSync9(stagedPath, join20(targetDir, file.name));
|
|
33352
33610
|
}
|
|
33353
33611
|
removeRetiredPresetFiles(targetDir, previousManifest, new Set(manifest.files.map((file) => file.name)));
|
|
33354
|
-
const stagedManifest =
|
|
33355
|
-
|
|
33612
|
+
const stagedManifest = join20(stageDir, PRESET_TEMPLATE_MANIFEST_FILE);
|
|
33613
|
+
writeFileSync12(stagedManifest, `${JSON.stringify({
|
|
33356
33614
|
schemaVersion: manifest.schemaVersion,
|
|
33357
33615
|
files: manifest.files
|
|
33358
33616
|
}, null, 2)}
|
|
33359
33617
|
`, { mode: 292 });
|
|
33360
|
-
|
|
33361
|
-
|
|
33618
|
+
chmodSync6(stagedManifest, 292);
|
|
33619
|
+
renameSync9(stagedManifest, join20(targetDir, PRESET_TEMPLATE_MANIFEST_FILE));
|
|
33362
33620
|
} finally {
|
|
33363
|
-
|
|
33621
|
+
rmSync10(stageDir, { recursive: true, force: true });
|
|
33364
33622
|
}
|
|
33365
|
-
|
|
33623
|
+
chmodSync6(targetDir, 493);
|
|
33366
33624
|
return {
|
|
33367
33625
|
fileCount: manifest.files.length,
|
|
33368
33626
|
totalBytes: manifest.totalBytes,
|
|
@@ -33375,12 +33633,12 @@ function materializeRuntimePresetTemplates(input) {
|
|
|
33375
33633
|
sourceDir,
|
|
33376
33634
|
targetDir: input.targetDir
|
|
33377
33635
|
});
|
|
33378
|
-
const manifestBody =
|
|
33379
|
-
|
|
33636
|
+
const manifestBody = readFileSync15(
|
|
33637
|
+
join20(materialized.targetDir, PRESET_TEMPLATE_MANIFEST_FILE)
|
|
33380
33638
|
);
|
|
33381
33639
|
const manifest = JSON.parse(manifestBody.toString("utf8"));
|
|
33382
33640
|
for (const file of manifest.files) {
|
|
33383
|
-
const body =
|
|
33641
|
+
const body = readFileSync15(join20(materialized.targetDir, file.name));
|
|
33384
33642
|
if (sha2562(body) !== file.sha256) {
|
|
33385
33643
|
throw new Error(`preset_template_materialized_digest_mismatch: ${file.name}`);
|
|
33386
33644
|
}
|
|
@@ -33404,7 +33662,7 @@ function materializeRuntimePresetTemplates(input) {
|
|
|
33404
33662
|
|
|
33405
33663
|
// src/amaster-runtime-daemon/runtime-status-summary.mjs
|
|
33406
33664
|
import { existsSync as existsSync16, readdirSync as readdirSync10, statSync as statSync10 } from "node:fs";
|
|
33407
|
-
import { dirname as dirname10, join as
|
|
33665
|
+
import { dirname as dirname10, join as join21, resolve as resolve16 } from "node:path";
|
|
33408
33666
|
function runtimeStatusDirectoryEntries(path) {
|
|
33409
33667
|
try {
|
|
33410
33668
|
return readdirSync10(path, { withFileTypes: true });
|
|
@@ -33427,7 +33685,7 @@ function runtimeStatusDirectorySizeBytes(path) {
|
|
|
33427
33685
|
if (!stat || stat.isSymbolicLink()) continue;
|
|
33428
33686
|
if (stat.isDirectory()) {
|
|
33429
33687
|
for (const entry of runtimeStatusDirectoryEntries(current)) {
|
|
33430
|
-
stack.push(
|
|
33688
|
+
stack.push(join21(current, entry.name));
|
|
33431
33689
|
}
|
|
33432
33690
|
continue;
|
|
33433
33691
|
}
|
|
@@ -33444,7 +33702,7 @@ function walkRuntimeStatusManagedWorkdirs(root) {
|
|
|
33444
33702
|
if (!current) continue;
|
|
33445
33703
|
for (const entry of runtimeStatusDirectoryEntries(current)) {
|
|
33446
33704
|
if (!entry.isDirectory()) continue;
|
|
33447
|
-
const fullPath =
|
|
33705
|
+
const fullPath = join21(current, entry.name);
|
|
33448
33706
|
if (entry.name === "workdir" && existsSync16(workspaceManifestPath(fullPath))) {
|
|
33449
33707
|
workdirs.push(fullPath);
|
|
33450
33708
|
continue;
|
|
@@ -33456,8 +33714,8 @@ function walkRuntimeStatusManagedWorkdirs(root) {
|
|
|
33456
33714
|
}
|
|
33457
33715
|
function readRuntimeStatusIsoTime(value) {
|
|
33458
33716
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
33459
|
-
const
|
|
33460
|
-
return Number.isFinite(
|
|
33717
|
+
const time2 = Date.parse(value);
|
|
33718
|
+
return Number.isFinite(time2) ? time2 : null;
|
|
33461
33719
|
}
|
|
33462
33720
|
function readRuntimeStatusString(value) {
|
|
33463
33721
|
return typeof value === "string" && value.trim() ? value : null;
|
|
@@ -33486,15 +33744,15 @@ function summarizeRuntimeStatusRecentRun(workdir, manifest) {
|
|
|
33486
33744
|
}
|
|
33487
33745
|
function runtimeStatusOutboxDir(config) {
|
|
33488
33746
|
const statePath = config.AMASTER_DAEMON_STATE_FILE ?? config.daemonStateFile;
|
|
33489
|
-
return
|
|
33747
|
+
return join21(dirname10(stateFilePath({
|
|
33490
33748
|
AMASTER_DAEMON_STATE_FILE: statePath
|
|
33491
33749
|
})), "result-outbox");
|
|
33492
33750
|
}
|
|
33493
33751
|
function runtimeStatusRunCompletionDir(config) {
|
|
33494
33752
|
const explicit = config.AMASTER_RUN_COMPLETION_STATE_DIR ?? config.runCompletionStateDir;
|
|
33495
|
-
if (typeof explicit === "string" && explicit.trim()) return
|
|
33753
|
+
if (typeof explicit === "string" && explicit.trim()) return resolve16(explicit);
|
|
33496
33754
|
const statePath = config.AMASTER_DAEMON_STATE_FILE ?? config.daemonStateFile;
|
|
33497
|
-
return
|
|
33755
|
+
return join21(dirname10(stateFilePath({
|
|
33498
33756
|
AMASTER_DAEMON_STATE_FILE: statePath
|
|
33499
33757
|
})), "run-completion-state");
|
|
33500
33758
|
}
|
|
@@ -33504,7 +33762,7 @@ function countRuntimeStatusJsonEntries(dir) {
|
|
|
33504
33762
|
}
|
|
33505
33763
|
function summarizeRuntimeLocalState(input) {
|
|
33506
33764
|
const config = input.config ?? {};
|
|
33507
|
-
const root =
|
|
33765
|
+
const root = resolve16(String(config.AMASTER_RUNTIME_WORKSPACES_ROOT ?? config.runtimeWorkspacesRoot ?? input.runtimeWorkspacesRoot ?? ""));
|
|
33508
33766
|
const now = input.now instanceof Date ? input.now : /* @__PURE__ */ new Date();
|
|
33509
33767
|
const workdirs = walkRuntimeStatusManagedWorkdirs(root);
|
|
33510
33768
|
let managedWorkdirBytes = 0;
|
|
@@ -33531,9 +33789,9 @@ function summarizeRuntimeLocalState(input) {
|
|
|
33531
33789
|
}
|
|
33532
33790
|
}
|
|
33533
33791
|
const pendingOutboxDir = runtimeStatusOutboxDir(config);
|
|
33534
|
-
const invalidOutboxDir =
|
|
33792
|
+
const invalidOutboxDir = join21(pendingOutboxDir, "invalid");
|
|
33535
33793
|
const pendingRunCompletionDir = runtimeStatusRunCompletionDir(config);
|
|
33536
|
-
const invalidRunCompletionDir =
|
|
33794
|
+
const invalidRunCompletionDir = join21(pendingRunCompletionDir, "invalid");
|
|
33537
33795
|
return {
|
|
33538
33796
|
managedWorkspacesRoot: root,
|
|
33539
33797
|
managedWorkdirCount: workdirs.length,
|
|
@@ -33655,7 +33913,7 @@ function summarizeAmasterRuntimeVersionDrift(input = {}) {
|
|
|
33655
33913
|
}
|
|
33656
33914
|
|
|
33657
33915
|
// src/amaster-runtime-daemon/pi-context-budget.mjs
|
|
33658
|
-
import { readFileSync as
|
|
33916
|
+
import { readFileSync as readFileSync16 } from "node:fs";
|
|
33659
33917
|
var CONTEXT_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
33660
33918
|
"context_effective_tool_schema_attestation_mismatch",
|
|
33661
33919
|
"context_output_reserve_exceeds_model_limit",
|
|
@@ -33770,7 +34028,7 @@ function measureRestoredPiNativeHistory(managedMcpProfile) {
|
|
|
33770
34028
|
if (!rolloutPath) {
|
|
33771
34029
|
return { status: "fresh", tokens: 0, rolloutBytes: 0, usageTokens: 0 };
|
|
33772
34030
|
}
|
|
33773
|
-
const rollout =
|
|
34031
|
+
const rollout = readFileSync16(rolloutPath);
|
|
33774
34032
|
const maximumRolloutBytes = 64 * 1024 * 1024;
|
|
33775
34033
|
if (rollout.byteLength > maximumRolloutBytes) {
|
|
33776
34034
|
throw stableContextError(
|
|
@@ -33864,8 +34122,8 @@ function resolvePiModelContextBudget({
|
|
|
33864
34122
|
}
|
|
33865
34123
|
|
|
33866
34124
|
// src/amaster-runtime-daemon/pi-project-instruction-extension.mjs
|
|
33867
|
-
import { lstatSync as
|
|
33868
|
-
import { resolve as
|
|
34125
|
+
import { lstatSync as lstatSync12, readFileSync as readFileSync17 } from "node:fs";
|
|
34126
|
+
import { resolve as resolve17 } from "node:path";
|
|
33869
34127
|
var MANAGED_PI_PROJECT_INSTRUCTION_FILENAME = "amaster-project-instructions.js";
|
|
33870
34128
|
function requiredString4(value, name) {
|
|
33871
34129
|
if (typeof value !== "string" || !value.trim()) {
|
|
@@ -33874,12 +34132,12 @@ function requiredString4(value, name) {
|
|
|
33874
34132
|
return value.trim();
|
|
33875
34133
|
}
|
|
33876
34134
|
function managedPiProjectInstructionExtensionSource(input) {
|
|
33877
|
-
const projectInstructionPath =
|
|
33878
|
-
const stat =
|
|
34135
|
+
const projectInstructionPath = resolve17(requiredString4(input.projectInstructionPath, "projectInstructionPath"));
|
|
34136
|
+
const stat = lstatSync12(projectInstructionPath);
|
|
33879
34137
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
33880
34138
|
throw new Error("pi_project_instruction_extension_invalid: unsafe projectInstructionPath");
|
|
33881
34139
|
}
|
|
33882
|
-
const projectInstructions =
|
|
34140
|
+
const projectInstructions = readFileSync17(projectInstructionPath, "utf8");
|
|
33883
34141
|
return String.raw`const PROJECT_INSTRUCTIONS = ${JSON.stringify(projectInstructions.trim())};
|
|
33884
34142
|
|
|
33885
34143
|
export default function amasterProjectInstructions(pi) {
|
|
@@ -33894,8 +34152,8 @@ export default function amasterProjectInstructions(pi) {
|
|
|
33894
34152
|
// src/amaster-runtime-daemon/workspace-status.mjs
|
|
33895
34153
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
33896
34154
|
import { createHash as createHash18 } from "node:crypto";
|
|
33897
|
-
import { existsSync as existsSync17, readdirSync as readdirSync11, readFileSync as
|
|
33898
|
-
import { basename as basename7, extname as extname2, isAbsolute as isAbsolute11, join as
|
|
34155
|
+
import { existsSync as existsSync17, readdirSync as readdirSync11, readFileSync as readFileSync18, statSync as statSync11 } from "node:fs";
|
|
34156
|
+
import { basename as basename7, extname as extname2, isAbsolute as isAbsolute11, join as join22, relative as relative8, resolve as resolve18 } from "node:path";
|
|
33899
34157
|
var WORKSPACE_RUNTIME_SERVICES_FILENAME = ".amaster-runtime-services.json";
|
|
33900
34158
|
var ARTIFACT_EXTENSIONS = /* @__PURE__ */ new Map([
|
|
33901
34159
|
[".md", "markdown"],
|
|
@@ -33964,35 +34222,35 @@ function sanitizeTrackedChange(line) {
|
|
|
33964
34222
|
return isSafeRelativePath(path) ? line : null;
|
|
33965
34223
|
}
|
|
33966
34224
|
function sha256File(filePath) {
|
|
33967
|
-
return createHash18("sha256").update(
|
|
34225
|
+
return createHash18("sha256").update(readFileSync18(filePath)).digest("hex");
|
|
33968
34226
|
}
|
|
33969
34227
|
function artifactHashCacheKey(relativePath, stat) {
|
|
33970
34228
|
return `${relativePath}\0${stat.size}\0${stat.mtimeMs}`;
|
|
33971
34229
|
}
|
|
33972
34230
|
function artifactSha256(filePath, relativePath, stat, opts = {}) {
|
|
33973
|
-
const
|
|
34231
|
+
const cache2 = opts.hashCache;
|
|
33974
34232
|
const key = artifactHashCacheKey(relativePath, stat);
|
|
33975
|
-
if (
|
|
33976
|
-
const cached =
|
|
33977
|
-
|
|
33978
|
-
|
|
34233
|
+
if (cache2?.has(key)) {
|
|
34234
|
+
const cached = cache2.get(key);
|
|
34235
|
+
cache2.delete(key);
|
|
34236
|
+
cache2.set(key, cached);
|
|
33979
34237
|
return cached;
|
|
33980
34238
|
}
|
|
33981
34239
|
const hashFile = typeof opts.hashFile === "function" ? opts.hashFile : sha256File;
|
|
33982
34240
|
const hash3 = hashFile(filePath);
|
|
33983
|
-
if (
|
|
33984
|
-
|
|
34241
|
+
if (cache2) {
|
|
34242
|
+
cache2.set(key, hash3);
|
|
33985
34243
|
const maxEntries = Math.max(0, Number(opts.hashCacheMaxEntries ?? MAX_HASH_CACHE_ENTRIES) || 0);
|
|
33986
|
-
while (maxEntries > 0 &&
|
|
33987
|
-
const oldestKey =
|
|
33988
|
-
|
|
34244
|
+
while (maxEntries > 0 && cache2.size > maxEntries) {
|
|
34245
|
+
const oldestKey = cache2.keys().next().value;
|
|
34246
|
+
cache2.delete(oldestKey);
|
|
33989
34247
|
}
|
|
33990
|
-
if (maxEntries === 0)
|
|
34248
|
+
if (maxEntries === 0) cache2.clear();
|
|
33991
34249
|
}
|
|
33992
34250
|
return hash3;
|
|
33993
34251
|
}
|
|
33994
34252
|
function scanArtifactCandidates(cwd, opts = {}) {
|
|
33995
|
-
const root =
|
|
34253
|
+
const root = resolve18(cwd);
|
|
33996
34254
|
const maxCandidates = opts.maxCandidates ?? MAX_CANDIDATES;
|
|
33997
34255
|
const maxEntries = opts.maxEntries ?? MAX_SCAN_ENTRIES;
|
|
33998
34256
|
const candidates = [];
|
|
@@ -34013,7 +34271,7 @@ function scanArtifactCandidates(cwd, opts = {}) {
|
|
|
34013
34271
|
if (entry.name.startsWith(".") && entry.name !== ".amaster-runtime.json") {
|
|
34014
34272
|
if (entry.name === ".git") continue;
|
|
34015
34273
|
}
|
|
34016
|
-
const fullPath =
|
|
34274
|
+
const fullPath = join22(current, entry.name);
|
|
34017
34275
|
const relativePath = normalizeRelativePath(root, fullPath);
|
|
34018
34276
|
if (!isSafeRelativePath(relativePath)) continue;
|
|
34019
34277
|
if (basename7(relativePath) === ".amaster-runtime.json") continue;
|
|
@@ -34031,7 +34289,7 @@ function scanArtifactCandidates(cwd, opts = {}) {
|
|
|
34031
34289
|
} catch {
|
|
34032
34290
|
continue;
|
|
34033
34291
|
}
|
|
34034
|
-
if (!statusPathWithin(
|
|
34292
|
+
if (!statusPathWithin(resolve18(fullPath), root) || stat.size > MAX_HASH_BYTES) continue;
|
|
34035
34293
|
candidates.push({
|
|
34036
34294
|
relativePath,
|
|
34037
34295
|
name: basename7(fullPath),
|
|
@@ -34091,10 +34349,10 @@ function sanitizeRuntimeService(entry) {
|
|
|
34091
34349
|
};
|
|
34092
34350
|
}
|
|
34093
34351
|
function readRuntimeServicesSnapshot(cwd) {
|
|
34094
|
-
const snapshotPath =
|
|
34352
|
+
const snapshotPath = join22(resolve18(cwd), WORKSPACE_RUNTIME_SERVICES_FILENAME);
|
|
34095
34353
|
if (!existsSync17(snapshotPath)) return [];
|
|
34096
34354
|
try {
|
|
34097
|
-
const parsed = JSON.parse(
|
|
34355
|
+
const parsed = JSON.parse(readFileSync18(snapshotPath, "utf8"));
|
|
34098
34356
|
const rawServices = Array.isArray(parsed) ? parsed : Array.isArray(parsed?.services) ? parsed.services : [];
|
|
34099
34357
|
return rawServices.map((entry) => sanitizeRuntimeService(entry)).filter((entry) => entry !== null).slice(0, 50);
|
|
34100
34358
|
} catch {
|
|
@@ -34196,7 +34454,7 @@ function assertRequiredTaskAttachmentMaterialized(input, materialized) {
|
|
|
34196
34454
|
}
|
|
34197
34455
|
|
|
34198
34456
|
// src/amaster-runtime-daemon.mjs
|
|
34199
|
-
var CONNECTOR_VERSION = "0.1.
|
|
34457
|
+
var CONNECTOR_VERSION = "0.1.3";
|
|
34200
34458
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
34201
34459
|
var SUPPORTED_TASK_CONTEXT_VERSIONS = Object.freeze([TASK_CONTEXT_MANIFEST_VERSION, TASK_CONTEXT_V2]);
|
|
34202
34460
|
var daemonRequire = createRequire(import.meta.url);
|
|
@@ -34268,12 +34526,12 @@ function notifyDaemonLoop() {
|
|
|
34268
34526
|
}
|
|
34269
34527
|
function waitForDaemonLoop(timeoutMs, observedVersion) {
|
|
34270
34528
|
if (daemonLoopWakeVersion !== observedVersion) return Promise.resolve();
|
|
34271
|
-
return new Promise((
|
|
34529
|
+
return new Promise((resolve20) => {
|
|
34272
34530
|
const finish = () => {
|
|
34273
34531
|
clearTimeout(timer);
|
|
34274
34532
|
if (wakeDaemonLoop === finish) wakeDaemonLoop = () => {
|
|
34275
34533
|
};
|
|
34276
|
-
|
|
34534
|
+
resolve20();
|
|
34277
34535
|
};
|
|
34278
34536
|
const timer = setTimeout(finish, timeoutMs);
|
|
34279
34537
|
wakeDaemonLoop = finish;
|
|
@@ -34296,7 +34554,7 @@ function resultOutboxPendingCount(config) {
|
|
|
34296
34554
|
try {
|
|
34297
34555
|
let pending = 0;
|
|
34298
34556
|
for (const file of readdirSync12(dir).filter((name) => name.endsWith(".json"))) {
|
|
34299
|
-
if (readValidResultOutboxEntryOrQuarantine(config, file,
|
|
34557
|
+
if (readValidResultOutboxEntryOrQuarantine(config, file, join23(dir, file))) {
|
|
34300
34558
|
pending += 1;
|
|
34301
34559
|
}
|
|
34302
34560
|
}
|
|
@@ -34307,18 +34565,18 @@ function resultOutboxPendingCount(config) {
|
|
|
34307
34565
|
}
|
|
34308
34566
|
function runCompletionStateDir(config) {
|
|
34309
34567
|
const explicit = readString(process.env.AMASTER_RUN_COMPLETION_STATE_DIR);
|
|
34310
|
-
if (explicit) return
|
|
34311
|
-
return
|
|
34568
|
+
if (explicit) return resolve19(expandHomePath(explicit));
|
|
34569
|
+
return join23(dirname11(stateFilePath(process.env)), "run-completion-state");
|
|
34312
34570
|
}
|
|
34313
34571
|
function runCompletionStateInvalidDir(config) {
|
|
34314
|
-
return
|
|
34572
|
+
return join23(runCompletionStateDir(config), "invalid");
|
|
34315
34573
|
}
|
|
34316
34574
|
function quarantineInvalidRunCompletionState(config, filePath, reason) {
|
|
34317
34575
|
const invalidDir = runCompletionStateInvalidDir(config);
|
|
34318
34576
|
mkdirSync12(invalidDir, { recursive: true, mode: 448 });
|
|
34319
|
-
const destination =
|
|
34577
|
+
const destination = join23(invalidDir, basename8(filePath));
|
|
34320
34578
|
try {
|
|
34321
|
-
|
|
34579
|
+
renameSync10(filePath, destination);
|
|
34322
34580
|
} catch {
|
|
34323
34581
|
copyFileSync2(filePath, destination);
|
|
34324
34582
|
unlinkSync3(filePath);
|
|
@@ -34374,7 +34632,7 @@ function resultOutboxActiveRunCommands(config) {
|
|
|
34374
34632
|
const outboxPending = resultOutboxPendingCount(config);
|
|
34375
34633
|
const entries = [];
|
|
34376
34634
|
for (const file of readdirSync12(dir).filter((name) => name.endsWith(".json")).sort()) {
|
|
34377
|
-
const entry = readValidResultOutboxEntryOrQuarantine(config, file,
|
|
34635
|
+
const entry = readValidResultOutboxEntryOrQuarantine(config, file, join23(dir, file));
|
|
34378
34636
|
if (!entry) continue;
|
|
34379
34637
|
const activeRun = asRecord(entry.activeRun);
|
|
34380
34638
|
const commandId = readString(activeRun.commandId) ?? readString(entry.commandId);
|
|
@@ -34410,7 +34668,7 @@ function resultOutboxFailedRunCommands(config) {
|
|
|
34410
34668
|
for (const file of readdirSync12(dir).filter((name) => name.endsWith(".json")).sort().slice(-100)) {
|
|
34411
34669
|
let entry;
|
|
34412
34670
|
try {
|
|
34413
|
-
entry = asRecord(JSON.parse(
|
|
34671
|
+
entry = asRecord(JSON.parse(readFileSync19(join23(dir, file), "utf8")));
|
|
34414
34672
|
} catch {
|
|
34415
34673
|
continue;
|
|
34416
34674
|
}
|
|
@@ -34473,11 +34731,11 @@ function piExtraArgsDiagnostics(value) {
|
|
|
34473
34731
|
}
|
|
34474
34732
|
function safeExpandPath(value) {
|
|
34475
34733
|
const text2 = readString(value);
|
|
34476
|
-
return text2 ?
|
|
34734
|
+
return text2 ? resolve19(expandHomePath(text2)) : null;
|
|
34477
34735
|
}
|
|
34478
34736
|
function safeJsonObjectFromFile(filePath) {
|
|
34479
34737
|
try {
|
|
34480
|
-
const parsed = JSON.parse(
|
|
34738
|
+
const parsed = JSON.parse(readFileSync19(filePath, "utf8"));
|
|
34481
34739
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
34482
34740
|
} catch {
|
|
34483
34741
|
return null;
|
|
@@ -34520,10 +34778,10 @@ function safeSkillRootSummary(kind, source, pathValue) {
|
|
|
34520
34778
|
try {
|
|
34521
34779
|
for (const name of readdirSync12(pathValue)) {
|
|
34522
34780
|
if (name.startsWith(".")) continue;
|
|
34523
|
-
const skillDir =
|
|
34781
|
+
const skillDir = join23(pathValue, name);
|
|
34524
34782
|
try {
|
|
34525
34783
|
if (!statSync12(skillDir).isDirectory()) continue;
|
|
34526
|
-
if (!existsSync18(
|
|
34784
|
+
if (!existsSync18(join23(skillDir, "SKILL.md"))) continue;
|
|
34527
34785
|
skillCount += 1;
|
|
34528
34786
|
if (skillCount >= MAX_PI_CAPABILITY_SOURCE_ENTRIES) {
|
|
34529
34787
|
truncated = true;
|
|
@@ -34574,7 +34832,7 @@ function objectKeyCount(value) {
|
|
|
34574
34832
|
return value && typeof value === "object" && !Array.isArray(value) ? Object.keys(value).length : 0;
|
|
34575
34833
|
}
|
|
34576
34834
|
function defaultPiCodingAgentDir() {
|
|
34577
|
-
return
|
|
34835
|
+
return join23(homedir6(), ".pi", "agent");
|
|
34578
34836
|
}
|
|
34579
34837
|
function piCapabilitySourcesDiagnostics() {
|
|
34580
34838
|
const configuredPiCodingAgentDir = safeExpandPath(process.env.PI_CODING_AGENT_DIR);
|
|
@@ -34583,14 +34841,14 @@ function piCapabilitySourcesDiagnostics() {
|
|
|
34583
34841
|
const configuredPiAgentHome = safeExpandPath(process.env.PI_AGENT_HOME);
|
|
34584
34842
|
const piAgentHome = configuredPiAgentHome ?? piCodingAgentDir;
|
|
34585
34843
|
const piAgentHomeSource = configuredPiAgentHome ? "PI_AGENT_HOME" : piCodingAgentDirSource;
|
|
34586
|
-
const userSkillsPath = piAgentHome ?
|
|
34844
|
+
const userSkillsPath = piAgentHome ? join23(piAgentHome, "skills") : null;
|
|
34587
34845
|
const configuredMarketplaceSkillsPath = safeExpandPath(
|
|
34588
34846
|
process.env.PI_AGENT_MARKETPLACE_SKILLS_DIR
|
|
34589
34847
|
);
|
|
34590
|
-
const marketplaceSkillsPath = configuredMarketplaceSkillsPath ?? (piAgentHome ?
|
|
34848
|
+
const marketplaceSkillsPath = configuredMarketplaceSkillsPath ?? (piAgentHome ? join23(piAgentHome, "marketplace", "skills") : null);
|
|
34591
34849
|
const builtinSkillsPath = safeExpandPath(process.env.PI_AGENT_BUILTIN_SKILLS_DIR) ?? safeExpandPath(process.env.AMASTER_BUILTIN_SKILLS);
|
|
34592
|
-
const mcpConfigPath = safeExpandPath(process.env.PI_AGENT_MCP_SERVERS_FILE) ?? (piAgentHome ?
|
|
34593
|
-
const settingsConfigPath = piCodingAgentDir ?
|
|
34850
|
+
const mcpConfigPath = safeExpandPath(process.env.PI_AGENT_MCP_SERVERS_FILE) ?? (piAgentHome ? join23(piAgentHome, "mcp.json") : null);
|
|
34851
|
+
const settingsConfigPath = piCodingAgentDir ? join23(piCodingAgentDir, "settings.json") : null;
|
|
34594
34852
|
const skillRoots = [
|
|
34595
34853
|
safeSkillRootSummary("user", `${piAgentHomeSource}/skills`, userSkillsPath),
|
|
34596
34854
|
safeSkillRootSummary(
|
|
@@ -34747,9 +35005,13 @@ function runtimeAdvertisedCapabilities(config) {
|
|
|
34747
35005
|
templateCatalog: config.templateCatalog,
|
|
34748
35006
|
runtimeTemplatesRoot: config.runtimeTemplatesRoot,
|
|
34749
35007
|
runnerKind: config.runnerKind,
|
|
35008
|
+
piExecutorUid: config.piExecutorUid,
|
|
35009
|
+
piExecutorGid: config.piExecutorGid,
|
|
35010
|
+
connectorUid: typeof process.getuid === "function" ? process.getuid() : null,
|
|
34750
35011
|
checkpointUploadEnabled: config.checkpointUploadEnabled,
|
|
34751
35012
|
executors: config.executors,
|
|
34752
|
-
browserCredentialAuth: inspectBrowserCredentialAuthReadiness()
|
|
35013
|
+
browserCredentialAuth: inspectBrowserCredentialAuthReadiness(),
|
|
35014
|
+
browserCredentialEnv: inspectBrowserCredentialEnvReadiness()
|
|
34753
35015
|
});
|
|
34754
35016
|
}
|
|
34755
35017
|
function buildRegisterPayload(config) {
|
|
@@ -34882,25 +35144,25 @@ function materializePiRuntimeSystemPrompt(config, promptRoot, commandId, content
|
|
|
34882
35144
|
const normalizedCommandId = readString(commandId);
|
|
34883
35145
|
if (!normalizedCommandId) throw new Error("pi_runtime_system_prompt_command_id_missing");
|
|
34884
35146
|
const promptIdentity = createHash19("sha256").update(normalizedCommandId).digest("hex");
|
|
34885
|
-
const promptDir =
|
|
35147
|
+
const promptDir = join23(promptRoot, "tmp");
|
|
34886
35148
|
mkdirSync12(promptDir, { recursive: true, mode: 448 });
|
|
34887
|
-
const promptDirStat =
|
|
35149
|
+
const promptDirStat = lstatSync13(promptDir);
|
|
34888
35150
|
if (!promptDirStat.isDirectory() || promptDirStat.isSymbolicLink()) {
|
|
34889
35151
|
throw new Error("pi_runtime_system_prompt_directory_invalid");
|
|
34890
35152
|
}
|
|
34891
|
-
|
|
34892
|
-
const promptPath =
|
|
34893
|
-
const temporaryPath =
|
|
35153
|
+
chmodSync7(promptDir, 448);
|
|
35154
|
+
const promptPath = join23(promptDir, `runtime-system-${promptIdentity}.md`);
|
|
35155
|
+
const temporaryPath = join23(promptDir, `.runtime-system.${process.pid}.${randomUUID2()}.tmp`);
|
|
34894
35156
|
try {
|
|
34895
|
-
|
|
34896
|
-
|
|
34897
|
-
|
|
35157
|
+
writeFileSync13(temporaryPath, contents, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
35158
|
+
renameSync10(temporaryPath, promptPath);
|
|
35159
|
+
chmodSync7(promptPath, 384);
|
|
34898
35160
|
const promptMode = statSync12(promptPath).mode & 511;
|
|
34899
35161
|
if (promptMode !== 384) {
|
|
34900
35162
|
throw new Error(`pi_runtime_system_prompt_permissions_failed: mode=${promptMode.toString(8)}`);
|
|
34901
35163
|
}
|
|
34902
35164
|
} finally {
|
|
34903
|
-
|
|
35165
|
+
rmSync11(temporaryPath, { force: true });
|
|
34904
35166
|
}
|
|
34905
35167
|
handoffPiRunPathsToChild(config, [promptDir, promptPath]);
|
|
34906
35168
|
return promptPath;
|
|
@@ -35066,7 +35328,7 @@ AMASTER_MACHINE_ID=${quoteShell(config.machineId)}
|
|
|
35066
35328
|
AMASTER_WORKSPACE_ALLOWLIST=${quoteShell(config.workspaceBindings.join(","))}
|
|
35067
35329
|
AMASTER_EXECUTORS=${quoteShell(executorEnv)}
|
|
35068
35330
|
AMASTER_NETWORK_DOMAINS=${quoteShell(config.networkDomains.join(","))}
|
|
35069
|
-
AMASTER_DAEMON_STATE_FILE=${quoteShell(
|
|
35331
|
+
AMASTER_DAEMON_STATE_FILE=${quoteShell(join23(homedir6(), ".amaster-employee", "runtime-connector-state.json"))}
|
|
35070
35332
|
EOF
|
|
35071
35333
|
|
|
35072
35334
|
set -a
|
|
@@ -35543,24 +35805,24 @@ function browserSessionProfileIdentity(config, session) {
|
|
|
35543
35805
|
}
|
|
35544
35806
|
function ensureBrowserSessionProfile(config, session) {
|
|
35545
35807
|
const identity = browserSessionProfileIdentity(config, session);
|
|
35546
|
-
const profileRoot =
|
|
35808
|
+
const profileRoot = resolve19(config.browserSessionStateRoot);
|
|
35547
35809
|
mkdirSync12(profileRoot, { recursive: true, mode: 448 });
|
|
35548
|
-
if (
|
|
35810
|
+
if (lstatSync13(profileRoot).isSymbolicLink() || !lstatSync13(profileRoot).isDirectory()) {
|
|
35549
35811
|
throw new Error("browser_session_profile_path_invalid");
|
|
35550
35812
|
}
|
|
35551
|
-
|
|
35552
|
-
const userDataDir =
|
|
35813
|
+
chmodSync7(profileRoot, 448);
|
|
35814
|
+
const userDataDir = resolve19(profileRoot, identity.localOpaqueRef);
|
|
35553
35815
|
if (!pathWithin3(userDataDir, profileRoot)) {
|
|
35554
35816
|
throw new Error("browser_session_profile_path_invalid");
|
|
35555
35817
|
}
|
|
35556
35818
|
mkdirSync12(userDataDir, { recursive: true, mode: 448 });
|
|
35557
|
-
if (
|
|
35819
|
+
if (lstatSync13(userDataDir).isSymbolicLink() || !lstatSync13(userDataDir).isDirectory()) {
|
|
35558
35820
|
throw new Error("browser_session_profile_path_invalid");
|
|
35559
35821
|
}
|
|
35560
|
-
|
|
35561
|
-
const markerPath =
|
|
35822
|
+
chmodSync7(userDataDir, 448);
|
|
35823
|
+
const markerPath = join23(userDataDir, BROWSER_SESSION_PROFILE_OWNER_MARKER);
|
|
35562
35824
|
if (existsSync18(markerPath)) {
|
|
35563
|
-
if (
|
|
35825
|
+
if (lstatSync13(markerPath).isSymbolicLink()) {
|
|
35564
35826
|
throw new Error("browser_session_profile_identity_invalid");
|
|
35565
35827
|
}
|
|
35566
35828
|
const existing = readJsonFile2(markerPath);
|
|
@@ -35568,41 +35830,41 @@ function ensureBrowserSessionProfile(config, session) {
|
|
|
35568
35830
|
throw new Error("browser_session_profile_identity_invalid");
|
|
35569
35831
|
}
|
|
35570
35832
|
} else {
|
|
35571
|
-
const temporaryPath =
|
|
35833
|
+
const temporaryPath = join23(
|
|
35572
35834
|
userDataDir,
|
|
35573
35835
|
`.${BROWSER_SESSION_PROFILE_OWNER_MARKER}.${process.pid}.${createHash19("sha256").update(randomUUID2()).digest("hex")}`
|
|
35574
35836
|
);
|
|
35575
|
-
|
|
35837
|
+
writeFileSync13(temporaryPath, `${JSON.stringify(identity)}
|
|
35576
35838
|
`, { mode: 384, flag: "wx" });
|
|
35577
|
-
|
|
35839
|
+
renameSync10(temporaryPath, markerPath);
|
|
35578
35840
|
}
|
|
35579
|
-
|
|
35841
|
+
chmodSync7(markerPath, 384);
|
|
35580
35842
|
return { profileRoot, userDataDir, identity };
|
|
35581
35843
|
}
|
|
35582
35844
|
function cleanupBrowserSessionProfile(config, value) {
|
|
35583
35845
|
const identity = browserSessionProfileIdentity(config, value);
|
|
35584
|
-
const profileRoot =
|
|
35585
|
-
const userDataDir =
|
|
35846
|
+
const profileRoot = resolve19(config.browserSessionStateRoot);
|
|
35847
|
+
const userDataDir = resolve19(profileRoot, identity.localOpaqueRef);
|
|
35586
35848
|
if (!pathWithin3(userDataDir, profileRoot)) {
|
|
35587
35849
|
throw new Error("browser_session_profile_cleanup_invalid");
|
|
35588
35850
|
}
|
|
35589
35851
|
if (!existsSync18(userDataDir)) return { outcome: "absent", identity };
|
|
35590
|
-
if (
|
|
35852
|
+
if (lstatSync13(userDataDir).isSymbolicLink() || !lstatSync13(userDataDir).isDirectory()) {
|
|
35591
35853
|
throw new Error("browser_session_profile_cleanup_invalid");
|
|
35592
35854
|
}
|
|
35593
|
-
const markerPath =
|
|
35594
|
-
if (!existsSync18(markerPath) ||
|
|
35855
|
+
const markerPath = join23(userDataDir, BROWSER_SESSION_PROFILE_OWNER_MARKER);
|
|
35856
|
+
if (!existsSync18(markerPath) || lstatSync13(markerPath).isSymbolicLink()) {
|
|
35595
35857
|
throw new Error("browser_session_profile_cleanup_invalid");
|
|
35596
35858
|
}
|
|
35597
35859
|
if (JSON.stringify(readJsonFile2(markerPath)) !== JSON.stringify(identity)) {
|
|
35598
35860
|
throw new Error("browser_session_profile_cleanup_invalid");
|
|
35599
35861
|
}
|
|
35600
|
-
|
|
35862
|
+
rmSync11(userDataDir, { recursive: true, force: false });
|
|
35601
35863
|
return { outcome: "deleted", identity };
|
|
35602
35864
|
}
|
|
35603
35865
|
function readJsonFile2(filePath) {
|
|
35604
35866
|
try {
|
|
35605
|
-
const parsed = JSON.parse(
|
|
35867
|
+
const parsed = JSON.parse(readFileSync19(filePath, "utf8"));
|
|
35606
35868
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
35607
35869
|
} catch {
|
|
35608
35870
|
return {};
|
|
@@ -35613,8 +35875,8 @@ function syncPiExecutorProviderConfig(config, agentDir, providerConfig) {
|
|
|
35613
35875
|
const { modelsSynced, settingsSynced } = syncAmasterProviderFiles(agentDir, providerConfig);
|
|
35614
35876
|
if (!modelsSynced && !settingsSynced) return null;
|
|
35615
35877
|
handoffPiRunPathsToChild(config, [
|
|
35616
|
-
modelsSynced ?
|
|
35617
|
-
settingsSynced ?
|
|
35878
|
+
modelsSynced ? join23(agentDir, "models.json") : null,
|
|
35879
|
+
settingsSynced ? join23(agentDir, "settings.json") : null
|
|
35618
35880
|
]);
|
|
35619
35881
|
return { modelsSynced, settingsSynced };
|
|
35620
35882
|
}
|
|
@@ -35645,7 +35907,7 @@ function safeAgentInstructionMaterializationTarget(workspace, filePath) {
|
|
|
35645
35907
|
const segments = normalized.split("/").filter(Boolean);
|
|
35646
35908
|
if (segments.length === 0 || segments.some((segment) => segment === "." || segment === "..")) return null;
|
|
35647
35909
|
const relativePath = segments.join("/");
|
|
35648
|
-
const targetPath =
|
|
35910
|
+
const targetPath = resolve19(workspace.cwd, relativePath);
|
|
35649
35911
|
if (!pathWithin3(targetPath, workspace.cwd)) return null;
|
|
35650
35912
|
return { relativePath, targetPath };
|
|
35651
35913
|
}
|
|
@@ -35734,14 +35996,14 @@ async function materializeEffectiveAgentInstructions(config, command, workspace,
|
|
|
35734
35996
|
mkdirSync12(dirname11(target.targetPath), { recursive: true });
|
|
35735
35997
|
const temporaryPath = `${target.targetPath}.mirrorx-${command.commandId}.tmp`;
|
|
35736
35998
|
try {
|
|
35737
|
-
|
|
35738
|
-
const readBack =
|
|
35999
|
+
writeFileSync13(temporaryPath, content, { encoding: "utf8", mode: 384 });
|
|
36000
|
+
const readBack = readFileSync19(temporaryPath, "utf8");
|
|
35739
36001
|
if (readBack !== content) {
|
|
35740
36002
|
throw new Error(`context_envelope_instruction_readback_mismatch: ${filePath}`);
|
|
35741
36003
|
}
|
|
35742
|
-
|
|
36004
|
+
renameSync10(temporaryPath, target.targetPath);
|
|
35743
36005
|
} finally {
|
|
35744
|
-
|
|
36006
|
+
rmSync11(temporaryPath, { force: true });
|
|
35745
36007
|
}
|
|
35746
36008
|
materialized.push({
|
|
35747
36009
|
path: target.relativePath,
|
|
@@ -35751,7 +36013,7 @@ async function materializeEffectiveAgentInstructions(config, command, workspace,
|
|
|
35751
36013
|
}
|
|
35752
36014
|
const readBackFiles = Object.fromEntries(materialized.map((entry) => [
|
|
35753
36015
|
entry.path,
|
|
35754
|
-
|
|
36016
|
+
readFileSync19(resolve19(workspace.cwd, entry.path), "utf8")
|
|
35755
36017
|
]));
|
|
35756
36018
|
if (stableInstructionFilesHash(readBackFiles) !== readString(instructionContract.contentHash)) {
|
|
35757
36019
|
throw new Error("context_envelope_materialized_hash_mismatch");
|
|
@@ -35775,7 +36037,7 @@ function wikiTreePathForCommand(command, workspaceBindings) {
|
|
|
35775
36037
|
const candidates = [];
|
|
35776
36038
|
if (root.endsWith("paperclipai.plugin-llm-wiki")) candidates.push(root);
|
|
35777
36039
|
if (basename8(root) === "plugin-data" && companyId) {
|
|
35778
|
-
candidates.push(
|
|
36040
|
+
candidates.push(join23(root, companyId, "paperclipai.plugin-llm-wiki"));
|
|
35779
36041
|
}
|
|
35780
36042
|
for (const candidate of candidates) {
|
|
35781
36043
|
try {
|
|
@@ -35786,6 +36048,62 @@ function wikiTreePathForCommand(command, workspaceBindings) {
|
|
|
35786
36048
|
}
|
|
35787
36049
|
return null;
|
|
35788
36050
|
}
|
|
36051
|
+
function commandMentionContext(command) {
|
|
36052
|
+
const mention = asRecord(requireCommandContextEnvelope(command).dynamicContext.paperclipMentionContext);
|
|
36053
|
+
return readString(mention.schemaVersion) === MENTION_CONTEXT_SCHEMA_VERSION ? mention : null;
|
|
36054
|
+
}
|
|
36055
|
+
function renderMentionContextText(mention) {
|
|
36056
|
+
if (!mention) return "";
|
|
36057
|
+
const agents = (Array.isArray(mention.agents) ? mention.agents : []).map(asRecord);
|
|
36058
|
+
const applications = (Array.isArray(mention.applications) ? mention.applications : []).map(asRecord);
|
|
36059
|
+
if (agents.length === 0 && applications.length === 0) return "";
|
|
36060
|
+
const blocks = [
|
|
36061
|
+
"The user's message @-mentioned the following entities. Treat them as explicit context the user wants you to consider."
|
|
36062
|
+
];
|
|
36063
|
+
if (agents.length > 0) {
|
|
36064
|
+
blocks.push([
|
|
36065
|
+
"Mentioned employees (reference only \u2014 a mention is not a handoff; to have one act, invoke it with the invoke_employee runtime action using its agentId):",
|
|
36066
|
+
...agents.map((agent) => {
|
|
36067
|
+
const role = readString(agent.role);
|
|
36068
|
+
const title = readString(agent.title);
|
|
36069
|
+
const details = [
|
|
36070
|
+
role ? `role: ${role}` : "",
|
|
36071
|
+
title ? `title: ${title}` : ""
|
|
36072
|
+
].filter(Boolean).join(", ");
|
|
36073
|
+
return `- ${readString(agent.name) ?? "unknown"}${details ? ` \u2014 ${details}` : ""} (agentId: ${readString(agent.agentId) ?? "unknown"})`;
|
|
36074
|
+
})
|
|
36075
|
+
].join("\n"));
|
|
36076
|
+
}
|
|
36077
|
+
if (applications.length > 0) {
|
|
36078
|
+
blocks.push([
|
|
36079
|
+
"Mentioned applications:",
|
|
36080
|
+
...applications.map((application) => {
|
|
36081
|
+
const provider = readString(application.provider);
|
|
36082
|
+
const environment = readString(application.environment);
|
|
36083
|
+
const headline = [
|
|
36084
|
+
provider ? `provider: ${provider}` : "",
|
|
36085
|
+
environment ? `environment: ${environment}` : ""
|
|
36086
|
+
].filter(Boolean).join(", ");
|
|
36087
|
+
const lines = [
|
|
36088
|
+
`- ${readString(application.title) ?? "unknown"}${headline ? ` (${headline})` : ""}`
|
|
36089
|
+
];
|
|
36090
|
+
const url = readString(application.url);
|
|
36091
|
+
if (url) lines.push(` url: ${url}`);
|
|
36092
|
+
const identity = ["applicationId", "appCode", "releaseId", "releaseVersion"].map((key) => {
|
|
36093
|
+
const value = readString(application[key]);
|
|
36094
|
+
return value ? `${key}: ${value}` : "";
|
|
36095
|
+
}).filter(Boolean).join(" | ");
|
|
36096
|
+
if (identity) lines.push(` ${identity}`);
|
|
36097
|
+
const skills = (Array.isArray(application.requiredSkills) ? application.requiredSkills : []).map((skill) => readString(skill)).filter(Boolean);
|
|
36098
|
+
if (skills.length > 0) {
|
|
36099
|
+
lines.push(` required skills: ${skills.map((skill) => MENTIONED_APPLICATION_SKILL_HINTS[skill] ? `${skill} (${MENTIONED_APPLICATION_SKILL_HINTS[skill]})` : skill).join(", ")}`);
|
|
36100
|
+
}
|
|
36101
|
+
return lines.join("\n");
|
|
36102
|
+
})
|
|
36103
|
+
].join("\n"));
|
|
36104
|
+
}
|
|
36105
|
+
return blocks.join("\n\n");
|
|
36106
|
+
}
|
|
35789
36107
|
function buildCommandPrompt(command, workspace, materializedAttachments = [], options = {}) {
|
|
35790
36108
|
const workspaceContext = normalizeWorkspaceContext(workspace);
|
|
35791
36109
|
const cwd = workspaceContext.cwd;
|
|
@@ -35833,6 +36151,7 @@ function buildCommandPrompt(command, workspace, materializedAttachments = [], op
|
|
|
35833
36151
|
return `- ${details}`;
|
|
35834
36152
|
})
|
|
35835
36153
|
].join("\n") : "";
|
|
36154
|
+
const mentionContextText = renderMentionContextText(commandMentionContext(command));
|
|
35836
36155
|
const compilation = compileCommandPromptWithManifest({
|
|
35837
36156
|
commandId: command.commandId,
|
|
35838
36157
|
runId: commandRunId(command),
|
|
@@ -35851,6 +36170,7 @@ function buildCommandPrompt(command, workspace, materializedAttachments = [], op
|
|
|
35851
36170
|
agentInstructions,
|
|
35852
36171
|
taskMarkdown,
|
|
35853
36172
|
attachmentsText,
|
|
36173
|
+
mentionContextText,
|
|
35854
36174
|
comments,
|
|
35855
36175
|
context,
|
|
35856
36176
|
nativeSession: asRecord(payload.nativeSession),
|
|
@@ -35859,7 +36179,8 @@ function buildCommandPrompt(command, workspace, materializedAttachments = [], op
|
|
|
35859
36179
|
treePath: wikiTreePathForCommand(command, options.workspaceBindings)
|
|
35860
36180
|
},
|
|
35861
36181
|
runtimeTemplateCatalog: options.runtimeTemplateCatalog,
|
|
35862
|
-
executorCapabilityNotice: options.executorCapabilityNotice
|
|
36182
|
+
executorCapabilityNotice: options.executorCapabilityNotice,
|
|
36183
|
+
browserCredentialEnv: options.browserCredentialEnv
|
|
35863
36184
|
}, { maxChars: options.maxChars, separateRuntimeRules: options.executorKind === "pi" });
|
|
35864
36185
|
const auditedCompilation = attachCurrentRunContractShadowAudit(
|
|
35865
36186
|
compilation,
|
|
@@ -35955,13 +36276,13 @@ function attachPiProjectInstructionExtension(profile, input) {
|
|
|
35955
36276
|
"managed Pi profile is missing"
|
|
35956
36277
|
);
|
|
35957
36278
|
}
|
|
35958
|
-
const projectInstructionExtensionPath =
|
|
36279
|
+
const projectInstructionExtensionPath = join23(
|
|
35959
36280
|
profile.profileRoot,
|
|
35960
36281
|
"extensions",
|
|
35961
36282
|
MANAGED_PI_PROJECT_INSTRUCTION_FILENAME
|
|
35962
36283
|
);
|
|
35963
|
-
const contract = { projectInstructionPath:
|
|
35964
|
-
|
|
36284
|
+
const contract = { projectInstructionPath: resolve19(input.cwd, "AGENTS.md") };
|
|
36285
|
+
writeFileSync13(projectInstructionExtensionPath, managedPiProjectInstructionExtensionSource(contract), { mode: 384 });
|
|
35965
36286
|
return projectInstructionExtensionPath;
|
|
35966
36287
|
}
|
|
35967
36288
|
function commandUsesPiExecutor(command) {
|
|
@@ -36004,18 +36325,18 @@ function buildExecutorEnv(config, command, workspace) {
|
|
|
36004
36325
|
};
|
|
36005
36326
|
}
|
|
36006
36327
|
function preparePiModelCallProfile(commandId, baseEnv, options = {}) {
|
|
36007
|
-
const profileRoot =
|
|
36008
|
-
const home =
|
|
36009
|
-
const sessionsDir =
|
|
36010
|
-
const tempDir =
|
|
36328
|
+
const profileRoot = mkdtempSync5(join23(tmpdir(), "amaster-pi-model-call-"));
|
|
36329
|
+
const home = join23(profileRoot, "home");
|
|
36330
|
+
const sessionsDir = join23(profileRoot, "sessions");
|
|
36331
|
+
const tempDir = join23(profileRoot, "tmp");
|
|
36011
36332
|
for (const directory of [home, sessionsDir, tempDir]) {
|
|
36012
36333
|
mkdirSync12(directory, { recursive: true, mode: 448 });
|
|
36013
36334
|
}
|
|
36014
36335
|
try {
|
|
36015
36336
|
const extensionArgs = [];
|
|
36016
36337
|
if (options.responseContract) {
|
|
36017
|
-
const extensionPath =
|
|
36018
|
-
|
|
36338
|
+
const extensionPath = join23(profileRoot, "model-call-output-contract.js");
|
|
36339
|
+
writeFileSync13(
|
|
36019
36340
|
extensionPath,
|
|
36020
36341
|
modelCallOutputContractExtensionSource(options.responseContract.maxOutputTokens),
|
|
36021
36342
|
{ mode: 384 }
|
|
@@ -36035,12 +36356,12 @@ function preparePiModelCallProfile(commandId, baseEnv, options = {}) {
|
|
|
36035
36356
|
}
|
|
36036
36357
|
};
|
|
36037
36358
|
} catch (error) {
|
|
36038
|
-
|
|
36359
|
+
rmSync11(profileRoot, { recursive: true, force: true });
|
|
36039
36360
|
throw error;
|
|
36040
36361
|
}
|
|
36041
36362
|
}
|
|
36042
36363
|
function cleanupPiModelCallProfile(profile) {
|
|
36043
|
-
if (profile?.profileRoot)
|
|
36364
|
+
if (profile?.profileRoot) rmSync11(profile.profileRoot, { recursive: true, force: true });
|
|
36044
36365
|
}
|
|
36045
36366
|
function splitExtraArgs(value) {
|
|
36046
36367
|
return splitList(value).flatMap((entry) => entry.split(/\s+/).filter(Boolean));
|
|
@@ -36080,7 +36401,7 @@ function resolveNativeSessionRequest(command, workspace) {
|
|
|
36080
36401
|
try {
|
|
36081
36402
|
cwdMatched = realpathSync12(requestedCwd) === realpathSync12(sourceWorkspacePath);
|
|
36082
36403
|
} catch {
|
|
36083
|
-
cwdMatched =
|
|
36404
|
+
cwdMatched = resolve19(requestedCwd) === resolve19(sourceWorkspacePath);
|
|
36084
36405
|
}
|
|
36085
36406
|
}
|
|
36086
36407
|
const used = Boolean(enabled && requested && sessionId && requestedCwd && cwdMatched);
|
|
@@ -36688,7 +37009,7 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
36688
37009
|
}
|
|
36689
37010
|
}
|
|
36690
37011
|
if (MIRRORX_FORMAL_TASK_EXECUTOR_KINDS.includes(executorKind) && event) {
|
|
36691
|
-
const results = executorKind === "codex" ? codexMcpToolResults(event) : executorKind === "codebuddy" ? codebuddyMcpToolResultTracker.record(event) : piMcpToolResults(event
|
|
37012
|
+
const results = executorKind === "codex" ? codexMcpToolResults(event) : executorKind === "codebuddy" ? codebuddyMcpToolResultTracker.record(event) : piMcpToolResults(event);
|
|
36692
37013
|
liveMcpToolResults.push(...results);
|
|
36693
37014
|
if (results.length > 0) onMcpToolResults?.(results);
|
|
36694
37015
|
}
|
|
@@ -36906,7 +37227,7 @@ function realOrResolvedPath(value) {
|
|
|
36906
37227
|
try {
|
|
36907
37228
|
return realpathSync12(value);
|
|
36908
37229
|
} catch {
|
|
36909
|
-
return
|
|
37230
|
+
return resolve19(value);
|
|
36910
37231
|
}
|
|
36911
37232
|
}
|
|
36912
37233
|
var LSOF_COMMAND = process.platform === "darwin" && existsSync18("/usr/sbin/lsof") ? "/usr/sbin/lsof" : "lsof";
|
|
@@ -37034,7 +37355,7 @@ function walkManagedWorkdirs(root) {
|
|
|
37034
37355
|
}
|
|
37035
37356
|
for (const entry of entries) {
|
|
37036
37357
|
if (!entry.isDirectory()) continue;
|
|
37037
|
-
const fullPath =
|
|
37358
|
+
const fullPath = join23(current, entry.name);
|
|
37038
37359
|
if (entry.name === "workdir" && existsSync18(workspaceManifestPath(fullPath))) {
|
|
37039
37360
|
workdirs.push(fullPath);
|
|
37040
37361
|
continue;
|
|
@@ -38036,11 +38357,11 @@ async function completeCommand(config, command, status, result2, error) {
|
|
|
38036
38357
|
}
|
|
38037
38358
|
function resultOutboxDir(config) {
|
|
38038
38359
|
const explicit = readString(process.env.AMASTER_RESULT_OUTBOX_DIR);
|
|
38039
|
-
if (explicit) return
|
|
38040
|
-
return
|
|
38360
|
+
if (explicit) return resolve19(expandHomePath(explicit));
|
|
38361
|
+
return join23(dirname11(stateFilePath(process.env)), "result-outbox");
|
|
38041
38362
|
}
|
|
38042
38363
|
function resultOutboxInvalidDir(config) {
|
|
38043
|
-
return
|
|
38364
|
+
return join23(resultOutboxDir(config), "invalid");
|
|
38044
38365
|
}
|
|
38045
38366
|
function writeResultOutboxEntry(config, entry) {
|
|
38046
38367
|
const dir = resultOutboxDir(config);
|
|
@@ -38054,16 +38375,16 @@ function writeResultOutboxEntry(config, entry) {
|
|
|
38054
38375
|
...entry,
|
|
38055
38376
|
...pendingLogEntries.length > 0 ? { pendingLogEntries } : {}
|
|
38056
38377
|
};
|
|
38057
|
-
|
|
38378
|
+
writeFileSync13(join23(dir, resultOutboxFileName(entry.commandId)), `${JSON.stringify(body, null, 2)}
|
|
38058
38379
|
`, { mode: 384 });
|
|
38059
38380
|
}
|
|
38060
38381
|
function moveResultOutboxEntryToInvalid(config, file, fullPath, reason, detail, original) {
|
|
38061
38382
|
const invalidDir = resultOutboxInvalidDir(config);
|
|
38062
38383
|
mkdirSync12(invalidDir, { recursive: true });
|
|
38063
|
-
const invalidPath =
|
|
38384
|
+
const invalidPath = join23(invalidDir, file);
|
|
38064
38385
|
if (original === void 0) {
|
|
38065
38386
|
try {
|
|
38066
|
-
|
|
38387
|
+
renameSync10(fullPath, invalidPath);
|
|
38067
38388
|
} catch {
|
|
38068
38389
|
copyFileSync2(fullPath, invalidPath);
|
|
38069
38390
|
unlinkSync3(fullPath);
|
|
@@ -38076,14 +38397,14 @@ function moveResultOutboxEntryToInvalid(config, file, fullPath, reason, detail,
|
|
|
38076
38397
|
...detail ? { detail: truncateText(detail, 1e3) } : {},
|
|
38077
38398
|
original
|
|
38078
38399
|
};
|
|
38079
|
-
|
|
38400
|
+
writeFileSync13(invalidPath, `${JSON.stringify(evidence, null, 2)}
|
|
38080
38401
|
`, { mode: 384 });
|
|
38081
38402
|
unlinkSync3(fullPath);
|
|
38082
38403
|
}
|
|
38083
38404
|
function readValidResultOutboxEntryOrQuarantine(config, file, fullPath) {
|
|
38084
38405
|
let entry;
|
|
38085
38406
|
try {
|
|
38086
|
-
entry = JSON.parse(
|
|
38407
|
+
entry = JSON.parse(readFileSync19(fullPath, "utf8"));
|
|
38087
38408
|
} catch (err) {
|
|
38088
38409
|
const message = err instanceof Error ? err.message : String(err);
|
|
38089
38410
|
moveResultOutboxEntryToInvalid(config, file, fullPath, "malformed_result_outbox_json", message);
|
|
@@ -38116,7 +38437,7 @@ function updateResultOutboxAttempt(fullPath, entry, err) {
|
|
|
38116
38437
|
...typeof err?.httpStatus === "number" ? { httpStatus: err.httpStatus } : {},
|
|
38117
38438
|
lastError: truncateText(err instanceof Error ? err.message : String(err), 1e3)
|
|
38118
38439
|
};
|
|
38119
|
-
|
|
38440
|
+
writeFileSync13(fullPath, `${JSON.stringify(next, null, 2)}
|
|
38120
38441
|
`, { mode: 384 });
|
|
38121
38442
|
return next;
|
|
38122
38443
|
}
|
|
@@ -38130,8 +38451,8 @@ function quarantineResultOutboxEntry(config, fullPath, file, entry, reason, err)
|
|
|
38130
38451
|
...typeof err?.httpStatus === "number" ? { httpStatus: err.httpStatus } : {},
|
|
38131
38452
|
lastError: truncateText(err instanceof Error ? err.message : String(err), 1e3)
|
|
38132
38453
|
};
|
|
38133
|
-
const invalidPath =
|
|
38134
|
-
|
|
38454
|
+
const invalidPath = join23(invalidDir, file);
|
|
38455
|
+
writeFileSync13(invalidPath, `${JSON.stringify(body, null, 2)}
|
|
38135
38456
|
`, { mode: 384 });
|
|
38136
38457
|
try {
|
|
38137
38458
|
unlinkSync3(fullPath);
|
|
@@ -38149,7 +38470,7 @@ async function flushResultOutbox(config) {
|
|
|
38149
38470
|
const files = readdirSync12(dir).filter((name) => name.endsWith(".json")).sort();
|
|
38150
38471
|
let completed = 0;
|
|
38151
38472
|
for (const file of files) {
|
|
38152
|
-
const fullPath =
|
|
38473
|
+
const fullPath = join23(dir, file);
|
|
38153
38474
|
let entry = readValidResultOutboxEntryOrQuarantine(config, file, fullPath);
|
|
38154
38475
|
if (!entry) continue;
|
|
38155
38476
|
const pendingLogEntries = Array.isArray(entry.pendingLogEntries) ? entry.pendingLogEntries.filter((logEntry) => typeof asRecord(logEntry).message === "string") : [];
|
|
@@ -38164,7 +38485,7 @@ async function flushResultOutbox(config) {
|
|
|
38164
38485
|
if (!isTerminalResultOutboxStatus(logHttpStatus)) {
|
|
38165
38486
|
const logAttemptCount = readNumber(entry.logAttemptCount, 0) + 1;
|
|
38166
38487
|
if (logAttemptCount < maxResultOutboxAttempts()) {
|
|
38167
|
-
|
|
38488
|
+
writeFileSync13(fullPath, `${JSON.stringify({ ...entry, logAttemptCount }, null, 2)}
|
|
38168
38489
|
`, { mode: 384 });
|
|
38169
38490
|
process.stderr.write(`AMaster daemon deferred live log delivery retry failed for ${entry.commandId ?? file}: ${logMessage}
|
|
38170
38491
|
`);
|
|
@@ -38177,7 +38498,7 @@ async function flushResultOutbox(config) {
|
|
|
38177
38498
|
entry = { ...entry };
|
|
38178
38499
|
delete entry.pendingLogEntries;
|
|
38179
38500
|
delete entry.logAttemptCount;
|
|
38180
|
-
|
|
38501
|
+
writeFileSync13(fullPath, `${JSON.stringify(entry, null, 2)}
|
|
38181
38502
|
`, { mode: 384 });
|
|
38182
38503
|
}
|
|
38183
38504
|
try {
|
|
@@ -38280,6 +38601,12 @@ function safeMaterializedAttachmentFilename(attachment, index) {
|
|
|
38280
38601
|
const name = basename8(original ?? `${id}.bin`).replace(/[\/\\:\0]/g, "_").trim();
|
|
38281
38602
|
return name && name !== "." && name !== ".." ? name : `${id}.bin`;
|
|
38282
38603
|
}
|
|
38604
|
+
function dedupeMaterializedFilename(filename, index, usedFilenames) {
|
|
38605
|
+
if (!usedFilenames.has(filename)) return filename;
|
|
38606
|
+
const ext = extname3(filename);
|
|
38607
|
+
const stem = ext ? filename.slice(0, -ext.length) : filename;
|
|
38608
|
+
return `${stem}-${index + 1}${ext}`;
|
|
38609
|
+
}
|
|
38283
38610
|
function compareAttachmentLineageCandidates(left, right) {
|
|
38284
38611
|
const versionDiff = Number(right.artifactVersionState === "current") - Number(left.artifactVersionState === "current");
|
|
38285
38612
|
if (versionDiff !== 0) return versionDiff;
|
|
@@ -38382,7 +38709,7 @@ async function materializeIssueAttachments(config, command, workspace) {
|
|
|
38382
38709
|
runtimeAuth,
|
|
38383
38710
|
issueId
|
|
38384
38711
|
);
|
|
38385
|
-
const targetDir =
|
|
38712
|
+
const targetDir = join23(workspace.cwd, "input-attachments");
|
|
38386
38713
|
mkdirSync12(targetDir, { recursive: true });
|
|
38387
38714
|
const usedFilenames = /* @__PURE__ */ new Set();
|
|
38388
38715
|
const materialized = [];
|
|
@@ -38394,18 +38721,14 @@ async function materializeIssueAttachments(config, command, workspace) {
|
|
|
38394
38721
|
continue;
|
|
38395
38722
|
}
|
|
38396
38723
|
let filename = safeMaterializedAttachmentFilename(attachment, index);
|
|
38397
|
-
|
|
38398
|
-
const ext = extname3(filename);
|
|
38399
|
-
const stem = ext ? filename.slice(0, -ext.length) : filename;
|
|
38400
|
-
filename = `${stem}-${index + 1}${ext}`;
|
|
38401
|
-
}
|
|
38724
|
+
filename = dedupeMaterializedFilename(filename, index, usedFilenames);
|
|
38402
38725
|
usedFilenames.add(filename);
|
|
38403
|
-
const targetPath =
|
|
38726
|
+
const targetPath = join23(targetDir, filename);
|
|
38404
38727
|
const body = await runtimeApiBuffer(runtimeAuth, contentPath);
|
|
38405
38728
|
if (attachment.initializationInput === true && (body.byteLength !== attachment.byteSize || createHash19("sha256").update(body).digest("hex") !== attachment.sha256)) {
|
|
38406
38729
|
throw new Error("Initialization input content does not match its preparation receipt");
|
|
38407
38730
|
}
|
|
38408
|
-
|
|
38731
|
+
writeFileSync13(targetPath, body);
|
|
38409
38732
|
const attachmentId = readString(attachment.id);
|
|
38410
38733
|
const actualSha256 = createHash19("sha256").update(body).digest("hex");
|
|
38411
38734
|
const lineageCandidates = lineageCandidatesByAttachmentId.get(attachmentId) ?? [];
|
|
@@ -38472,8 +38795,8 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
38472
38795
|
if (manifest.version !== 1 || !Array.isArray(manifest.entries)) {
|
|
38473
38796
|
throw new Error("artifact_input_manifest_invalid: expected version 1 entries array");
|
|
38474
38797
|
}
|
|
38475
|
-
const targetRoot =
|
|
38476
|
-
|
|
38798
|
+
const targetRoot = join23(workspace.cwd, "input-artifacts");
|
|
38799
|
+
rmSync11(targetRoot, { recursive: true, force: true });
|
|
38477
38800
|
mkdirSync12(targetRoot, { recursive: true });
|
|
38478
38801
|
const usedPaths = /* @__PURE__ */ new Set();
|
|
38479
38802
|
const materialized = [];
|
|
@@ -38503,18 +38826,18 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
38503
38826
|
id: attachmentId,
|
|
38504
38827
|
originalFilename: readString(entry.originalFilename)
|
|
38505
38828
|
}, index);
|
|
38506
|
-
let relativePath =
|
|
38829
|
+
let relativePath = join23("input-artifacts", sourceDir, filename).split(/[\\/]+/).join("/");
|
|
38507
38830
|
if (usedPaths.has(relativePath)) {
|
|
38508
38831
|
const ext = extname3(filename);
|
|
38509
38832
|
const stem = ext ? filename.slice(0, -ext.length) : filename;
|
|
38510
38833
|
filename = `${stem}-${index + 1}${ext}`;
|
|
38511
|
-
relativePath =
|
|
38834
|
+
relativePath = join23("input-artifacts", sourceDir, filename).split(/[\\/]+/).join("/");
|
|
38512
38835
|
}
|
|
38513
38836
|
usedPaths.add(relativePath);
|
|
38514
|
-
const targetPath =
|
|
38837
|
+
const targetPath = join23(workspace.cwd, relativePath);
|
|
38515
38838
|
mkdirSync12(dirname11(targetPath), { recursive: true });
|
|
38516
|
-
|
|
38517
|
-
|
|
38839
|
+
writeFileSync13(targetPath, body);
|
|
38840
|
+
chmodSync7(targetPath, 292);
|
|
38518
38841
|
materialized.push({
|
|
38519
38842
|
id: attachmentId,
|
|
38520
38843
|
workProductId,
|
|
@@ -38533,14 +38856,84 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
38533
38856
|
version: 1,
|
|
38534
38857
|
entries: materialized.map(({ path: _path, relativePath, ...entry }) => ({ ...entry, path: relativePath }))
|
|
38535
38858
|
};
|
|
38536
|
-
const manifestPath =
|
|
38537
|
-
|
|
38538
|
-
|
|
38859
|
+
const manifestPath = join23(targetRoot, "artifact-input-manifest.json");
|
|
38860
|
+
writeFileSync13(manifestPath, JSON.stringify(localManifest, null, 2) + "\n");
|
|
38861
|
+
chmodSync7(manifestPath, 292);
|
|
38539
38862
|
updateWorkspaceManifest(workspaceManifestPath(workspace), { artifactInputManifest: localManifest });
|
|
38540
38863
|
return materialized;
|
|
38541
38864
|
}
|
|
38865
|
+
async function materializeMentionedArtifactFiles(config, command, workspace) {
|
|
38866
|
+
const empty = { materialized: [], skipped: [] };
|
|
38867
|
+
const mention = commandMentionContext(command);
|
|
38868
|
+
if (!mention) return empty;
|
|
38869
|
+
const runtimeAuth = commandRuntimeAuth(command);
|
|
38870
|
+
const files = Array.isArray(mention.files) ? mention.files : [];
|
|
38871
|
+
if (files.length === 0 || !readString(runtimeAuth.apiUrl) || !readString(runtimeAuth.apiKey)) return empty;
|
|
38872
|
+
const targetDir = join23(workspace.cwd, "input-artifacts", "mentioned");
|
|
38873
|
+
rmSync11(targetDir, { recursive: true, force: true });
|
|
38874
|
+
mkdirSync12(targetDir, { recursive: true });
|
|
38875
|
+
const usedFilenames = /* @__PURE__ */ new Set();
|
|
38876
|
+
const materialized = [];
|
|
38877
|
+
const skipped = [];
|
|
38878
|
+
for (const [index, rawEntry] of files.entries()) {
|
|
38879
|
+
const entry = asRecord(rawEntry);
|
|
38880
|
+
const artifactId = readString(entry.artifactId) ?? `mentioned-${index + 1}`;
|
|
38881
|
+
const contentPath = readString(entry.contentPath);
|
|
38882
|
+
if (!contentPath) {
|
|
38883
|
+
skipped.push({ artifactId, reason: "content_path_missing" });
|
|
38884
|
+
continue;
|
|
38885
|
+
}
|
|
38886
|
+
let body;
|
|
38887
|
+
try {
|
|
38888
|
+
body = await runtimeApiBuffer(runtimeAuth, contentPath);
|
|
38889
|
+
} catch (err) {
|
|
38890
|
+
skipped.push({
|
|
38891
|
+
artifactId,
|
|
38892
|
+
reason: "download_failed",
|
|
38893
|
+
error: truncateText(err instanceof Error ? err.message : String(err), 1e3)
|
|
38894
|
+
});
|
|
38895
|
+
continue;
|
|
38896
|
+
}
|
|
38897
|
+
const actualSha256 = createHash19("sha256").update(body).digest("hex");
|
|
38898
|
+
const expectedSha256 = readString(entry.sha256)?.toLowerCase() ?? null;
|
|
38899
|
+
const expectedByteSize = readNumber(entry.byteSize, null);
|
|
38900
|
+
if (expectedByteSize !== null && body.byteLength !== expectedByteSize || expectedSha256 && actualSha256 !== expectedSha256) {
|
|
38901
|
+
skipped.push({
|
|
38902
|
+
artifactId,
|
|
38903
|
+
reason: "integrity_mismatch",
|
|
38904
|
+
expectedByteSize,
|
|
38905
|
+
actualByteSize: body.byteLength,
|
|
38906
|
+
...expectedSha256 ? { expectedSha256 } : {},
|
|
38907
|
+
actualSha256
|
|
38908
|
+
});
|
|
38909
|
+
continue;
|
|
38910
|
+
}
|
|
38911
|
+
let filename = safeMaterializedAttachmentFilename({
|
|
38912
|
+
id: artifactId,
|
|
38913
|
+
originalFilename: readString(entry.originalFilename),
|
|
38914
|
+
title: readString(entry.title)
|
|
38915
|
+
}, index);
|
|
38916
|
+
filename = dedupeMaterializedFilename(filename, index, usedFilenames);
|
|
38917
|
+
usedFilenames.add(filename);
|
|
38918
|
+
const targetPath = join23(targetDir, filename);
|
|
38919
|
+
writeFileSync13(targetPath, body);
|
|
38920
|
+
chmodSync7(targetPath, 292);
|
|
38921
|
+
materialized.push({
|
|
38922
|
+
id: artifactId,
|
|
38923
|
+
name: readString(entry.title) ?? readString(entry.originalFilename) ?? filename,
|
|
38924
|
+
path: targetPath,
|
|
38925
|
+
relativePath: relative9(workspace.cwd, targetPath),
|
|
38926
|
+
contentType: readString(entry.contentType),
|
|
38927
|
+
byteSize: body.byteLength,
|
|
38928
|
+
sha256: actualSha256,
|
|
38929
|
+
contentPath,
|
|
38930
|
+
...readString(entry.workProductId) ? { workProductId: readString(entry.workProductId) } : {}
|
|
38931
|
+
});
|
|
38932
|
+
}
|
|
38933
|
+
return { materialized, skipped };
|
|
38934
|
+
}
|
|
38542
38935
|
function issueCheckpointDir(workspace) {
|
|
38543
|
-
return
|
|
38936
|
+
return join23(dirname11(workspace.runDir), "checkpoint");
|
|
38544
38937
|
}
|
|
38545
38938
|
async function clearIssueCheckpoint(config, command, workspace, reason, consumedSource = null) {
|
|
38546
38939
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
@@ -38550,13 +38943,13 @@ async function clearIssueCheckpoint(config, command, workspace, reason, consumed
|
|
|
38550
38943
|
if (!sourceRunId) return false;
|
|
38551
38944
|
let manifest;
|
|
38552
38945
|
try {
|
|
38553
|
-
manifest = asRecord(JSON.parse(
|
|
38946
|
+
manifest = asRecord(JSON.parse(readFileSync19(join23(checkpointDir, "manifest.json"), "utf8")));
|
|
38554
38947
|
} catch {
|
|
38555
38948
|
return false;
|
|
38556
38949
|
}
|
|
38557
38950
|
if (readString(manifest.issueId) !== commandIssueId(command) || readString(manifest.sourceRunId) !== sourceRunId) return false;
|
|
38558
38951
|
}
|
|
38559
|
-
|
|
38952
|
+
rmSync11(checkpointDir, { recursive: true, force: true });
|
|
38560
38953
|
await ingestLog(config, command, "system", "info", "Cleared issue continuation checkpoint", { reason });
|
|
38561
38954
|
return true;
|
|
38562
38955
|
}
|
|
@@ -38569,7 +38962,7 @@ function safeCheckpointRelativePath(rawPath) {
|
|
|
38569
38962
|
return normalized;
|
|
38570
38963
|
}
|
|
38571
38964
|
function hashFileSha256(filePath) {
|
|
38572
|
-
return createHash19("sha256").update(
|
|
38965
|
+
return createHash19("sha256").update(readFileSync19(filePath)).digest("hex");
|
|
38573
38966
|
}
|
|
38574
38967
|
function expectedContinuationCheckpoint(command) {
|
|
38575
38968
|
const payload = asRecord(command.payload);
|
|
@@ -38595,7 +38988,7 @@ function expectedContinuationCheckpoint(command) {
|
|
|
38595
38988
|
}
|
|
38596
38989
|
async function materializeIssueCheckpoint(config, command, workspace) {
|
|
38597
38990
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
38598
|
-
const manifestPath =
|
|
38991
|
+
const manifestPath = join23(checkpointDir, "manifest.json");
|
|
38599
38992
|
const expectedContinuation = expectedContinuationCheckpoint(command);
|
|
38600
38993
|
const nativeRequest = asRecord(asRecord(command.payload).nativeSession);
|
|
38601
38994
|
let portableNativeSession;
|
|
@@ -38625,14 +39018,14 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38625
39018
|
}
|
|
38626
39019
|
let manifest;
|
|
38627
39020
|
try {
|
|
38628
|
-
manifest = asRecord(JSON.parse(
|
|
39021
|
+
manifest = asRecord(JSON.parse(readFileSync19(manifestPath, "utf8")));
|
|
38629
39022
|
} catch (err) {
|
|
38630
|
-
|
|
39023
|
+
rmSync11(checkpointDir, { recursive: true, force: true });
|
|
38631
39024
|
throw new Error(`invalid issue checkpoint manifest: ${err instanceof Error ? err.message : String(err)}`);
|
|
38632
39025
|
}
|
|
38633
39026
|
const expiresAt = Date.parse(readString(manifest.expiresAt) ?? "");
|
|
38634
39027
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() || readString(manifest.issueId) !== commandIssueId(command)) {
|
|
38635
|
-
|
|
39028
|
+
rmSync11(checkpointDir, { recursive: true, force: true });
|
|
38636
39029
|
if (expectedContinuation) throw new Error("continuation_checkpoint_unavailable: manifest_expired_or_mismatched");
|
|
38637
39030
|
return unavailable2;
|
|
38638
39031
|
}
|
|
@@ -38656,7 +39049,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38656
39049
|
throw new Error("continuation_checkpoint_lineage_mismatch");
|
|
38657
39050
|
}
|
|
38658
39051
|
}
|
|
38659
|
-
const filesRoot = realpathSync12(
|
|
39052
|
+
const filesRoot = files.length > 0 ? realpathSync12(join23(checkpointDir, "files")) : null;
|
|
38660
39053
|
const workspaceRoot = realpathSync12(workspace.cwd);
|
|
38661
39054
|
const validated = [];
|
|
38662
39055
|
let totalBytes = 0;
|
|
@@ -38664,8 +39057,8 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38664
39057
|
const file = asRecord(rawFile);
|
|
38665
39058
|
const relativePath = safeCheckpointRelativePath(readString(file.path));
|
|
38666
39059
|
if (!relativePath) throw new Error("issue checkpoint manifest contains an invalid file path");
|
|
38667
|
-
const sourceCandidate =
|
|
38668
|
-
const target =
|
|
39060
|
+
const sourceCandidate = resolve19(filesRoot, relativePath);
|
|
39061
|
+
const target = resolve19(workspaceRoot, relativePath);
|
|
38669
39062
|
if (!pathWithin3(sourceCandidate, filesRoot) || !pathWithin3(target, workspaceRoot)) {
|
|
38670
39063
|
throw new Error(`issue checkpoint path escapes its workspace: ${relativePath}`);
|
|
38671
39064
|
}
|
|
@@ -38701,7 +39094,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38701
39094
|
}
|
|
38702
39095
|
let existingTarget = null;
|
|
38703
39096
|
try {
|
|
38704
|
-
existingTarget =
|
|
39097
|
+
existingTarget = lstatSync13(target);
|
|
38705
39098
|
} catch (err) {
|
|
38706
39099
|
if (err?.code !== "ENOENT") throw err;
|
|
38707
39100
|
}
|
|
@@ -38712,16 +39105,16 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38712
39105
|
materialized.push(relativePath);
|
|
38713
39106
|
continue;
|
|
38714
39107
|
}
|
|
38715
|
-
const temporaryTarget =
|
|
39108
|
+
const temporaryTarget = join23(targetParent, `.${basename8(target)}.checkpoint-${randomUUID2()}.tmp`);
|
|
38716
39109
|
try {
|
|
38717
39110
|
copyFileSync2(source, temporaryTarget);
|
|
38718
|
-
const temporaryStat =
|
|
39111
|
+
const temporaryStat = lstatSync13(temporaryTarget);
|
|
38719
39112
|
if (!temporaryStat.isFile() || temporaryStat.size !== expectedByteSize || hashFileSha256(temporaryTarget) !== expectedSha256) {
|
|
38720
39113
|
throw new Error(`issue checkpoint target verification failed: ${relativePath}`);
|
|
38721
39114
|
}
|
|
38722
|
-
|
|
39115
|
+
renameSync10(temporaryTarget, target);
|
|
38723
39116
|
} finally {
|
|
38724
|
-
|
|
39117
|
+
rmSync11(temporaryTarget, { force: true });
|
|
38725
39118
|
}
|
|
38726
39119
|
materialized.push(relativePath);
|
|
38727
39120
|
}
|
|
@@ -38748,9 +39141,9 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38748
39141
|
const commandKey = readString(command.commandId)?.replace(/[^A-Za-z0-9_-]/g, "-") ?? randomUUID2();
|
|
38749
39142
|
const stagingDir = `${checkpointDir}.tmp-${commandKey}`;
|
|
38750
39143
|
const backupDir = `${checkpointDir}.previous-${commandKey}`;
|
|
38751
|
-
const filesDir =
|
|
38752
|
-
|
|
38753
|
-
|
|
39144
|
+
const filesDir = join23(stagingDir, "files");
|
|
39145
|
+
rmSync11(stagingDir, { recursive: true, force: true });
|
|
39146
|
+
rmSync11(backupDir, { recursive: true, force: true });
|
|
38754
39147
|
mkdirSync12(filesDir, { recursive: true });
|
|
38755
39148
|
try {
|
|
38756
39149
|
const files = [];
|
|
@@ -38762,13 +39155,13 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38762
39155
|
if (!normalized) {
|
|
38763
39156
|
throw new Error(`continuation_checkpoint_file_unavailable: ${requiredPath}`);
|
|
38764
39157
|
}
|
|
38765
|
-
const sourceCandidate =
|
|
39158
|
+
const sourceCandidate = resolve19(workspaceRoot, normalized);
|
|
38766
39159
|
if (!pathWithin3(sourceCandidate, workspaceRoot)) {
|
|
38767
39160
|
throw new Error(`continuation_checkpoint_file_unavailable: ${requiredPath}`);
|
|
38768
39161
|
}
|
|
38769
39162
|
let sourceStat;
|
|
38770
39163
|
try {
|
|
38771
|
-
sourceStat =
|
|
39164
|
+
sourceStat = lstatSync13(sourceCandidate);
|
|
38772
39165
|
} catch (err) {
|
|
38773
39166
|
if (err?.code === "ENOENT") {
|
|
38774
39167
|
throw new Error(`continuation_checkpoint_file_unavailable: ${requiredPath}`);
|
|
@@ -38800,11 +39193,11 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38800
39193
|
if (requiredPaths.length > 0 || options.taskSession) throw new Error(`continuation_checkpoint_file_size_invalid: ${relativePath}`);
|
|
38801
39194
|
continue;
|
|
38802
39195
|
}
|
|
38803
|
-
const target =
|
|
39196
|
+
const target = resolve19(filesDir, relativePath);
|
|
38804
39197
|
if (!pathWithin3(target, filesDir)) continue;
|
|
38805
39198
|
mkdirSync12(dirname11(target), { recursive: true });
|
|
38806
39199
|
copyFileSync2(ownedSource, target);
|
|
38807
|
-
const storedStat =
|
|
39200
|
+
const storedStat = lstatSync13(target);
|
|
38808
39201
|
if (!storedStat.isFile() || storedStat.size !== byteSize) {
|
|
38809
39202
|
throw new Error(`issue checkpoint copy verification failed: ${relativePath}`);
|
|
38810
39203
|
}
|
|
@@ -38812,8 +39205,8 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38812
39205
|
files.push({ path: relativePath, byteSize, sha256: hashFileSha256(target) });
|
|
38813
39206
|
}
|
|
38814
39207
|
if (files.length === 0 && !options.taskSession) {
|
|
38815
|
-
|
|
38816
|
-
|
|
39208
|
+
rmSync11(stagingDir, { recursive: true, force: true });
|
|
39209
|
+
rmSync11(checkpointDir, { recursive: true, force: true });
|
|
38817
39210
|
return null;
|
|
38818
39211
|
}
|
|
38819
39212
|
const checkpointCreatedAt = Date.now();
|
|
@@ -38838,26 +39231,26 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38838
39231
|
totalBytes,
|
|
38839
39232
|
files
|
|
38840
39233
|
};
|
|
38841
|
-
|
|
39234
|
+
writeFileSync13(join23(stagingDir, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
38842
39235
|
`);
|
|
38843
39236
|
const replacingExistingCheckpoint = existsSync18(checkpointDir);
|
|
38844
|
-
if (replacingExistingCheckpoint)
|
|
39237
|
+
if (replacingExistingCheckpoint) renameSync10(checkpointDir, backupDir);
|
|
38845
39238
|
try {
|
|
38846
|
-
|
|
39239
|
+
renameSync10(stagingDir, checkpointDir);
|
|
38847
39240
|
} catch (err) {
|
|
38848
39241
|
if (replacingExistingCheckpoint && existsSync18(backupDir) && !existsSync18(checkpointDir)) {
|
|
38849
|
-
|
|
39242
|
+
renameSync10(backupDir, checkpointDir);
|
|
38850
39243
|
}
|
|
38851
39244
|
throw err;
|
|
38852
39245
|
}
|
|
38853
|
-
|
|
39246
|
+
rmSync11(backupDir, { recursive: true, force: true });
|
|
38854
39247
|
if (config.checkpointUploadEnabled) {
|
|
38855
39248
|
await uploadCheckpoint(config, command, checkpointDir, manifest, void 0, options.nativeSession);
|
|
38856
39249
|
}
|
|
38857
39250
|
await ingestLog(config, command, "system", "info", `Saved ${files.length} issue checkpoint file(s) for continuation`, manifest);
|
|
38858
39251
|
return manifest;
|
|
38859
39252
|
} catch (err) {
|
|
38860
|
-
|
|
39253
|
+
rmSync11(stagingDir, { recursive: true, force: true });
|
|
38861
39254
|
throw err;
|
|
38862
39255
|
}
|
|
38863
39256
|
}
|
|
@@ -38998,8 +39391,36 @@ async function executeRunCommand(config, command) {
|
|
|
38998
39391
|
});
|
|
38999
39392
|
}
|
|
39000
39393
|
assertRequiredTaskAttachmentMaterialized(commandTaskResourceInput(command), materializedAttachments);
|
|
39394
|
+
try {
|
|
39395
|
+
const mentionResult = await materializeMentionedArtifactFiles(config, command, workspace);
|
|
39396
|
+
if (mentionResult.materialized.length > 0 || mentionResult.skipped.length > 0) {
|
|
39397
|
+
enqueuePreparationLog("system", "info", `Materialized ${mentionResult.materialized.length} mentioned file(s) into the execution workspace (${mentionResult.skipped.length} skipped)`, {
|
|
39398
|
+
mentionedFileCount: mentionResult.materialized.length,
|
|
39399
|
+
mentionedSkippedCount: mentionResult.skipped.length,
|
|
39400
|
+
mentionedFiles: mentionResult.materialized.map((entry) => ({
|
|
39401
|
+
id: entry.id,
|
|
39402
|
+
name: entry.name,
|
|
39403
|
+
path: entry.relativePath
|
|
39404
|
+
})),
|
|
39405
|
+
...mentionResult.skipped.length > 0 ? { mentionedSkipped: mentionResult.skipped } : {}
|
|
39406
|
+
});
|
|
39407
|
+
}
|
|
39408
|
+
materializedAttachments = [...materializedAttachments, ...mentionResult.materialized];
|
|
39409
|
+
} catch (err) {
|
|
39410
|
+
enqueuePreparationLog("system", "warn", `Failed to materialize mentioned files: ${err instanceof Error ? err.message : String(err)}`, {
|
|
39411
|
+
error: err instanceof Error ? err.message : String(err)
|
|
39412
|
+
});
|
|
39413
|
+
}
|
|
39001
39414
|
await ingestWorkspaceStatus(config, command, cwd);
|
|
39002
39415
|
const browserSession = commandBrowserSession(command);
|
|
39416
|
+
const browserCredentialPresentationKind = browserCredentialPresentation(command);
|
|
39417
|
+
const browserCredentialPlan = browserCredentialEnvPlan(command, browserCredentialPresentationKind);
|
|
39418
|
+
if (browserCredentialPlan && executor.kind !== "pi") {
|
|
39419
|
+
throw new Error("browser_credential_env_pi_executor_required");
|
|
39420
|
+
}
|
|
39421
|
+
if (browserCredentialPlan && (config.runnerKind !== RUNNER_KIND_CLOUD_MANAGED || config.piExecutorUid <= 0 || config.piExecutorGid <= 0 || typeof process.getuid !== "function" || config.piExecutorUid === process.getuid())) {
|
|
39422
|
+
throw new Error("browser_credential_env_managed_isolation_required");
|
|
39423
|
+
}
|
|
39003
39424
|
const nativeSessionRequest = asRecord(asRecord(command.payload).nativeSession);
|
|
39004
39425
|
let invocation = null;
|
|
39005
39426
|
let executorEnv = buildExecutorEnv(config, command, workspace);
|
|
@@ -39007,6 +39428,7 @@ async function executeRunCommand(config, command) {
|
|
|
39007
39428
|
let managedMcpCleanup = null;
|
|
39008
39429
|
let cleanupManagedMcpProfile = null;
|
|
39009
39430
|
let piRuntimeSystemPromptCleanupPath = null;
|
|
39431
|
+
let browserCredentialEnvMaterialization = null;
|
|
39010
39432
|
let piExecutorIdentity = null;
|
|
39011
39433
|
const providerProtectedValues = [];
|
|
39012
39434
|
let piResolvedProviderConfig = null;
|
|
@@ -39121,7 +39543,7 @@ async function executeRunCommand(config, command) {
|
|
|
39121
39543
|
executorCommand: invocation.command,
|
|
39122
39544
|
executorHome: workspace.executorHome,
|
|
39123
39545
|
runDir: workspace.runDir,
|
|
39124
|
-
runtimeCacheRoot:
|
|
39546
|
+
runtimeCacheRoot: join23(dirname11(config.daemonStateFile), "cache"),
|
|
39125
39547
|
cwd,
|
|
39126
39548
|
runtimeAuth: commandRuntimeAuth(command),
|
|
39127
39549
|
nativeSession: asRecord(asRecord(executionCommand.payload).nativeSession),
|
|
@@ -39208,7 +39630,7 @@ async function executeRunCommand(config, command) {
|
|
|
39208
39630
|
const sharedPiHome = readString(process.env.PI_CODING_AGENT_DIR) ?? readString(process.env.PI_AGENT_HOME) ?? null;
|
|
39209
39631
|
let agentDir = managedMcpProfile ? readString(managedMcpProfile.env.PI_CODING_AGENT_DIR) ?? readString(managedMcpProfile.env.PI_AGENT_HOME) ?? null : desktopDelegatedRunnerEnabled(config) ? readString(executorEnv.PI_AGENT_HOME) ?? readString(executorEnv.PI_CODING_AGENT_DIR) ?? null : readString(executorEnv.PI_CODING_AGENT_DIR) ?? readString(executorEnv.PI_AGENT_HOME) ?? null;
|
|
39210
39632
|
piAgentDirForContextBudget = agentDir;
|
|
39211
|
-
if (agentDir && sharedPiHome &&
|
|
39633
|
+
if (agentDir && sharedPiHome && resolve19(agentDir) === resolve19(sharedPiHome)) {
|
|
39212
39634
|
agentDir = null;
|
|
39213
39635
|
}
|
|
39214
39636
|
try {
|
|
@@ -39315,6 +39737,7 @@ async function executeRunCommand(config, command) {
|
|
|
39315
39737
|
runtimeTemplateCatalog: config.templateCatalog,
|
|
39316
39738
|
runtimeInstructionInjectionEnabled: strictContextGovernance,
|
|
39317
39739
|
executorCapabilityNotice: executor.kind === "codebuddy" ? codebuddyExecutionCapabilityNotice(managedMcpProfile) : "",
|
|
39740
|
+
browserCredentialEnv: browserCredentialPlan?.promptText ?? "",
|
|
39318
39741
|
maxChars: modelContextBudget.dynamicPromptMaxChars
|
|
39319
39742
|
}));
|
|
39320
39743
|
const requiredGoalAuthority = goalAuthorityBlock(requireCommandContextEnvelope(command).dynamicContext);
|
|
@@ -39373,6 +39796,40 @@ async function executeRunCommand(config, command) {
|
|
|
39373
39796
|
preparationStages
|
|
39374
39797
|
});
|
|
39375
39798
|
await preparationLogChain;
|
|
39799
|
+
const abortController = new AbortController();
|
|
39800
|
+
if (browserCredentialPlan) {
|
|
39801
|
+
browserCredentialEnvMaterialization = await runExecutionStage(
|
|
39802
|
+
"browser_credential_env",
|
|
39803
|
+
() => materializeBrowserCredentialEnv(browserCredentialPlan, {
|
|
39804
|
+
runDir: workspace.runDir,
|
|
39805
|
+
consume: (credentialRef, controlSemantic) => consumeRuntimeBrowserCredentialRef(
|
|
39806
|
+
config,
|
|
39807
|
+
requireConnectorId(config),
|
|
39808
|
+
command.commandId,
|
|
39809
|
+
{ ...credentialRef, controlSemantic },
|
|
39810
|
+
{ signal: abortController.signal }
|
|
39811
|
+
)
|
|
39812
|
+
})
|
|
39813
|
+
);
|
|
39814
|
+
executorEnv = {
|
|
39815
|
+
...executorEnv,
|
|
39816
|
+
[BROWSER_CREDENTIAL_ENV_FILE]: browserCredentialEnvMaterialization.filePath
|
|
39817
|
+
};
|
|
39818
|
+
for (const protectedValue of browserCredentialEnvMaterialization.protectedValues) {
|
|
39819
|
+
if (!providerProtectedValues.includes(protectedValue)) providerProtectedValues.push(protectedValue);
|
|
39820
|
+
}
|
|
39821
|
+
if (piExecutorIdentity) handoffPiRunPathsToChild(config, [
|
|
39822
|
+
browserCredentialEnvMaterialization.dirPath,
|
|
39823
|
+
browserCredentialEnvMaterialization.filePath
|
|
39824
|
+
]);
|
|
39825
|
+
enqueuePreparationLog("system", "info", "Materialized command-scoped browser credential environment", {
|
|
39826
|
+
presentationKind: "browser_credential_env",
|
|
39827
|
+
origin: browserCredentialPlan.origin,
|
|
39828
|
+
keys: browserCredentialPlan.availableKeys,
|
|
39829
|
+
modelVisible: true
|
|
39830
|
+
});
|
|
39831
|
+
await preparationLogChain;
|
|
39832
|
+
}
|
|
39376
39833
|
forgetActiveRunCommand = rememberActiveRunCommand(command, {
|
|
39377
39834
|
executorKind: executor.kind,
|
|
39378
39835
|
workspacePath: cwd,
|
|
@@ -39382,9 +39839,11 @@ async function executeRunCommand(config, command) {
|
|
|
39382
39839
|
outputFloodLimitBytesPerStream: config.executorMaxOutputBytes,
|
|
39383
39840
|
...managedMcpProfile ? { managedMcpAttestation: managedMcpProfile.attestation } : {}
|
|
39384
39841
|
});
|
|
39385
|
-
const abortController = new AbortController();
|
|
39386
39842
|
stopActiveRunHeartbeats = startActiveRunHeartbeats(config, command, abortController);
|
|
39387
|
-
const protectedExecutorValues =
|
|
39843
|
+
const protectedExecutorValues = [.../* @__PURE__ */ new Set([
|
|
39844
|
+
...managedMcpProfile?.protectedValues ?? [],
|
|
39845
|
+
...providerProtectedValues
|
|
39846
|
+
])];
|
|
39388
39847
|
const runtimeArtifacts = [];
|
|
39389
39848
|
const runtimeDocuments = [];
|
|
39390
39849
|
const runtimeArtifactIngest = createRuntimeArtifactIngestQueue({
|
|
@@ -39426,7 +39885,7 @@ async function executeRunCommand(config, command) {
|
|
|
39426
39885
|
}
|
|
39427
39886
|
);
|
|
39428
39887
|
let execution;
|
|
39429
|
-
const browserCredentialConsumer =
|
|
39888
|
+
const browserCredentialConsumer = browserCredentialPresentationKind === "private_channel" ? async (request) => {
|
|
39430
39889
|
const credentialRef = browserCredentialRefForRequest(command, request);
|
|
39431
39890
|
return consumeRuntimeBrowserCredentialRef(
|
|
39432
39891
|
config,
|
|
@@ -39558,7 +40017,7 @@ async function executeRunCommand(config, command) {
|
|
|
39558
40017
|
workspace,
|
|
39559
40018
|
workspaceStatus.artifacts.map((artifact) => ({
|
|
39560
40019
|
rawPath: artifact.relativePath,
|
|
39561
|
-
filePath:
|
|
40020
|
+
filePath: resolve19(cwd, artifact.relativePath)
|
|
39562
40021
|
})),
|
|
39563
40022
|
{
|
|
39564
40023
|
requiredPaths: checkpointPaths,
|
|
@@ -39669,7 +40128,7 @@ async function executeRunCommand(config, command) {
|
|
|
39669
40128
|
workspace,
|
|
39670
40129
|
workspaceStatus.artifacts.map((artifact) => ({
|
|
39671
40130
|
rawPath: artifact.relativePath,
|
|
39672
|
-
filePath:
|
|
40131
|
+
filePath: resolve19(cwd, artifact.relativePath)
|
|
39673
40132
|
}))
|
|
39674
40133
|
) : readString(terminalRunDisposition?.disposition) !== "continuation_scheduled" ? await saveIssueCheckpoint(config, command, workspace, [], {
|
|
39675
40134
|
requiredPaths: taskSessionCheckpointPaths(workspaceStatus),
|
|
@@ -40027,8 +40486,9 @@ async function executeRunCommand(config, command) {
|
|
|
40027
40486
|
} finally {
|
|
40028
40487
|
await preparationLogChain;
|
|
40029
40488
|
if (piRuntimeSystemPromptCleanupPath) {
|
|
40030
|
-
|
|
40489
|
+
rmSync11(piRuntimeSystemPromptCleanupPath, { force: true });
|
|
40031
40490
|
}
|
|
40491
|
+
browserCredentialEnvMaterialization?.cleanup();
|
|
40032
40492
|
if (managedMcpProfile && !managedMcpCleanup && !completionOwnsManagedMcpProfile) {
|
|
40033
40493
|
managedMcpCleanup = cleanupManagedMcpProfile(managedMcpProfile, {
|
|
40034
40494
|
commandId: command.commandId,
|