@amaster.ai/employee-runtime-connector 0.1.2 → 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,6 +16882,7 @@ 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,
|
|
@@ -18045,6 +18082,18 @@ var API = {
|
|
|
18045
18082
|
admin: `${API_PREFIX}/admin`
|
|
18046
18083
|
};
|
|
18047
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
|
+
|
|
18048
18097
|
// ../shared/src/config-schema.ts
|
|
18049
18098
|
var configMetaSchema = external_exports.object({
|
|
18050
18099
|
version: external_exports.literal(1),
|
|
@@ -18481,10 +18530,71 @@ var prerequisiteOperationsSchema = external_exports.object({
|
|
|
18481
18530
|
}))
|
|
18482
18531
|
});
|
|
18483
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
|
+
|
|
18484
18594
|
// src/amaster-runtime-daemon.mjs
|
|
18485
|
-
import { chmodSync as
|
|
18486
|
-
import { arch as arch4, homedir as
|
|
18487
|
-
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";
|
|
18488
18598
|
import { spawn, spawnSync as spawnSync5 } from "node:child_process";
|
|
18489
18599
|
|
|
18490
18600
|
// src/amaster-runtime-daemon/common.mjs
|
|
@@ -18993,7 +19103,7 @@ async function postRuntimeConnectorJsonWithRetry(config, path, payload, options
|
|
|
18993
19103
|
} catch (error) {
|
|
18994
19104
|
lastError = error;
|
|
18995
19105
|
if (attempt >= maxAttempts || !retryableRuntimeConnectorPost(error)) throw error;
|
|
18996
|
-
if (delayMs > 0) await new Promise((
|
|
19106
|
+
if (delayMs > 0) await new Promise((resolve20) => setTimeout(resolve20, delayMs));
|
|
18997
19107
|
}
|
|
18998
19108
|
}
|
|
18999
19109
|
throw lastError;
|
|
@@ -19129,7 +19239,7 @@ var MAX_BYTES = 20 * 1024 * 1024;
|
|
|
19129
19239
|
var digest = (bytes) => createHash3("sha256").update(bytes).digest("hex");
|
|
19130
19240
|
function buildCheckpointUpload(checkpointDir, manifest, nativeSession) {
|
|
19131
19241
|
if (!Array.isArray(manifest?.files) || manifest.files.length > 20) throw new Error("Invalid checkpoint inventory");
|
|
19132
|
-
const root = realpathSync2(join3(checkpointDir, "files"));
|
|
19242
|
+
const root = manifest.files.length > 0 ? realpathSync2(join3(checkpointDir, "files")) : null;
|
|
19133
19243
|
const paths = /* @__PURE__ */ new Set();
|
|
19134
19244
|
let total = 0;
|
|
19135
19245
|
const files = manifest.files.map((file) => {
|
|
@@ -19247,6 +19357,7 @@ function installCheckpoint(target, bytes, expected, kind) {
|
|
|
19247
19357
|
if (existsSync(target) && (!lstatSync2(target).isDirectory() || lstatSync2(target).isSymbolicLink())) throw new Error("Checkpoint target must be a private directory");
|
|
19248
19358
|
mkdirSync2(dirname(target), { recursive: true });
|
|
19249
19359
|
const staging = mkdtempSync2(`${target}.restore-`);
|
|
19360
|
+
mkdirSync2(join4(staging, "files"), { recursive: true, mode: 448 });
|
|
19250
19361
|
const backup = `${target}.previous-${randomUUID()}`;
|
|
19251
19362
|
let moved = false;
|
|
19252
19363
|
try {
|
|
@@ -21338,48 +21449,48 @@ var FULL_DIRECT_TYPED_V1_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
21338
21449
|
function record5(value) {
|
|
21339
21450
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21340
21451
|
}
|
|
21341
|
-
function requiredString(value, label,
|
|
21342
|
-
if (typeof value !== "string" || value.trim() === "")
|
|
21452
|
+
function requiredString(value, label, fail3) {
|
|
21453
|
+
if (typeof value !== "string" || value.trim() === "") fail3(`${label} is required`);
|
|
21343
21454
|
return value.trim();
|
|
21344
21455
|
}
|
|
21345
21456
|
function validateDirectTypedMcpCatalog(catalogValue, options = {}) {
|
|
21346
21457
|
const errorPrefix = typeof options.errorPrefix === "string" && options.errorPrefix ? options.errorPrefix : "direct_typed_mcp_invalid";
|
|
21347
|
-
const
|
|
21458
|
+
const fail3 = (detail) => {
|
|
21348
21459
|
throw new Error(`${errorPrefix}: ${detail}`);
|
|
21349
21460
|
};
|
|
21350
21461
|
const admittedToolNames = options.admittedToolNames instanceof Set ? options.admittedToolNames : options.admittedToolNames == null ? null : new Set(options.admittedToolNames);
|
|
21351
21462
|
const catalog = record5(catalogValue);
|
|
21352
21463
|
if (catalog.schemaVersion !== DIRECT_TYPED_MCP_CATALOG_SCHEMA_VERSION) {
|
|
21353
|
-
|
|
21464
|
+
fail3("direct tool catalog schema mismatch");
|
|
21354
21465
|
}
|
|
21355
21466
|
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(record5) : [];
|
|
21356
21467
|
const names = /* @__PURE__ */ new Set();
|
|
21357
21468
|
const exposedNames = /* @__PURE__ */ new Set();
|
|
21358
21469
|
const tools = rawTools.map((tool) => {
|
|
21359
|
-
const name = requiredString(tool.name, "toolCatalog.tools.name",
|
|
21470
|
+
const name = requiredString(tool.name, "toolCatalog.tools.name", fail3);
|
|
21360
21471
|
if (admittedToolNames && !admittedToolNames.has(name) || names.has(name)) {
|
|
21361
|
-
|
|
21472
|
+
fail3("direct tool catalog name mismatch");
|
|
21362
21473
|
}
|
|
21363
21474
|
names.add(name);
|
|
21364
|
-
const exposedName = requiredString(tool.exposedName, `toolCatalog.tools.exposedName:${name}`,
|
|
21475
|
+
const exposedName = requiredString(tool.exposedName, `toolCatalog.tools.exposedName:${name}`, fail3);
|
|
21365
21476
|
if (!PROVIDER_SAFE_DIRECT_TOOL_NAME.test(exposedName)) {
|
|
21366
|
-
|
|
21477
|
+
fail3(`direct tool exposed name is unsafe for ${name}`);
|
|
21367
21478
|
}
|
|
21368
21479
|
if (exposedNames.has(exposedName)) {
|
|
21369
|
-
|
|
21480
|
+
fail3(`direct tool exposed name collision for ${exposedName}`);
|
|
21370
21481
|
}
|
|
21371
21482
|
exposedNames.add(exposedName);
|
|
21372
21483
|
const inputSchema = record5(tool.inputSchema);
|
|
21373
21484
|
if (inputSchema.type !== "object" || inputSchema.additionalProperties !== false) {
|
|
21374
|
-
|
|
21485
|
+
fail3(`direct tool schema is not strict for ${name}`);
|
|
21375
21486
|
}
|
|
21376
21487
|
const schemaHash = stablePiToolSchemaHash(inputSchema);
|
|
21377
21488
|
if (tool.schemaHash !== schemaHash) {
|
|
21378
|
-
|
|
21489
|
+
fail3(`direct tool schema hash mismatch for ${name}`);
|
|
21379
21490
|
}
|
|
21380
|
-
const riskLevel = requiredString(tool.riskLevel, `toolCatalog.tools.riskLevel:${name}`,
|
|
21491
|
+
const riskLevel = requiredString(tool.riskLevel, `toolCatalog.tools.riskLevel:${name}`, fail3);
|
|
21381
21492
|
if (!(/* @__PURE__ */ new Set(["read", "write", "destructive"])).has(riskLevel)) {
|
|
21382
|
-
|
|
21493
|
+
fail3(`direct tool risk level mismatch for ${name}`);
|
|
21383
21494
|
}
|
|
21384
21495
|
return {
|
|
21385
21496
|
name,
|
|
@@ -21397,7 +21508,7 @@ function validateDirectTypedMcpCatalog(catalogValue, options = {}) {
|
|
|
21397
21508
|
schemaHash: tool.schemaHash,
|
|
21398
21509
|
riskLevel: tool.riskLevel
|
|
21399
21510
|
})));
|
|
21400
|
-
if (catalog.setHash !== setHash)
|
|
21511
|
+
if (catalog.setHash !== setHash) fail3("direct tool catalog set hash mismatch");
|
|
21401
21512
|
return {
|
|
21402
21513
|
setHash,
|
|
21403
21514
|
tools: tools.sort((left, right) => left.name.localeCompare(right.name))
|
|
@@ -22640,14 +22751,14 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22640
22751
|
const receipts = [];
|
|
22641
22752
|
let stage = "upload";
|
|
22642
22753
|
let callId;
|
|
22643
|
-
const
|
|
22754
|
+
const fail3 = (code, detail) => {
|
|
22644
22755
|
throw Object.assign(new Error(code), { detail });
|
|
22645
22756
|
};
|
|
22646
22757
|
async function invoke(name, args) {
|
|
22647
|
-
if (now() >= deadline)
|
|
22758
|
+
if (now() >= deadline) fail3("initialization_completion_deadline");
|
|
22648
22759
|
let envelope;
|
|
22649
22760
|
for (let transportFailures = 0; ; ) {
|
|
22650
|
-
if (now() >= deadline)
|
|
22761
|
+
if (now() >= deadline) fail3("initialization_completion_deadline");
|
|
22651
22762
|
try {
|
|
22652
22763
|
envelope = await call(name, args, Math.min(45e3, deadline - now()));
|
|
22653
22764
|
break;
|
|
@@ -22660,12 +22771,11 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22660
22771
|
}
|
|
22661
22772
|
}
|
|
22662
22773
|
const content = envelope?.content;
|
|
22663
|
-
|
|
22664
|
-
|
|
22665
|
-
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");
|
|
22666
22776
|
}
|
|
22667
22777
|
if (envelope.status !== "succeeded" || !["accepted", "pending_reconcile"].includes(content.status)) {
|
|
22668
|
-
|
|
22778
|
+
fail3("initialization_completion_action_not_accepted", content.error ?? { status: envelope.status });
|
|
22669
22779
|
}
|
|
22670
22780
|
const result2 = content.result;
|
|
22671
22781
|
await onReceipt(envelope);
|
|
@@ -22676,19 +22786,19 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22676
22786
|
planId: result2?.planId,
|
|
22677
22787
|
status: result2?.status
|
|
22678
22788
|
});
|
|
22679
|
-
if (!result2 || result2.error)
|
|
22789
|
+
if (!result2 || result2.error) fail3("initialization_completion_action_failed", result2?.error);
|
|
22680
22790
|
return result2;
|
|
22681
22791
|
}
|
|
22682
22792
|
async function settleCall(value, actionType) {
|
|
22683
22793
|
callId = value.callId;
|
|
22684
|
-
if (!callId || value.actionType !== actionType)
|
|
22794
|
+
if (!callId || value.actionType !== actionType) fail3("initialization_completion_call_mismatch");
|
|
22685
22795
|
for (let attempt = 0; ; attempt++) {
|
|
22686
|
-
if (value.callId !== callId || value.actionType !== actionType)
|
|
22796
|
+
if (value.callId !== callId || value.actionType !== actionType) fail3("initialization_completion_call_mismatch");
|
|
22687
22797
|
if (value.status === "succeeded") return value;
|
|
22688
22798
|
if (!["pending_reconcile", "claimed", "executing"].includes(value.status)) {
|
|
22689
|
-
|
|
22799
|
+
fail3("initialization_completion_action_incomplete", { status: value.status, error: value.error });
|
|
22690
22800
|
}
|
|
22691
|
-
if (now() >= deadline)
|
|
22801
|
+
if (now() >= deadline) fail3("initialization_completion_deadline");
|
|
22692
22802
|
await sleep(Math.min(1e3 * (attempt + 1), 5e3));
|
|
22693
22803
|
value = await invoke("runtime_action_status", { callId });
|
|
22694
22804
|
}
|
|
@@ -22697,7 +22807,7 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22697
22807
|
const doc = plan.initializationDocument;
|
|
22698
22808
|
const materialized = plan.initializationDocumentMaterialization;
|
|
22699
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) {
|
|
22700
|
-
|
|
22810
|
+
fail3("initialization_completion_invalid_plan");
|
|
22701
22811
|
}
|
|
22702
22812
|
const prefix = "initialization-complete:" + plan.planId;
|
|
22703
22813
|
const { createHash: createHash20 } = await import("node:crypto");
|
|
@@ -22718,13 +22828,13 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22718
22828
|
}
|
|
22719
22829
|
}), "upload_artifact");
|
|
22720
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) {
|
|
22721
|
-
|
|
22831
|
+
fail3("initialization_completion_artifact_mismatch");
|
|
22722
22832
|
}
|
|
22723
22833
|
stage = "commit";
|
|
22724
22834
|
callId = void 0;
|
|
22725
22835
|
const committed = await invoke("runtime_action_commit", { planId: plan.planId, revision: plan.revision });
|
|
22726
22836
|
if (committed.planId !== plan.planId || committed.revision !== plan.revision || committed.status !== "completed" || committed.failure || committed.nextActionIndex !== committed.actionCount) {
|
|
22727
|
-
|
|
22837
|
+
fail3("initialization_completion_plan_incomplete", { status: committed.status, failure: committed.failure });
|
|
22728
22838
|
}
|
|
22729
22839
|
stage = "ready";
|
|
22730
22840
|
const completed = await settleCall(await invoke("runtime_action_submit", {
|
|
@@ -22732,7 +22842,7 @@ async function runInitializationCompletion({ plan, authority, call, sleep, now,
|
|
|
22732
22842
|
action: { type: "update_parent", status: "done" }
|
|
22733
22843
|
}), "update_parent");
|
|
22734
22844
|
if (completed.effectResult?.issueId !== authority.issueId || completed.effectResult?.status !== "done" || completed.postcondition?.issuePersisted !== true || completed.postcondition?.status !== "done" || completed.postcondition?.issueTerminalizationDeferred === true) {
|
|
22735
|
-
|
|
22845
|
+
fail3("initialization_completion_ready_not_confirmed");
|
|
22736
22846
|
}
|
|
22737
22847
|
return {
|
|
22738
22848
|
status: "completed",
|
|
@@ -22818,8 +22928,7 @@ export default function(pi) {
|
|
|
22818
22928
|
const result = call?.result;
|
|
22819
22929
|
const doc = result?.initializationDocument;
|
|
22820
22930
|
if (envelope?.status !== "succeeded" || call?.status !== "accepted"
|
|
22821
|
-
|| call?.
|
|
22822
|
-
|| !["runtime_action.plan", "runtime_action.status"].includes(call?.toolName) || !doc) return;
|
|
22931
|
+
|| call?.toolName !== event.toolName.replace("runtime_action_", "runtime_action.") || !doc) return;
|
|
22823
22932
|
let root, parent, file, temp;
|
|
22824
22933
|
const canonicalName = "organization-plan-" + result.planId + ".md";
|
|
22825
22934
|
let targetName = canonicalName;
|
|
@@ -22969,12 +23078,10 @@ export default function(pi) {
|
|
|
22969
23078
|
if (root !== undefined) fs.closeSync(root);
|
|
22970
23079
|
}
|
|
22971
23080
|
// Only an explicitly negotiated planning call starts effects. Status/document reads stay reads.
|
|
22972
|
-
|
|
23081
|
+
// The session token in the run config binds every call to this run's
|
|
23082
|
+
// authority, so receipt authority is established by transport.
|
|
22973
23083
|
if (completionAuthority && event.toolName === "runtime_action_plan"
|
|
22974
|
-
&& result.initializationDocumentMaterialization?.status === "materialized"
|
|
22975
|
-
&& provider?.provider === "amaster_actions" && provider.invocationId === envelope.invocationId
|
|
22976
|
-
&& provider.planId === result.planId
|
|
22977
|
-
&& ["runId", "commandId", "issueId"].every((key) => completionAuthority[key] && provider[key] === completionAuthority[key])) {
|
|
23084
|
+
&& result.initializationDocumentMaterialization?.status === "materialized") {
|
|
22978
23085
|
result.initializationCompletion = await runInitializationCompletion({ plan: result, authority: completionAuthority,
|
|
22979
23086
|
call: initializationCompletionCall, sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)), now: Date.now,
|
|
22980
23087
|
// Pi redirects extension stdout.write to stderr. This is an explicit
|
|
@@ -23531,25 +23638,20 @@ const terminalActionDispositions = new Map([
|
|
|
23531
23638
|
["schedule_monitor", new Set(["scheduled_monitor"])],
|
|
23532
23639
|
["continue_task", new Set(["continuation_scheduled"])],
|
|
23533
23640
|
]);
|
|
23534
|
-
const terminalToolNames = new Set(["
|
|
23535
|
-
|
|
23536
|
-
function shouldStopFromReceipt(rawResult) {
|
|
23537
|
-
const expectedRunId = readString(process.env.AMASTER_RUNTIME_RUN_ID);
|
|
23538
|
-
const expectedCommandId = readString(process.env.AMASTER_RUNTIME_COMMAND_ID);
|
|
23539
|
-
const expectedIssueId = readString(process.env.AMASTER_RUNTIME_ISSUE_ID);
|
|
23540
|
-
if (!expectedRunId || !expectedCommandId || !expectedIssueId) return false;
|
|
23641
|
+
const terminalToolNames = new Set(["runtime_action_submit", "runtime_action_status"]);
|
|
23541
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) {
|
|
23542
23647
|
const result = asRecord(rawResult);
|
|
23543
23648
|
const structured = asRecord(result.structuredContent);
|
|
23544
23649
|
const providerContent = asRecord(structured.content);
|
|
23545
23650
|
const providerResult = asRecord(providerContent.result);
|
|
23546
23651
|
const effectResult = asRecord(providerResult.effectResult);
|
|
23547
|
-
const providerReceipt = asRecord(structured.providerReceipt);
|
|
23548
23652
|
const invocationId = readString(structured.invocationId);
|
|
23549
23653
|
const callId = readString(providerResult.callId);
|
|
23550
|
-
const
|
|
23551
|
-
const receiptCallId = readString(providerReceipt.callId);
|
|
23552
|
-
const actionType = readString(providerReceipt.actionType);
|
|
23654
|
+
const actionType = readString(providerResult.actionType);
|
|
23553
23655
|
const disposition = readString(effectResult.runDisposition);
|
|
23554
23656
|
const existingOwner = asRecord(effectResult.existingOwner);
|
|
23555
23657
|
const existingOwnerEpoch = Number(existingOwner.executionEpoch);
|
|
@@ -23565,7 +23667,7 @@ function shouldStopFromReceipt(rawResult) {
|
|
|
23565
23667
|
&& continuationCount > 0
|
|
23566
23668
|
&& Number.isSafeInteger(maxContinuations)
|
|
23567
23669
|
&& continuationCount <= maxContinuations;
|
|
23568
|
-
if (!invocationId || !
|
|
23670
|
+
if (!invocationId || !callId) return false;
|
|
23569
23671
|
|
|
23570
23672
|
const exactQueuedWakeHandoff = disposition === "handoff_existing_live_path"
|
|
23571
23673
|
&& readString(existingOwner.kind) === "queued_wake"
|
|
@@ -23578,16 +23680,9 @@ function shouldStopFromReceipt(rawResult) {
|
|
|
23578
23680
|
return readString(structured.status) === "succeeded"
|
|
23579
23681
|
&& readString(providerContent.status) === "accepted"
|
|
23580
23682
|
&& ["succeeded", "completed"].includes(readString(providerResult.status) ?? "")
|
|
23581
|
-
&& terminalToolNames.has(readString(
|
|
23683
|
+
&& terminalToolNames.has(readString(eventToolName) ?? "")
|
|
23582
23684
|
&& effectResult.mustEndRun === true
|
|
23583
23685
|
&& Boolean(terminalActionDispositions.get(actionType ?? "")?.has(disposition ?? ""))
|
|
23584
|
-
&& readString(providerReceipt.provider) === "amaster_actions"
|
|
23585
|
-
&& readString(providerReceipt.status) === "accepted"
|
|
23586
|
-
&& receiptInvocationId === invocationId
|
|
23587
|
-
&& readString(providerReceipt.runId) === expectedRunId
|
|
23588
|
-
&& readString(providerReceipt.commandId) === expectedCommandId
|
|
23589
|
-
&& readString(providerReceipt.issueId) === expectedIssueId
|
|
23590
|
-
&& receiptCallId === callId
|
|
23591
23686
|
&& (disposition !== "waiting_human"
|
|
23592
23687
|
|| Boolean(readString(effectResult.interactionId) && readString(effectResult.epochKey)))
|
|
23593
23688
|
&& (disposition !== "handoff_existing_live_path"
|
|
@@ -23599,7 +23694,7 @@ export default function mirrorxRunTermination(pi) {
|
|
|
23599
23694
|
pi.on("tool_result", (event) => {
|
|
23600
23695
|
if (event.isError === true) return undefined;
|
|
23601
23696
|
const rawResult = asRecord(event.details).mcpResult;
|
|
23602
|
-
return shouldStopFromReceipt(rawResult) ? { stopAfterTurn: true } : undefined;
|
|
23697
|
+
return shouldStopFromReceipt(rawResult, event.toolName) ? { stopAfterTurn: true } : undefined;
|
|
23603
23698
|
});
|
|
23604
23699
|
}
|
|
23605
23700
|
`;
|
|
@@ -23761,6 +23856,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23761
23856
|
const SESSION_ROLLOUT_MARKER3 = ".amaster-pi-session-rollout.json";
|
|
23762
23857
|
const DEFAULT_SESSION_ROLLOUT_TTL_MS3 = 24 * 60 * 60 * 1e3;
|
|
23763
23858
|
const PI_VERSION_ATTESTATION_TIMEOUT_MS = 3e4;
|
|
23859
|
+
const MANAGED_PI_GOVERNED_MCP_REQUEST_TIMEOUT_MS = 66e4;
|
|
23764
23860
|
const PI_ATTESTATION_MAX_ATTEMPTS = 2;
|
|
23765
23861
|
const livePiVersionProbes = /* @__PURE__ */ new Map();
|
|
23766
23862
|
function record11(value) {
|
|
@@ -24563,7 +24659,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24563
24659
|
schema: tool.inputSchema
|
|
24564
24660
|
})))
|
|
24565
24661
|
);
|
|
24566
|
-
const
|
|
24662
|
+
const cache2 = {
|
|
24567
24663
|
version: 1,
|
|
24568
24664
|
servers: {
|
|
24569
24665
|
[SUPPORTED_SERVER_NAME3]: {
|
|
@@ -24578,7 +24674,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24578
24674
|
}
|
|
24579
24675
|
}
|
|
24580
24676
|
};
|
|
24581
|
-
const cacheBytes = Buffer.from(`${JSON.stringify(
|
|
24677
|
+
const cacheBytes = Buffer.from(`${JSON.stringify(cache2, null, 2)}
|
|
24582
24678
|
`);
|
|
24583
24679
|
writeOwnedFileAtomic(cachePath, cacheBytes);
|
|
24584
24680
|
const toolSchemaBytes = input.directCatalog.tools.reduce((total, tool) => total + Buffer.byteLength(JSON.stringify({
|
|
@@ -24681,6 +24777,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24681
24777
|
url: gatewayUrl,
|
|
24682
24778
|
headers: { Authorization: `Bearer ${sessionToken}`, ...headers },
|
|
24683
24779
|
lifecycle: directCatalog ? "lazy" : "eager",
|
|
24780
|
+
requestTimeoutMs: MANAGED_PI_GOVERNED_MCP_REQUEST_TIMEOUT_MS,
|
|
24684
24781
|
...directCatalog ? { exposeResources: false, directTools: directToolNames } : {}
|
|
24685
24782
|
};
|
|
24686
24783
|
const config = {
|
|
@@ -24988,6 +25085,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24988
25085
|
url: gatewayUrl,
|
|
24989
25086
|
headers: { Authorization: `Bearer ${sessionToken}`, ...headers },
|
|
24990
25087
|
lifecycle: directCatalog ? "lazy" : "eager",
|
|
25088
|
+
requestTimeoutMs: MANAGED_PI_GOVERNED_MCP_REQUEST_TIMEOUT_MS,
|
|
24991
25089
|
...directCatalog ? { exposeResources: false, directTools: directToolNames } : {}
|
|
24992
25090
|
};
|
|
24993
25091
|
const config = {
|
|
@@ -26565,7 +26663,6 @@ function governedMcpToolResult(structuredContent) {
|
|
|
26565
26663
|
if (!status) return null;
|
|
26566
26664
|
const invocationId = readString(structuredContent.invocationId);
|
|
26567
26665
|
const providerContent = asRecord(structuredContent.content);
|
|
26568
|
-
const providerReceipt = asRecord(structuredContent.providerReceipt);
|
|
26569
26666
|
const providerStatus = readString(providerContent.status);
|
|
26570
26667
|
const providerResult = asRecord(providerContent.result);
|
|
26571
26668
|
const effectResult = asRecord(providerResult.effectResult);
|
|
@@ -26599,13 +26696,9 @@ function governedMcpToolResult(structuredContent) {
|
|
|
26599
26696
|
...runtimeActionResultStatus ? { resultStatus: runtimeActionResultStatus } : {},
|
|
26600
26697
|
...readString(providerResult.errorCode) ?? readString(runtimeActionError.code) ? { errorCode: readString(providerResult.errorCode) ?? readString(runtimeActionError.code) } : {}
|
|
26601
26698
|
} : null;
|
|
26602
|
-
const
|
|
26699
|
+
const actionType = readString(providerResult.actionType);
|
|
26603
26700
|
const runDisposition = readString(effectResult.runDisposition);
|
|
26604
|
-
const expectedDispositions = PI_TERMINATING_RUNTIME_ACTION_TO_DISPOSITION.get(
|
|
26605
|
-
const receiptRunId = readString(providerReceipt.runId);
|
|
26606
|
-
const receiptCommandId = readString(providerReceipt.commandId);
|
|
26607
|
-
const receiptIssueId = readString(providerReceipt.issueId);
|
|
26608
|
-
const receiptCallId = readString(providerReceipt.callId);
|
|
26701
|
+
const expectedDispositions = PI_TERMINATING_RUNTIME_ACTION_TO_DISPOSITION.get(actionType ?? "");
|
|
26609
26702
|
const interactionId = readString(effectResult.interactionId);
|
|
26610
26703
|
const epochKey = readString(effectResult.epochKey);
|
|
26611
26704
|
const existingOwner = asRecord(effectResult.existingOwner);
|
|
@@ -26621,15 +26714,12 @@ function governedMcpToolResult(structuredContent) {
|
|
|
26621
26714
|
const exactQueuedWakeHandoff = runDisposition === "handoff_existing_live_path" && readString(existingOwner.kind) === "queued_wake" && Boolean(readString(existingOwner.id)) && ["pending_dispatch", "queued", "deferred_issue_execution"].includes(
|
|
26622
26715
|
readString(existingOwner.status) ?? ""
|
|
26623
26716
|
) && Number.isSafeInteger(existingOwnerEpoch) && existingOwnerEpoch > 0 && readString(existingOwner.nextAction) === "end_current_run";
|
|
26624
|
-
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)) ? {
|
|
26625
26718
|
disposition: runDisposition,
|
|
26626
|
-
actionType
|
|
26719
|
+
actionType,
|
|
26627
26720
|
toolName: runtimeActionToolName,
|
|
26628
26721
|
invocationId,
|
|
26629
26722
|
callId: runtimeActionCallId,
|
|
26630
|
-
runId: receiptRunId,
|
|
26631
|
-
commandId: receiptCommandId,
|
|
26632
|
-
issueId: receiptIssueId,
|
|
26633
26723
|
...interactionId ? { interactionId } : {},
|
|
26634
26724
|
...epochKey ? { epochKey } : {},
|
|
26635
26725
|
...exactContinuation ? {
|
|
@@ -26704,10 +26794,7 @@ function terminatingRunDispositionEvidence(results, expected = {}) {
|
|
|
26704
26794
|
const expectedCommandId = readString(expected.commandId);
|
|
26705
26795
|
const expectedIssueId = readString(expected.issueId);
|
|
26706
26796
|
if (!expectedRunId || !expectedCommandId || !expectedIssueId) return null;
|
|
26707
|
-
const result2 = (Array.isArray(results) ? results : []).map(asRecord).find((entry) =>
|
|
26708
|
-
const disposition2 = asRecord(entry.terminalRunDisposition);
|
|
26709
|
-
return readString(entry.status) === "succeeded" && readString(disposition2.runId) === expectedRunId && readString(disposition2.commandId) === expectedCommandId && readString(disposition2.issueId) === expectedIssueId;
|
|
26710
|
-
});
|
|
26797
|
+
const result2 = (Array.isArray(results) ? results : []).map(asRecord).find((entry) => readString(entry.status) === "succeeded" && Object.keys(asRecord(entry.terminalRunDisposition)).length > 0);
|
|
26711
26798
|
if (!result2) return null;
|
|
26712
26799
|
const disposition = asRecord(result2.terminalRunDisposition);
|
|
26713
26800
|
const existingOwner = asRecord(disposition.existingOwner);
|
|
@@ -28229,7 +28316,7 @@ function maybeCapturePiMessage(event, messages, usage) {
|
|
|
28229
28316
|
}
|
|
28230
28317
|
return capturedAssistantOutput;
|
|
28231
28318
|
}
|
|
28232
|
-
function piMcpToolResults(event
|
|
28319
|
+
function piMcpToolResults(event) {
|
|
28233
28320
|
const results = [];
|
|
28234
28321
|
const seen = /* @__PURE__ */ new Set();
|
|
28235
28322
|
const retain = (parsed) => {
|
|
@@ -28258,15 +28345,7 @@ function piMcpToolResults(event, expectedAuthority = null) {
|
|
|
28258
28345
|
const invocationId = readString(directStructuredContent.invocationId);
|
|
28259
28346
|
const status = readString(directStructuredContent.status);
|
|
28260
28347
|
if (!invocationId || !status) continue;
|
|
28261
|
-
|
|
28262
|
-
const trustedProviderReceipt = readString(providerReceipt.provider) === "amaster_actions" && readString(providerReceipt.invocationId) === invocationId && Boolean(readString(providerReceipt.status));
|
|
28263
|
-
retain(governedMcpToolResult(trustedProviderReceipt ? directStructuredContent : {
|
|
28264
|
-
invocationId,
|
|
28265
|
-
status,
|
|
28266
|
-
// Never let a receipt-free success satisfy approved-action
|
|
28267
|
-
// completion; non-success states remain useful for control flow.
|
|
28268
|
-
...status === "succeeded" ? { content: { status: "blocked" } } : {}
|
|
28269
|
-
}));
|
|
28348
|
+
retain(governedMcpToolResult(directStructuredContent));
|
|
28270
28349
|
} catch {
|
|
28271
28350
|
}
|
|
28272
28351
|
}
|
|
@@ -28284,11 +28363,10 @@ function piMcpToolResults(event, expectedAuthority = null) {
|
|
|
28284
28363
|
if (readString(event?.type) === "tool_execution_end") {
|
|
28285
28364
|
retainMcpResult(event?.result);
|
|
28286
28365
|
}
|
|
28287
|
-
if (readString(event?.type) === "mirrorx_initialization_action_receipt"
|
|
28366
|
+
if (readString(event?.type) === "mirrorx_initialization_action_receipt") {
|
|
28288
28367
|
const receipt = asRecord(event.receipt);
|
|
28289
|
-
const provider = asRecord(receipt.providerReceipt);
|
|
28290
28368
|
const content = asRecord(receipt.content);
|
|
28291
|
-
if (
|
|
28369
|
+
if (readString(receipt.invocationId) && readString(receipt.status) && readString(content.status)) {
|
|
28292
28370
|
retainMcpResult({ details: { server: "amaster" }, content: [{ type: "text", text: JSON.stringify(receipt) }] });
|
|
28293
28371
|
}
|
|
28294
28372
|
}
|
|
@@ -28619,9 +28697,9 @@ function parseOpenCodeJsonl(stdout) {
|
|
|
28619
28697
|
if (event.type === "step_finish") {
|
|
28620
28698
|
const part = asRecord(event.part);
|
|
28621
28699
|
const tokens = asRecord(part.tokens);
|
|
28622
|
-
const
|
|
28700
|
+
const cache2 = asRecord(tokens.cache);
|
|
28623
28701
|
usage.inputTokens += readNumber(tokens.input, 0);
|
|
28624
|
-
usage.cachedInputTokens += readNumber(
|
|
28702
|
+
usage.cachedInputTokens += readNumber(cache2.read, 0);
|
|
28625
28703
|
usage.outputTokens += readNumber(tokens.output, 0) + readNumber(tokens.reasoning, 0);
|
|
28626
28704
|
continue;
|
|
28627
28705
|
}
|
|
@@ -29020,7 +29098,7 @@ function createRunCompletionRuntimePorts(input) {
|
|
|
29020
29098
|
outbox,
|
|
29021
29099
|
limits,
|
|
29022
29100
|
now = () => (/* @__PURE__ */ new Date()).toISOString(),
|
|
29023
|
-
sleep = (delayMs) => new Promise((
|
|
29101
|
+
sleep = (delayMs) => new Promise((resolve20) => setTimeout(resolve20, delayMs)),
|
|
29024
29102
|
diagnostic = (message) => process.stderr.write(`${message}
|
|
29025
29103
|
`)
|
|
29026
29104
|
} = input;
|
|
@@ -30248,6 +30326,30 @@ function fixedRules(input, includeIssueLine, runContract = "producer") {
|
|
|
30248
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."
|
|
30249
30327
|
].filter(Boolean).join("\n");
|
|
30250
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
|
+
}
|
|
30251
30353
|
function compileConversationPrompt(input, context, maxChars) {
|
|
30252
30354
|
const mode = promptContextMode(input);
|
|
30253
30355
|
const taskText = readString(input.taskMarkdown) ?? "";
|
|
@@ -30268,9 +30370,12 @@ function compileConversationPrompt(input, context, maxChars) {
|
|
|
30268
30370
|
if (!userPrompt) throw new Error("conversation_user_message_missing");
|
|
30269
30371
|
const rawSections = [
|
|
30270
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) }] : [],
|
|
30271
30374
|
{ name: "runtime_safety", title: "Runtime Safety", priority: 100, sourceRef: `command:${input.commandId}`, content: runtimeSafety },
|
|
30272
30375
|
...piGovernedTools ? [{ name: "pi_governed_tools", title: "Pi Governed Tools", priority: 96, sourceRef: "amaster_governed_mcp_direct_typed_contract", content: piGovernedTools }] : [],
|
|
30273
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) ?? "" },
|
|
30274
30379
|
{ name: "attachments", title: "Materialized Inputs", priority: 80, sourceRef: "materialized_attachments", content: readString(input.attachmentsText) ?? "" },
|
|
30275
30380
|
{ name: "raw_snapshot", title: "Raw Context Snapshot", priority: 0, sourceRef: `run:${input.runId ?? "unknown"}`, originalChars: jsonCharLength(context), content: "", truncationReason: "on_demand_large_object" }
|
|
30276
30381
|
];
|
|
@@ -30960,9 +31065,12 @@ var COMPANY_INITIALIZATION_PRE_AUTHORITY_SECTIONS = /* @__PURE__ */ new Set([
|
|
|
30960
31065
|
"verified_company_context",
|
|
30961
31066
|
"governed_reads",
|
|
30962
31067
|
"optional_task_wiki_context",
|
|
31068
|
+
"mention_context",
|
|
31069
|
+
"agent_roster",
|
|
30963
31070
|
"attachments"
|
|
30964
31071
|
]);
|
|
30965
31072
|
var COMPANY_INITIALIZATION_POST_AUTHORITY_SECTIONS = /* @__PURE__ */ new Set([
|
|
31073
|
+
"browser_credential_env",
|
|
30966
31074
|
"runtime_rules",
|
|
30967
31075
|
"runtime_authorization",
|
|
30968
31076
|
"runtime_decomposition_requirement",
|
|
@@ -31136,6 +31244,8 @@ var CONTEXT_AVAILABILITY_SECTION_TITLES = Object.freeze({
|
|
|
31136
31244
|
governed_reads: "Governed External Reads",
|
|
31137
31245
|
optional_task_wiki_context: "Optional Company Wiki Context",
|
|
31138
31246
|
agent_instructions: "Agent Instructions",
|
|
31247
|
+
mention_context: "Mentioned Context",
|
|
31248
|
+
agent_roster: "Company Agent Roster",
|
|
31139
31249
|
attachments: "Materialized Inputs",
|
|
31140
31250
|
on_demand_refs: "On-demand Context References",
|
|
31141
31251
|
raw_snapshot: "Raw Context Snapshot"
|
|
@@ -31391,6 +31501,7 @@ ${resolvedDependencies.details.content}` : resolvedDependencies.details.content
|
|
|
31391
31501
|
} : fallbackTemplateCatalog;
|
|
31392
31502
|
const rawSections = [
|
|
31393
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) }] : [],
|
|
31394
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" },
|
|
31395
31506
|
...continuationNextAction ? [{ name: "continuation_next_action", title: "Authoritative Continuation Next Action", priority: 100, ...continuationNextAction }] : [],
|
|
31396
31507
|
{ name: "wake_comments", title: wakeDeltaTitle, priority: interactionResolution ? 99 : 95, sourceRef: wakeDeltaSourceRefs, originalContent: wakeDeltaOriginal, content: wakeDeltaContent, truncationReason: commentsSelected ? null : "duplicate_task_context" },
|
|
@@ -31432,6 +31543,7 @@ ${resolvedDependencies.details.content}` : resolvedDependencies.details.content
|
|
|
31432
31543
|
...optionalTaskWikiContext ? [optionalTaskWikiContext] : [],
|
|
31433
31544
|
...runtimeTemplateCatalog ? [{ name: "runtime_template_catalog", title: "Runtime Template Catalog", priority: 100, ...runtimeTemplateCatalog }] : [],
|
|
31434
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) ?? "" },
|
|
31435
31547
|
{ name: "attachments", title: "Materialized Inputs", priority: 80, sourceRef: "materialized_attachments", content: readString(input.attachmentsText) ?? "" },
|
|
31436
31548
|
{
|
|
31437
31549
|
name: "on_demand_refs",
|
|
@@ -31928,12 +32040,17 @@ var BUILD_SUPPORTED_CAPABILITIES = Object.freeze([
|
|
|
31928
32040
|
"run_terminate",
|
|
31929
32041
|
"logs_cost_workspace_status",
|
|
31930
32042
|
"browser_credential_auth_transaction_v1",
|
|
32043
|
+
"browser_credential_env_read_v1",
|
|
31931
32044
|
"execution_lanes_v1",
|
|
31932
32045
|
"mirrorx_initialization_context_v1",
|
|
31933
32046
|
"mirrorx_initialization_completion_v1",
|
|
31934
32047
|
"native_session_checkpoint_v1"
|
|
31935
32048
|
]);
|
|
31936
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
|
+
},
|
|
31937
32054
|
browser_credential_auth_transaction_v1: {
|
|
31938
32055
|
reasonCode: "browser_credential_auth_runtime_incomplete",
|
|
31939
32056
|
ready: (input) => {
|
|
@@ -32594,10 +32711,150 @@ function sameCredentialBrowserTcb(value) {
|
|
|
32594
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;
|
|
32595
32712
|
}
|
|
32596
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
|
+
|
|
32597
32854
|
// src/amaster-runtime-daemon/runtime-artifact-upload.mjs
|
|
32598
32855
|
import { createHash as createHash14 } from "node:crypto";
|
|
32599
|
-
import { closeSync as closeSync4, constants as constants3, fstatSync as fstatSync4, lstatSync as
|
|
32600
|
-
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";
|
|
32601
32858
|
var SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
32602
32859
|
function requiredString2(value, name) {
|
|
32603
32860
|
if (typeof value !== "string" || !value.trim()) throw new Error(`Runtime Artifact ${name} is required`);
|
|
@@ -32616,10 +32873,10 @@ function sameFileSnapshot(left, right) {
|
|
|
32616
32873
|
return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
32617
32874
|
}
|
|
32618
32875
|
function readOwnedWorkspaceFile(rootPath, sourceRelativePath, label = "Runtime workspace file", options = {}) {
|
|
32619
|
-
const root = realpathSync10(
|
|
32876
|
+
const root = realpathSync10(resolve12(rootPath));
|
|
32620
32877
|
const relativePath = ownedRelativePath(sourceRelativePath);
|
|
32621
|
-
const sourcePath =
|
|
32622
|
-
const pathStat =
|
|
32878
|
+
const sourcePath = resolve12(root, relativePath);
|
|
32879
|
+
const pathStat = lstatSync10(sourcePath);
|
|
32623
32880
|
if (!pathStat.isFile() || pathStat.isSymbolicLink() || !pathWithin2(realpathSync10(sourcePath), root)) {
|
|
32624
32881
|
throw new Error(`${label} source is not an owned regular file`);
|
|
32625
32882
|
}
|
|
@@ -32648,10 +32905,10 @@ function readOwnedWorkspaceFile(rootPath, sourceRelativePath, label = "Runtime w
|
|
|
32648
32905
|
);
|
|
32649
32906
|
}
|
|
32650
32907
|
}
|
|
32651
|
-
const body =
|
|
32908
|
+
const body = readFileSync14(descriptor);
|
|
32652
32909
|
options.afterRead?.({ sourcePath, descriptor });
|
|
32653
32910
|
const after = fstatSync4(descriptor);
|
|
32654
|
-
const pathAfter =
|
|
32911
|
+
const pathAfter = lstatSync10(sourcePath);
|
|
32655
32912
|
if (!sameFileSnapshot(before, after) || !sameFileSnapshot(pathAfter, after) || !pathAfter.isFile() || pathAfter.isSymbolicLink() || !pathWithin2(realpathSync10(sourcePath), root) || body.length !== after.size) {
|
|
32656
32913
|
throw new Error(`${label} source changed during the governed read`);
|
|
32657
32914
|
}
|
|
@@ -32976,7 +33233,7 @@ function createRuntimeArtifactIngestQueue({ ingest, onError }) {
|
|
|
32976
33233
|
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
32977
33234
|
import { createHash as createHash16 } from "node:crypto";
|
|
32978
33235
|
import { existsSync as existsSync13, mkdirSync as mkdirSync10, realpathSync as realpathSync11, statSync as statSync7 } from "node:fs";
|
|
32979
|
-
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";
|
|
32980
33237
|
function pathWithin3(candidate, root) {
|
|
32981
33238
|
const rel = relative7(root, candidate);
|
|
32982
33239
|
return rel === "" || !rel.startsWith("..") && !isAbsolute9(rel);
|
|
@@ -32985,10 +33242,10 @@ function resolveWorkspaceCwd(config, command) {
|
|
|
32985
33242
|
const payload = asRecord(command.payload);
|
|
32986
33243
|
const requested = readString(payload.workspacePath);
|
|
32987
33244
|
const fallback = config.workspaceBindings[0] ?? process.cwd();
|
|
32988
|
-
const cwd = realpathSync11(
|
|
33245
|
+
const cwd = realpathSync11(resolve13(expandHomePath(requested ?? fallback)));
|
|
32989
33246
|
const allowlist = config.workspaceBindings.flatMap((entry) => {
|
|
32990
33247
|
try {
|
|
32991
|
-
return [realpathSync11(
|
|
33248
|
+
return [realpathSync11(resolve13(expandHomePath(entry)))];
|
|
32992
33249
|
} catch {
|
|
32993
33250
|
return [];
|
|
32994
33251
|
}
|
|
@@ -33031,7 +33288,7 @@ function workspaceLabel(sourceWorkspacePath, payload) {
|
|
|
33031
33288
|
return readString(payload.workspaceName) ?? readString(payload.projectName) ?? readString(context.projectName) ?? basename6(sourceWorkspacePath) ?? "workspace";
|
|
33032
33289
|
}
|
|
33033
33290
|
function workspacesRoot(config) {
|
|
33034
|
-
const root =
|
|
33291
|
+
const root = resolve13(expandHomePath(config.runtimeWorkspacesRoot ?? "~/.amaster-employee/workspaces"));
|
|
33035
33292
|
mkdirSync10(root, { recursive: true });
|
|
33036
33293
|
return realpathSync11(root);
|
|
33037
33294
|
}
|
|
@@ -33045,9 +33302,9 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
|
33045
33302
|
const workspaceKey = `${safeSegment(workspaceLabel(sourceWorkspacePath, payload), "workspace")}-${shortHash(sourceWorkspacePath)}`;
|
|
33046
33303
|
const issueKey = `${safeSegment(issueLabel(command, payload), "issue")}-${shortHash(issueId, 8)}`;
|
|
33047
33304
|
const runKey = `${safeSegment(runId, "run")}-${shortHash(runId, 8)}`;
|
|
33048
|
-
const runDir =
|
|
33049
|
-
const cwd =
|
|
33050
|
-
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"));
|
|
33051
33308
|
mkdirSync10(cwd, { recursive: true });
|
|
33052
33309
|
mkdirSync10(executorHome, { recursive: true });
|
|
33053
33310
|
const workspace = {
|
|
@@ -33072,11 +33329,11 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
|
33072
33329
|
|
|
33073
33330
|
// src/amaster-runtime-daemon/workspace-gc.mjs
|
|
33074
33331
|
import { existsSync as existsSync14, readdirSync as readdirSync8, statSync as statSync8 } from "node:fs";
|
|
33075
|
-
import { join as
|
|
33332
|
+
import { join as join19, resolve as resolve14 } from "node:path";
|
|
33076
33333
|
function readIsoTime(value) {
|
|
33077
33334
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
33078
|
-
const
|
|
33079
|
-
return Number.isFinite(
|
|
33335
|
+
const time2 = new Date(value).getTime();
|
|
33336
|
+
return Number.isFinite(time2) ? time2 : null;
|
|
33080
33337
|
}
|
|
33081
33338
|
function safeManifestString(value) {
|
|
33082
33339
|
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
@@ -33095,7 +33352,7 @@ function walkWorkdirs(root) {
|
|
|
33095
33352
|
}
|
|
33096
33353
|
for (const entry of entries) {
|
|
33097
33354
|
if (!entry.isDirectory()) continue;
|
|
33098
|
-
const fullPath =
|
|
33355
|
+
const fullPath = join19(current, entry.name);
|
|
33099
33356
|
if (entry.name === "workdir" && existsSync14(workspaceManifestPath(fullPath))) {
|
|
33100
33357
|
workdirs.push(fullPath);
|
|
33101
33358
|
continue;
|
|
@@ -33127,7 +33384,7 @@ function directorySizeBytes(path) {
|
|
|
33127
33384
|
continue;
|
|
33128
33385
|
}
|
|
33129
33386
|
for (const entry of entries) {
|
|
33130
|
-
stack.push(
|
|
33387
|
+
stack.push(join19(current, entry.name));
|
|
33131
33388
|
}
|
|
33132
33389
|
continue;
|
|
33133
33390
|
}
|
|
@@ -33154,7 +33411,7 @@ function summarizeWorkdir(path, manifest, nowMs) {
|
|
|
33154
33411
|
};
|
|
33155
33412
|
}
|
|
33156
33413
|
function planManagedWorkspaceGcDryRun(input) {
|
|
33157
|
-
const root =
|
|
33414
|
+
const root = resolve14(String(input.root ?? ""));
|
|
33158
33415
|
const now = input.now instanceof Date ? input.now : /* @__PURE__ */ new Date();
|
|
33159
33416
|
const nowMs = now.getTime();
|
|
33160
33417
|
const ttlHours = Math.max(1, Number(input.ttlHours ?? 72));
|
|
@@ -33202,21 +33459,21 @@ function planManagedWorkspaceGcDryRun(input) {
|
|
|
33202
33459
|
import { createHash as createHash17 } from "node:crypto";
|
|
33203
33460
|
import {
|
|
33204
33461
|
accessSync,
|
|
33205
|
-
chmodSync as
|
|
33462
|
+
chmodSync as chmodSync6,
|
|
33206
33463
|
constants as constants4,
|
|
33207
33464
|
existsSync as existsSync15,
|
|
33208
|
-
lstatSync as
|
|
33465
|
+
lstatSync as lstatSync11,
|
|
33209
33466
|
mkdirSync as mkdirSync11,
|
|
33210
|
-
mkdtempSync as
|
|
33211
|
-
readFileSync as
|
|
33467
|
+
mkdtempSync as mkdtempSync4,
|
|
33468
|
+
readFileSync as readFileSync15,
|
|
33212
33469
|
readdirSync as readdirSync9,
|
|
33213
|
-
renameSync as
|
|
33214
|
-
rmSync as
|
|
33470
|
+
renameSync as renameSync9,
|
|
33471
|
+
rmSync as rmSync10,
|
|
33215
33472
|
statSync as statSync9,
|
|
33216
33473
|
unlinkSync as unlinkSync2,
|
|
33217
|
-
writeFileSync as
|
|
33474
|
+
writeFileSync as writeFileSync12
|
|
33218
33475
|
} from "node:fs";
|
|
33219
|
-
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";
|
|
33220
33477
|
import { fileURLToPath } from "node:url";
|
|
33221
33478
|
var PRESET_TEMPLATE_MANIFEST_FILE = ".mirrorx-preset-templates.json";
|
|
33222
33479
|
var MAX_PRESET_TEMPLATE_FILES = 256;
|
|
@@ -33227,7 +33484,7 @@ function sha2562(value) {
|
|
|
33227
33484
|
}
|
|
33228
33485
|
function lstatIfExists(path) {
|
|
33229
33486
|
try {
|
|
33230
|
-
return
|
|
33487
|
+
return lstatSync11(path);
|
|
33231
33488
|
} catch (error) {
|
|
33232
33489
|
if (error?.code === "ENOENT") return null;
|
|
33233
33490
|
throw error;
|
|
@@ -33242,7 +33499,7 @@ function modeAllows(stat, identity, ownerBit, groupBit, otherBit) {
|
|
|
33242
33499
|
function assertCatalogReadableByExecutor(targetDir, fileNames, identity) {
|
|
33243
33500
|
if (!identity) {
|
|
33244
33501
|
accessSync(targetDir, constants4.R_OK | constants4.X_OK);
|
|
33245
|
-
for (const name of fileNames) accessSync(
|
|
33502
|
+
for (const name of fileNames) accessSync(join20(targetDir, name), constants4.R_OK);
|
|
33246
33503
|
return;
|
|
33247
33504
|
}
|
|
33248
33505
|
let current = targetDir;
|
|
@@ -33260,7 +33517,7 @@ function assertCatalogReadableByExecutor(targetDir, fileNames, identity) {
|
|
|
33260
33517
|
throw new Error(`preset_template_executor_catalog_unreadable: ${targetDir}`);
|
|
33261
33518
|
}
|
|
33262
33519
|
for (const name of fileNames) {
|
|
33263
|
-
const path =
|
|
33520
|
+
const path = join20(targetDir, name);
|
|
33264
33521
|
const stat = statSync9(path);
|
|
33265
33522
|
if (!stat.isFile() || !modeAllows(stat, identity, 256, 32, 4)) {
|
|
33266
33523
|
throw new Error(`preset_template_executor_file_unreadable: ${name}`);
|
|
@@ -33276,7 +33533,7 @@ function validTemplateName(value) {
|
|
|
33276
33533
|
}
|
|
33277
33534
|
function readManifest(manifestPath, { strict }) {
|
|
33278
33535
|
try {
|
|
33279
|
-
const parsed = JSON.parse(
|
|
33536
|
+
const parsed = JSON.parse(readFileSync15(manifestPath, "utf8"));
|
|
33280
33537
|
if (parsed?.schemaVersion !== 1 || !Array.isArray(parsed.files)) {
|
|
33281
33538
|
throw new Error("preset_template_bundle_manifest_invalid");
|
|
33282
33539
|
}
|
|
@@ -33304,12 +33561,12 @@ function readManifest(manifestPath, { strict }) {
|
|
|
33304
33561
|
}
|
|
33305
33562
|
function verifiedBundleFiles(sourceDir, manifest) {
|
|
33306
33563
|
return manifest.files.map((entry) => {
|
|
33307
|
-
const sourcePath =
|
|
33308
|
-
const stat =
|
|
33564
|
+
const sourcePath = join20(sourceDir, entry.name);
|
|
33565
|
+
const stat = lstatSync11(sourcePath);
|
|
33309
33566
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
33310
33567
|
throw new Error(`preset_template_bundle_file_unsafe: ${entry.name}`);
|
|
33311
33568
|
}
|
|
33312
|
-
const body =
|
|
33569
|
+
const body = readFileSync15(sourcePath);
|
|
33313
33570
|
if (body.byteLength !== entry.bytes || sha2562(body) !== entry.sha256) {
|
|
33314
33571
|
throw new Error(`preset_template_bundle_digest_mismatch: ${entry.name}`);
|
|
33315
33572
|
}
|
|
@@ -33319,9 +33576,9 @@ function verifiedBundleFiles(sourceDir, manifest) {
|
|
|
33319
33576
|
function removeRetiredPresetFiles(targetDir, previousManifest, nextNames) {
|
|
33320
33577
|
for (const entry of previousManifest.files) {
|
|
33321
33578
|
if (nextNames.has(entry.name)) continue;
|
|
33322
|
-
const targetPath =
|
|
33579
|
+
const targetPath = join20(targetDir, entry.name);
|
|
33323
33580
|
if (!existsSync15(targetPath)) continue;
|
|
33324
|
-
const stat =
|
|
33581
|
+
const stat = lstatSync11(targetPath);
|
|
33325
33582
|
if (stat.isDirectory()) {
|
|
33326
33583
|
throw new Error(`preset_template_target_conflict: ${entry.name}`);
|
|
33327
33584
|
}
|
|
@@ -33329,12 +33586,12 @@ function removeRetiredPresetFiles(targetDir, previousManifest, nextNames) {
|
|
|
33329
33586
|
}
|
|
33330
33587
|
}
|
|
33331
33588
|
function materializeBundledPresetTemplates(input) {
|
|
33332
|
-
const sourceDir =
|
|
33333
|
-
const targetDir =
|
|
33589
|
+
const sourceDir = resolve15(input.sourceDir);
|
|
33590
|
+
const targetDir = resolve15(input.targetDir);
|
|
33334
33591
|
if (sourceDir === targetDir || sourceDir.startsWith(`${targetDir}${sep4}`) || targetDir.startsWith(`${sourceDir}${sep4}`)) {
|
|
33335
33592
|
throw new Error("preset_template_source_target_overlap");
|
|
33336
33593
|
}
|
|
33337
|
-
const manifest = readManifest(
|
|
33594
|
+
const manifest = readManifest(join20(sourceDir, PRESET_TEMPLATE_MANIFEST_FILE), { strict: true });
|
|
33338
33595
|
const verifiedFiles = verifiedBundleFiles(sourceDir, manifest);
|
|
33339
33596
|
mkdirSync11(dirname9(targetDir), { recursive: true, mode: 493 });
|
|
33340
33597
|
const targetStat = lstatIfExists(targetDir);
|
|
@@ -33342,28 +33599,28 @@ function materializeBundledPresetTemplates(input) {
|
|
|
33342
33599
|
throw new Error("preset_template_target_root_unsafe");
|
|
33343
33600
|
}
|
|
33344
33601
|
mkdirSync11(targetDir, { recursive: true, mode: 493 });
|
|
33345
|
-
const previousManifest = readManifest(
|
|
33346
|
-
const stageDir =
|
|
33602
|
+
const previousManifest = readManifest(join20(targetDir, PRESET_TEMPLATE_MANIFEST_FILE), { strict: false });
|
|
33603
|
+
const stageDir = mkdtempSync4(join20(dirname9(targetDir), ".mirrorx-preset-templates-"));
|
|
33347
33604
|
try {
|
|
33348
33605
|
for (const file of verifiedFiles) {
|
|
33349
|
-
const stagedPath =
|
|
33350
|
-
|
|
33351
|
-
|
|
33352
|
-
|
|
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));
|
|
33353
33610
|
}
|
|
33354
33611
|
removeRetiredPresetFiles(targetDir, previousManifest, new Set(manifest.files.map((file) => file.name)));
|
|
33355
|
-
const stagedManifest =
|
|
33356
|
-
|
|
33612
|
+
const stagedManifest = join20(stageDir, PRESET_TEMPLATE_MANIFEST_FILE);
|
|
33613
|
+
writeFileSync12(stagedManifest, `${JSON.stringify({
|
|
33357
33614
|
schemaVersion: manifest.schemaVersion,
|
|
33358
33615
|
files: manifest.files
|
|
33359
33616
|
}, null, 2)}
|
|
33360
33617
|
`, { mode: 292 });
|
|
33361
|
-
|
|
33362
|
-
|
|
33618
|
+
chmodSync6(stagedManifest, 292);
|
|
33619
|
+
renameSync9(stagedManifest, join20(targetDir, PRESET_TEMPLATE_MANIFEST_FILE));
|
|
33363
33620
|
} finally {
|
|
33364
|
-
|
|
33621
|
+
rmSync10(stageDir, { recursive: true, force: true });
|
|
33365
33622
|
}
|
|
33366
|
-
|
|
33623
|
+
chmodSync6(targetDir, 493);
|
|
33367
33624
|
return {
|
|
33368
33625
|
fileCount: manifest.files.length,
|
|
33369
33626
|
totalBytes: manifest.totalBytes,
|
|
@@ -33376,12 +33633,12 @@ function materializeRuntimePresetTemplates(input) {
|
|
|
33376
33633
|
sourceDir,
|
|
33377
33634
|
targetDir: input.targetDir
|
|
33378
33635
|
});
|
|
33379
|
-
const manifestBody =
|
|
33380
|
-
|
|
33636
|
+
const manifestBody = readFileSync15(
|
|
33637
|
+
join20(materialized.targetDir, PRESET_TEMPLATE_MANIFEST_FILE)
|
|
33381
33638
|
);
|
|
33382
33639
|
const manifest = JSON.parse(manifestBody.toString("utf8"));
|
|
33383
33640
|
for (const file of manifest.files) {
|
|
33384
|
-
const body =
|
|
33641
|
+
const body = readFileSync15(join20(materialized.targetDir, file.name));
|
|
33385
33642
|
if (sha2562(body) !== file.sha256) {
|
|
33386
33643
|
throw new Error(`preset_template_materialized_digest_mismatch: ${file.name}`);
|
|
33387
33644
|
}
|
|
@@ -33405,7 +33662,7 @@ function materializeRuntimePresetTemplates(input) {
|
|
|
33405
33662
|
|
|
33406
33663
|
// src/amaster-runtime-daemon/runtime-status-summary.mjs
|
|
33407
33664
|
import { existsSync as existsSync16, readdirSync as readdirSync10, statSync as statSync10 } from "node:fs";
|
|
33408
|
-
import { dirname as dirname10, join as
|
|
33665
|
+
import { dirname as dirname10, join as join21, resolve as resolve16 } from "node:path";
|
|
33409
33666
|
function runtimeStatusDirectoryEntries(path) {
|
|
33410
33667
|
try {
|
|
33411
33668
|
return readdirSync10(path, { withFileTypes: true });
|
|
@@ -33428,7 +33685,7 @@ function runtimeStatusDirectorySizeBytes(path) {
|
|
|
33428
33685
|
if (!stat || stat.isSymbolicLink()) continue;
|
|
33429
33686
|
if (stat.isDirectory()) {
|
|
33430
33687
|
for (const entry of runtimeStatusDirectoryEntries(current)) {
|
|
33431
|
-
stack.push(
|
|
33688
|
+
stack.push(join21(current, entry.name));
|
|
33432
33689
|
}
|
|
33433
33690
|
continue;
|
|
33434
33691
|
}
|
|
@@ -33445,7 +33702,7 @@ function walkRuntimeStatusManagedWorkdirs(root) {
|
|
|
33445
33702
|
if (!current) continue;
|
|
33446
33703
|
for (const entry of runtimeStatusDirectoryEntries(current)) {
|
|
33447
33704
|
if (!entry.isDirectory()) continue;
|
|
33448
|
-
const fullPath =
|
|
33705
|
+
const fullPath = join21(current, entry.name);
|
|
33449
33706
|
if (entry.name === "workdir" && existsSync16(workspaceManifestPath(fullPath))) {
|
|
33450
33707
|
workdirs.push(fullPath);
|
|
33451
33708
|
continue;
|
|
@@ -33457,8 +33714,8 @@ function walkRuntimeStatusManagedWorkdirs(root) {
|
|
|
33457
33714
|
}
|
|
33458
33715
|
function readRuntimeStatusIsoTime(value) {
|
|
33459
33716
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
33460
|
-
const
|
|
33461
|
-
return Number.isFinite(
|
|
33717
|
+
const time2 = Date.parse(value);
|
|
33718
|
+
return Number.isFinite(time2) ? time2 : null;
|
|
33462
33719
|
}
|
|
33463
33720
|
function readRuntimeStatusString(value) {
|
|
33464
33721
|
return typeof value === "string" && value.trim() ? value : null;
|
|
@@ -33487,15 +33744,15 @@ function summarizeRuntimeStatusRecentRun(workdir, manifest) {
|
|
|
33487
33744
|
}
|
|
33488
33745
|
function runtimeStatusOutboxDir(config) {
|
|
33489
33746
|
const statePath = config.AMASTER_DAEMON_STATE_FILE ?? config.daemonStateFile;
|
|
33490
|
-
return
|
|
33747
|
+
return join21(dirname10(stateFilePath({
|
|
33491
33748
|
AMASTER_DAEMON_STATE_FILE: statePath
|
|
33492
33749
|
})), "result-outbox");
|
|
33493
33750
|
}
|
|
33494
33751
|
function runtimeStatusRunCompletionDir(config) {
|
|
33495
33752
|
const explicit = config.AMASTER_RUN_COMPLETION_STATE_DIR ?? config.runCompletionStateDir;
|
|
33496
|
-
if (typeof explicit === "string" && explicit.trim()) return
|
|
33753
|
+
if (typeof explicit === "string" && explicit.trim()) return resolve16(explicit);
|
|
33497
33754
|
const statePath = config.AMASTER_DAEMON_STATE_FILE ?? config.daemonStateFile;
|
|
33498
|
-
return
|
|
33755
|
+
return join21(dirname10(stateFilePath({
|
|
33499
33756
|
AMASTER_DAEMON_STATE_FILE: statePath
|
|
33500
33757
|
})), "run-completion-state");
|
|
33501
33758
|
}
|
|
@@ -33505,7 +33762,7 @@ function countRuntimeStatusJsonEntries(dir) {
|
|
|
33505
33762
|
}
|
|
33506
33763
|
function summarizeRuntimeLocalState(input) {
|
|
33507
33764
|
const config = input.config ?? {};
|
|
33508
|
-
const root =
|
|
33765
|
+
const root = resolve16(String(config.AMASTER_RUNTIME_WORKSPACES_ROOT ?? config.runtimeWorkspacesRoot ?? input.runtimeWorkspacesRoot ?? ""));
|
|
33509
33766
|
const now = input.now instanceof Date ? input.now : /* @__PURE__ */ new Date();
|
|
33510
33767
|
const workdirs = walkRuntimeStatusManagedWorkdirs(root);
|
|
33511
33768
|
let managedWorkdirBytes = 0;
|
|
@@ -33532,9 +33789,9 @@ function summarizeRuntimeLocalState(input) {
|
|
|
33532
33789
|
}
|
|
33533
33790
|
}
|
|
33534
33791
|
const pendingOutboxDir = runtimeStatusOutboxDir(config);
|
|
33535
|
-
const invalidOutboxDir =
|
|
33792
|
+
const invalidOutboxDir = join21(pendingOutboxDir, "invalid");
|
|
33536
33793
|
const pendingRunCompletionDir = runtimeStatusRunCompletionDir(config);
|
|
33537
|
-
const invalidRunCompletionDir =
|
|
33794
|
+
const invalidRunCompletionDir = join21(pendingRunCompletionDir, "invalid");
|
|
33538
33795
|
return {
|
|
33539
33796
|
managedWorkspacesRoot: root,
|
|
33540
33797
|
managedWorkdirCount: workdirs.length,
|
|
@@ -33656,7 +33913,7 @@ function summarizeAmasterRuntimeVersionDrift(input = {}) {
|
|
|
33656
33913
|
}
|
|
33657
33914
|
|
|
33658
33915
|
// src/amaster-runtime-daemon/pi-context-budget.mjs
|
|
33659
|
-
import { readFileSync as
|
|
33916
|
+
import { readFileSync as readFileSync16 } from "node:fs";
|
|
33660
33917
|
var CONTEXT_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
33661
33918
|
"context_effective_tool_schema_attestation_mismatch",
|
|
33662
33919
|
"context_output_reserve_exceeds_model_limit",
|
|
@@ -33771,7 +34028,7 @@ function measureRestoredPiNativeHistory(managedMcpProfile) {
|
|
|
33771
34028
|
if (!rolloutPath) {
|
|
33772
34029
|
return { status: "fresh", tokens: 0, rolloutBytes: 0, usageTokens: 0 };
|
|
33773
34030
|
}
|
|
33774
|
-
const rollout =
|
|
34031
|
+
const rollout = readFileSync16(rolloutPath);
|
|
33775
34032
|
const maximumRolloutBytes = 64 * 1024 * 1024;
|
|
33776
34033
|
if (rollout.byteLength > maximumRolloutBytes) {
|
|
33777
34034
|
throw stableContextError(
|
|
@@ -33865,8 +34122,8 @@ function resolvePiModelContextBudget({
|
|
|
33865
34122
|
}
|
|
33866
34123
|
|
|
33867
34124
|
// src/amaster-runtime-daemon/pi-project-instruction-extension.mjs
|
|
33868
|
-
import { lstatSync as
|
|
33869
|
-
import { resolve as
|
|
34125
|
+
import { lstatSync as lstatSync12, readFileSync as readFileSync17 } from "node:fs";
|
|
34126
|
+
import { resolve as resolve17 } from "node:path";
|
|
33870
34127
|
var MANAGED_PI_PROJECT_INSTRUCTION_FILENAME = "amaster-project-instructions.js";
|
|
33871
34128
|
function requiredString4(value, name) {
|
|
33872
34129
|
if (typeof value !== "string" || !value.trim()) {
|
|
@@ -33875,12 +34132,12 @@ function requiredString4(value, name) {
|
|
|
33875
34132
|
return value.trim();
|
|
33876
34133
|
}
|
|
33877
34134
|
function managedPiProjectInstructionExtensionSource(input) {
|
|
33878
|
-
const projectInstructionPath =
|
|
33879
|
-
const stat =
|
|
34135
|
+
const projectInstructionPath = resolve17(requiredString4(input.projectInstructionPath, "projectInstructionPath"));
|
|
34136
|
+
const stat = lstatSync12(projectInstructionPath);
|
|
33880
34137
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
33881
34138
|
throw new Error("pi_project_instruction_extension_invalid: unsafe projectInstructionPath");
|
|
33882
34139
|
}
|
|
33883
|
-
const projectInstructions =
|
|
34140
|
+
const projectInstructions = readFileSync17(projectInstructionPath, "utf8");
|
|
33884
34141
|
return String.raw`const PROJECT_INSTRUCTIONS = ${JSON.stringify(projectInstructions.trim())};
|
|
33885
34142
|
|
|
33886
34143
|
export default function amasterProjectInstructions(pi) {
|
|
@@ -33895,8 +34152,8 @@ export default function amasterProjectInstructions(pi) {
|
|
|
33895
34152
|
// src/amaster-runtime-daemon/workspace-status.mjs
|
|
33896
34153
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
33897
34154
|
import { createHash as createHash18 } from "node:crypto";
|
|
33898
|
-
import { existsSync as existsSync17, readdirSync as readdirSync11, readFileSync as
|
|
33899
|
-
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";
|
|
33900
34157
|
var WORKSPACE_RUNTIME_SERVICES_FILENAME = ".amaster-runtime-services.json";
|
|
33901
34158
|
var ARTIFACT_EXTENSIONS = /* @__PURE__ */ new Map([
|
|
33902
34159
|
[".md", "markdown"],
|
|
@@ -33965,35 +34222,35 @@ function sanitizeTrackedChange(line) {
|
|
|
33965
34222
|
return isSafeRelativePath(path) ? line : null;
|
|
33966
34223
|
}
|
|
33967
34224
|
function sha256File(filePath) {
|
|
33968
|
-
return createHash18("sha256").update(
|
|
34225
|
+
return createHash18("sha256").update(readFileSync18(filePath)).digest("hex");
|
|
33969
34226
|
}
|
|
33970
34227
|
function artifactHashCacheKey(relativePath, stat) {
|
|
33971
34228
|
return `${relativePath}\0${stat.size}\0${stat.mtimeMs}`;
|
|
33972
34229
|
}
|
|
33973
34230
|
function artifactSha256(filePath, relativePath, stat, opts = {}) {
|
|
33974
|
-
const
|
|
34231
|
+
const cache2 = opts.hashCache;
|
|
33975
34232
|
const key = artifactHashCacheKey(relativePath, stat);
|
|
33976
|
-
if (
|
|
33977
|
-
const cached =
|
|
33978
|
-
|
|
33979
|
-
|
|
34233
|
+
if (cache2?.has(key)) {
|
|
34234
|
+
const cached = cache2.get(key);
|
|
34235
|
+
cache2.delete(key);
|
|
34236
|
+
cache2.set(key, cached);
|
|
33980
34237
|
return cached;
|
|
33981
34238
|
}
|
|
33982
34239
|
const hashFile = typeof opts.hashFile === "function" ? opts.hashFile : sha256File;
|
|
33983
34240
|
const hash3 = hashFile(filePath);
|
|
33984
|
-
if (
|
|
33985
|
-
|
|
34241
|
+
if (cache2) {
|
|
34242
|
+
cache2.set(key, hash3);
|
|
33986
34243
|
const maxEntries = Math.max(0, Number(opts.hashCacheMaxEntries ?? MAX_HASH_CACHE_ENTRIES) || 0);
|
|
33987
|
-
while (maxEntries > 0 &&
|
|
33988
|
-
const oldestKey =
|
|
33989
|
-
|
|
34244
|
+
while (maxEntries > 0 && cache2.size > maxEntries) {
|
|
34245
|
+
const oldestKey = cache2.keys().next().value;
|
|
34246
|
+
cache2.delete(oldestKey);
|
|
33990
34247
|
}
|
|
33991
|
-
if (maxEntries === 0)
|
|
34248
|
+
if (maxEntries === 0) cache2.clear();
|
|
33992
34249
|
}
|
|
33993
34250
|
return hash3;
|
|
33994
34251
|
}
|
|
33995
34252
|
function scanArtifactCandidates(cwd, opts = {}) {
|
|
33996
|
-
const root =
|
|
34253
|
+
const root = resolve18(cwd);
|
|
33997
34254
|
const maxCandidates = opts.maxCandidates ?? MAX_CANDIDATES;
|
|
33998
34255
|
const maxEntries = opts.maxEntries ?? MAX_SCAN_ENTRIES;
|
|
33999
34256
|
const candidates = [];
|
|
@@ -34014,7 +34271,7 @@ function scanArtifactCandidates(cwd, opts = {}) {
|
|
|
34014
34271
|
if (entry.name.startsWith(".") && entry.name !== ".amaster-runtime.json") {
|
|
34015
34272
|
if (entry.name === ".git") continue;
|
|
34016
34273
|
}
|
|
34017
|
-
const fullPath =
|
|
34274
|
+
const fullPath = join22(current, entry.name);
|
|
34018
34275
|
const relativePath = normalizeRelativePath(root, fullPath);
|
|
34019
34276
|
if (!isSafeRelativePath(relativePath)) continue;
|
|
34020
34277
|
if (basename7(relativePath) === ".amaster-runtime.json") continue;
|
|
@@ -34032,7 +34289,7 @@ function scanArtifactCandidates(cwd, opts = {}) {
|
|
|
34032
34289
|
} catch {
|
|
34033
34290
|
continue;
|
|
34034
34291
|
}
|
|
34035
|
-
if (!statusPathWithin(
|
|
34292
|
+
if (!statusPathWithin(resolve18(fullPath), root) || stat.size > MAX_HASH_BYTES) continue;
|
|
34036
34293
|
candidates.push({
|
|
34037
34294
|
relativePath,
|
|
34038
34295
|
name: basename7(fullPath),
|
|
@@ -34092,10 +34349,10 @@ function sanitizeRuntimeService(entry) {
|
|
|
34092
34349
|
};
|
|
34093
34350
|
}
|
|
34094
34351
|
function readRuntimeServicesSnapshot(cwd) {
|
|
34095
|
-
const snapshotPath =
|
|
34352
|
+
const snapshotPath = join22(resolve18(cwd), WORKSPACE_RUNTIME_SERVICES_FILENAME);
|
|
34096
34353
|
if (!existsSync17(snapshotPath)) return [];
|
|
34097
34354
|
try {
|
|
34098
|
-
const parsed = JSON.parse(
|
|
34355
|
+
const parsed = JSON.parse(readFileSync18(snapshotPath, "utf8"));
|
|
34099
34356
|
const rawServices = Array.isArray(parsed) ? parsed : Array.isArray(parsed?.services) ? parsed.services : [];
|
|
34100
34357
|
return rawServices.map((entry) => sanitizeRuntimeService(entry)).filter((entry) => entry !== null).slice(0, 50);
|
|
34101
34358
|
} catch {
|
|
@@ -34197,7 +34454,7 @@ function assertRequiredTaskAttachmentMaterialized(input, materialized) {
|
|
|
34197
34454
|
}
|
|
34198
34455
|
|
|
34199
34456
|
// src/amaster-runtime-daemon.mjs
|
|
34200
|
-
var CONNECTOR_VERSION = "0.1.
|
|
34457
|
+
var CONNECTOR_VERSION = "0.1.3";
|
|
34201
34458
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
34202
34459
|
var SUPPORTED_TASK_CONTEXT_VERSIONS = Object.freeze([TASK_CONTEXT_MANIFEST_VERSION, TASK_CONTEXT_V2]);
|
|
34203
34460
|
var daemonRequire = createRequire(import.meta.url);
|
|
@@ -34269,12 +34526,12 @@ function notifyDaemonLoop() {
|
|
|
34269
34526
|
}
|
|
34270
34527
|
function waitForDaemonLoop(timeoutMs, observedVersion) {
|
|
34271
34528
|
if (daemonLoopWakeVersion !== observedVersion) return Promise.resolve();
|
|
34272
|
-
return new Promise((
|
|
34529
|
+
return new Promise((resolve20) => {
|
|
34273
34530
|
const finish = () => {
|
|
34274
34531
|
clearTimeout(timer);
|
|
34275
34532
|
if (wakeDaemonLoop === finish) wakeDaemonLoop = () => {
|
|
34276
34533
|
};
|
|
34277
|
-
|
|
34534
|
+
resolve20();
|
|
34278
34535
|
};
|
|
34279
34536
|
const timer = setTimeout(finish, timeoutMs);
|
|
34280
34537
|
wakeDaemonLoop = finish;
|
|
@@ -34297,7 +34554,7 @@ function resultOutboxPendingCount(config) {
|
|
|
34297
34554
|
try {
|
|
34298
34555
|
let pending = 0;
|
|
34299
34556
|
for (const file of readdirSync12(dir).filter((name) => name.endsWith(".json"))) {
|
|
34300
|
-
if (readValidResultOutboxEntryOrQuarantine(config, file,
|
|
34557
|
+
if (readValidResultOutboxEntryOrQuarantine(config, file, join23(dir, file))) {
|
|
34301
34558
|
pending += 1;
|
|
34302
34559
|
}
|
|
34303
34560
|
}
|
|
@@ -34308,18 +34565,18 @@ function resultOutboxPendingCount(config) {
|
|
|
34308
34565
|
}
|
|
34309
34566
|
function runCompletionStateDir(config) {
|
|
34310
34567
|
const explicit = readString(process.env.AMASTER_RUN_COMPLETION_STATE_DIR);
|
|
34311
|
-
if (explicit) return
|
|
34312
|
-
return
|
|
34568
|
+
if (explicit) return resolve19(expandHomePath(explicit));
|
|
34569
|
+
return join23(dirname11(stateFilePath(process.env)), "run-completion-state");
|
|
34313
34570
|
}
|
|
34314
34571
|
function runCompletionStateInvalidDir(config) {
|
|
34315
|
-
return
|
|
34572
|
+
return join23(runCompletionStateDir(config), "invalid");
|
|
34316
34573
|
}
|
|
34317
34574
|
function quarantineInvalidRunCompletionState(config, filePath, reason) {
|
|
34318
34575
|
const invalidDir = runCompletionStateInvalidDir(config);
|
|
34319
34576
|
mkdirSync12(invalidDir, { recursive: true, mode: 448 });
|
|
34320
|
-
const destination =
|
|
34577
|
+
const destination = join23(invalidDir, basename8(filePath));
|
|
34321
34578
|
try {
|
|
34322
|
-
|
|
34579
|
+
renameSync10(filePath, destination);
|
|
34323
34580
|
} catch {
|
|
34324
34581
|
copyFileSync2(filePath, destination);
|
|
34325
34582
|
unlinkSync3(filePath);
|
|
@@ -34375,7 +34632,7 @@ function resultOutboxActiveRunCommands(config) {
|
|
|
34375
34632
|
const outboxPending = resultOutboxPendingCount(config);
|
|
34376
34633
|
const entries = [];
|
|
34377
34634
|
for (const file of readdirSync12(dir).filter((name) => name.endsWith(".json")).sort()) {
|
|
34378
|
-
const entry = readValidResultOutboxEntryOrQuarantine(config, file,
|
|
34635
|
+
const entry = readValidResultOutboxEntryOrQuarantine(config, file, join23(dir, file));
|
|
34379
34636
|
if (!entry) continue;
|
|
34380
34637
|
const activeRun = asRecord(entry.activeRun);
|
|
34381
34638
|
const commandId = readString(activeRun.commandId) ?? readString(entry.commandId);
|
|
@@ -34411,7 +34668,7 @@ function resultOutboxFailedRunCommands(config) {
|
|
|
34411
34668
|
for (const file of readdirSync12(dir).filter((name) => name.endsWith(".json")).sort().slice(-100)) {
|
|
34412
34669
|
let entry;
|
|
34413
34670
|
try {
|
|
34414
|
-
entry = asRecord(JSON.parse(
|
|
34671
|
+
entry = asRecord(JSON.parse(readFileSync19(join23(dir, file), "utf8")));
|
|
34415
34672
|
} catch {
|
|
34416
34673
|
continue;
|
|
34417
34674
|
}
|
|
@@ -34474,11 +34731,11 @@ function piExtraArgsDiagnostics(value) {
|
|
|
34474
34731
|
}
|
|
34475
34732
|
function safeExpandPath(value) {
|
|
34476
34733
|
const text2 = readString(value);
|
|
34477
|
-
return text2 ?
|
|
34734
|
+
return text2 ? resolve19(expandHomePath(text2)) : null;
|
|
34478
34735
|
}
|
|
34479
34736
|
function safeJsonObjectFromFile(filePath) {
|
|
34480
34737
|
try {
|
|
34481
|
-
const parsed = JSON.parse(
|
|
34738
|
+
const parsed = JSON.parse(readFileSync19(filePath, "utf8"));
|
|
34482
34739
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
34483
34740
|
} catch {
|
|
34484
34741
|
return null;
|
|
@@ -34521,10 +34778,10 @@ function safeSkillRootSummary(kind, source, pathValue) {
|
|
|
34521
34778
|
try {
|
|
34522
34779
|
for (const name of readdirSync12(pathValue)) {
|
|
34523
34780
|
if (name.startsWith(".")) continue;
|
|
34524
|
-
const skillDir =
|
|
34781
|
+
const skillDir = join23(pathValue, name);
|
|
34525
34782
|
try {
|
|
34526
34783
|
if (!statSync12(skillDir).isDirectory()) continue;
|
|
34527
|
-
if (!existsSync18(
|
|
34784
|
+
if (!existsSync18(join23(skillDir, "SKILL.md"))) continue;
|
|
34528
34785
|
skillCount += 1;
|
|
34529
34786
|
if (skillCount >= MAX_PI_CAPABILITY_SOURCE_ENTRIES) {
|
|
34530
34787
|
truncated = true;
|
|
@@ -34575,7 +34832,7 @@ function objectKeyCount(value) {
|
|
|
34575
34832
|
return value && typeof value === "object" && !Array.isArray(value) ? Object.keys(value).length : 0;
|
|
34576
34833
|
}
|
|
34577
34834
|
function defaultPiCodingAgentDir() {
|
|
34578
|
-
return
|
|
34835
|
+
return join23(homedir6(), ".pi", "agent");
|
|
34579
34836
|
}
|
|
34580
34837
|
function piCapabilitySourcesDiagnostics() {
|
|
34581
34838
|
const configuredPiCodingAgentDir = safeExpandPath(process.env.PI_CODING_AGENT_DIR);
|
|
@@ -34584,14 +34841,14 @@ function piCapabilitySourcesDiagnostics() {
|
|
|
34584
34841
|
const configuredPiAgentHome = safeExpandPath(process.env.PI_AGENT_HOME);
|
|
34585
34842
|
const piAgentHome = configuredPiAgentHome ?? piCodingAgentDir;
|
|
34586
34843
|
const piAgentHomeSource = configuredPiAgentHome ? "PI_AGENT_HOME" : piCodingAgentDirSource;
|
|
34587
|
-
const userSkillsPath = piAgentHome ?
|
|
34844
|
+
const userSkillsPath = piAgentHome ? join23(piAgentHome, "skills") : null;
|
|
34588
34845
|
const configuredMarketplaceSkillsPath = safeExpandPath(
|
|
34589
34846
|
process.env.PI_AGENT_MARKETPLACE_SKILLS_DIR
|
|
34590
34847
|
);
|
|
34591
|
-
const marketplaceSkillsPath = configuredMarketplaceSkillsPath ?? (piAgentHome ?
|
|
34848
|
+
const marketplaceSkillsPath = configuredMarketplaceSkillsPath ?? (piAgentHome ? join23(piAgentHome, "marketplace", "skills") : null);
|
|
34592
34849
|
const builtinSkillsPath = safeExpandPath(process.env.PI_AGENT_BUILTIN_SKILLS_DIR) ?? safeExpandPath(process.env.AMASTER_BUILTIN_SKILLS);
|
|
34593
|
-
const mcpConfigPath = safeExpandPath(process.env.PI_AGENT_MCP_SERVERS_FILE) ?? (piAgentHome ?
|
|
34594
|
-
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;
|
|
34595
34852
|
const skillRoots = [
|
|
34596
34853
|
safeSkillRootSummary("user", `${piAgentHomeSource}/skills`, userSkillsPath),
|
|
34597
34854
|
safeSkillRootSummary(
|
|
@@ -34748,9 +35005,13 @@ function runtimeAdvertisedCapabilities(config) {
|
|
|
34748
35005
|
templateCatalog: config.templateCatalog,
|
|
34749
35006
|
runtimeTemplatesRoot: config.runtimeTemplatesRoot,
|
|
34750
35007
|
runnerKind: config.runnerKind,
|
|
35008
|
+
piExecutorUid: config.piExecutorUid,
|
|
35009
|
+
piExecutorGid: config.piExecutorGid,
|
|
35010
|
+
connectorUid: typeof process.getuid === "function" ? process.getuid() : null,
|
|
34751
35011
|
checkpointUploadEnabled: config.checkpointUploadEnabled,
|
|
34752
35012
|
executors: config.executors,
|
|
34753
|
-
browserCredentialAuth: inspectBrowserCredentialAuthReadiness()
|
|
35013
|
+
browserCredentialAuth: inspectBrowserCredentialAuthReadiness(),
|
|
35014
|
+
browserCredentialEnv: inspectBrowserCredentialEnvReadiness()
|
|
34754
35015
|
});
|
|
34755
35016
|
}
|
|
34756
35017
|
function buildRegisterPayload(config) {
|
|
@@ -34883,25 +35144,25 @@ function materializePiRuntimeSystemPrompt(config, promptRoot, commandId, content
|
|
|
34883
35144
|
const normalizedCommandId = readString(commandId);
|
|
34884
35145
|
if (!normalizedCommandId) throw new Error("pi_runtime_system_prompt_command_id_missing");
|
|
34885
35146
|
const promptIdentity = createHash19("sha256").update(normalizedCommandId).digest("hex");
|
|
34886
|
-
const promptDir =
|
|
35147
|
+
const promptDir = join23(promptRoot, "tmp");
|
|
34887
35148
|
mkdirSync12(promptDir, { recursive: true, mode: 448 });
|
|
34888
|
-
const promptDirStat =
|
|
35149
|
+
const promptDirStat = lstatSync13(promptDir);
|
|
34889
35150
|
if (!promptDirStat.isDirectory() || promptDirStat.isSymbolicLink()) {
|
|
34890
35151
|
throw new Error("pi_runtime_system_prompt_directory_invalid");
|
|
34891
35152
|
}
|
|
34892
|
-
|
|
34893
|
-
const promptPath =
|
|
34894
|
-
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`);
|
|
34895
35156
|
try {
|
|
34896
|
-
|
|
34897
|
-
|
|
34898
|
-
|
|
35157
|
+
writeFileSync13(temporaryPath, contents, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
35158
|
+
renameSync10(temporaryPath, promptPath);
|
|
35159
|
+
chmodSync7(promptPath, 384);
|
|
34899
35160
|
const promptMode = statSync12(promptPath).mode & 511;
|
|
34900
35161
|
if (promptMode !== 384) {
|
|
34901
35162
|
throw new Error(`pi_runtime_system_prompt_permissions_failed: mode=${promptMode.toString(8)}`);
|
|
34902
35163
|
}
|
|
34903
35164
|
} finally {
|
|
34904
|
-
|
|
35165
|
+
rmSync11(temporaryPath, { force: true });
|
|
34905
35166
|
}
|
|
34906
35167
|
handoffPiRunPathsToChild(config, [promptDir, promptPath]);
|
|
34907
35168
|
return promptPath;
|
|
@@ -35067,7 +35328,7 @@ AMASTER_MACHINE_ID=${quoteShell(config.machineId)}
|
|
|
35067
35328
|
AMASTER_WORKSPACE_ALLOWLIST=${quoteShell(config.workspaceBindings.join(","))}
|
|
35068
35329
|
AMASTER_EXECUTORS=${quoteShell(executorEnv)}
|
|
35069
35330
|
AMASTER_NETWORK_DOMAINS=${quoteShell(config.networkDomains.join(","))}
|
|
35070
|
-
AMASTER_DAEMON_STATE_FILE=${quoteShell(
|
|
35331
|
+
AMASTER_DAEMON_STATE_FILE=${quoteShell(join23(homedir6(), ".amaster-employee", "runtime-connector-state.json"))}
|
|
35071
35332
|
EOF
|
|
35072
35333
|
|
|
35073
35334
|
set -a
|
|
@@ -35544,24 +35805,24 @@ function browserSessionProfileIdentity(config, session) {
|
|
|
35544
35805
|
}
|
|
35545
35806
|
function ensureBrowserSessionProfile(config, session) {
|
|
35546
35807
|
const identity = browserSessionProfileIdentity(config, session);
|
|
35547
|
-
const profileRoot =
|
|
35808
|
+
const profileRoot = resolve19(config.browserSessionStateRoot);
|
|
35548
35809
|
mkdirSync12(profileRoot, { recursive: true, mode: 448 });
|
|
35549
|
-
if (
|
|
35810
|
+
if (lstatSync13(profileRoot).isSymbolicLink() || !lstatSync13(profileRoot).isDirectory()) {
|
|
35550
35811
|
throw new Error("browser_session_profile_path_invalid");
|
|
35551
35812
|
}
|
|
35552
|
-
|
|
35553
|
-
const userDataDir =
|
|
35813
|
+
chmodSync7(profileRoot, 448);
|
|
35814
|
+
const userDataDir = resolve19(profileRoot, identity.localOpaqueRef);
|
|
35554
35815
|
if (!pathWithin3(userDataDir, profileRoot)) {
|
|
35555
35816
|
throw new Error("browser_session_profile_path_invalid");
|
|
35556
35817
|
}
|
|
35557
35818
|
mkdirSync12(userDataDir, { recursive: true, mode: 448 });
|
|
35558
|
-
if (
|
|
35819
|
+
if (lstatSync13(userDataDir).isSymbolicLink() || !lstatSync13(userDataDir).isDirectory()) {
|
|
35559
35820
|
throw new Error("browser_session_profile_path_invalid");
|
|
35560
35821
|
}
|
|
35561
|
-
|
|
35562
|
-
const markerPath =
|
|
35822
|
+
chmodSync7(userDataDir, 448);
|
|
35823
|
+
const markerPath = join23(userDataDir, BROWSER_SESSION_PROFILE_OWNER_MARKER);
|
|
35563
35824
|
if (existsSync18(markerPath)) {
|
|
35564
|
-
if (
|
|
35825
|
+
if (lstatSync13(markerPath).isSymbolicLink()) {
|
|
35565
35826
|
throw new Error("browser_session_profile_identity_invalid");
|
|
35566
35827
|
}
|
|
35567
35828
|
const existing = readJsonFile2(markerPath);
|
|
@@ -35569,41 +35830,41 @@ function ensureBrowserSessionProfile(config, session) {
|
|
|
35569
35830
|
throw new Error("browser_session_profile_identity_invalid");
|
|
35570
35831
|
}
|
|
35571
35832
|
} else {
|
|
35572
|
-
const temporaryPath =
|
|
35833
|
+
const temporaryPath = join23(
|
|
35573
35834
|
userDataDir,
|
|
35574
35835
|
`.${BROWSER_SESSION_PROFILE_OWNER_MARKER}.${process.pid}.${createHash19("sha256").update(randomUUID2()).digest("hex")}`
|
|
35575
35836
|
);
|
|
35576
|
-
|
|
35837
|
+
writeFileSync13(temporaryPath, `${JSON.stringify(identity)}
|
|
35577
35838
|
`, { mode: 384, flag: "wx" });
|
|
35578
|
-
|
|
35839
|
+
renameSync10(temporaryPath, markerPath);
|
|
35579
35840
|
}
|
|
35580
|
-
|
|
35841
|
+
chmodSync7(markerPath, 384);
|
|
35581
35842
|
return { profileRoot, userDataDir, identity };
|
|
35582
35843
|
}
|
|
35583
35844
|
function cleanupBrowserSessionProfile(config, value) {
|
|
35584
35845
|
const identity = browserSessionProfileIdentity(config, value);
|
|
35585
|
-
const profileRoot =
|
|
35586
|
-
const userDataDir =
|
|
35846
|
+
const profileRoot = resolve19(config.browserSessionStateRoot);
|
|
35847
|
+
const userDataDir = resolve19(profileRoot, identity.localOpaqueRef);
|
|
35587
35848
|
if (!pathWithin3(userDataDir, profileRoot)) {
|
|
35588
35849
|
throw new Error("browser_session_profile_cleanup_invalid");
|
|
35589
35850
|
}
|
|
35590
35851
|
if (!existsSync18(userDataDir)) return { outcome: "absent", identity };
|
|
35591
|
-
if (
|
|
35852
|
+
if (lstatSync13(userDataDir).isSymbolicLink() || !lstatSync13(userDataDir).isDirectory()) {
|
|
35592
35853
|
throw new Error("browser_session_profile_cleanup_invalid");
|
|
35593
35854
|
}
|
|
35594
|
-
const markerPath =
|
|
35595
|
-
if (!existsSync18(markerPath) ||
|
|
35855
|
+
const markerPath = join23(userDataDir, BROWSER_SESSION_PROFILE_OWNER_MARKER);
|
|
35856
|
+
if (!existsSync18(markerPath) || lstatSync13(markerPath).isSymbolicLink()) {
|
|
35596
35857
|
throw new Error("browser_session_profile_cleanup_invalid");
|
|
35597
35858
|
}
|
|
35598
35859
|
if (JSON.stringify(readJsonFile2(markerPath)) !== JSON.stringify(identity)) {
|
|
35599
35860
|
throw new Error("browser_session_profile_cleanup_invalid");
|
|
35600
35861
|
}
|
|
35601
|
-
|
|
35862
|
+
rmSync11(userDataDir, { recursive: true, force: false });
|
|
35602
35863
|
return { outcome: "deleted", identity };
|
|
35603
35864
|
}
|
|
35604
35865
|
function readJsonFile2(filePath) {
|
|
35605
35866
|
try {
|
|
35606
|
-
const parsed = JSON.parse(
|
|
35867
|
+
const parsed = JSON.parse(readFileSync19(filePath, "utf8"));
|
|
35607
35868
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
35608
35869
|
} catch {
|
|
35609
35870
|
return {};
|
|
@@ -35614,8 +35875,8 @@ function syncPiExecutorProviderConfig(config, agentDir, providerConfig) {
|
|
|
35614
35875
|
const { modelsSynced, settingsSynced } = syncAmasterProviderFiles(agentDir, providerConfig);
|
|
35615
35876
|
if (!modelsSynced && !settingsSynced) return null;
|
|
35616
35877
|
handoffPiRunPathsToChild(config, [
|
|
35617
|
-
modelsSynced ?
|
|
35618
|
-
settingsSynced ?
|
|
35878
|
+
modelsSynced ? join23(agentDir, "models.json") : null,
|
|
35879
|
+
settingsSynced ? join23(agentDir, "settings.json") : null
|
|
35619
35880
|
]);
|
|
35620
35881
|
return { modelsSynced, settingsSynced };
|
|
35621
35882
|
}
|
|
@@ -35646,7 +35907,7 @@ function safeAgentInstructionMaterializationTarget(workspace, filePath) {
|
|
|
35646
35907
|
const segments = normalized.split("/").filter(Boolean);
|
|
35647
35908
|
if (segments.length === 0 || segments.some((segment) => segment === "." || segment === "..")) return null;
|
|
35648
35909
|
const relativePath = segments.join("/");
|
|
35649
|
-
const targetPath =
|
|
35910
|
+
const targetPath = resolve19(workspace.cwd, relativePath);
|
|
35650
35911
|
if (!pathWithin3(targetPath, workspace.cwd)) return null;
|
|
35651
35912
|
return { relativePath, targetPath };
|
|
35652
35913
|
}
|
|
@@ -35735,14 +35996,14 @@ async function materializeEffectiveAgentInstructions(config, command, workspace,
|
|
|
35735
35996
|
mkdirSync12(dirname11(target.targetPath), { recursive: true });
|
|
35736
35997
|
const temporaryPath = `${target.targetPath}.mirrorx-${command.commandId}.tmp`;
|
|
35737
35998
|
try {
|
|
35738
|
-
|
|
35739
|
-
const readBack =
|
|
35999
|
+
writeFileSync13(temporaryPath, content, { encoding: "utf8", mode: 384 });
|
|
36000
|
+
const readBack = readFileSync19(temporaryPath, "utf8");
|
|
35740
36001
|
if (readBack !== content) {
|
|
35741
36002
|
throw new Error(`context_envelope_instruction_readback_mismatch: ${filePath}`);
|
|
35742
36003
|
}
|
|
35743
|
-
|
|
36004
|
+
renameSync10(temporaryPath, target.targetPath);
|
|
35744
36005
|
} finally {
|
|
35745
|
-
|
|
36006
|
+
rmSync11(temporaryPath, { force: true });
|
|
35746
36007
|
}
|
|
35747
36008
|
materialized.push({
|
|
35748
36009
|
path: target.relativePath,
|
|
@@ -35752,7 +36013,7 @@ async function materializeEffectiveAgentInstructions(config, command, workspace,
|
|
|
35752
36013
|
}
|
|
35753
36014
|
const readBackFiles = Object.fromEntries(materialized.map((entry) => [
|
|
35754
36015
|
entry.path,
|
|
35755
|
-
|
|
36016
|
+
readFileSync19(resolve19(workspace.cwd, entry.path), "utf8")
|
|
35756
36017
|
]));
|
|
35757
36018
|
if (stableInstructionFilesHash(readBackFiles) !== readString(instructionContract.contentHash)) {
|
|
35758
36019
|
throw new Error("context_envelope_materialized_hash_mismatch");
|
|
@@ -35776,7 +36037,7 @@ function wikiTreePathForCommand(command, workspaceBindings) {
|
|
|
35776
36037
|
const candidates = [];
|
|
35777
36038
|
if (root.endsWith("paperclipai.plugin-llm-wiki")) candidates.push(root);
|
|
35778
36039
|
if (basename8(root) === "plugin-data" && companyId) {
|
|
35779
|
-
candidates.push(
|
|
36040
|
+
candidates.push(join23(root, companyId, "paperclipai.plugin-llm-wiki"));
|
|
35780
36041
|
}
|
|
35781
36042
|
for (const candidate of candidates) {
|
|
35782
36043
|
try {
|
|
@@ -35787,6 +36048,62 @@ function wikiTreePathForCommand(command, workspaceBindings) {
|
|
|
35787
36048
|
}
|
|
35788
36049
|
return null;
|
|
35789
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
|
+
}
|
|
35790
36107
|
function buildCommandPrompt(command, workspace, materializedAttachments = [], options = {}) {
|
|
35791
36108
|
const workspaceContext = normalizeWorkspaceContext(workspace);
|
|
35792
36109
|
const cwd = workspaceContext.cwd;
|
|
@@ -35834,6 +36151,7 @@ function buildCommandPrompt(command, workspace, materializedAttachments = [], op
|
|
|
35834
36151
|
return `- ${details}`;
|
|
35835
36152
|
})
|
|
35836
36153
|
].join("\n") : "";
|
|
36154
|
+
const mentionContextText = renderMentionContextText(commandMentionContext(command));
|
|
35837
36155
|
const compilation = compileCommandPromptWithManifest({
|
|
35838
36156
|
commandId: command.commandId,
|
|
35839
36157
|
runId: commandRunId(command),
|
|
@@ -35852,6 +36170,7 @@ function buildCommandPrompt(command, workspace, materializedAttachments = [], op
|
|
|
35852
36170
|
agentInstructions,
|
|
35853
36171
|
taskMarkdown,
|
|
35854
36172
|
attachmentsText,
|
|
36173
|
+
mentionContextText,
|
|
35855
36174
|
comments,
|
|
35856
36175
|
context,
|
|
35857
36176
|
nativeSession: asRecord(payload.nativeSession),
|
|
@@ -35860,7 +36179,8 @@ function buildCommandPrompt(command, workspace, materializedAttachments = [], op
|
|
|
35860
36179
|
treePath: wikiTreePathForCommand(command, options.workspaceBindings)
|
|
35861
36180
|
},
|
|
35862
36181
|
runtimeTemplateCatalog: options.runtimeTemplateCatalog,
|
|
35863
|
-
executorCapabilityNotice: options.executorCapabilityNotice
|
|
36182
|
+
executorCapabilityNotice: options.executorCapabilityNotice,
|
|
36183
|
+
browserCredentialEnv: options.browserCredentialEnv
|
|
35864
36184
|
}, { maxChars: options.maxChars, separateRuntimeRules: options.executorKind === "pi" });
|
|
35865
36185
|
const auditedCompilation = attachCurrentRunContractShadowAudit(
|
|
35866
36186
|
compilation,
|
|
@@ -35956,13 +36276,13 @@ function attachPiProjectInstructionExtension(profile, input) {
|
|
|
35956
36276
|
"managed Pi profile is missing"
|
|
35957
36277
|
);
|
|
35958
36278
|
}
|
|
35959
|
-
const projectInstructionExtensionPath =
|
|
36279
|
+
const projectInstructionExtensionPath = join23(
|
|
35960
36280
|
profile.profileRoot,
|
|
35961
36281
|
"extensions",
|
|
35962
36282
|
MANAGED_PI_PROJECT_INSTRUCTION_FILENAME
|
|
35963
36283
|
);
|
|
35964
|
-
const contract = { projectInstructionPath:
|
|
35965
|
-
|
|
36284
|
+
const contract = { projectInstructionPath: resolve19(input.cwd, "AGENTS.md") };
|
|
36285
|
+
writeFileSync13(projectInstructionExtensionPath, managedPiProjectInstructionExtensionSource(contract), { mode: 384 });
|
|
35966
36286
|
return projectInstructionExtensionPath;
|
|
35967
36287
|
}
|
|
35968
36288
|
function commandUsesPiExecutor(command) {
|
|
@@ -36005,18 +36325,18 @@ function buildExecutorEnv(config, command, workspace) {
|
|
|
36005
36325
|
};
|
|
36006
36326
|
}
|
|
36007
36327
|
function preparePiModelCallProfile(commandId, baseEnv, options = {}) {
|
|
36008
|
-
const profileRoot =
|
|
36009
|
-
const home =
|
|
36010
|
-
const sessionsDir =
|
|
36011
|
-
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");
|
|
36012
36332
|
for (const directory of [home, sessionsDir, tempDir]) {
|
|
36013
36333
|
mkdirSync12(directory, { recursive: true, mode: 448 });
|
|
36014
36334
|
}
|
|
36015
36335
|
try {
|
|
36016
36336
|
const extensionArgs = [];
|
|
36017
36337
|
if (options.responseContract) {
|
|
36018
|
-
const extensionPath =
|
|
36019
|
-
|
|
36338
|
+
const extensionPath = join23(profileRoot, "model-call-output-contract.js");
|
|
36339
|
+
writeFileSync13(
|
|
36020
36340
|
extensionPath,
|
|
36021
36341
|
modelCallOutputContractExtensionSource(options.responseContract.maxOutputTokens),
|
|
36022
36342
|
{ mode: 384 }
|
|
@@ -36036,12 +36356,12 @@ function preparePiModelCallProfile(commandId, baseEnv, options = {}) {
|
|
|
36036
36356
|
}
|
|
36037
36357
|
};
|
|
36038
36358
|
} catch (error) {
|
|
36039
|
-
|
|
36359
|
+
rmSync11(profileRoot, { recursive: true, force: true });
|
|
36040
36360
|
throw error;
|
|
36041
36361
|
}
|
|
36042
36362
|
}
|
|
36043
36363
|
function cleanupPiModelCallProfile(profile) {
|
|
36044
|
-
if (profile?.profileRoot)
|
|
36364
|
+
if (profile?.profileRoot) rmSync11(profile.profileRoot, { recursive: true, force: true });
|
|
36045
36365
|
}
|
|
36046
36366
|
function splitExtraArgs(value) {
|
|
36047
36367
|
return splitList(value).flatMap((entry) => entry.split(/\s+/).filter(Boolean));
|
|
@@ -36081,7 +36401,7 @@ function resolveNativeSessionRequest(command, workspace) {
|
|
|
36081
36401
|
try {
|
|
36082
36402
|
cwdMatched = realpathSync12(requestedCwd) === realpathSync12(sourceWorkspacePath);
|
|
36083
36403
|
} catch {
|
|
36084
|
-
cwdMatched =
|
|
36404
|
+
cwdMatched = resolve19(requestedCwd) === resolve19(sourceWorkspacePath);
|
|
36085
36405
|
}
|
|
36086
36406
|
}
|
|
36087
36407
|
const used = Boolean(enabled && requested && sessionId && requestedCwd && cwdMatched);
|
|
@@ -36689,7 +37009,7 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
36689
37009
|
}
|
|
36690
37010
|
}
|
|
36691
37011
|
if (MIRRORX_FORMAL_TASK_EXECUTOR_KINDS.includes(executorKind) && event) {
|
|
36692
|
-
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);
|
|
36693
37013
|
liveMcpToolResults.push(...results);
|
|
36694
37014
|
if (results.length > 0) onMcpToolResults?.(results);
|
|
36695
37015
|
}
|
|
@@ -36907,7 +37227,7 @@ function realOrResolvedPath(value) {
|
|
|
36907
37227
|
try {
|
|
36908
37228
|
return realpathSync12(value);
|
|
36909
37229
|
} catch {
|
|
36910
|
-
return
|
|
37230
|
+
return resolve19(value);
|
|
36911
37231
|
}
|
|
36912
37232
|
}
|
|
36913
37233
|
var LSOF_COMMAND = process.platform === "darwin" && existsSync18("/usr/sbin/lsof") ? "/usr/sbin/lsof" : "lsof";
|
|
@@ -37035,7 +37355,7 @@ function walkManagedWorkdirs(root) {
|
|
|
37035
37355
|
}
|
|
37036
37356
|
for (const entry of entries) {
|
|
37037
37357
|
if (!entry.isDirectory()) continue;
|
|
37038
|
-
const fullPath =
|
|
37358
|
+
const fullPath = join23(current, entry.name);
|
|
37039
37359
|
if (entry.name === "workdir" && existsSync18(workspaceManifestPath(fullPath))) {
|
|
37040
37360
|
workdirs.push(fullPath);
|
|
37041
37361
|
continue;
|
|
@@ -38037,11 +38357,11 @@ async function completeCommand(config, command, status, result2, error) {
|
|
|
38037
38357
|
}
|
|
38038
38358
|
function resultOutboxDir(config) {
|
|
38039
38359
|
const explicit = readString(process.env.AMASTER_RESULT_OUTBOX_DIR);
|
|
38040
|
-
if (explicit) return
|
|
38041
|
-
return
|
|
38360
|
+
if (explicit) return resolve19(expandHomePath(explicit));
|
|
38361
|
+
return join23(dirname11(stateFilePath(process.env)), "result-outbox");
|
|
38042
38362
|
}
|
|
38043
38363
|
function resultOutboxInvalidDir(config) {
|
|
38044
|
-
return
|
|
38364
|
+
return join23(resultOutboxDir(config), "invalid");
|
|
38045
38365
|
}
|
|
38046
38366
|
function writeResultOutboxEntry(config, entry) {
|
|
38047
38367
|
const dir = resultOutboxDir(config);
|
|
@@ -38055,16 +38375,16 @@ function writeResultOutboxEntry(config, entry) {
|
|
|
38055
38375
|
...entry,
|
|
38056
38376
|
...pendingLogEntries.length > 0 ? { pendingLogEntries } : {}
|
|
38057
38377
|
};
|
|
38058
|
-
|
|
38378
|
+
writeFileSync13(join23(dir, resultOutboxFileName(entry.commandId)), `${JSON.stringify(body, null, 2)}
|
|
38059
38379
|
`, { mode: 384 });
|
|
38060
38380
|
}
|
|
38061
38381
|
function moveResultOutboxEntryToInvalid(config, file, fullPath, reason, detail, original) {
|
|
38062
38382
|
const invalidDir = resultOutboxInvalidDir(config);
|
|
38063
38383
|
mkdirSync12(invalidDir, { recursive: true });
|
|
38064
|
-
const invalidPath =
|
|
38384
|
+
const invalidPath = join23(invalidDir, file);
|
|
38065
38385
|
if (original === void 0) {
|
|
38066
38386
|
try {
|
|
38067
|
-
|
|
38387
|
+
renameSync10(fullPath, invalidPath);
|
|
38068
38388
|
} catch {
|
|
38069
38389
|
copyFileSync2(fullPath, invalidPath);
|
|
38070
38390
|
unlinkSync3(fullPath);
|
|
@@ -38077,14 +38397,14 @@ function moveResultOutboxEntryToInvalid(config, file, fullPath, reason, detail,
|
|
|
38077
38397
|
...detail ? { detail: truncateText(detail, 1e3) } : {},
|
|
38078
38398
|
original
|
|
38079
38399
|
};
|
|
38080
|
-
|
|
38400
|
+
writeFileSync13(invalidPath, `${JSON.stringify(evidence, null, 2)}
|
|
38081
38401
|
`, { mode: 384 });
|
|
38082
38402
|
unlinkSync3(fullPath);
|
|
38083
38403
|
}
|
|
38084
38404
|
function readValidResultOutboxEntryOrQuarantine(config, file, fullPath) {
|
|
38085
38405
|
let entry;
|
|
38086
38406
|
try {
|
|
38087
|
-
entry = JSON.parse(
|
|
38407
|
+
entry = JSON.parse(readFileSync19(fullPath, "utf8"));
|
|
38088
38408
|
} catch (err) {
|
|
38089
38409
|
const message = err instanceof Error ? err.message : String(err);
|
|
38090
38410
|
moveResultOutboxEntryToInvalid(config, file, fullPath, "malformed_result_outbox_json", message);
|
|
@@ -38117,7 +38437,7 @@ function updateResultOutboxAttempt(fullPath, entry, err) {
|
|
|
38117
38437
|
...typeof err?.httpStatus === "number" ? { httpStatus: err.httpStatus } : {},
|
|
38118
38438
|
lastError: truncateText(err instanceof Error ? err.message : String(err), 1e3)
|
|
38119
38439
|
};
|
|
38120
|
-
|
|
38440
|
+
writeFileSync13(fullPath, `${JSON.stringify(next, null, 2)}
|
|
38121
38441
|
`, { mode: 384 });
|
|
38122
38442
|
return next;
|
|
38123
38443
|
}
|
|
@@ -38131,8 +38451,8 @@ function quarantineResultOutboxEntry(config, fullPath, file, entry, reason, err)
|
|
|
38131
38451
|
...typeof err?.httpStatus === "number" ? { httpStatus: err.httpStatus } : {},
|
|
38132
38452
|
lastError: truncateText(err instanceof Error ? err.message : String(err), 1e3)
|
|
38133
38453
|
};
|
|
38134
|
-
const invalidPath =
|
|
38135
|
-
|
|
38454
|
+
const invalidPath = join23(invalidDir, file);
|
|
38455
|
+
writeFileSync13(invalidPath, `${JSON.stringify(body, null, 2)}
|
|
38136
38456
|
`, { mode: 384 });
|
|
38137
38457
|
try {
|
|
38138
38458
|
unlinkSync3(fullPath);
|
|
@@ -38150,7 +38470,7 @@ async function flushResultOutbox(config) {
|
|
|
38150
38470
|
const files = readdirSync12(dir).filter((name) => name.endsWith(".json")).sort();
|
|
38151
38471
|
let completed = 0;
|
|
38152
38472
|
for (const file of files) {
|
|
38153
|
-
const fullPath =
|
|
38473
|
+
const fullPath = join23(dir, file);
|
|
38154
38474
|
let entry = readValidResultOutboxEntryOrQuarantine(config, file, fullPath);
|
|
38155
38475
|
if (!entry) continue;
|
|
38156
38476
|
const pendingLogEntries = Array.isArray(entry.pendingLogEntries) ? entry.pendingLogEntries.filter((logEntry) => typeof asRecord(logEntry).message === "string") : [];
|
|
@@ -38165,7 +38485,7 @@ async function flushResultOutbox(config) {
|
|
|
38165
38485
|
if (!isTerminalResultOutboxStatus(logHttpStatus)) {
|
|
38166
38486
|
const logAttemptCount = readNumber(entry.logAttemptCount, 0) + 1;
|
|
38167
38487
|
if (logAttemptCount < maxResultOutboxAttempts()) {
|
|
38168
|
-
|
|
38488
|
+
writeFileSync13(fullPath, `${JSON.stringify({ ...entry, logAttemptCount }, null, 2)}
|
|
38169
38489
|
`, { mode: 384 });
|
|
38170
38490
|
process.stderr.write(`AMaster daemon deferred live log delivery retry failed for ${entry.commandId ?? file}: ${logMessage}
|
|
38171
38491
|
`);
|
|
@@ -38178,7 +38498,7 @@ async function flushResultOutbox(config) {
|
|
|
38178
38498
|
entry = { ...entry };
|
|
38179
38499
|
delete entry.pendingLogEntries;
|
|
38180
38500
|
delete entry.logAttemptCount;
|
|
38181
|
-
|
|
38501
|
+
writeFileSync13(fullPath, `${JSON.stringify(entry, null, 2)}
|
|
38182
38502
|
`, { mode: 384 });
|
|
38183
38503
|
}
|
|
38184
38504
|
try {
|
|
@@ -38281,6 +38601,12 @@ function safeMaterializedAttachmentFilename(attachment, index) {
|
|
|
38281
38601
|
const name = basename8(original ?? `${id}.bin`).replace(/[\/\\:\0]/g, "_").trim();
|
|
38282
38602
|
return name && name !== "." && name !== ".." ? name : `${id}.bin`;
|
|
38283
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
|
+
}
|
|
38284
38610
|
function compareAttachmentLineageCandidates(left, right) {
|
|
38285
38611
|
const versionDiff = Number(right.artifactVersionState === "current") - Number(left.artifactVersionState === "current");
|
|
38286
38612
|
if (versionDiff !== 0) return versionDiff;
|
|
@@ -38383,7 +38709,7 @@ async function materializeIssueAttachments(config, command, workspace) {
|
|
|
38383
38709
|
runtimeAuth,
|
|
38384
38710
|
issueId
|
|
38385
38711
|
);
|
|
38386
|
-
const targetDir =
|
|
38712
|
+
const targetDir = join23(workspace.cwd, "input-attachments");
|
|
38387
38713
|
mkdirSync12(targetDir, { recursive: true });
|
|
38388
38714
|
const usedFilenames = /* @__PURE__ */ new Set();
|
|
38389
38715
|
const materialized = [];
|
|
@@ -38395,18 +38721,14 @@ async function materializeIssueAttachments(config, command, workspace) {
|
|
|
38395
38721
|
continue;
|
|
38396
38722
|
}
|
|
38397
38723
|
let filename = safeMaterializedAttachmentFilename(attachment, index);
|
|
38398
|
-
|
|
38399
|
-
const ext = extname3(filename);
|
|
38400
|
-
const stem = ext ? filename.slice(0, -ext.length) : filename;
|
|
38401
|
-
filename = `${stem}-${index + 1}${ext}`;
|
|
38402
|
-
}
|
|
38724
|
+
filename = dedupeMaterializedFilename(filename, index, usedFilenames);
|
|
38403
38725
|
usedFilenames.add(filename);
|
|
38404
|
-
const targetPath =
|
|
38726
|
+
const targetPath = join23(targetDir, filename);
|
|
38405
38727
|
const body = await runtimeApiBuffer(runtimeAuth, contentPath);
|
|
38406
38728
|
if (attachment.initializationInput === true && (body.byteLength !== attachment.byteSize || createHash19("sha256").update(body).digest("hex") !== attachment.sha256)) {
|
|
38407
38729
|
throw new Error("Initialization input content does not match its preparation receipt");
|
|
38408
38730
|
}
|
|
38409
|
-
|
|
38731
|
+
writeFileSync13(targetPath, body);
|
|
38410
38732
|
const attachmentId = readString(attachment.id);
|
|
38411
38733
|
const actualSha256 = createHash19("sha256").update(body).digest("hex");
|
|
38412
38734
|
const lineageCandidates = lineageCandidatesByAttachmentId.get(attachmentId) ?? [];
|
|
@@ -38473,8 +38795,8 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
38473
38795
|
if (manifest.version !== 1 || !Array.isArray(manifest.entries)) {
|
|
38474
38796
|
throw new Error("artifact_input_manifest_invalid: expected version 1 entries array");
|
|
38475
38797
|
}
|
|
38476
|
-
const targetRoot =
|
|
38477
|
-
|
|
38798
|
+
const targetRoot = join23(workspace.cwd, "input-artifacts");
|
|
38799
|
+
rmSync11(targetRoot, { recursive: true, force: true });
|
|
38478
38800
|
mkdirSync12(targetRoot, { recursive: true });
|
|
38479
38801
|
const usedPaths = /* @__PURE__ */ new Set();
|
|
38480
38802
|
const materialized = [];
|
|
@@ -38504,18 +38826,18 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
38504
38826
|
id: attachmentId,
|
|
38505
38827
|
originalFilename: readString(entry.originalFilename)
|
|
38506
38828
|
}, index);
|
|
38507
|
-
let relativePath =
|
|
38829
|
+
let relativePath = join23("input-artifacts", sourceDir, filename).split(/[\\/]+/).join("/");
|
|
38508
38830
|
if (usedPaths.has(relativePath)) {
|
|
38509
38831
|
const ext = extname3(filename);
|
|
38510
38832
|
const stem = ext ? filename.slice(0, -ext.length) : filename;
|
|
38511
38833
|
filename = `${stem}-${index + 1}${ext}`;
|
|
38512
|
-
relativePath =
|
|
38834
|
+
relativePath = join23("input-artifacts", sourceDir, filename).split(/[\\/]+/).join("/");
|
|
38513
38835
|
}
|
|
38514
38836
|
usedPaths.add(relativePath);
|
|
38515
|
-
const targetPath =
|
|
38837
|
+
const targetPath = join23(workspace.cwd, relativePath);
|
|
38516
38838
|
mkdirSync12(dirname11(targetPath), { recursive: true });
|
|
38517
|
-
|
|
38518
|
-
|
|
38839
|
+
writeFileSync13(targetPath, body);
|
|
38840
|
+
chmodSync7(targetPath, 292);
|
|
38519
38841
|
materialized.push({
|
|
38520
38842
|
id: attachmentId,
|
|
38521
38843
|
workProductId,
|
|
@@ -38534,14 +38856,84 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
38534
38856
|
version: 1,
|
|
38535
38857
|
entries: materialized.map(({ path: _path, relativePath, ...entry }) => ({ ...entry, path: relativePath }))
|
|
38536
38858
|
};
|
|
38537
|
-
const manifestPath =
|
|
38538
|
-
|
|
38539
|
-
|
|
38859
|
+
const manifestPath = join23(targetRoot, "artifact-input-manifest.json");
|
|
38860
|
+
writeFileSync13(manifestPath, JSON.stringify(localManifest, null, 2) + "\n");
|
|
38861
|
+
chmodSync7(manifestPath, 292);
|
|
38540
38862
|
updateWorkspaceManifest(workspaceManifestPath(workspace), { artifactInputManifest: localManifest });
|
|
38541
38863
|
return materialized;
|
|
38542
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
|
+
}
|
|
38543
38935
|
function issueCheckpointDir(workspace) {
|
|
38544
|
-
return
|
|
38936
|
+
return join23(dirname11(workspace.runDir), "checkpoint");
|
|
38545
38937
|
}
|
|
38546
38938
|
async function clearIssueCheckpoint(config, command, workspace, reason, consumedSource = null) {
|
|
38547
38939
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
@@ -38551,13 +38943,13 @@ async function clearIssueCheckpoint(config, command, workspace, reason, consumed
|
|
|
38551
38943
|
if (!sourceRunId) return false;
|
|
38552
38944
|
let manifest;
|
|
38553
38945
|
try {
|
|
38554
|
-
manifest = asRecord(JSON.parse(
|
|
38946
|
+
manifest = asRecord(JSON.parse(readFileSync19(join23(checkpointDir, "manifest.json"), "utf8")));
|
|
38555
38947
|
} catch {
|
|
38556
38948
|
return false;
|
|
38557
38949
|
}
|
|
38558
38950
|
if (readString(manifest.issueId) !== commandIssueId(command) || readString(manifest.sourceRunId) !== sourceRunId) return false;
|
|
38559
38951
|
}
|
|
38560
|
-
|
|
38952
|
+
rmSync11(checkpointDir, { recursive: true, force: true });
|
|
38561
38953
|
await ingestLog(config, command, "system", "info", "Cleared issue continuation checkpoint", { reason });
|
|
38562
38954
|
return true;
|
|
38563
38955
|
}
|
|
@@ -38570,7 +38962,7 @@ function safeCheckpointRelativePath(rawPath) {
|
|
|
38570
38962
|
return normalized;
|
|
38571
38963
|
}
|
|
38572
38964
|
function hashFileSha256(filePath) {
|
|
38573
|
-
return createHash19("sha256").update(
|
|
38965
|
+
return createHash19("sha256").update(readFileSync19(filePath)).digest("hex");
|
|
38574
38966
|
}
|
|
38575
38967
|
function expectedContinuationCheckpoint(command) {
|
|
38576
38968
|
const payload = asRecord(command.payload);
|
|
@@ -38596,7 +38988,7 @@ function expectedContinuationCheckpoint(command) {
|
|
|
38596
38988
|
}
|
|
38597
38989
|
async function materializeIssueCheckpoint(config, command, workspace) {
|
|
38598
38990
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
38599
|
-
const manifestPath =
|
|
38991
|
+
const manifestPath = join23(checkpointDir, "manifest.json");
|
|
38600
38992
|
const expectedContinuation = expectedContinuationCheckpoint(command);
|
|
38601
38993
|
const nativeRequest = asRecord(asRecord(command.payload).nativeSession);
|
|
38602
38994
|
let portableNativeSession;
|
|
@@ -38626,14 +39018,14 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38626
39018
|
}
|
|
38627
39019
|
let manifest;
|
|
38628
39020
|
try {
|
|
38629
|
-
manifest = asRecord(JSON.parse(
|
|
39021
|
+
manifest = asRecord(JSON.parse(readFileSync19(manifestPath, "utf8")));
|
|
38630
39022
|
} catch (err) {
|
|
38631
|
-
|
|
39023
|
+
rmSync11(checkpointDir, { recursive: true, force: true });
|
|
38632
39024
|
throw new Error(`invalid issue checkpoint manifest: ${err instanceof Error ? err.message : String(err)}`);
|
|
38633
39025
|
}
|
|
38634
39026
|
const expiresAt = Date.parse(readString(manifest.expiresAt) ?? "");
|
|
38635
39027
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() || readString(manifest.issueId) !== commandIssueId(command)) {
|
|
38636
|
-
|
|
39028
|
+
rmSync11(checkpointDir, { recursive: true, force: true });
|
|
38637
39029
|
if (expectedContinuation) throw new Error("continuation_checkpoint_unavailable: manifest_expired_or_mismatched");
|
|
38638
39030
|
return unavailable2;
|
|
38639
39031
|
}
|
|
@@ -38657,7 +39049,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38657
39049
|
throw new Error("continuation_checkpoint_lineage_mismatch");
|
|
38658
39050
|
}
|
|
38659
39051
|
}
|
|
38660
|
-
const filesRoot = realpathSync12(
|
|
39052
|
+
const filesRoot = files.length > 0 ? realpathSync12(join23(checkpointDir, "files")) : null;
|
|
38661
39053
|
const workspaceRoot = realpathSync12(workspace.cwd);
|
|
38662
39054
|
const validated = [];
|
|
38663
39055
|
let totalBytes = 0;
|
|
@@ -38665,8 +39057,8 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38665
39057
|
const file = asRecord(rawFile);
|
|
38666
39058
|
const relativePath = safeCheckpointRelativePath(readString(file.path));
|
|
38667
39059
|
if (!relativePath) throw new Error("issue checkpoint manifest contains an invalid file path");
|
|
38668
|
-
const sourceCandidate =
|
|
38669
|
-
const target =
|
|
39060
|
+
const sourceCandidate = resolve19(filesRoot, relativePath);
|
|
39061
|
+
const target = resolve19(workspaceRoot, relativePath);
|
|
38670
39062
|
if (!pathWithin3(sourceCandidate, filesRoot) || !pathWithin3(target, workspaceRoot)) {
|
|
38671
39063
|
throw new Error(`issue checkpoint path escapes its workspace: ${relativePath}`);
|
|
38672
39064
|
}
|
|
@@ -38702,7 +39094,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38702
39094
|
}
|
|
38703
39095
|
let existingTarget = null;
|
|
38704
39096
|
try {
|
|
38705
|
-
existingTarget =
|
|
39097
|
+
existingTarget = lstatSync13(target);
|
|
38706
39098
|
} catch (err) {
|
|
38707
39099
|
if (err?.code !== "ENOENT") throw err;
|
|
38708
39100
|
}
|
|
@@ -38713,16 +39105,16 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
38713
39105
|
materialized.push(relativePath);
|
|
38714
39106
|
continue;
|
|
38715
39107
|
}
|
|
38716
|
-
const temporaryTarget =
|
|
39108
|
+
const temporaryTarget = join23(targetParent, `.${basename8(target)}.checkpoint-${randomUUID2()}.tmp`);
|
|
38717
39109
|
try {
|
|
38718
39110
|
copyFileSync2(source, temporaryTarget);
|
|
38719
|
-
const temporaryStat =
|
|
39111
|
+
const temporaryStat = lstatSync13(temporaryTarget);
|
|
38720
39112
|
if (!temporaryStat.isFile() || temporaryStat.size !== expectedByteSize || hashFileSha256(temporaryTarget) !== expectedSha256) {
|
|
38721
39113
|
throw new Error(`issue checkpoint target verification failed: ${relativePath}`);
|
|
38722
39114
|
}
|
|
38723
|
-
|
|
39115
|
+
renameSync10(temporaryTarget, target);
|
|
38724
39116
|
} finally {
|
|
38725
|
-
|
|
39117
|
+
rmSync11(temporaryTarget, { force: true });
|
|
38726
39118
|
}
|
|
38727
39119
|
materialized.push(relativePath);
|
|
38728
39120
|
}
|
|
@@ -38749,9 +39141,9 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38749
39141
|
const commandKey = readString(command.commandId)?.replace(/[^A-Za-z0-9_-]/g, "-") ?? randomUUID2();
|
|
38750
39142
|
const stagingDir = `${checkpointDir}.tmp-${commandKey}`;
|
|
38751
39143
|
const backupDir = `${checkpointDir}.previous-${commandKey}`;
|
|
38752
|
-
const filesDir =
|
|
38753
|
-
|
|
38754
|
-
|
|
39144
|
+
const filesDir = join23(stagingDir, "files");
|
|
39145
|
+
rmSync11(stagingDir, { recursive: true, force: true });
|
|
39146
|
+
rmSync11(backupDir, { recursive: true, force: true });
|
|
38755
39147
|
mkdirSync12(filesDir, { recursive: true });
|
|
38756
39148
|
try {
|
|
38757
39149
|
const files = [];
|
|
@@ -38763,13 +39155,13 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38763
39155
|
if (!normalized) {
|
|
38764
39156
|
throw new Error(`continuation_checkpoint_file_unavailable: ${requiredPath}`);
|
|
38765
39157
|
}
|
|
38766
|
-
const sourceCandidate =
|
|
39158
|
+
const sourceCandidate = resolve19(workspaceRoot, normalized);
|
|
38767
39159
|
if (!pathWithin3(sourceCandidate, workspaceRoot)) {
|
|
38768
39160
|
throw new Error(`continuation_checkpoint_file_unavailable: ${requiredPath}`);
|
|
38769
39161
|
}
|
|
38770
39162
|
let sourceStat;
|
|
38771
39163
|
try {
|
|
38772
|
-
sourceStat =
|
|
39164
|
+
sourceStat = lstatSync13(sourceCandidate);
|
|
38773
39165
|
} catch (err) {
|
|
38774
39166
|
if (err?.code === "ENOENT") {
|
|
38775
39167
|
throw new Error(`continuation_checkpoint_file_unavailable: ${requiredPath}`);
|
|
@@ -38801,11 +39193,11 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38801
39193
|
if (requiredPaths.length > 0 || options.taskSession) throw new Error(`continuation_checkpoint_file_size_invalid: ${relativePath}`);
|
|
38802
39194
|
continue;
|
|
38803
39195
|
}
|
|
38804
|
-
const target =
|
|
39196
|
+
const target = resolve19(filesDir, relativePath);
|
|
38805
39197
|
if (!pathWithin3(target, filesDir)) continue;
|
|
38806
39198
|
mkdirSync12(dirname11(target), { recursive: true });
|
|
38807
39199
|
copyFileSync2(ownedSource, target);
|
|
38808
|
-
const storedStat =
|
|
39200
|
+
const storedStat = lstatSync13(target);
|
|
38809
39201
|
if (!storedStat.isFile() || storedStat.size !== byteSize) {
|
|
38810
39202
|
throw new Error(`issue checkpoint copy verification failed: ${relativePath}`);
|
|
38811
39203
|
}
|
|
@@ -38813,8 +39205,8 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38813
39205
|
files.push({ path: relativePath, byteSize, sha256: hashFileSha256(target) });
|
|
38814
39206
|
}
|
|
38815
39207
|
if (files.length === 0 && !options.taskSession) {
|
|
38816
|
-
|
|
38817
|
-
|
|
39208
|
+
rmSync11(stagingDir, { recursive: true, force: true });
|
|
39209
|
+
rmSync11(checkpointDir, { recursive: true, force: true });
|
|
38818
39210
|
return null;
|
|
38819
39211
|
}
|
|
38820
39212
|
const checkpointCreatedAt = Date.now();
|
|
@@ -38839,26 +39231,26 @@ async function saveIssueCheckpoint(config, command, workspace, candidates, optio
|
|
|
38839
39231
|
totalBytes,
|
|
38840
39232
|
files
|
|
38841
39233
|
};
|
|
38842
|
-
|
|
39234
|
+
writeFileSync13(join23(stagingDir, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
38843
39235
|
`);
|
|
38844
39236
|
const replacingExistingCheckpoint = existsSync18(checkpointDir);
|
|
38845
|
-
if (replacingExistingCheckpoint)
|
|
39237
|
+
if (replacingExistingCheckpoint) renameSync10(checkpointDir, backupDir);
|
|
38846
39238
|
try {
|
|
38847
|
-
|
|
39239
|
+
renameSync10(stagingDir, checkpointDir);
|
|
38848
39240
|
} catch (err) {
|
|
38849
39241
|
if (replacingExistingCheckpoint && existsSync18(backupDir) && !existsSync18(checkpointDir)) {
|
|
38850
|
-
|
|
39242
|
+
renameSync10(backupDir, checkpointDir);
|
|
38851
39243
|
}
|
|
38852
39244
|
throw err;
|
|
38853
39245
|
}
|
|
38854
|
-
|
|
39246
|
+
rmSync11(backupDir, { recursive: true, force: true });
|
|
38855
39247
|
if (config.checkpointUploadEnabled) {
|
|
38856
39248
|
await uploadCheckpoint(config, command, checkpointDir, manifest, void 0, options.nativeSession);
|
|
38857
39249
|
}
|
|
38858
39250
|
await ingestLog(config, command, "system", "info", `Saved ${files.length} issue checkpoint file(s) for continuation`, manifest);
|
|
38859
39251
|
return manifest;
|
|
38860
39252
|
} catch (err) {
|
|
38861
|
-
|
|
39253
|
+
rmSync11(stagingDir, { recursive: true, force: true });
|
|
38862
39254
|
throw err;
|
|
38863
39255
|
}
|
|
38864
39256
|
}
|
|
@@ -38999,8 +39391,36 @@ async function executeRunCommand(config, command) {
|
|
|
38999
39391
|
});
|
|
39000
39392
|
}
|
|
39001
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
|
+
}
|
|
39002
39414
|
await ingestWorkspaceStatus(config, command, cwd);
|
|
39003
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
|
+
}
|
|
39004
39424
|
const nativeSessionRequest = asRecord(asRecord(command.payload).nativeSession);
|
|
39005
39425
|
let invocation = null;
|
|
39006
39426
|
let executorEnv = buildExecutorEnv(config, command, workspace);
|
|
@@ -39008,6 +39428,7 @@ async function executeRunCommand(config, command) {
|
|
|
39008
39428
|
let managedMcpCleanup = null;
|
|
39009
39429
|
let cleanupManagedMcpProfile = null;
|
|
39010
39430
|
let piRuntimeSystemPromptCleanupPath = null;
|
|
39431
|
+
let browserCredentialEnvMaterialization = null;
|
|
39011
39432
|
let piExecutorIdentity = null;
|
|
39012
39433
|
const providerProtectedValues = [];
|
|
39013
39434
|
let piResolvedProviderConfig = null;
|
|
@@ -39122,7 +39543,7 @@ async function executeRunCommand(config, command) {
|
|
|
39122
39543
|
executorCommand: invocation.command,
|
|
39123
39544
|
executorHome: workspace.executorHome,
|
|
39124
39545
|
runDir: workspace.runDir,
|
|
39125
|
-
runtimeCacheRoot:
|
|
39546
|
+
runtimeCacheRoot: join23(dirname11(config.daemonStateFile), "cache"),
|
|
39126
39547
|
cwd,
|
|
39127
39548
|
runtimeAuth: commandRuntimeAuth(command),
|
|
39128
39549
|
nativeSession: asRecord(asRecord(executionCommand.payload).nativeSession),
|
|
@@ -39209,7 +39630,7 @@ async function executeRunCommand(config, command) {
|
|
|
39209
39630
|
const sharedPiHome = readString(process.env.PI_CODING_AGENT_DIR) ?? readString(process.env.PI_AGENT_HOME) ?? null;
|
|
39210
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;
|
|
39211
39632
|
piAgentDirForContextBudget = agentDir;
|
|
39212
|
-
if (agentDir && sharedPiHome &&
|
|
39633
|
+
if (agentDir && sharedPiHome && resolve19(agentDir) === resolve19(sharedPiHome)) {
|
|
39213
39634
|
agentDir = null;
|
|
39214
39635
|
}
|
|
39215
39636
|
try {
|
|
@@ -39316,6 +39737,7 @@ async function executeRunCommand(config, command) {
|
|
|
39316
39737
|
runtimeTemplateCatalog: config.templateCatalog,
|
|
39317
39738
|
runtimeInstructionInjectionEnabled: strictContextGovernance,
|
|
39318
39739
|
executorCapabilityNotice: executor.kind === "codebuddy" ? codebuddyExecutionCapabilityNotice(managedMcpProfile) : "",
|
|
39740
|
+
browserCredentialEnv: browserCredentialPlan?.promptText ?? "",
|
|
39319
39741
|
maxChars: modelContextBudget.dynamicPromptMaxChars
|
|
39320
39742
|
}));
|
|
39321
39743
|
const requiredGoalAuthority = goalAuthorityBlock(requireCommandContextEnvelope(command).dynamicContext);
|
|
@@ -39374,6 +39796,40 @@ async function executeRunCommand(config, command) {
|
|
|
39374
39796
|
preparationStages
|
|
39375
39797
|
});
|
|
39376
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
|
+
}
|
|
39377
39833
|
forgetActiveRunCommand = rememberActiveRunCommand(command, {
|
|
39378
39834
|
executorKind: executor.kind,
|
|
39379
39835
|
workspacePath: cwd,
|
|
@@ -39383,9 +39839,11 @@ async function executeRunCommand(config, command) {
|
|
|
39383
39839
|
outputFloodLimitBytesPerStream: config.executorMaxOutputBytes,
|
|
39384
39840
|
...managedMcpProfile ? { managedMcpAttestation: managedMcpProfile.attestation } : {}
|
|
39385
39841
|
});
|
|
39386
|
-
const abortController = new AbortController();
|
|
39387
39842
|
stopActiveRunHeartbeats = startActiveRunHeartbeats(config, command, abortController);
|
|
39388
|
-
const protectedExecutorValues =
|
|
39843
|
+
const protectedExecutorValues = [.../* @__PURE__ */ new Set([
|
|
39844
|
+
...managedMcpProfile?.protectedValues ?? [],
|
|
39845
|
+
...providerProtectedValues
|
|
39846
|
+
])];
|
|
39389
39847
|
const runtimeArtifacts = [];
|
|
39390
39848
|
const runtimeDocuments = [];
|
|
39391
39849
|
const runtimeArtifactIngest = createRuntimeArtifactIngestQueue({
|
|
@@ -39427,7 +39885,7 @@ async function executeRunCommand(config, command) {
|
|
|
39427
39885
|
}
|
|
39428
39886
|
);
|
|
39429
39887
|
let execution;
|
|
39430
|
-
const browserCredentialConsumer =
|
|
39888
|
+
const browserCredentialConsumer = browserCredentialPresentationKind === "private_channel" ? async (request) => {
|
|
39431
39889
|
const credentialRef = browserCredentialRefForRequest(command, request);
|
|
39432
39890
|
return consumeRuntimeBrowserCredentialRef(
|
|
39433
39891
|
config,
|
|
@@ -39559,7 +40017,7 @@ async function executeRunCommand(config, command) {
|
|
|
39559
40017
|
workspace,
|
|
39560
40018
|
workspaceStatus.artifacts.map((artifact) => ({
|
|
39561
40019
|
rawPath: artifact.relativePath,
|
|
39562
|
-
filePath:
|
|
40020
|
+
filePath: resolve19(cwd, artifact.relativePath)
|
|
39563
40021
|
})),
|
|
39564
40022
|
{
|
|
39565
40023
|
requiredPaths: checkpointPaths,
|
|
@@ -39670,7 +40128,7 @@ async function executeRunCommand(config, command) {
|
|
|
39670
40128
|
workspace,
|
|
39671
40129
|
workspaceStatus.artifacts.map((artifact) => ({
|
|
39672
40130
|
rawPath: artifact.relativePath,
|
|
39673
|
-
filePath:
|
|
40131
|
+
filePath: resolve19(cwd, artifact.relativePath)
|
|
39674
40132
|
}))
|
|
39675
40133
|
) : readString(terminalRunDisposition?.disposition) !== "continuation_scheduled" ? await saveIssueCheckpoint(config, command, workspace, [], {
|
|
39676
40134
|
requiredPaths: taskSessionCheckpointPaths(workspaceStatus),
|
|
@@ -40028,8 +40486,9 @@ async function executeRunCommand(config, command) {
|
|
|
40028
40486
|
} finally {
|
|
40029
40487
|
await preparationLogChain;
|
|
40030
40488
|
if (piRuntimeSystemPromptCleanupPath) {
|
|
40031
|
-
|
|
40489
|
+
rmSync11(piRuntimeSystemPromptCleanupPath, { force: true });
|
|
40032
40490
|
}
|
|
40491
|
+
browserCredentialEnvMaterialization?.cleanup();
|
|
40033
40492
|
if (managedMcpProfile && !managedMcpCleanup && !completionOwnsManagedMcpProfile) {
|
|
40034
40493
|
managedMcpCleanup = cleanupManagedMcpProfile(managedMcpProfile, {
|
|
40035
40494
|
commandId: command.commandId,
|