@reasontrail/cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +38 -3
- package/package.json +1 -1
- package/runtime/reasontrail-runtime.mjs +811 -70
- package/runtime/reasontrail-runtime.mjs.sha256 +1 -0
- package/skills/reasontrail/SKILL.md +153 -6
- package/src/build-info.json +1 -1
- package/src/cli.mjs +398 -122
- package/src/codex-sync.mjs +290 -23
- package/src/systemd-scope.mjs +3 -0
|
@@ -14574,6 +14574,12 @@ var RuntimeClient = class {
|
|
|
14574
14574
|
{ leaseToken, workspaceLeaseToken, progress }
|
|
14575
14575
|
);
|
|
14576
14576
|
}
|
|
14577
|
+
expandContext(executionId, input) {
|
|
14578
|
+
return this.post(
|
|
14579
|
+
`/executions/${executionId}/context`,
|
|
14580
|
+
input
|
|
14581
|
+
);
|
|
14582
|
+
}
|
|
14577
14583
|
registerExecutionWorkspace(executionId, leaseToken, workspaceLeaseToken, registration) {
|
|
14578
14584
|
return this.post(
|
|
14579
14585
|
`/executions/${executionId}/workspace`,
|
|
@@ -14626,6 +14632,17 @@ function extractWorkerResult(rawOutput) {
|
|
|
14626
14632
|
return null;
|
|
14627
14633
|
}
|
|
14628
14634
|
|
|
14635
|
+
// src/services/mission/dependency-preparation.ts
|
|
14636
|
+
var DEPENDENCY_PREPARATION_POLICIES = [
|
|
14637
|
+
"NONE",
|
|
14638
|
+
"REQUIRED",
|
|
14639
|
+
"PREPARED",
|
|
14640
|
+
"AUTO"
|
|
14641
|
+
];
|
|
14642
|
+
var dependencyPreparationPolicySchema = external_exports.enum(
|
|
14643
|
+
DEPENDENCY_PREPARATION_POLICIES
|
|
14644
|
+
);
|
|
14645
|
+
|
|
14629
14646
|
// src/cli/claimed-assignment.ts
|
|
14630
14647
|
var claimedAssignmentSchema = external_exports.object({
|
|
14631
14648
|
executionId: external_exports.string().min(1),
|
|
@@ -14633,6 +14650,11 @@ var claimedAssignmentSchema = external_exports.object({
|
|
|
14633
14650
|
leaseToken: external_exports.string().min(1),
|
|
14634
14651
|
leaseExpiresAt: external_exports.string().datetime(),
|
|
14635
14652
|
workspaceLeaseToken: external_exports.string().min(1),
|
|
14653
|
+
progressiveRetrieval: external_exports.object({
|
|
14654
|
+
endpoint: external_exports.string().regex(/^\/executions\/[A-Za-z0-9_-]+\/context$/),
|
|
14655
|
+
operations: external_exports.array(external_exports.enum(["inspect_context", "trace_context", "expand_tests", "expand_dependencies"])).max(4),
|
|
14656
|
+
tokenBudget: external_exports.number().int().positive()
|
|
14657
|
+
}).strict().nullable(),
|
|
14636
14658
|
assignmentId: external_exports.string().min(1),
|
|
14637
14659
|
missionId: external_exports.string().min(1),
|
|
14638
14660
|
sequence: external_exports.number().int().positive(),
|
|
@@ -14650,14 +14672,115 @@ var claimedAssignmentSchema = external_exports.object({
|
|
|
14650
14672
|
branch: external_exports.string().min(1),
|
|
14651
14673
|
expectedStartingSha: external_exports.string().regex(/^[0-9a-f]{40}$/i)
|
|
14652
14674
|
}).strict(),
|
|
14653
|
-
package: external_exports.
|
|
14675
|
+
package: external_exports.object({
|
|
14676
|
+
// Legacy packages omitted this field and retain the pre-fix AUTO behavior.
|
|
14677
|
+
dependencyPreparation: dependencyPreparationPolicySchema.default("AUTO")
|
|
14678
|
+
}).passthrough()
|
|
14654
14679
|
}).strict();
|
|
14655
14680
|
|
|
14681
|
+
// src/cli/context-bridge.ts
|
|
14682
|
+
import { createServer } from "node:net";
|
|
14683
|
+
import { chmod, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
14684
|
+
import { tmpdir } from "node:os";
|
|
14685
|
+
import { join } from "node:path";
|
|
14686
|
+
var OPERATIONS = /* @__PURE__ */ new Set(["inspect_context", "trace_context", "expand_tests", "expand_dependencies"]);
|
|
14687
|
+
var MAX_REQUEST_BYTES = 8192;
|
|
14688
|
+
var HELPER = `#!/usr/bin/env node
|
|
14689
|
+
const net = require("node:net");
|
|
14690
|
+
const [operation, ref, reason] = process.argv.slice(2);
|
|
14691
|
+
if (!operation || !ref || !reason || process.argv.length !== 5) {
|
|
14692
|
+
console.error("usage: reasontrail-context <operation> <ref> <reason>");
|
|
14693
|
+
process.exit(2);
|
|
14694
|
+
}
|
|
14695
|
+
const socket = process.env.REASONTRAIL_CONTEXT_SOCKET;
|
|
14696
|
+
if (!socket) { console.error("context bridge unavailable"); process.exit(3); }
|
|
14697
|
+
const client = net.createConnection(socket);
|
|
14698
|
+
let response = "";
|
|
14699
|
+
client.on("connect", () => client.write(JSON.stringify({ operation, ref, reason }) + "\\n"));
|
|
14700
|
+
client.on("data", chunk => { if (response.length < 100000) response += chunk.toString("utf8"); });
|
|
14701
|
+
client.on("end", () => { process.stdout.write(response); });
|
|
14702
|
+
client.on("error", error => { console.error(error.message); process.exit(4); });
|
|
14703
|
+
`;
|
|
14704
|
+
function handleConnection(socket, invoke) {
|
|
14705
|
+
let body = "";
|
|
14706
|
+
let handled = false;
|
|
14707
|
+
socket.on("data", (chunk) => {
|
|
14708
|
+
body += chunk.toString("utf8");
|
|
14709
|
+
if (Buffer.byteLength(body, "utf8") > MAX_REQUEST_BYTES) socket.destroy(new Error("request too large"));
|
|
14710
|
+
if (handled || !body.includes("\n")) return;
|
|
14711
|
+
handled = true;
|
|
14712
|
+
void respond();
|
|
14713
|
+
});
|
|
14714
|
+
const respond = async () => {
|
|
14715
|
+
try {
|
|
14716
|
+
const value = JSON.parse(body.trim());
|
|
14717
|
+
const operation = typeof value.operation === "string" ? value.operation : "";
|
|
14718
|
+
const ref = typeof value.ref === "string" ? value.ref : "";
|
|
14719
|
+
const reason = typeof value.reason === "string" ? value.reason.trim() : "";
|
|
14720
|
+
if (!OPERATIONS.has(operation) || !ref || ref.length > 2e3 || !reason || reason.length > 400) {
|
|
14721
|
+
throw new Error("invalid progressive retrieval request");
|
|
14722
|
+
}
|
|
14723
|
+
const result = await invoke({ operation, ref, reason });
|
|
14724
|
+
socket.end(`${JSON.stringify({ ok: true, result })}
|
|
14725
|
+
`);
|
|
14726
|
+
} catch (error51) {
|
|
14727
|
+
socket.end(`${JSON.stringify({ ok: false, error: error51 instanceof Error ? error51.message.slice(0, 300) : "request failed" })}
|
|
14728
|
+
`);
|
|
14729
|
+
}
|
|
14730
|
+
};
|
|
14731
|
+
}
|
|
14732
|
+
async function startExecutionContextBridge(input) {
|
|
14733
|
+
const directory = await mkdtemp(join(tmpdir(), "reasontrail-context-"));
|
|
14734
|
+
const helper = join(directory, "reasontrail-context");
|
|
14735
|
+
const socketPath = join(directory, "bridge.sock");
|
|
14736
|
+
await writeFile(helper, HELPER, { encoding: "utf8", mode: 448 });
|
|
14737
|
+
await chmod(directory, 448);
|
|
14738
|
+
const connections = /* @__PURE__ */ new Set();
|
|
14739
|
+
const server = createServer((socket) => {
|
|
14740
|
+
connections.add(socket);
|
|
14741
|
+
socket.once("close", () => connections.delete(socket));
|
|
14742
|
+
handleConnection(
|
|
14743
|
+
socket,
|
|
14744
|
+
(request) => input.client.expandContext(input.executionId, {
|
|
14745
|
+
leaseToken: input.leaseToken,
|
|
14746
|
+
workspaceLeaseToken: input.workspaceLeaseToken,
|
|
14747
|
+
operation: request.operation,
|
|
14748
|
+
ref: request.ref,
|
|
14749
|
+
reason: request.reason
|
|
14750
|
+
})
|
|
14751
|
+
);
|
|
14752
|
+
});
|
|
14753
|
+
await new Promise((resolve4, reject) => {
|
|
14754
|
+
server.once("error", reject);
|
|
14755
|
+
server.listen(socketPath, () => {
|
|
14756
|
+
server.off("error", reject);
|
|
14757
|
+
resolve4();
|
|
14758
|
+
});
|
|
14759
|
+
});
|
|
14760
|
+
await chmod(socketPath, 384);
|
|
14761
|
+
let closed = false;
|
|
14762
|
+
return {
|
|
14763
|
+
command: "reasontrail-context",
|
|
14764
|
+
operations: input.operations.filter((operation) => OPERATIONS.has(operation)),
|
|
14765
|
+
environment: {
|
|
14766
|
+
PATH: `${directory}:${process.env.PATH ?? ""}`,
|
|
14767
|
+
REASONTRAIL_CONTEXT_SOCKET: socketPath
|
|
14768
|
+
},
|
|
14769
|
+
async close() {
|
|
14770
|
+
if (closed) return;
|
|
14771
|
+
closed = true;
|
|
14772
|
+
for (const connection of connections) connection.destroy();
|
|
14773
|
+
await new Promise((resolve4) => server.close(() => resolve4()));
|
|
14774
|
+
await rm(directory, { recursive: true, force: true });
|
|
14775
|
+
}
|
|
14776
|
+
};
|
|
14777
|
+
}
|
|
14778
|
+
|
|
14656
14779
|
// src/cli/workers/claude-code.ts
|
|
14657
14780
|
import { spawn } from "node:child_process";
|
|
14658
14781
|
import { readFileSync, accessSync, constants as fsConstants } from "node:fs";
|
|
14659
14782
|
import { homedir } from "node:os";
|
|
14660
|
-
import { join } from "node:path";
|
|
14783
|
+
import { join as join2 } from "node:path";
|
|
14661
14784
|
|
|
14662
14785
|
// src/cli/workers/provider-environment.ts
|
|
14663
14786
|
var COMMON_KEYS = [
|
|
@@ -14698,12 +14821,16 @@ function commonSubprocessEnvironment(source) {
|
|
|
14698
14821
|
}
|
|
14699
14822
|
return environment;
|
|
14700
14823
|
}
|
|
14701
|
-
function providerSubprocessEnvironment(provider, source = process.env) {
|
|
14824
|
+
function providerSubprocessEnvironment(provider, source = process.env, additions = {}) {
|
|
14702
14825
|
const environment = commonSubprocessEnvironment(source);
|
|
14703
14826
|
for (const key of PROVIDER_KEYS[provider]) {
|
|
14704
14827
|
const value = source[key];
|
|
14705
14828
|
if (value !== void 0) environment[key] = value;
|
|
14706
14829
|
}
|
|
14830
|
+
if (additions.PATH !== void 0) environment.PATH = additions.PATH;
|
|
14831
|
+
if (additions.REASONTRAIL_CONTEXT_SOCKET !== void 0) {
|
|
14832
|
+
environment.REASONTRAIL_CONTEXT_SOCKET = additions.REASONTRAIL_CONTEXT_SOCKET;
|
|
14833
|
+
}
|
|
14707
14834
|
return environment;
|
|
14708
14835
|
}
|
|
14709
14836
|
function workspacePreparationEnvironment(input, source = process.env) {
|
|
@@ -14738,6 +14865,177 @@ function workspacePreparationEnvironment(input, source = process.env) {
|
|
|
14738
14865
|
// src/services/mission/roles.ts
|
|
14739
14866
|
var MISSION_ROLE_IDS = ["IMPLEMENTER", "INVESTIGATOR", "BROWSER_QA"];
|
|
14740
14867
|
|
|
14868
|
+
// src/services/execution-retrieval/contracts.ts
|
|
14869
|
+
var RETRIEVAL_STAGES = ["WORK_PREPARATION", "MISSION_INITIAL", "RUNTIME_EXPANSION"];
|
|
14870
|
+
var EVIDENCE_KINDS = [
|
|
14871
|
+
"DECISION",
|
|
14872
|
+
"IDEA",
|
|
14873
|
+
"TASK",
|
|
14874
|
+
"BLOCKER",
|
|
14875
|
+
"WORK_REQUEST",
|
|
14876
|
+
"REPOSITORY_SYMBOL",
|
|
14877
|
+
"SOURCE_EXCERPT",
|
|
14878
|
+
"TEST",
|
|
14879
|
+
"RELATION",
|
|
14880
|
+
"CONFLICT",
|
|
14881
|
+
"FALLBACK"
|
|
14882
|
+
];
|
|
14883
|
+
var CURRENT_STATES = ["CURRENT", "HISTORICAL", "SUPERSEDED", "CONFLICTING", "UNKNOWN"];
|
|
14884
|
+
var ACTIONABILITY_TIERS = ["CANDIDATE", "CORROBORATED", "EXECUTION_SHA_VERIFIED"];
|
|
14885
|
+
var EXECUTION_COMPATIBILITY = ["EXACT_SHA", "INDEX_ONLY", "MISMATCH", "UNKNOWN"];
|
|
14886
|
+
var PROGRESSIVE_OPERATIONS = ["inspect_context", "trace_context", "expand_tests", "expand_dependencies"];
|
|
14887
|
+
var boundedText = (max) => external_exports.string().trim().max(max);
|
|
14888
|
+
var evidenceProvenanceSchema = external_exports.object({
|
|
14889
|
+
source: boundedText(80),
|
|
14890
|
+
recordId: boundedText(500),
|
|
14891
|
+
version: boundedText(200).nullable(),
|
|
14892
|
+
authority: boundedText(80),
|
|
14893
|
+
citation: boundedText(1e3).nullable()
|
|
14894
|
+
});
|
|
14895
|
+
var evidenceRelationsSchema = external_exports.object({
|
|
14896
|
+
callers: external_exports.array(boundedText(1e3)).max(20).default([]),
|
|
14897
|
+
dependencies: external_exports.array(boundedText(1e3)).max(20).default([]),
|
|
14898
|
+
tests: external_exports.array(boundedText(1e3)).max(20).default([]),
|
|
14899
|
+
relatedFiles: external_exports.array(boundedText(1e3)).max(30).default([])
|
|
14900
|
+
});
|
|
14901
|
+
var evidenceBundleSchema = external_exports.object({
|
|
14902
|
+
id: boundedText(100),
|
|
14903
|
+
kind: external_exports.enum(EVIDENCE_KINDS),
|
|
14904
|
+
sourceRecordId: boundedText(500),
|
|
14905
|
+
sourceVersion: boundedText(200).nullable(),
|
|
14906
|
+
projectId: boundedText(100),
|
|
14907
|
+
repositoryId: boundedText(100).nullable(),
|
|
14908
|
+
content: boundedText(8e3),
|
|
14909
|
+
summary: boundedText(1500),
|
|
14910
|
+
relevance: external_exports.number().min(0).max(1),
|
|
14911
|
+
lexicalScore: external_exports.number().min(0).max(1),
|
|
14912
|
+
semanticScore: external_exports.number().min(0).max(1).default(0),
|
|
14913
|
+
entityScore: external_exports.number().min(0).max(1),
|
|
14914
|
+
graphScore: external_exports.number().min(0).max(1),
|
|
14915
|
+
temporalScore: external_exports.number().min(0).max(1),
|
|
14916
|
+
lifecycleScore: external_exports.number().min(0).max(1),
|
|
14917
|
+
evidenceStrength: external_exports.number().min(0).max(1),
|
|
14918
|
+
actionabilityScore: external_exports.number().min(0).max(1),
|
|
14919
|
+
expectedUtility: external_exports.number().min(0),
|
|
14920
|
+
currentState: external_exports.enum(CURRENT_STATES),
|
|
14921
|
+
sourceConfidence: external_exports.number().min(0).max(1),
|
|
14922
|
+
repositoryRevision: boundedText(200).nullable(),
|
|
14923
|
+
executionCompatibility: external_exports.enum(EXECUTION_COMPATIBILITY),
|
|
14924
|
+
actionabilityTier: external_exports.enum(ACTIONABILITY_TIERS),
|
|
14925
|
+
estimatedTokens: external_exports.number().int().positive(),
|
|
14926
|
+
provenance: external_exports.array(evidenceProvenanceSchema).min(1).max(20),
|
|
14927
|
+
relations: evidenceRelationsSchema,
|
|
14928
|
+
canonicalEntityRefs: external_exports.array(boundedText(1e3)).max(20).default([]),
|
|
14929
|
+
progressiveRef: boundedText(2e3).nullable(),
|
|
14930
|
+
expectedSourceReadsReplaced: external_exports.array(boundedText(1e3)).max(20).default([])
|
|
14931
|
+
});
|
|
14932
|
+
var publicEvidenceSchema = evidenceBundleSchema.pick({
|
|
14933
|
+
id: true,
|
|
14934
|
+
kind: true,
|
|
14935
|
+
summary: true,
|
|
14936
|
+
content: true,
|
|
14937
|
+
currentState: true,
|
|
14938
|
+
sourceConfidence: true,
|
|
14939
|
+
repositoryRevision: true,
|
|
14940
|
+
executionCompatibility: true,
|
|
14941
|
+
actionabilityTier: true,
|
|
14942
|
+
estimatedTokens: true,
|
|
14943
|
+
provenance: true,
|
|
14944
|
+
relations: true,
|
|
14945
|
+
canonicalEntityRefs: true,
|
|
14946
|
+
progressiveRef: true,
|
|
14947
|
+
expectedSourceReadsReplaced: true
|
|
14948
|
+
});
|
|
14949
|
+
var executionAssistanceViewSchema = external_exports.object({
|
|
14950
|
+
version: external_exports.literal(1),
|
|
14951
|
+
bundleId: boundedText(100),
|
|
14952
|
+
stage: external_exports.enum(RETRIEVAL_STAGES),
|
|
14953
|
+
generatedAt: external_exports.string().datetime(),
|
|
14954
|
+
projectId: boundedText(100),
|
|
14955
|
+
repositoryId: boundedText(100).nullable(),
|
|
14956
|
+
repositoryRevision: boundedText(200).nullable(),
|
|
14957
|
+
executionSha: boundedText(200).nullable(),
|
|
14958
|
+
queryHash: boundedText(64),
|
|
14959
|
+
stateVersion: boundedText(64),
|
|
14960
|
+
budget: external_exports.object({
|
|
14961
|
+
assistanceTokens: external_exports.number().int().positive(),
|
|
14962
|
+
selectedTokens: external_exports.number().int().nonnegative(),
|
|
14963
|
+
protectedTokens: external_exports.number().int().nonnegative(),
|
|
14964
|
+
progressiveTokens: external_exports.number().int().positive(),
|
|
14965
|
+
respected: external_exports.boolean()
|
|
14966
|
+
}),
|
|
14967
|
+
protected: external_exports.object({
|
|
14968
|
+
objective: boundedText(1e4),
|
|
14969
|
+
constraints: external_exports.array(boundedText(2e3)).max(40),
|
|
14970
|
+
acceptanceCriteria: external_exports.array(boundedText(2e3)).max(40),
|
|
14971
|
+
governance: external_exports.array(boundedText(2e3)).max(40)
|
|
14972
|
+
}),
|
|
14973
|
+
evidence: external_exports.array(publicEvidenceSchema).max(100),
|
|
14974
|
+
omitted: external_exports.array(external_exports.object({ id: boundedText(100), kind: external_exports.enum(EVIDENCE_KINDS), reason: boundedText(200) })).max(200),
|
|
14975
|
+
warnings: external_exports.array(boundedText(1e3)).max(30),
|
|
14976
|
+
fallbacks: external_exports.array(boundedText(1e3)).max(30),
|
|
14977
|
+
progressive: external_exports.object({
|
|
14978
|
+
operations: external_exports.array(external_exports.enum(PROGRESSIVE_OPERATIONS)),
|
|
14979
|
+
availableRefs: external_exports.array(boundedText(2e3)).max(100),
|
|
14980
|
+
instruction: boundedText(1e3)
|
|
14981
|
+
}),
|
|
14982
|
+
rendered: boundedText(2e4),
|
|
14983
|
+
telemetry: external_exports.object({
|
|
14984
|
+
candidates: external_exports.number().int().nonnegative(),
|
|
14985
|
+
selected: external_exports.number().int().nonnegative(),
|
|
14986
|
+
duplicatesCollapsed: external_exports.number().int().nonnegative(),
|
|
14987
|
+
conflicts: external_exports.number().int().nonnegative(),
|
|
14988
|
+
cache: external_exports.enum(["MISS", "REUSED", "REFRESHED"])
|
|
14989
|
+
})
|
|
14990
|
+
});
|
|
14991
|
+
var selectionDecisionSchema = external_exports.object({
|
|
14992
|
+
id: boundedText(100),
|
|
14993
|
+
kind: external_exports.enum(EVIDENCE_KINDS),
|
|
14994
|
+
estimatedTokens: external_exports.number().int().nonnegative(),
|
|
14995
|
+
currentState: external_exports.enum(CURRENT_STATES),
|
|
14996
|
+
relevance: external_exports.object({
|
|
14997
|
+
classification: external_exports.enum(["LOW", "MEDIUM", "HIGH"]),
|
|
14998
|
+
score: external_exports.number().min(0).max(1)
|
|
14999
|
+
}),
|
|
15000
|
+
actionability: external_exports.object({
|
|
15001
|
+
tier: external_exports.enum(ACTIONABILITY_TIERS),
|
|
15002
|
+
score: external_exports.number().min(0).max(1),
|
|
15003
|
+
expectedRepositoryDiscoveryStepsReplaced: external_exports.array(boundedText(1e3)).max(20)
|
|
15004
|
+
}),
|
|
15005
|
+
selected: external_exports.boolean(),
|
|
15006
|
+
decision: external_exports.enum(["PROTECTED", "SELECTED", "OMITTED"]),
|
|
15007
|
+
exactReason: external_exports.enum([
|
|
15008
|
+
"protected_objective_or_governance",
|
|
15009
|
+
"selected_by_global_budget",
|
|
15010
|
+
"omitted_low_relevance",
|
|
15011
|
+
"omitted_duplicate",
|
|
15012
|
+
"omitted_budget"
|
|
15013
|
+
]),
|
|
15014
|
+
reasonDetail: boundedText(500),
|
|
15015
|
+
duplicateOfId: boundedText(100).nullable(),
|
|
15016
|
+
provenance: external_exports.array(evidenceProvenanceSchema).min(1).max(20),
|
|
15017
|
+
evidenceTier: external_exports.enum(ACTIONABILITY_TIERS)
|
|
15018
|
+
});
|
|
15019
|
+
var selectionTraceSchema = external_exports.object({
|
|
15020
|
+
assistanceBudgetTokens: external_exports.number().int().positive(),
|
|
15021
|
+
protectedBudgetTokens: external_exports.number().int().nonnegative(),
|
|
15022
|
+
optionalBudgetTokens: external_exports.number().int().nonnegative(),
|
|
15023
|
+
protectedContent: external_exports.object({
|
|
15024
|
+
objective: boundedText(1e4),
|
|
15025
|
+
constraints: external_exports.array(boundedText(2e3)).max(40),
|
|
15026
|
+
acceptanceCriteria: external_exports.array(boundedText(2e3)).max(40),
|
|
15027
|
+
governance: external_exports.array(boundedText(2e3)).max(40)
|
|
15028
|
+
}),
|
|
15029
|
+
candidates: external_exports.array(selectionDecisionSchema).max(400)
|
|
15030
|
+
});
|
|
15031
|
+
var progressiveRetrievalInputSchema = external_exports.object({
|
|
15032
|
+
leaseToken: external_exports.string().trim().min(1).max(500),
|
|
15033
|
+
workspaceLeaseToken: external_exports.string().trim().min(1).max(500),
|
|
15034
|
+
operation: external_exports.enum(PROGRESSIVE_OPERATIONS),
|
|
15035
|
+
ref: external_exports.string().trim().min(1).max(2e3),
|
|
15036
|
+
reason: external_exports.string().trim().min(1).max(400)
|
|
15037
|
+
}).strict();
|
|
15038
|
+
|
|
14741
15039
|
// src/services/mission/contracts.ts
|
|
14742
15040
|
var line = external_exports.string().trim().min(1).max(2e3);
|
|
14743
15041
|
var shortLine = external_exports.string().trim().min(1).max(400);
|
|
@@ -14759,12 +15057,22 @@ var executionPackageSchema = external_exports.object({
|
|
|
14759
15057
|
statement: line,
|
|
14760
15058
|
workspaceRoot: external_exports.string().trim().min(1).max(1e3)
|
|
14761
15059
|
}),
|
|
15060
|
+
/**
|
|
15061
|
+
* Runtime dependency preparation is an assignment requirement, not an
|
|
15062
|
+
* inference that repository-level package metadata may override. Missing on
|
|
15063
|
+
* persisted legacy packages means AUTO for backwards compatibility.
|
|
15064
|
+
*/
|
|
15065
|
+
dependencyPreparation: dependencyPreparationPolicySchema.default("AUTO"),
|
|
15066
|
+
/** User/project constraints are first-class and survive deterministic plans. */
|
|
15067
|
+
constraints: external_exports.array(line).max(20).default([]),
|
|
14762
15068
|
doNot: external_exports.array(shortLine).min(1).max(40),
|
|
14763
15069
|
/**
|
|
14764
15070
|
* Authoritative discoveries already established, so the worker does not spend
|
|
14765
15071
|
* a session re-deriving them. References into ReasonTrail where possible.
|
|
14766
15072
|
*/
|
|
14767
15073
|
knownFacts: external_exports.array(external_exports.object({ fact: line, source: shortLine.optional() })).max(40),
|
|
15074
|
+
/** One score-free view from the shared Work/Mission retrieval engine. */
|
|
15075
|
+
assistance: executionAssistanceViewSchema.optional(),
|
|
14768
15076
|
questionsToAnswer: external_exports.array(shortLine).max(20),
|
|
14769
15077
|
requiredActions: external_exports.array(external_exports.object({ order: external_exports.number().int().min(1), action: line })).max(20),
|
|
14770
15078
|
acceptanceCriteria: external_exports.array(external_exports.object({ id: shortLine, statement: line })).min(1).max(20),
|
|
@@ -14867,16 +15175,36 @@ var workerResultSchema = external_exports.object({
|
|
|
14867
15175
|
* anyone can type.
|
|
14868
15176
|
*/
|
|
14869
15177
|
runtimeEvidence: external_exports.array(evidenceSubmissionSchema).max(20).default([]),
|
|
15178
|
+
/** Native provider events captured by the runtime, not parsed from worker prose. */
|
|
15179
|
+
runtimeObservations: external_exports.array(external_exports.object({
|
|
15180
|
+
type: external_exports.literal("COMMAND"),
|
|
15181
|
+
command: shortLine
|
|
15182
|
+
})).max(200).default([]),
|
|
14870
15183
|
/**
|
|
14871
15184
|
* Reported ONLY when the worker's tooling actually supplies it. Omitted means
|
|
14872
15185
|
* unknown, and unknown is stored and displayed as unknown — never zero.
|
|
14873
15186
|
*/
|
|
14874
15187
|
usage: external_exports.object({
|
|
14875
15188
|
inputTokens: external_exports.number().int().min(0).optional(),
|
|
15189
|
+
cachedInputTokens: external_exports.number().int().min(0).optional(),
|
|
15190
|
+
cacheCreationTokens: external_exports.number().int().min(0).optional(),
|
|
14876
15191
|
outputTokens: external_exports.number().int().min(0).optional(),
|
|
15192
|
+
reasoningTokens: external_exports.number().int().min(0).optional(),
|
|
14877
15193
|
costMicros: external_exports.number().int().min(0).optional(),
|
|
14878
15194
|
/** How the numbers were obtained, so an estimate is never read as a measurement. */
|
|
14879
|
-
source: external_exports.enum(["PROVIDER_REPORTED", "UNAVAILABLE"]).default("UNAVAILABLE")
|
|
15195
|
+
source: external_exports.enum(["PROVIDER_REPORTED", "UNAVAILABLE"]).default("UNAVAILABLE"),
|
|
15196
|
+
/** Native events are per turn; these totals sum the completed turns in this process. */
|
|
15197
|
+
scope: external_exports.literal("SUMMED_PER_TURN").optional(),
|
|
15198
|
+
completedTurns: external_exports.number().int().min(0).optional(),
|
|
15199
|
+
/** False means one or more native counters were absent or malformed. */
|
|
15200
|
+
measurementComplete: external_exports.boolean().optional(),
|
|
15201
|
+
turns: external_exports.array(external_exports.object({
|
|
15202
|
+
inputTokens: external_exports.number().int().min(0).optional(),
|
|
15203
|
+
cachedInputTokens: external_exports.number().int().min(0).optional(),
|
|
15204
|
+
cacheCreationTokens: external_exports.number().int().min(0).optional(),
|
|
15205
|
+
outputTokens: external_exports.number().int().min(0).optional(),
|
|
15206
|
+
reasoningTokens: external_exports.number().int().min(0).optional()
|
|
15207
|
+
})).max(100).optional()
|
|
14880
15208
|
}).optional(),
|
|
14881
15209
|
durationMs: external_exports.number().int().min(0).optional(),
|
|
14882
15210
|
/** Repository state the work was performed against. */
|
|
@@ -14913,6 +15241,62 @@ function run(command, args, opts) {
|
|
|
14913
15241
|
}
|
|
14914
15242
|
});
|
|
14915
15243
|
}
|
|
15244
|
+
function normalizedRequirement(value) {
|
|
15245
|
+
return value.replace(/`([^`]*)`/g, "$1").replace(/\*\*([^*]+)\*\*/g, "$1").replace(/__([^_]+)__/g, "$1").replace(/\s+/g, " ").trim().toLowerCase();
|
|
15246
|
+
}
|
|
15247
|
+
var CRITERIA_HEADING = /^\s*(?:#{1,6}\s*)?acceptance\s+criteria\s*:?\s*$/i;
|
|
15248
|
+
var CRITERION_ITEM = /^\s*(?:\d+[.)]|[-+*])\s+(?:\[[ xX]\]\s*)?(.*)$/;
|
|
15249
|
+
function missionWithoutRepeatedAcceptanceCriteria(mission, criteria) {
|
|
15250
|
+
if (!mission.trim() || criteria.length === 0) return mission.trim();
|
|
15251
|
+
const lines = mission.replace(/\r\n/g, "\n").split("\n");
|
|
15252
|
+
const headingIndex = lines.findIndex((line2) => CRITERIA_HEADING.test(line2.replace(/\*\*/g, "")));
|
|
15253
|
+
if (headingIndex < 0) return mission.trim();
|
|
15254
|
+
const extracted = [];
|
|
15255
|
+
let current = "";
|
|
15256
|
+
let lastContentIndex = headingIndex;
|
|
15257
|
+
let sawBlankAfterItem = false;
|
|
15258
|
+
let cursor = headingIndex + 1;
|
|
15259
|
+
for (; cursor < lines.length; cursor += 1) {
|
|
15260
|
+
const line2 = lines[cursor];
|
|
15261
|
+
const item = line2.match(CRITERION_ITEM);
|
|
15262
|
+
if (item) {
|
|
15263
|
+
if (current) extracted.push(current);
|
|
15264
|
+
current = item[1].trim();
|
|
15265
|
+
lastContentIndex = cursor;
|
|
15266
|
+
sawBlankAfterItem = false;
|
|
15267
|
+
continue;
|
|
15268
|
+
}
|
|
15269
|
+
if (!line2.trim()) {
|
|
15270
|
+
if (current) sawBlankAfterItem = true;
|
|
15271
|
+
continue;
|
|
15272
|
+
}
|
|
15273
|
+
if (!current || sawBlankAfterItem || /^\s*#{1,6}\s+/.test(line2)) break;
|
|
15274
|
+
current = `${current} ${line2.trim()}`;
|
|
15275
|
+
lastContentIndex = cursor;
|
|
15276
|
+
}
|
|
15277
|
+
if (current) extracted.push(current);
|
|
15278
|
+
const expected = criteria.map((criterion) => normalizedRequirement(criterion.statement));
|
|
15279
|
+
const actual = extracted.map(normalizedRequirement);
|
|
15280
|
+
if (actual.length !== expected.length || actual.some((item, index) => item !== expected[index])) {
|
|
15281
|
+
return mission.trim();
|
|
15282
|
+
}
|
|
15283
|
+
const before = lines.slice(0, headingIndex);
|
|
15284
|
+
const after = lines.slice(lastContentIndex + 1);
|
|
15285
|
+
return [...before, ...after].join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
15286
|
+
}
|
|
15287
|
+
function renderCheckoutProvenance(assignment) {
|
|
15288
|
+
const checkout = assignment.checkout;
|
|
15289
|
+
if (!checkout) return "";
|
|
15290
|
+
const expected = checkout.missionExpectedStartingSha.trim().toLowerCase();
|
|
15291
|
+
const registered = checkout.runtimeRegisteredStartingSha.trim().toLowerCase();
|
|
15292
|
+
const verified = checkout.cleanBaselineVerified && /^[0-9a-f]{40}$/.test(expected) && expected === registered;
|
|
15293
|
+
return [
|
|
15294
|
+
`- Mission-pinned starting revision: ${expected || "unknown"}`,
|
|
15295
|
+
`- Runtime-registered execution checkout HEAD: ${registered || "unknown"}`,
|
|
15296
|
+
`- Checkout compatibility with Mission pin: ${verified ? "VERIFIED_CURRENT" : "UNKNOWN"}`,
|
|
15297
|
+
"- This attests only to the disposable execution checkout; it does not assert repository graph HEAD freshness, which remains as stated under KNOWN FACTS."
|
|
15298
|
+
].join("\n");
|
|
15299
|
+
}
|
|
14916
15300
|
function renderPackagePrompt(assignment) {
|
|
14917
15301
|
const p = assignment.package;
|
|
14918
15302
|
const section2 = (title, body) => body.trim() ? `## ${title}
|
|
@@ -14922,37 +15306,39 @@ ${body.trim()}
|
|
|
14922
15306
|
return [
|
|
14923
15307
|
`# ReasonTrail assignment #${assignment.sequence} \u2014 ${p.role}`,
|
|
14924
15308
|
"",
|
|
14925
|
-
section2("MISSION", String(p.mission ?? "")),
|
|
15309
|
+
section2("MISSION", missionWithoutRepeatedAcceptanceCriteria(String(p.mission ?? ""), p.acceptanceCriteria ?? [])),
|
|
14926
15310
|
section2("WHY THIS ASSIGNMENT EXISTS", String(p.whyThisAssignmentExists ?? "")),
|
|
14927
15311
|
section2("SCOPE", `${p.scope?.statement ?? ""}
|
|
14928
15312
|
Workspace root: ${assignment.workspaceRoot}
|
|
14929
15313
|
${(p.scope?.paths ?? []).length ? `Paths:
|
|
14930
15314
|
${list(p.scope?.paths)}` : ""}`),
|
|
15315
|
+
section2("EXECUTION CHECKOUT PROVENANCE", renderCheckoutProvenance(assignment)),
|
|
15316
|
+
section2("CONSTRAINTS", list(p.constraints)),
|
|
14931
15317
|
section2("DO NOT", list(p.doNot)),
|
|
14932
15318
|
section2("KNOWN FACTS", (p.knownFacts ?? []).map((f) => `- ${f.fact}${f.source ? ` (source: ${f.source})` : ""}`).join("\n")),
|
|
15319
|
+
section2("EXECUTION ASSISTANCE", [
|
|
15320
|
+
p.assistance?.rendered ?? "",
|
|
15321
|
+
p.assistance?.progressive?.operations?.length ? `Progressive retrieval: ${p.assistance.progressive.operations.join(", ")}. ${p.assistance.progressive.instruction ?? ""}` : ""
|
|
15322
|
+
].filter(Boolean).join("\n")),
|
|
15323
|
+
section2("PROGRESSIVE CONTEXT TOOL", assignment.contextTool ? `Use only when the initial evidence is insufficient: ${assignment.contextTool.command} <operation> <ref> '<reason>'. Allowed operations: ${assignment.contextTool.operations.join(", ")}. The ref must be copied from EXECUTION ASSISTANCE.` : ""),
|
|
14933
15324
|
section2("QUESTIONS TO ANSWER", list(p.questionsToAnswer)),
|
|
14934
15325
|
section2("REQUIRED ACTIONS", (p.requiredActions ?? []).map((a) => `${a.order}. ${a.action}`).join("\n")),
|
|
14935
15326
|
section2("ACCEPTANCE CRITERIA", (p.acceptanceCriteria ?? []).map((c) => `- [${c.id}] ${c.statement}`).join("\n")),
|
|
14936
15327
|
section2("REQUIRED EVIDENCE", (p.requiredEvidence ?? []).map((e) => `- ${e.kind}: ${e.description}${e.command ? ` (run: ${e.command})` : ""}`).join("\n")),
|
|
14937
15328
|
section2(
|
|
14938
|
-
"
|
|
14939
|
-
`Use only these exact evidence kind values: ${MISSION_EVIDENCE_KINDS.join(", ")}. A git status transcript is COMMAND_OUTPUT; GIT_STATUS is not a protocol-v3 evidence kind.`
|
|
14940
|
-
),
|
|
14941
|
-
section2(
|
|
14942
|
-
"FILE CHANGE CONTRACT",
|
|
14943
|
-
`Use only these exact file change values: ${WORKER_FILE_CHANGE_KINDS.join(", ")}.`
|
|
15329
|
+
"RESULT VOCABULARY",
|
|
15330
|
+
`Use only these exact evidence kind values: ${MISSION_EVIDENCE_KINDS.join(", ")}. A git status transcript is COMMAND_OUTPUT; GIT_STATUS is not a protocol-v3 evidence kind. Use only these exact file change values: ${WORKER_FILE_CHANGE_KINDS.join(", ")}.`
|
|
14944
15331
|
),
|
|
14945
15332
|
section2("VALIDATION POLICY", [
|
|
14946
15333
|
"Run every validation command from this disposable workspace and capture its literal result as evidence.",
|
|
14947
|
-
"Use an exact command named under REQUIRED EVIDENCE when one is supplied.",
|
|
14948
|
-
"
|
|
14949
|
-
"
|
|
14950
|
-
"Never skip a required check, run validation in the canonical checkout, or report a missing command as success."
|
|
15334
|
+
"Use an exact command named under REQUIRED EVIDENCE when one is supplied; otherwise choose the smallest real checks that prove the acceptance criteria. Verify static facts directly; for executable behavior run focused tests, and run the full suite only when the criteria, repository policy, or lack of a narrower check requires it; do not invent a full repository suite merely because package.json exposes one.",
|
|
15335
|
+
"Never skip a required check, run validation in the canonical checkout, or report a missing command as success.",
|
|
15336
|
+
"Run required provenance and validation checks independently from optional discovery searches. Tools such as rg normally exit 1 when nothing matches; putting them first in an && chain would skip later checks. Preserve and report the real exit code."
|
|
14951
15337
|
].map((line2) => `- ${line2}`).join("\n")),
|
|
14952
15338
|
section2("STOP CONDITIONS", list(p.stopConditions)),
|
|
14953
15339
|
section2("HUMAN DECISION CONDITIONS", `You are NOT authorized to decide these. Stop and report status BLOCKED with the question instead:
|
|
14954
15340
|
${list(p.humanDecisionConditions)}`),
|
|
14955
|
-
section2("REPORT
|
|
15341
|
+
section2("REPORT AUTHORITY", "Your confidence is informational; ReasonTrail decides completion from literal evidence."),
|
|
14956
15342
|
"",
|
|
14957
15343
|
"## OUTPUT",
|
|
14958
15344
|
"When you are finished, print ONE fenced JSON block and nothing after it:",
|
|
@@ -14976,7 +15362,7 @@ async function workspaceUnattendedReadiness(root, deps = {}) {
|
|
|
14976
15362
|
}
|
|
14977
15363
|
let config2;
|
|
14978
15364
|
try {
|
|
14979
|
-
config2 = JSON.parse(readFile2(
|
|
15365
|
+
config2 = JSON.parse(readFile2(join2(home, ".claude.json")));
|
|
14980
15366
|
} catch {
|
|
14981
15367
|
return {
|
|
14982
15368
|
ready: false,
|
|
@@ -15024,9 +15410,9 @@ import { createHash } from "node:crypto";
|
|
|
15024
15410
|
|
|
15025
15411
|
// src/services/targets/ssh-client.ts
|
|
15026
15412
|
import { spawn as spawn2 } from "node:child_process";
|
|
15027
|
-
import { writeFile, rm, mkdtemp } from "node:fs/promises";
|
|
15028
|
-
import { tmpdir } from "node:os";
|
|
15029
|
-
import { join as
|
|
15413
|
+
import { writeFile as writeFile2, rm as rm2, mkdtemp as mkdtemp2 } from "node:fs/promises";
|
|
15414
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
15415
|
+
import { join as join3 } from "node:path";
|
|
15030
15416
|
import { performance } from "node:perf_hooks";
|
|
15031
15417
|
|
|
15032
15418
|
// src/services/targets/workspace-provenance.ts
|
|
@@ -15105,11 +15491,151 @@ function shellQuote(value) {
|
|
|
15105
15491
|
import { spawn as spawn3 } from "node:child_process";
|
|
15106
15492
|
import { performance as performance2 } from "node:perf_hooks";
|
|
15107
15493
|
var MAX_OUTPUT_BYTES2 = 4e6;
|
|
15494
|
+
var SHA40 = /^[0-9a-f]{40}$/i;
|
|
15495
|
+
var SAFE_REPOSITORY_PATH = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9_.@+\-/]{1,500}$/;
|
|
15496
|
+
var MAX_SUBSTITUTION_TARGETS = 12;
|
|
15497
|
+
function exactSha(value) {
|
|
15498
|
+
return typeof value === "string" && SHA40.test(value) ? value.toLowerCase() : null;
|
|
15499
|
+
}
|
|
15500
|
+
function safeTargets(value) {
|
|
15501
|
+
if (!Array.isArray(value)) return [];
|
|
15502
|
+
return value.filter(
|
|
15503
|
+
(item) => typeof item === "string" && SAFE_REPOSITORY_PATH.test(item)
|
|
15504
|
+
);
|
|
15505
|
+
}
|
|
15506
|
+
function buildCodexSubstitutionInstructions(assignment) {
|
|
15507
|
+
const checkout = assignment.checkout;
|
|
15508
|
+
if (!checkout?.cleanBaselineVerified) return null;
|
|
15509
|
+
const expectedSha = exactSha(checkout.missionExpectedStartingSha);
|
|
15510
|
+
const registeredSha = exactSha(checkout.runtimeRegisteredStartingSha);
|
|
15511
|
+
if (!expectedSha || expectedSha !== registeredSha) return null;
|
|
15512
|
+
const assistance = assignment.package.assistance;
|
|
15513
|
+
if (!assistance || exactSha(assistance.repositoryRevision) !== expectedSha) return null;
|
|
15514
|
+
if (exactSha(assistance.executionSha) !== expectedSha || !Array.isArray(assistance.evidence)) {
|
|
15515
|
+
return null;
|
|
15516
|
+
}
|
|
15517
|
+
const exactEvidence = assistance.evidence.filter(
|
|
15518
|
+
(item) => item && item.currentState === "CURRENT" && item.executionCompatibility === "EXACT_SHA" && item.actionabilityTier === "EXECUTION_SHA_VERIFIED" && exactSha(item.repositoryRevision) === expectedSha
|
|
15519
|
+
);
|
|
15520
|
+
if (exactEvidence.length === 0) return null;
|
|
15521
|
+
const targets = [...new Set(exactEvidence.flatMap((item) => [
|
|
15522
|
+
...safeTargets(item.expectedSourceReadsReplaced),
|
|
15523
|
+
...safeTargets(item.relations?.relatedFiles)
|
|
15524
|
+
]))].slice(0, MAX_SUBSTITUTION_TARGETS);
|
|
15525
|
+
if (targets.length === 0) return null;
|
|
15526
|
+
return [
|
|
15527
|
+
`ReasonTrail supplied execution-SHA-verified evidence for checkout ${expectedSha}.`,
|
|
15528
|
+
"Treat CURRENT/EXACT_SHA/EXECUTION_SHA_VERIFIED evidence in EXECUTION ASSISTANCE as trusted for the named locations and relationships; do not rediscover equivalent facts.",
|
|
15529
|
+
`Begin with these verified targets: ${targets.map((path) => JSON.stringify(path)).join(", ")}.`,
|
|
15530
|
+
"The Runtime already verified the clean checkout and execution SHA. Do not repeat SHA, status, or repository-instruction discovery before editing unless you observe a contradiction.",
|
|
15531
|
+
"Read a named source file only when needed to modify it or resolve an implementation detail absent from the evidence.",
|
|
15532
|
+
"Batch independent named-source reads into one tool call. After editing, batch independent verifier, diff-check, status, and focused-diff commands into one tool call when safe.",
|
|
15533
|
+
"Before any broad repository search, state one concrete unresolved gap. The initial broad-discovery budget is one command. If the gap remains, use the ReasonTrail progressive-context command before a second broad search when that command is available.",
|
|
15534
|
+
"Diff inspection, provenance checks, and required validation are not discovery and remain mandatory.",
|
|
15535
|
+
"If the checkout or source contradicts the evidence, stop trusting the affected evidence, report the contradiction, and use bounded discovery."
|
|
15536
|
+
].join("\n");
|
|
15537
|
+
}
|
|
15538
|
+
function codexExecArgs(assignment) {
|
|
15539
|
+
const args = [
|
|
15540
|
+
"exec",
|
|
15541
|
+
"--json",
|
|
15542
|
+
"--color",
|
|
15543
|
+
"never",
|
|
15544
|
+
"--sandbox",
|
|
15545
|
+
"workspace-write",
|
|
15546
|
+
"--cd",
|
|
15547
|
+
assignment.workspaceRoot
|
|
15548
|
+
];
|
|
15549
|
+
const developerInstructions = buildCodexSubstitutionInstructions(assignment);
|
|
15550
|
+
if (developerInstructions) {
|
|
15551
|
+
args.push("--config", `developer_instructions=${JSON.stringify(developerInstructions)}`);
|
|
15552
|
+
}
|
|
15553
|
+
args.push("-");
|
|
15554
|
+
return args;
|
|
15555
|
+
}
|
|
15556
|
+
function nativeCounter(value) {
|
|
15557
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
15558
|
+
}
|
|
15559
|
+
function sumWhenComplete(turns, key) {
|
|
15560
|
+
let total = 0;
|
|
15561
|
+
for (const turn of turns) {
|
|
15562
|
+
const value = turn[key];
|
|
15563
|
+
if (value === void 0) return void 0;
|
|
15564
|
+
total += value;
|
|
15565
|
+
if (!Number.isSafeInteger(total)) return void 0;
|
|
15566
|
+
}
|
|
15567
|
+
return turns.length > 0 ? total : void 0;
|
|
15568
|
+
}
|
|
15569
|
+
function parseCodexJsonl(output) {
|
|
15570
|
+
const messages = [];
|
|
15571
|
+
const turns = [];
|
|
15572
|
+
const observations = [];
|
|
15573
|
+
for (const line2 of output.split(/\r?\n/)) {
|
|
15574
|
+
if (!line2.trim()) continue;
|
|
15575
|
+
let event;
|
|
15576
|
+
try {
|
|
15577
|
+
const parsed = JSON.parse(line2);
|
|
15578
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) continue;
|
|
15579
|
+
event = parsed;
|
|
15580
|
+
} catch {
|
|
15581
|
+
continue;
|
|
15582
|
+
}
|
|
15583
|
+
if (event.type === "item.completed") {
|
|
15584
|
+
const item = event.item;
|
|
15585
|
+
if (item && typeof item === "object" && !Array.isArray(item)) {
|
|
15586
|
+
const record2 = item;
|
|
15587
|
+
if (record2.type === "agent_message" && typeof record2.text === "string") {
|
|
15588
|
+
messages.push(record2.text);
|
|
15589
|
+
}
|
|
15590
|
+
if (record2.type === "command_execution" && typeof record2.command === "string") {
|
|
15591
|
+
observations.push({ type: "COMMAND", command: record2.command.slice(0, 400) });
|
|
15592
|
+
}
|
|
15593
|
+
}
|
|
15594
|
+
}
|
|
15595
|
+
if (event.type === "turn.completed") {
|
|
15596
|
+
const value = event.usage;
|
|
15597
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
15598
|
+
turns.push({});
|
|
15599
|
+
continue;
|
|
15600
|
+
}
|
|
15601
|
+
const usage = value;
|
|
15602
|
+
turns.push({
|
|
15603
|
+
inputTokens: nativeCounter(usage.input_tokens),
|
|
15604
|
+
cachedInputTokens: nativeCounter(usage.cached_input_tokens),
|
|
15605
|
+
cacheCreationTokens: nativeCounter(usage.cache_write_input_tokens),
|
|
15606
|
+
outputTokens: nativeCounter(usage.output_tokens),
|
|
15607
|
+
reasoningTokens: nativeCounter(usage.reasoning_output_tokens)
|
|
15608
|
+
});
|
|
15609
|
+
}
|
|
15610
|
+
}
|
|
15611
|
+
const inputTokens = sumWhenComplete(turns, "inputTokens");
|
|
15612
|
+
const cachedInputTokens = sumWhenComplete(turns, "cachedInputTokens");
|
|
15613
|
+
const cacheCreationTokens = sumWhenComplete(turns, "cacheCreationTokens");
|
|
15614
|
+
const outputTokens = sumWhenComplete(turns, "outputTokens");
|
|
15615
|
+
const reasoningTokens = sumWhenComplete(turns, "reasoningTokens");
|
|
15616
|
+
const measurementComplete = turns.length > 0 && inputTokens !== void 0 && cachedInputTokens !== void 0 && cacheCreationTokens !== void 0 && outputTokens !== void 0 && reasoningTokens !== void 0;
|
|
15617
|
+
return {
|
|
15618
|
+
rawOutput: messages.length > 0 ? messages.join("\n") : output,
|
|
15619
|
+
observations,
|
|
15620
|
+
usage: {
|
|
15621
|
+
source: inputTokens !== void 0 && outputTokens !== void 0 ? "PROVIDER_REPORTED" : "UNAVAILABLE",
|
|
15622
|
+
scope: "SUMMED_PER_TURN",
|
|
15623
|
+
completedTurns: turns.length,
|
|
15624
|
+
measurementComplete,
|
|
15625
|
+
turns,
|
|
15626
|
+
...inputTokens === void 0 ? {} : { inputTokens },
|
|
15627
|
+
...cachedInputTokens === void 0 ? {} : { cachedInputTokens },
|
|
15628
|
+
...cacheCreationTokens === void 0 ? {} : { cacheCreationTokens },
|
|
15629
|
+
...outputTokens === void 0 ? {} : { outputTokens },
|
|
15630
|
+
...reasoningTokens === void 0 ? {} : { reasoningTokens }
|
|
15631
|
+
}
|
|
15632
|
+
};
|
|
15633
|
+
}
|
|
15108
15634
|
function invokeCodex(args, input, opts = {}) {
|
|
15109
15635
|
return new Promise((resolve4, reject) => {
|
|
15110
15636
|
const child = spawn3("codex", args, {
|
|
15111
15637
|
cwd: opts.cwd,
|
|
15112
|
-
env: providerSubprocessEnvironment("codex-cli"),
|
|
15638
|
+
env: providerSubprocessEnvironment("codex-cli", process.env, opts.environment),
|
|
15113
15639
|
stdio: ["pipe", "pipe", "pipe"],
|
|
15114
15640
|
signal: opts.signal
|
|
15115
15641
|
});
|
|
@@ -15158,11 +15684,18 @@ var codexAdapter = {
|
|
|
15158
15684
|
async run(assignment, opts) {
|
|
15159
15685
|
const started = performance2.now();
|
|
15160
15686
|
const result = await invokeCodex(
|
|
15161
|
-
|
|
15687
|
+
codexExecArgs(assignment),
|
|
15162
15688
|
renderPackagePrompt(assignment),
|
|
15163
|
-
{ cwd: assignment.workspaceRoot, signal: opts.signal, onLine: opts.onProgress }
|
|
15689
|
+
{ cwd: assignment.workspaceRoot, signal: opts.signal, onLine: opts.onProgress, environment: assignment.contextTool?.environment }
|
|
15164
15690
|
);
|
|
15165
|
-
|
|
15691
|
+
const parsed = parseCodexJsonl(result.stdout);
|
|
15692
|
+
return {
|
|
15693
|
+
rawOutput: parsed.rawOutput || result.stderr,
|
|
15694
|
+
exitCode: result.code,
|
|
15695
|
+
usage: parsed.usage,
|
|
15696
|
+
durationMs: Math.round(performance2.now() - started),
|
|
15697
|
+
observations: parsed.observations
|
|
15698
|
+
};
|
|
15166
15699
|
}
|
|
15167
15700
|
};
|
|
15168
15701
|
|
|
@@ -15266,8 +15799,8 @@ function normalizeWorkerResultForSubmission(value) {
|
|
|
15266
15799
|
// src/cli/execution-workspace.ts
|
|
15267
15800
|
import { execFile } from "node:child_process";
|
|
15268
15801
|
import { randomBytes } from "node:crypto";
|
|
15269
|
-
import { chmod, lstat, mkdir, realpath } from "node:fs/promises";
|
|
15270
|
-
import { basename, dirname, isAbsolute, join as
|
|
15802
|
+
import { chmod as chmod2, lstat, mkdir, realpath } from "node:fs/promises";
|
|
15803
|
+
import { basename, dirname, isAbsolute, join as join4, relative, resolve, sep } from "node:path";
|
|
15271
15804
|
import { promisify } from "node:util";
|
|
15272
15805
|
var exec = promisify(execFile);
|
|
15273
15806
|
var FULL_SHA = /^[0-9a-f]{40}$/i;
|
|
@@ -15333,7 +15866,7 @@ async function prospectiveDirectory(path, label) {
|
|
|
15333
15866
|
if (resolvedAncestor !== cursor) {
|
|
15334
15867
|
throw new DisposableWorkspaceError("PATH_RESOLUTION_CHANGED", label + " resolves through a different filesystem path.");
|
|
15335
15868
|
}
|
|
15336
|
-
return
|
|
15869
|
+
return join4(resolvedAncestor, ...missing.reverse());
|
|
15337
15870
|
}
|
|
15338
15871
|
}
|
|
15339
15872
|
function assertRootsSeparate(sourceRoot, executionRoot) {
|
|
@@ -15411,7 +15944,7 @@ async function createDisposableExecutionWorkspace(input) {
|
|
|
15411
15944
|
const canonicalBefore = await canonicalFingerprint(sourceRoot);
|
|
15412
15945
|
const safeId = input.executionId.replace(/[^A-Za-z0-9_-]/g, "").slice(0, 80);
|
|
15413
15946
|
if (!safeId) throw new DisposableWorkspaceError("EXECUTION_ID_INVALID", "Execution identity cannot form a workspace name.");
|
|
15414
|
-
const path =
|
|
15947
|
+
const path = join4(executionRoot, `rtx-${safeId}-${randomBytes(8).toString("hex")}`);
|
|
15415
15948
|
if (!isWithin(executionRoot, path)) {
|
|
15416
15949
|
throw new DisposableWorkspaceError("WORKSPACE_PATH_ESCAPE", "Generated workspace escaped the approved execution root.");
|
|
15417
15950
|
}
|
|
@@ -15419,7 +15952,7 @@ async function createDisposableExecutionWorkspace(input) {
|
|
|
15419
15952
|
try {
|
|
15420
15953
|
await git(sourceRoot, ["worktree", "add", "--detach", path, expectedStartingSha]);
|
|
15421
15954
|
added = true;
|
|
15422
|
-
await
|
|
15955
|
+
await chmod2(path, 448);
|
|
15423
15956
|
const resolvedPath = await verifiedDirectory(path, "Disposable execution workspace");
|
|
15424
15957
|
if (!isWithin(executionRoot, resolvedPath)) {
|
|
15425
15958
|
throw new DisposableWorkspaceError("WORKSPACE_PATH_ESCAPE", "Created workspace escaped the approved execution root.");
|
|
@@ -15516,14 +16049,14 @@ import {
|
|
|
15516
16049
|
access,
|
|
15517
16050
|
lstat as lstat2,
|
|
15518
16051
|
mkdir as mkdir2,
|
|
15519
|
-
mkdtemp as
|
|
16052
|
+
mkdtemp as mkdtemp3,
|
|
15520
16053
|
opendir,
|
|
15521
16054
|
readFile,
|
|
15522
16055
|
realpath as realpath2,
|
|
15523
|
-
rm as
|
|
15524
|
-
writeFile as
|
|
16056
|
+
rm as rm3,
|
|
16057
|
+
writeFile as writeFile3
|
|
15525
16058
|
} from "node:fs/promises";
|
|
15526
|
-
import { delimiter, dirname as dirname2, isAbsolute as isAbsolute2, join as
|
|
16059
|
+
import { delimiter, dirname as dirname2, isAbsolute as isAbsolute2, join as join5, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
|
|
15527
16060
|
import { performance as performance3 } from "node:perf_hooks";
|
|
15528
16061
|
|
|
15529
16062
|
// src/services/mission/redaction.ts
|
|
@@ -15555,6 +16088,8 @@ var MAX_LOCKFILE_POLICY_BYTES = 2e7;
|
|
|
15555
16088
|
var MAX_PACKAGE_CONFIG_BYTES = 1e6;
|
|
15556
16089
|
var MAX_DEPENDENCY_TREE_ENTRIES = 5e5;
|
|
15557
16090
|
var MAX_CAPTURE_BYTES = 16e3;
|
|
16091
|
+
var MAX_PREPARED_MARKER_BYTES = 4096;
|
|
16092
|
+
var PREPARED_MARKER = ".reasontrail-prepared.json";
|
|
15558
16093
|
var DEFAULT_PREPARATION_TIMEOUT_MS = 10 * 6e4;
|
|
15559
16094
|
var WorkspacePreparationError = class extends Error {
|
|
15560
16095
|
constructor(code, message, evidence2) {
|
|
@@ -15630,7 +16165,7 @@ function assertLocalDependency(workspaceRoot, specifier) {
|
|
|
15630
16165
|
}
|
|
15631
16166
|
async function assertPublicPackageSources(workspaceRoot, detection) {
|
|
15632
16167
|
for (const name of [".npmrc", ".yarnrc", ".yarnrc.yml"]) {
|
|
15633
|
-
const path =
|
|
16168
|
+
const path = join5(workspaceRoot, name);
|
|
15634
16169
|
if (!await regularFile(path, name)) continue;
|
|
15635
16170
|
const info = await lstat2(path);
|
|
15636
16171
|
if (info.size > MAX_PACKAGE_CONFIG_BYTES) {
|
|
@@ -15656,7 +16191,7 @@ async function assertPublicPackageSources(workspaceRoot, detection) {
|
|
|
15656
16191
|
);
|
|
15657
16192
|
}
|
|
15658
16193
|
}
|
|
15659
|
-
const manifest = JSON.parse(await readFile(
|
|
16194
|
+
const manifest = JSON.parse(await readFile(join5(workspaceRoot, "package.json"), "utf8"));
|
|
15660
16195
|
for (const section2 of ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"]) {
|
|
15661
16196
|
const dependencies = manifest[section2];
|
|
15662
16197
|
if (!dependencies || typeof dependencies !== "object" || Array.isArray(dependencies)) continue;
|
|
@@ -15674,7 +16209,7 @@ async function assertPublicPackageSources(workspaceRoot, detection) {
|
|
|
15674
16209
|
}
|
|
15675
16210
|
}
|
|
15676
16211
|
}
|
|
15677
|
-
const lockPath =
|
|
16212
|
+
const lockPath = join5(workspaceRoot, detection.lockfile);
|
|
15678
16213
|
const lockInfo = await lstat2(lockPath);
|
|
15679
16214
|
if (lockInfo.size > MAX_LOCKFILE_POLICY_BYTES) {
|
|
15680
16215
|
throw new WorkspacePreparationError(
|
|
@@ -15741,11 +16276,11 @@ function packageManagerCommand(manager, declaredVersion) {
|
|
|
15741
16276
|
return major >= 2 ? { executable: "yarn", args: ["install", "--immutable"] } : { executable: "yarn", args: ["install", "--frozen-lockfile", "--non-interactive"] };
|
|
15742
16277
|
}
|
|
15743
16278
|
async function detectPackageManager(workspaceRoot) {
|
|
15744
|
-
const packageJsonPath =
|
|
16279
|
+
const packageJsonPath = join5(workspaceRoot, "package.json");
|
|
15745
16280
|
const hasPackageJson = await regularFile(packageJsonPath, "package.json");
|
|
15746
16281
|
const presentLocks = [];
|
|
15747
16282
|
for (const lock2 of LOCKFILES) {
|
|
15748
|
-
if (await regularFile(
|
|
16283
|
+
if (await regularFile(join5(workspaceRoot, lock2.name), lock2.name)) presentLocks.push(lock2);
|
|
15749
16284
|
}
|
|
15750
16285
|
if (!hasPackageJson) {
|
|
15751
16286
|
if (presentLocks.length > 0) {
|
|
@@ -15758,6 +16293,7 @@ async function detectPackageManager(workspaceRoot) {
|
|
|
15758
16293
|
required: false,
|
|
15759
16294
|
manager: null,
|
|
15760
16295
|
declaredPackageManager: null,
|
|
16296
|
+
packageJsonSha256: null,
|
|
15761
16297
|
lockfile: null,
|
|
15762
16298
|
lockfileSha256: null,
|
|
15763
16299
|
command: null,
|
|
@@ -15777,6 +16313,7 @@ async function detectPackageManager(workspaceRoot) {
|
|
|
15777
16313
|
if (!manifest || Array.isArray(manifest) || typeof manifest !== "object") {
|
|
15778
16314
|
throw new WorkspacePreparationError("PACKAGE_METADATA_MALFORMED", "package.json must contain a JSON object.");
|
|
15779
16315
|
}
|
|
16316
|
+
const packageJsonSha256 = await sha256File(packageJsonPath);
|
|
15780
16317
|
const dependencySections = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
15781
16318
|
const hasDependencies = dependencySections.some((key) => {
|
|
15782
16319
|
const value = manifest[key];
|
|
@@ -15830,6 +16367,7 @@ async function detectPackageManager(workspaceRoot) {
|
|
|
15830
16367
|
required: false,
|
|
15831
16368
|
manager: null,
|
|
15832
16369
|
declaredPackageManager,
|
|
16370
|
+
packageJsonSha256,
|
|
15833
16371
|
lockfile: null,
|
|
15834
16372
|
lockfileSha256: null,
|
|
15835
16373
|
command: null,
|
|
@@ -15842,11 +16380,12 @@ async function detectPackageManager(workspaceRoot) {
|
|
|
15842
16380
|
`${manager} dependency preparation requires its repository lockfile.`
|
|
15843
16381
|
);
|
|
15844
16382
|
}
|
|
15845
|
-
const lockfileSha256 = await sha256File(
|
|
16383
|
+
const lockfileSha256 = await sha256File(join5(workspaceRoot, lock.name));
|
|
15846
16384
|
return {
|
|
15847
16385
|
required: true,
|
|
15848
16386
|
manager,
|
|
15849
16387
|
declaredPackageManager,
|
|
16388
|
+
packageJsonSha256,
|
|
15850
16389
|
lockfile: lock.name,
|
|
15851
16390
|
lockfileSha256,
|
|
15852
16391
|
command: packageManagerCommand(manager, declaredMatch?.[2] ?? null),
|
|
@@ -15966,16 +16505,21 @@ function sanitizedOutput(result, sensitivePaths) {
|
|
|
15966
16505
|
${sanitized.slice(-half)}`;
|
|
15967
16506
|
}
|
|
15968
16507
|
function evidence(input) {
|
|
16508
|
+
const commandCategory = input.policy === "NONE" ? "ASSIGNMENT_DECLARED_NONE" : input.policy === "PREPARED" ? "PREPARED_ENVIRONMENT_VERIFICATION" : input.detection?.required ? "LOCKFILE_INSTALL" : "NOT_REQUIRED";
|
|
16509
|
+
const filesystemContainment = input.policy === "PREPARED" ? "workspace-contained-tree-and-hash-attestation" : input.detection?.required ? "bubblewrap-read-only-host" : "not-required";
|
|
15969
16510
|
const document = {
|
|
15970
16511
|
version: 1,
|
|
15971
16512
|
state: input.state,
|
|
16513
|
+
dependencyPreparationPolicy: input.policy,
|
|
16514
|
+
decisionReason: input.decisionReason,
|
|
15972
16515
|
packageManager: input.detection?.manager ?? null,
|
|
15973
16516
|
declaredPackageManager: input.detection?.declaredPackageManager ?? null,
|
|
16517
|
+
packageJsonSha256: input.detection?.packageJsonSha256 ?? null,
|
|
15974
16518
|
lockfile: input.detection?.lockfile ?? null,
|
|
15975
16519
|
lockfileSha256: input.detection?.lockfileSha256 ?? null,
|
|
15976
|
-
commandCategory
|
|
16520
|
+
commandCategory,
|
|
15977
16521
|
lifecycleScripts: input.detection?.lifecycleScripts ?? "repository-authorized",
|
|
15978
|
-
filesystemContainment
|
|
16522
|
+
filesystemContainment,
|
|
15979
16523
|
networkPolicy: input.networkPolicy,
|
|
15980
16524
|
startedAt: input.startedAt,
|
|
15981
16525
|
finishedAt: input.finishedAt,
|
|
@@ -15994,12 +16538,15 @@ function evidence(input) {
|
|
|
15994
16538
|
metadata: {
|
|
15995
16539
|
preparation: true,
|
|
15996
16540
|
state: input.state,
|
|
16541
|
+
dependencyPreparationPolicy: input.policy,
|
|
16542
|
+
decisionReason: input.decisionReason,
|
|
15997
16543
|
packageManager: input.detection?.manager ?? null,
|
|
16544
|
+
packageJsonSha256: input.detection?.packageJsonSha256 ?? null,
|
|
15998
16545
|
lockfile: input.detection?.lockfile ?? null,
|
|
15999
16546
|
lockfileSha256: input.detection?.lockfileSha256 ?? null,
|
|
16000
|
-
commandCategory
|
|
16547
|
+
commandCategory,
|
|
16001
16548
|
lifecycleScripts: input.detection?.lifecycleScripts ?? "repository-authorized",
|
|
16002
|
-
filesystemContainment
|
|
16549
|
+
filesystemContainment,
|
|
16003
16550
|
networkPolicy: input.networkPolicy,
|
|
16004
16551
|
durationMs: input.durationMs,
|
|
16005
16552
|
exitCode: input.exitCode,
|
|
@@ -16013,7 +16560,7 @@ async function privateCacheRoot(executionRoot) {
|
|
|
16013
16560
|
if (rootInfo.isSymbolicLink() || !rootInfo.isDirectory() || await realpath2(root) !== root) {
|
|
16014
16561
|
throw new WorkspacePreparationError("PREPARATION_CACHE_INVALID", "Execution root must remain a real directory.");
|
|
16015
16562
|
}
|
|
16016
|
-
const cache =
|
|
16563
|
+
const cache = join5(root, ".reasontrail-package-cache");
|
|
16017
16564
|
try {
|
|
16018
16565
|
const info = await lstat2(cache);
|
|
16019
16566
|
if (info.isSymbolicLink() || !info.isDirectory()) {
|
|
@@ -16064,7 +16611,7 @@ async function assertDependencyTreeContained(workspaceRoot, nodeModules) {
|
|
|
16064
16611
|
"The installed dependency tree exceeds the bounded containment inspection limit."
|
|
16065
16612
|
);
|
|
16066
16613
|
}
|
|
16067
|
-
const path =
|
|
16614
|
+
const path = join5(directory, entry.name);
|
|
16068
16615
|
if (entry.isDirectory()) {
|
|
16069
16616
|
pending.push(path);
|
|
16070
16617
|
} else if (entry.isSymbolicLink()) {
|
|
@@ -16087,8 +16634,91 @@ async function assertDependencyTreeContained(workspaceRoot, nodeModules) {
|
|
|
16087
16634
|
}
|
|
16088
16635
|
}
|
|
16089
16636
|
}
|
|
16637
|
+
async function verifyContainedDependencyTree(workspaceRoot) {
|
|
16638
|
+
const nodeModules = join5(workspaceRoot, "node_modules");
|
|
16639
|
+
let info;
|
|
16640
|
+
try {
|
|
16641
|
+
info = await lstat2(nodeModules);
|
|
16642
|
+
} catch (error51) {
|
|
16643
|
+
if (error51.code === "ENOENT") {
|
|
16644
|
+
throw new WorkspacePreparationError(
|
|
16645
|
+
"DEPENDENCY_TREE_MISSING",
|
|
16646
|
+
"The declared prepared dependency environment has no local node_modules tree."
|
|
16647
|
+
);
|
|
16648
|
+
}
|
|
16649
|
+
throw error51;
|
|
16650
|
+
}
|
|
16651
|
+
const resolvedModules = await realpath2(nodeModules).catch(() => null);
|
|
16652
|
+
if (info.isSymbolicLink() || !info.isDirectory() || !resolvedModules || !isWithin2(resolve2(workspaceRoot), resolvedModules)) {
|
|
16653
|
+
throw new WorkspacePreparationError(
|
|
16654
|
+
"NODE_MODULES_SYMLINK_REFUSED",
|
|
16655
|
+
"The dependency tree escaped the disposable workspace."
|
|
16656
|
+
);
|
|
16657
|
+
}
|
|
16658
|
+
await assertDependencyTreeContained(workspaceRoot, nodeModules);
|
|
16659
|
+
}
|
|
16660
|
+
function expectedPreparedMarker(detection) {
|
|
16661
|
+
if (!detection.manager || !detection.packageJsonSha256 || !detection.lockfile || !detection.lockfileSha256) {
|
|
16662
|
+
throw new WorkspacePreparationError(
|
|
16663
|
+
"PREPARED_DEPENDENCY_ENVIRONMENT_UNVERIFIABLE",
|
|
16664
|
+
"Prepared dependency verification requires complete package and lockfile identity."
|
|
16665
|
+
);
|
|
16666
|
+
}
|
|
16667
|
+
return {
|
|
16668
|
+
version: 1,
|
|
16669
|
+
manager: detection.manager,
|
|
16670
|
+
packageJsonSha256: detection.packageJsonSha256,
|
|
16671
|
+
lockfile: detection.lockfile,
|
|
16672
|
+
lockfileSha256: detection.lockfileSha256
|
|
16673
|
+
};
|
|
16674
|
+
}
|
|
16675
|
+
async function writePreparedDependencyMarker(workspaceRoot, detection) {
|
|
16676
|
+
const marker = expectedPreparedMarker(detection);
|
|
16677
|
+
await writeFile3(
|
|
16678
|
+
join5(workspaceRoot, "node_modules", PREPARED_MARKER),
|
|
16679
|
+
`${JSON.stringify(marker)}
|
|
16680
|
+
`,
|
|
16681
|
+
{ mode: 384 }
|
|
16682
|
+
);
|
|
16683
|
+
}
|
|
16684
|
+
async function verifyPreparedDependencyMarker(workspaceRoot, detection) {
|
|
16685
|
+
const markerPath = join5(workspaceRoot, "node_modules", PREPARED_MARKER);
|
|
16686
|
+
let info;
|
|
16687
|
+
try {
|
|
16688
|
+
info = await lstat2(markerPath);
|
|
16689
|
+
} catch (error51) {
|
|
16690
|
+
if (error51.code === "ENOENT") {
|
|
16691
|
+
throw new WorkspacePreparationError(
|
|
16692
|
+
"PREPARED_DEPENDENCY_ATTESTATION_MISSING",
|
|
16693
|
+
"The dependency tree has no Runtime preparation attestation."
|
|
16694
|
+
);
|
|
16695
|
+
}
|
|
16696
|
+
throw error51;
|
|
16697
|
+
}
|
|
16698
|
+
if (info.isSymbolicLink() || !info.isFile() || info.size > MAX_PREPARED_MARKER_BYTES) {
|
|
16699
|
+
throw new WorkspacePreparationError(
|
|
16700
|
+
"PREPARED_DEPENDENCY_ATTESTATION_INVALID",
|
|
16701
|
+
"The Runtime preparation attestation is not a bounded regular file."
|
|
16702
|
+
);
|
|
16703
|
+
}
|
|
16704
|
+
let actual;
|
|
16705
|
+
try {
|
|
16706
|
+
actual = JSON.parse(await readFile(markerPath, "utf8"));
|
|
16707
|
+
} catch {
|
|
16708
|
+
throw new WorkspacePreparationError(
|
|
16709
|
+
"PREPARED_DEPENDENCY_ATTESTATION_INVALID",
|
|
16710
|
+
"The Runtime preparation attestation is malformed."
|
|
16711
|
+
);
|
|
16712
|
+
}
|
|
16713
|
+
if (JSON.stringify(actual) !== JSON.stringify(expectedPreparedMarker(detection))) {
|
|
16714
|
+
throw new WorkspacePreparationError(
|
|
16715
|
+
"PREPARED_DEPENDENCY_ATTESTATION_STALE",
|
|
16716
|
+
"The prepared dependency tree does not match the current package and lockfile hashes."
|
|
16717
|
+
);
|
|
16718
|
+
}
|
|
16719
|
+
}
|
|
16090
16720
|
async function executableOnPath(name, pathValue) {
|
|
16091
|
-
const candidates = name.includes(sep2) ? [resolve2(name)] : (pathValue ?? "").split(delimiter).filter(Boolean).map((part) =>
|
|
16721
|
+
const candidates = name.includes(sep2) ? [resolve2(name)] : (pathValue ?? "").split(delimiter).filter(Boolean).map((part) => join5(part, name));
|
|
16092
16722
|
for (const candidate of candidates) {
|
|
16093
16723
|
try {
|
|
16094
16724
|
await access(candidate, fsConstants2.X_OK);
|
|
@@ -16218,6 +16848,7 @@ async function prepareDisposableWorkspaceDependencies(input) {
|
|
|
16218
16848
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
16219
16849
|
const started = performance3.now();
|
|
16220
16850
|
let detection = null;
|
|
16851
|
+
const policy = input.policy ?? "AUTO";
|
|
16221
16852
|
const fail = (code, message, result2) => {
|
|
16222
16853
|
const finishedAt2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
16223
16854
|
const output = result2 ? sanitizedOutput(result2, [input.workspaceRoot, input.executionRoot]) : "";
|
|
@@ -16227,6 +16858,8 @@ async function prepareDisposableWorkspaceDependencies(input) {
|
|
|
16227
16858
|
evidence({
|
|
16228
16859
|
state: "FAILED",
|
|
16229
16860
|
detection,
|
|
16861
|
+
policy,
|
|
16862
|
+
decisionReason: `ASSIGNMENT_${policy}_FAILED_${code}`,
|
|
16230
16863
|
networkPolicy: input.networkPolicy,
|
|
16231
16864
|
startedAt,
|
|
16232
16865
|
finishedAt: finishedAt2,
|
|
@@ -16242,12 +16875,90 @@ async function prepareDisposableWorkspaceDependencies(input) {
|
|
|
16242
16875
|
if (error51 instanceof WorkspacePreparationError) return fail(error51.code, error51.message);
|
|
16243
16876
|
return fail("PREPARATION_WORKSPACE_INVALID", "Dependency preparation roots could not be verified safely.");
|
|
16244
16877
|
});
|
|
16878
|
+
if (policy === "NONE") {
|
|
16879
|
+
const finishedAt2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
16880
|
+
return {
|
|
16881
|
+
state: "SKIPPED",
|
|
16882
|
+
detection: {
|
|
16883
|
+
required: false,
|
|
16884
|
+
manager: null,
|
|
16885
|
+
declaredPackageManager: null,
|
|
16886
|
+
packageJsonSha256: null,
|
|
16887
|
+
lockfile: null,
|
|
16888
|
+
lockfileSha256: null,
|
|
16889
|
+
command: null,
|
|
16890
|
+
lifecycleScripts: "repository-authorized"
|
|
16891
|
+
},
|
|
16892
|
+
evidence: evidence({
|
|
16893
|
+
state: "SKIPPED",
|
|
16894
|
+
detection: null,
|
|
16895
|
+
policy,
|
|
16896
|
+
decisionReason: "ASSIGNMENT_DECLARED_NONE",
|
|
16897
|
+
networkPolicy: input.networkPolicy,
|
|
16898
|
+
startedAt,
|
|
16899
|
+
finishedAt: finishedAt2,
|
|
16900
|
+
durationMs: Math.round(performance3.now() - started),
|
|
16901
|
+
exitCode: 0,
|
|
16902
|
+
failureCategory: null,
|
|
16903
|
+
output: "Dependency preparation intentionally skipped because the assignment declared policy NONE.",
|
|
16904
|
+
originalBytes: 0
|
|
16905
|
+
})
|
|
16906
|
+
};
|
|
16907
|
+
}
|
|
16245
16908
|
const selectedDetection = await detectPackageManager(input.workspaceRoot).catch((error51) => {
|
|
16246
16909
|
if (error51 instanceof WorkspacePreparationError) return fail(error51.code, error51.message);
|
|
16247
16910
|
return fail("PACKAGE_METADATA_MALFORMED", "Package-manager metadata could not be inspected safely.");
|
|
16248
16911
|
});
|
|
16249
16912
|
detection = selectedDetection;
|
|
16913
|
+
if (policy === "PREPARED") {
|
|
16914
|
+
if (!selectedDetection.required) {
|
|
16915
|
+
fail(
|
|
16916
|
+
"PREPARED_DEPENDENCY_ENVIRONMENT_UNVERIFIABLE",
|
|
16917
|
+
"PREPARED requires package metadata and a contained local dependency tree that Runtime can verify."
|
|
16918
|
+
);
|
|
16919
|
+
}
|
|
16920
|
+
try {
|
|
16921
|
+
await verifyContainedDependencyTree(input.workspaceRoot);
|
|
16922
|
+
await verifyPreparedDependencyMarker(input.workspaceRoot, selectedDetection);
|
|
16923
|
+
} catch (error51) {
|
|
16924
|
+
if (error51 instanceof WorkspacePreparationError) {
|
|
16925
|
+
fail(
|
|
16926
|
+
error51.code === "DEPENDENCY_TREE_MISSING" ? "PREPARED_DEPENDENCY_ENVIRONMENT_MISSING" : error51.code,
|
|
16927
|
+
error51.message
|
|
16928
|
+
);
|
|
16929
|
+
}
|
|
16930
|
+
fail(
|
|
16931
|
+
"PREPARED_DEPENDENCY_ENVIRONMENT_UNVERIFIABLE",
|
|
16932
|
+
"The declared prepared dependency environment could not be verified safely."
|
|
16933
|
+
);
|
|
16934
|
+
}
|
|
16935
|
+
const finishedAt2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
16936
|
+
return {
|
|
16937
|
+
state: "READY",
|
|
16938
|
+
detection: selectedDetection,
|
|
16939
|
+
evidence: evidence({
|
|
16940
|
+
state: "READY",
|
|
16941
|
+
detection: selectedDetection,
|
|
16942
|
+
policy,
|
|
16943
|
+
decisionReason: "ASSIGNMENT_DECLARED_PREPARED_VERIFIED",
|
|
16944
|
+
networkPolicy: input.networkPolicy,
|
|
16945
|
+
startedAt,
|
|
16946
|
+
finishedAt: finishedAt2,
|
|
16947
|
+
durationMs: Math.round(performance3.now() - started),
|
|
16948
|
+
exitCode: 0,
|
|
16949
|
+
failureCategory: null,
|
|
16950
|
+
output: "Verified the assignment's already prepared, workspace-contained dependency tree; no installer ran.",
|
|
16951
|
+
originalBytes: 0
|
|
16952
|
+
})
|
|
16953
|
+
};
|
|
16954
|
+
}
|
|
16250
16955
|
if (!selectedDetection.required) {
|
|
16956
|
+
if (policy === "REQUIRED") {
|
|
16957
|
+
fail(
|
|
16958
|
+
"DEPENDENCY_PREPARATION_REQUIRED",
|
|
16959
|
+
"The assignment requires dependency preparation, but no supported dependency tree is declared."
|
|
16960
|
+
);
|
|
16961
|
+
}
|
|
16251
16962
|
const finishedAt2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
16252
16963
|
return {
|
|
16253
16964
|
state: "SKIPPED",
|
|
@@ -16255,6 +16966,8 @@ async function prepareDisposableWorkspaceDependencies(input) {
|
|
|
16255
16966
|
evidence: evidence({
|
|
16256
16967
|
state: "SKIPPED",
|
|
16257
16968
|
detection: selectedDetection,
|
|
16969
|
+
policy,
|
|
16970
|
+
decisionReason: "AUTO_DETECTED_NO_DEPENDENCY_TREE",
|
|
16258
16971
|
networkPolicy: input.networkPolicy,
|
|
16259
16972
|
startedAt,
|
|
16260
16973
|
finishedAt: finishedAt2,
|
|
@@ -16281,7 +16994,7 @@ async function prepareDisposableWorkspaceDependencies(input) {
|
|
|
16281
16994
|
if (error51 instanceof WorkspacePreparationError) fail(error51.code, error51.message);
|
|
16282
16995
|
fail("DEPENDENCY_NETWORK_POLICY_VIOLATION", "Dependency sources could not be checked safely.");
|
|
16283
16996
|
}
|
|
16284
|
-
const nodeModules =
|
|
16997
|
+
const nodeModules = join5(input.workspaceRoot, "node_modules");
|
|
16285
16998
|
try {
|
|
16286
16999
|
const info = await lstat2(nodeModules);
|
|
16287
17000
|
if (info.isSymbolicLink()) fail("NODE_MODULES_SYMLINK_REFUSED", "node_modules must never be a symlink.");
|
|
@@ -16292,24 +17005,24 @@ async function prepareDisposableWorkspaceDependencies(input) {
|
|
|
16292
17005
|
fail("DEPENDENCY_TREE_INVALID", "The dependency-tree path could not be verified.");
|
|
16293
17006
|
}
|
|
16294
17007
|
}
|
|
16295
|
-
const lockfilePath =
|
|
17008
|
+
const lockfilePath = join5(input.workspaceRoot, selectedDetection.lockfile);
|
|
16296
17009
|
const lockHashBefore = selectedDetection.lockfileSha256;
|
|
16297
|
-
const packageHashBefore =
|
|
17010
|
+
const packageHashBefore = selectedDetection.packageJsonSha256;
|
|
16298
17011
|
const cacheRoot = await privateCacheRoot(input.executionRoot).catch((error51) => {
|
|
16299
17012
|
if (error51 instanceof WorkspacePreparationError) return fail(error51.code, error51.message);
|
|
16300
17013
|
return fail("PREPARATION_CACHE_INVALID", "The private package cache could not be prepared.");
|
|
16301
17014
|
});
|
|
16302
|
-
const sessionRoot = await
|
|
16303
|
-
const home =
|
|
16304
|
-
const temp =
|
|
16305
|
-
const cache =
|
|
17015
|
+
const sessionRoot = await mkdtemp3(join5(cacheRoot, "session-"));
|
|
17016
|
+
const home = join5(sessionRoot, "home");
|
|
17017
|
+
const temp = join5(sessionRoot, "tmp");
|
|
17018
|
+
const cache = join5(cacheRoot, selectedDetection.manager);
|
|
16306
17019
|
await Promise.all([
|
|
16307
17020
|
mkdir2(home, { mode: 448 }),
|
|
16308
17021
|
mkdir2(temp, { mode: 448 }),
|
|
16309
17022
|
mkdir2(cache, { recursive: true, mode: 448 })
|
|
16310
17023
|
]);
|
|
16311
|
-
const userConfig =
|
|
16312
|
-
await
|
|
17024
|
+
const userConfig = join5(home, ".npmrc");
|
|
17025
|
+
await writeFile3(userConfig, "", { mode: 384 });
|
|
16313
17026
|
const result = await (async () => {
|
|
16314
17027
|
try {
|
|
16315
17028
|
const sandboxed = input.runCommand ? {
|
|
@@ -16339,11 +17052,11 @@ async function prepareDisposableWorkspaceDependencies(input) {
|
|
|
16339
17052
|
if (error51 instanceof WorkspacePreparationError) return fail(error51.code, error51.message);
|
|
16340
17053
|
return fail("DEPENDENCY_SANDBOX_UNAVAILABLE", "Dependency containment could not be established safely.");
|
|
16341
17054
|
} finally {
|
|
16342
|
-
await
|
|
17055
|
+
await rm3(sessionRoot, { recursive: true, force: true });
|
|
16343
17056
|
}
|
|
16344
17057
|
})();
|
|
16345
17058
|
const [packageHashAfter, lockHashAfter] = await Promise.all([
|
|
16346
|
-
sha256File(
|
|
17059
|
+
sha256File(join5(input.workspaceRoot, "package.json")),
|
|
16347
17060
|
sha256File(lockfilePath)
|
|
16348
17061
|
]);
|
|
16349
17062
|
if (packageHashAfter !== packageHashBefore || lockHashAfter !== lockHashBefore) {
|
|
@@ -16358,12 +17071,9 @@ async function prepareDisposableWorkspaceDependencies(input) {
|
|
|
16358
17071
|
fail(category, `Disposable dependency preparation failed (${category}).`, result);
|
|
16359
17072
|
}
|
|
16360
17073
|
try {
|
|
16361
|
-
|
|
16362
|
-
|
|
16363
|
-
|
|
16364
|
-
fail("NODE_MODULES_SYMLINK_REFUSED", "The installed dependency tree escaped the disposable workspace.", result);
|
|
16365
|
-
}
|
|
16366
|
-
await assertDependencyTreeContained(input.workspaceRoot, nodeModules);
|
|
17074
|
+
await verifyContainedDependencyTree(input.workspaceRoot);
|
|
17075
|
+
await writePreparedDependencyMarker(input.workspaceRoot, selectedDetection);
|
|
17076
|
+
await verifyPreparedDependencyMarker(input.workspaceRoot, selectedDetection);
|
|
16367
17077
|
} catch (error51) {
|
|
16368
17078
|
if (error51 instanceof WorkspacePreparationError) fail(error51.code, error51.message, result);
|
|
16369
17079
|
fail("DEPENDENCY_TREE_MISSING", "Package installation exited successfully without a local node_modules tree.", result);
|
|
@@ -16375,6 +17085,8 @@ async function prepareDisposableWorkspaceDependencies(input) {
|
|
|
16375
17085
|
evidence: evidence({
|
|
16376
17086
|
state: "READY",
|
|
16377
17087
|
detection: selectedDetection,
|
|
17088
|
+
policy,
|
|
17089
|
+
decisionReason: policy === "REQUIRED" ? "ASSIGNMENT_DECLARED_REQUIRED_PREPARED" : "AUTO_DETECTED_DEPENDENCY_TREE_PREPARED",
|
|
16378
17090
|
networkPolicy: input.networkPolicy,
|
|
16379
17091
|
startedAt,
|
|
16380
17092
|
finishedAt,
|
|
@@ -16845,8 +17557,8 @@ var ADAPTERS = [codexAdapter, claudeCodeAdapter];
|
|
|
16845
17557
|
var POLL_IDLE_MS = 5e3;
|
|
16846
17558
|
var POLL_BACKOFF_MAX_MS = 6e4;
|
|
16847
17559
|
var HEARTBEAT_MS = 3e4;
|
|
16848
|
-
var RUNTIME_VERSION = "0.3.
|
|
16849
|
-
var RUNTIME_SOURCE_SHA = true ? "
|
|
17560
|
+
var RUNTIME_VERSION = "0.3.3";
|
|
17561
|
+
var RUNTIME_SOURCE_SHA = true ? "e2dec2f9fa038f10880c700bba89035713baab29" : "development";
|
|
16850
17562
|
var RUNTIME_PROTOCOL_VERSION = 3;
|
|
16851
17563
|
function parseArgs(argv) {
|
|
16852
17564
|
const baseUrl = process.env.REASONTRAIL_URL?.trim();
|
|
@@ -17310,6 +18022,7 @@ async function execute(client, rawClaimed, workspaces, executionRoot, dependency
|
|
|
17310
18022
|
const controller = new AbortController();
|
|
17311
18023
|
let latestProgress = "";
|
|
17312
18024
|
let timedOut = false;
|
|
18025
|
+
let contextBridge = null;
|
|
17313
18026
|
const preparationEvidence = [];
|
|
17314
18027
|
const timeout = setTimeout(() => {
|
|
17315
18028
|
timedOut = true;
|
|
@@ -17325,7 +18038,7 @@ async function execute(client, rawClaimed, workspaces, executionRoot, dependency
|
|
|
17325
18038
|
await client.heartbeat(
|
|
17326
18039
|
executionId,
|
|
17327
18040
|
leaseToken,
|
|
17328
|
-
|
|
18041
|
+
`Disposable Git workspace ready; evaluating dependency preparation policy ${claimed.package.dependencyPreparation}.`,
|
|
17329
18042
|
workspaceLeaseToken
|
|
17330
18043
|
);
|
|
17331
18044
|
try {
|
|
@@ -17333,6 +18046,7 @@ async function execute(client, rawClaimed, workspaces, executionRoot, dependency
|
|
|
17333
18046
|
workspaceRoot: disposable.path,
|
|
17334
18047
|
executionRoot: disposable.executionRoot,
|
|
17335
18048
|
networkPolicy: dependencyNetwork,
|
|
18049
|
+
policy: claimed.package.dependencyPreparation,
|
|
17336
18050
|
signal: controller.signal
|
|
17337
18051
|
});
|
|
17338
18052
|
preparationEvidence.push(preparation.evidence);
|
|
@@ -17347,7 +18061,7 @@ async function execute(client, rawClaimed, workspaces, executionRoot, dependency
|
|
|
17347
18061
|
await client.heartbeat(
|
|
17348
18062
|
executionId,
|
|
17349
18063
|
leaseToken,
|
|
17350
|
-
preparation.state === "READY" ? `Workspace dependencies prepared with ${preparation.detection.manager}.` : "
|
|
18064
|
+
preparation.state === "READY" ? claimed.package.dependencyPreparation === "PREPARED" ? "Verified the assignment's prepared dependency environment; no installer ran." : `Workspace dependencies prepared with ${preparation.detection.manager}.` : claimed.package.dependencyPreparation === "NONE" ? "Dependency preparation intentionally skipped because the assignment declared policy NONE." : "AUTO detected no declared dependency tree to prepare.",
|
|
17351
18065
|
workspaceLeaseToken
|
|
17352
18066
|
);
|
|
17353
18067
|
} catch (error51) {
|
|
@@ -17384,6 +18098,19 @@ async function execute(client, rawClaimed, workspaces, executionRoot, dependency
|
|
|
17384
18098
|
);
|
|
17385
18099
|
return;
|
|
17386
18100
|
}
|
|
18101
|
+
if (claimed.progressiveRetrieval) {
|
|
18102
|
+
try {
|
|
18103
|
+
contextBridge = await startExecutionContextBridge({
|
|
18104
|
+
client,
|
|
18105
|
+
executionId,
|
|
18106
|
+
leaseToken,
|
|
18107
|
+
workspaceLeaseToken,
|
|
18108
|
+
operations: claimed.progressiveRetrieval.operations
|
|
18109
|
+
});
|
|
18110
|
+
} catch (error51) {
|
|
18111
|
+
console.error(`Progressive context bridge unavailable: ${error51 instanceof Error ? error51.message : String(error51)}`);
|
|
18112
|
+
}
|
|
18113
|
+
}
|
|
17387
18114
|
const outcome = await adapter.run(
|
|
17388
18115
|
{
|
|
17389
18116
|
executionId,
|
|
@@ -17392,7 +18119,17 @@ async function execute(client, rawClaimed, workspaces, executionRoot, dependency
|
|
|
17392
18119
|
sequence: claimed.sequence,
|
|
17393
18120
|
role: claimed.role,
|
|
17394
18121
|
workspaceRoot: disposable.path,
|
|
17395
|
-
|
|
18122
|
+
checkout: {
|
|
18123
|
+
missionExpectedStartingSha: claimed.repository.expectedStartingSha,
|
|
18124
|
+
runtimeRegisteredStartingSha: disposable.startingSha,
|
|
18125
|
+
cleanBaselineVerified: true
|
|
18126
|
+
},
|
|
18127
|
+
package: claimed.package,
|
|
18128
|
+
...contextBridge ? { contextTool: {
|
|
18129
|
+
command: contextBridge.command,
|
|
18130
|
+
operations: contextBridge.operations,
|
|
18131
|
+
environment: contextBridge.environment
|
|
18132
|
+
} } : {}
|
|
17396
18133
|
},
|
|
17397
18134
|
{
|
|
17398
18135
|
signal: controller.signal,
|
|
@@ -17419,7 +18156,8 @@ async function execute(client, rawClaimed, workspaces, executionRoot, dependency
|
|
|
17419
18156
|
durationMs: outcome.durationMs,
|
|
17420
18157
|
usage: outcome.usage,
|
|
17421
18158
|
evidence: workerReport.evidence ?? [],
|
|
17422
|
-
runtimeEvidence
|
|
18159
|
+
runtimeEvidence,
|
|
18160
|
+
runtimeObservations: outcome.observations ?? []
|
|
17423
18161
|
};
|
|
17424
18162
|
if (providerFailure) {
|
|
17425
18163
|
result.status = providerFailure;
|
|
@@ -17442,7 +18180,8 @@ async function execute(client, rawClaimed, workspaces, executionRoot, dependency
|
|
|
17442
18180
|
content: outcome.rawOutput.slice(-2e4)
|
|
17443
18181
|
}
|
|
17444
18182
|
],
|
|
17445
|
-
runtimeEvidence
|
|
18183
|
+
runtimeEvidence,
|
|
18184
|
+
runtimeObservations: outcome.observations ?? []
|
|
17446
18185
|
};
|
|
17447
18186
|
}
|
|
17448
18187
|
await client.submitResult(
|
|
@@ -17479,6 +18218,8 @@ async function execute(client, rawClaimed, workspaces, executionRoot, dependency
|
|
|
17479
18218
|
}, `${executionId}:error`, workspaceLeaseToken).catch(() => {
|
|
17480
18219
|
});
|
|
17481
18220
|
} finally {
|
|
18221
|
+
await contextBridge?.close().catch(() => {
|
|
18222
|
+
});
|
|
17482
18223
|
clearInterval(heartbeat);
|
|
17483
18224
|
clearTimeout(timeout);
|
|
17484
18225
|
}
|