@amaster.ai/employee-runtime-connector 0.1.1-beta.124 → 0.1.1-beta.125
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/dist/amaster-runtime-daemon.mjs +269 -235
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
|
@@ -15332,9 +15332,9 @@ var completeCompanyCreationReviewSchema = external_exports.object({
|
|
|
15332
15332
|
}).strict();
|
|
15333
15333
|
|
|
15334
15334
|
// src/amaster-runtime-daemon.mjs
|
|
15335
|
-
import { chmodSync as chmodSync7, copyFileSync as copyFileSync2, existsSync as existsSync15, lstatSync as lstatSync9, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync2, readFileSync as readFileSync17, readdirSync as readdirSync11, realpathSync as
|
|
15335
|
+
import { chmodSync as chmodSync7, copyFileSync as copyFileSync2, existsSync as existsSync15, lstatSync as lstatSync9, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync2, readFileSync as readFileSync17, readdirSync as readdirSync11, realpathSync as realpathSync7, renameSync as renameSync9, rmSync as rmSync9, statSync as statSync9, symlinkSync as symlinkSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync11 } from "node:fs";
|
|
15336
15336
|
import { arch as arch3, homedir as homedir3, hostname as hostname2, platform as platform3, tmpdir } from "node:os";
|
|
15337
|
-
import { basename as basename6, delimiter as delimiter3, dirname as dirname11, extname as extname3, isAbsolute as isAbsolute9, join as
|
|
15337
|
+
import { basename as basename6, delimiter as delimiter3, dirname as dirname11, extname as extname3, isAbsolute as isAbsolute9, join as join16, relative as relative8, resolve as resolve13 } from "node:path";
|
|
15338
15338
|
import { spawn, spawnSync as spawnSync5 } from "node:child_process";
|
|
15339
15339
|
|
|
15340
15340
|
// src/amaster-runtime-daemon/common.mjs
|
|
@@ -23628,8 +23628,105 @@ ${resolvedDependencies.details.content}` : ""
|
|
|
23628
23628
|
|
|
23629
23629
|
// src/amaster-runtime-daemon/agent-instruction-delivery.mjs
|
|
23630
23630
|
import { createHash as createHash8, randomBytes as randomBytes2 } from "node:crypto";
|
|
23631
|
-
import { existsSync as
|
|
23632
|
-
import { dirname as
|
|
23631
|
+
import { existsSync as existsSync7, lstatSync as lstatSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync9, readdirSync as readdirSync6, realpathSync as realpathSync4, renameSync as renameSync6, rmSync as rmSync5, writeFileSync as writeFileSync7 } from "node:fs";
|
|
23632
|
+
import { dirname as dirname6, isAbsolute as isAbsolute4, join as join8, relative as relative3, resolve as resolve4 } from "node:path";
|
|
23633
|
+
|
|
23634
|
+
// src/amaster-runtime-daemon/workspace-manifest.mjs
|
|
23635
|
+
import { chownSync as chownSync3, existsSync as existsSync6, readFileSync as readFileSync8, renameSync as renameSync5, rmSync as rmSync4, statSync as statSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
23636
|
+
import { basename as basename3, dirname as dirname5, join as join7 } from "node:path";
|
|
23637
|
+
var WORKSPACE_MANIFEST_FILENAME = ".amaster-runtime.json";
|
|
23638
|
+
function syncManifestDirOwnership(manifestPath, deps = {}) {
|
|
23639
|
+
const stat = deps.statSync ?? statSync3;
|
|
23640
|
+
const chown = deps.chownSync ?? chownSync3;
|
|
23641
|
+
const geteuid = deps.geteuid ?? (typeof process.geteuid === "function" ? process.geteuid.bind(process) : () => null);
|
|
23642
|
+
try {
|
|
23643
|
+
if (geteuid() !== 0) return false;
|
|
23644
|
+
const dirStat = stat(dirname5(manifestPath));
|
|
23645
|
+
if (dirStat.uid === 0 && dirStat.gid === 0) return false;
|
|
23646
|
+
chown(manifestPath, dirStat.uid, dirStat.gid);
|
|
23647
|
+
return true;
|
|
23648
|
+
} catch {
|
|
23649
|
+
return false;
|
|
23650
|
+
}
|
|
23651
|
+
}
|
|
23652
|
+
function nowIso() {
|
|
23653
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
23654
|
+
}
|
|
23655
|
+
function workspaceManifestPath(workspaceOrCwd) {
|
|
23656
|
+
if (!workspaceOrCwd) return null;
|
|
23657
|
+
if (typeof workspaceOrCwd === "string") return join7(workspaceOrCwd, WORKSPACE_MANIFEST_FILENAME);
|
|
23658
|
+
if (typeof workspaceOrCwd.cwd === "string") return join7(workspaceOrCwd.cwd, WORKSPACE_MANIFEST_FILENAME);
|
|
23659
|
+
return null;
|
|
23660
|
+
}
|
|
23661
|
+
function readWorkspaceManifest(manifestPath) {
|
|
23662
|
+
if (!manifestPath || !existsSync6(manifestPath)) return null;
|
|
23663
|
+
try {
|
|
23664
|
+
const parsed = JSON.parse(readFileSync8(manifestPath, "utf8"));
|
|
23665
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
23666
|
+
} catch {
|
|
23667
|
+
return null;
|
|
23668
|
+
}
|
|
23669
|
+
}
|
|
23670
|
+
function writeWorkspaceManifest(manifestPath, manifest, deps) {
|
|
23671
|
+
const tempPath = join7(
|
|
23672
|
+
dirname5(manifestPath),
|
|
23673
|
+
`.${basename3(manifestPath)}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
|
23674
|
+
);
|
|
23675
|
+
try {
|
|
23676
|
+
writeFileSync6(tempPath, `${JSON.stringify(manifest, null, 2)}
|
|
23677
|
+
`, { mode: 384 });
|
|
23678
|
+
renameSync5(tempPath, manifestPath);
|
|
23679
|
+
syncManifestDirOwnership(manifestPath, deps);
|
|
23680
|
+
} catch (err) {
|
|
23681
|
+
rmSync4(tempPath, { force: true });
|
|
23682
|
+
throw err;
|
|
23683
|
+
}
|
|
23684
|
+
return manifest;
|
|
23685
|
+
}
|
|
23686
|
+
function createWorkspaceManifest(workspace, input = {}) {
|
|
23687
|
+
const manifestPath = workspaceManifestPath(workspace);
|
|
23688
|
+
const createdAt = nowIso();
|
|
23689
|
+
const manifest = {
|
|
23690
|
+
version: 2,
|
|
23691
|
+
managed: true,
|
|
23692
|
+
sourceWorkspacePath: workspace.sourceWorkspacePath,
|
|
23693
|
+
managedCwd: workspace.cwd,
|
|
23694
|
+
executionWorkdir: workspace.cwd,
|
|
23695
|
+
executorKind: input.executorKind ?? null,
|
|
23696
|
+
executorHome: workspace.executorHome ?? null,
|
|
23697
|
+
commandId: input.commandId ?? null,
|
|
23698
|
+
generation: input.generation ?? null,
|
|
23699
|
+
runId: input.runId ?? null,
|
|
23700
|
+
issueId: input.issueId ?? null,
|
|
23701
|
+
workspaceKey: workspace.workspaceKey ?? null,
|
|
23702
|
+
issueKey: workspace.issueKey ?? null,
|
|
23703
|
+
runKey: workspace.runKey ?? null,
|
|
23704
|
+
createdAt,
|
|
23705
|
+
lastTouchedAt: createdAt,
|
|
23706
|
+
lastWorkspaceScanAt: null,
|
|
23707
|
+
artifactCandidateCount: 0,
|
|
23708
|
+
artifactCandidates: [],
|
|
23709
|
+
outboxPending: 0
|
|
23710
|
+
};
|
|
23711
|
+
return writeWorkspaceManifest(manifestPath, manifest);
|
|
23712
|
+
}
|
|
23713
|
+
function updateWorkspaceManifest(workspaceOrManifestPath, patch = {}) {
|
|
23714
|
+
const manifestPath = typeof workspaceOrManifestPath === "string" ? workspaceOrManifestPath : workspaceManifestPath(workspaceOrManifestPath);
|
|
23715
|
+
if (!manifestPath) return null;
|
|
23716
|
+
const current = readWorkspaceManifest(manifestPath) ?? {
|
|
23717
|
+
version: 2,
|
|
23718
|
+
managed: true,
|
|
23719
|
+
createdAt: nowIso()
|
|
23720
|
+
};
|
|
23721
|
+
const next = {
|
|
23722
|
+
...current,
|
|
23723
|
+
...patch,
|
|
23724
|
+
lastTouchedAt: nowIso()
|
|
23725
|
+
};
|
|
23726
|
+
return writeWorkspaceManifest(manifestPath, next);
|
|
23727
|
+
}
|
|
23728
|
+
|
|
23729
|
+
// src/amaster-runtime-daemon/agent-instruction-delivery.mjs
|
|
23633
23730
|
var PROJECT_INSTRUCTION_NAMES = /* @__PURE__ */ new Set(["AGENTS.md", "AGENTS.override.md"]);
|
|
23634
23731
|
var PROJECT_INSTRUCTION_SCAN_IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
23635
23732
|
".git",
|
|
@@ -23645,13 +23742,55 @@ var PROJECT_INSTRUCTION_SCAN_MAX_DIRECTORIES = 5e4;
|
|
|
23645
23742
|
function instructionTopologyError(code, message, details = {}) {
|
|
23646
23743
|
return Object.assign(new Error(`${code}: ${message}`), { code, details });
|
|
23647
23744
|
}
|
|
23648
|
-
function
|
|
23745
|
+
function pathWithin(candidate, root) {
|
|
23746
|
+
const rel = relative3(root, candidate);
|
|
23747
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
|
|
23748
|
+
}
|
|
23749
|
+
function lstatIfPresent(path) {
|
|
23750
|
+
try {
|
|
23751
|
+
return lstatSync4(path);
|
|
23752
|
+
} catch (error) {
|
|
23753
|
+
if (error?.code === "ENOENT") return null;
|
|
23754
|
+
throw error;
|
|
23755
|
+
}
|
|
23756
|
+
}
|
|
23757
|
+
function canonicalExistingPath(path) {
|
|
23758
|
+
try {
|
|
23759
|
+
return realpathSync4(resolve4(path));
|
|
23760
|
+
} catch {
|
|
23761
|
+
return resolve4(path);
|
|
23762
|
+
}
|
|
23763
|
+
}
|
|
23764
|
+
function isManagedExecutionDirectory(directory, managedWorkspacesRoot) {
|
|
23765
|
+
if (typeof managedWorkspacesRoot !== "string" || !managedWorkspacesRoot.trim()) return false;
|
|
23766
|
+
const managedRoot = canonicalExistingPath(managedWorkspacesRoot);
|
|
23767
|
+
const candidate = canonicalExistingPath(directory);
|
|
23768
|
+
if (!pathWithin(candidate, managedRoot)) return false;
|
|
23769
|
+
const manifestPath = join8(candidate, WORKSPACE_MANIFEST_FILENAME);
|
|
23770
|
+
const manifestStat = lstatIfPresent(manifestPath);
|
|
23771
|
+
if (!manifestStat?.isFile() || manifestStat.isSymbolicLink()) return false;
|
|
23772
|
+
try {
|
|
23773
|
+
const manifest = JSON.parse(readFileSync9(manifestPath, "utf8"));
|
|
23774
|
+
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest) || manifest.managed !== true) {
|
|
23775
|
+
return false;
|
|
23776
|
+
}
|
|
23777
|
+
return [manifest.managedCwd, manifest.executionWorkdir].some((value) => typeof value === "string" && isAbsolute4(value) && canonicalExistingPath(value) === candidate);
|
|
23778
|
+
} catch {
|
|
23779
|
+
return false;
|
|
23780
|
+
}
|
|
23781
|
+
}
|
|
23782
|
+
function inspectExternalWorkspaceProjectInstructions(sourceWorkspacePath, options = {}) {
|
|
23649
23783
|
const root = resolve4(sourceWorkspacePath);
|
|
23650
23784
|
const pending = [root];
|
|
23651
23785
|
const sources = [];
|
|
23786
|
+
const ignoredManagedExecutionDirectories = [];
|
|
23652
23787
|
let visitedDirectories = 0;
|
|
23653
23788
|
while (pending.length > 0) {
|
|
23654
23789
|
const directory = pending.pop();
|
|
23790
|
+
if (isManagedExecutionDirectory(directory, options.managedWorkspacesRoot)) {
|
|
23791
|
+
ignoredManagedExecutionDirectories.push(relative3(root, directory).replaceAll("\\", "/") || ".");
|
|
23792
|
+
continue;
|
|
23793
|
+
}
|
|
23655
23794
|
visitedDirectories += 1;
|
|
23656
23795
|
if (visitedDirectories > PROJECT_INSTRUCTION_SCAN_MAX_DIRECTORIES) {
|
|
23657
23796
|
throw instructionTopologyError(
|
|
@@ -23695,7 +23834,7 @@ function inspectExternalWorkspaceProjectInstructions(sourceWorkspacePath) {
|
|
|
23695
23834
|
`project instruction source is not a regular file: ${relativePath}`
|
|
23696
23835
|
);
|
|
23697
23836
|
}
|
|
23698
|
-
const content =
|
|
23837
|
+
const content = readFileSync9(absolutePath);
|
|
23699
23838
|
sources.push({
|
|
23700
23839
|
path: relativePath,
|
|
23701
23840
|
scope: relativePath.includes("/") ? relativePath.slice(0, relativePath.lastIndexOf("/")) : ".",
|
|
@@ -23705,26 +23844,17 @@ function inspectExternalWorkspaceProjectInstructions(sourceWorkspacePath) {
|
|
|
23705
23844
|
}
|
|
23706
23845
|
}
|
|
23707
23846
|
sources.sort((left, right) => left.path.localeCompare(right.path));
|
|
23847
|
+
ignoredManagedExecutionDirectories.sort((left, right) => left.localeCompare(right));
|
|
23708
23848
|
return {
|
|
23709
23849
|
schemaVersion: "mirrorx.workspace-project-instruction-scan.v1",
|
|
23710
23850
|
status: sources.length === 0 ? "absent_verified" : "present_verified",
|
|
23711
23851
|
visitedDirectories,
|
|
23712
23852
|
sources,
|
|
23713
|
-
topologySha256: createHash8("sha256").update(JSON.stringify(sources)).digest("hex")
|
|
23853
|
+
topologySha256: createHash8("sha256").update(JSON.stringify(sources)).digest("hex"),
|
|
23854
|
+
ignoredManagedExecutionDirectoryCount: ignoredManagedExecutionDirectories.length,
|
|
23855
|
+
ignoredManagedExecutionDirectoriesSha256: createHash8("sha256").update(JSON.stringify(ignoredManagedExecutionDirectories)).digest("hex")
|
|
23714
23856
|
};
|
|
23715
23857
|
}
|
|
23716
|
-
function pathWithin(candidate, root) {
|
|
23717
|
-
const rel = relative3(root, candidate);
|
|
23718
|
-
return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
|
|
23719
|
-
}
|
|
23720
|
-
function lstatIfPresent(path) {
|
|
23721
|
-
try {
|
|
23722
|
-
return lstatSync4(path);
|
|
23723
|
-
} catch (error) {
|
|
23724
|
-
if (error?.code === "ENOENT") return null;
|
|
23725
|
-
throw error;
|
|
23726
|
-
}
|
|
23727
|
-
}
|
|
23728
23858
|
function composeProjectedInstruction(sources, platformInstructions) {
|
|
23729
23859
|
const platformBlock = [
|
|
23730
23860
|
'<mirrorx-platform-instructions priority="platform">',
|
|
@@ -23752,7 +23882,7 @@ ${repositoryBlock}
|
|
|
23752
23882
|
}
|
|
23753
23883
|
function assertProjectionTargetAncestors(targetPath, targetRoot) {
|
|
23754
23884
|
const pending = [];
|
|
23755
|
-
let current =
|
|
23885
|
+
let current = dirname6(targetPath);
|
|
23756
23886
|
while (current !== targetRoot) {
|
|
23757
23887
|
if (!pathWithin(current, targetRoot)) {
|
|
23758
23888
|
throw instructionTopologyError(
|
|
@@ -23761,11 +23891,11 @@ function assertProjectionTargetAncestors(targetPath, targetRoot) {
|
|
|
23761
23891
|
);
|
|
23762
23892
|
}
|
|
23763
23893
|
pending.push(current);
|
|
23764
|
-
current =
|
|
23894
|
+
current = dirname6(current);
|
|
23765
23895
|
}
|
|
23766
23896
|
pending.push(targetRoot);
|
|
23767
23897
|
for (const directory of pending.reverse()) {
|
|
23768
|
-
if (!
|
|
23898
|
+
if (!existsSync7(directory)) {
|
|
23769
23899
|
mkdirSync5(directory, { mode: 448 });
|
|
23770
23900
|
continue;
|
|
23771
23901
|
}
|
|
@@ -23778,7 +23908,7 @@ function assertProjectionTargetAncestors(targetPath, targetRoot) {
|
|
|
23778
23908
|
}
|
|
23779
23909
|
}
|
|
23780
23910
|
}
|
|
23781
|
-
function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, executionWorkspacePath, platformInstructions) {
|
|
23911
|
+
function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, executionWorkspacePath, platformInstructions, options = {}) {
|
|
23782
23912
|
const sourceRoot = resolve4(sourceWorkspacePath);
|
|
23783
23913
|
const targetRoot = resolve4(executionWorkspacePath);
|
|
23784
23914
|
if (sourceRoot === targetRoot || !platformInstructions?.trim()) {
|
|
@@ -23787,7 +23917,7 @@ function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, execut
|
|
|
23787
23917
|
sourceRoot === targetRoot ? "source and isolated execution workspaces must differ" : "MirrorX platform instructions are missing"
|
|
23788
23918
|
);
|
|
23789
23919
|
}
|
|
23790
|
-
const inspection = inspectExternalWorkspaceProjectInstructions(sourceRoot);
|
|
23920
|
+
const inspection = inspectExternalWorkspaceProjectInstructions(sourceRoot, options);
|
|
23791
23921
|
const sourcesByScope = /* @__PURE__ */ new Map();
|
|
23792
23922
|
for (const source of inspection.sources) {
|
|
23793
23923
|
const entries = sourcesByScope.get(source.scope) ?? [];
|
|
@@ -23810,7 +23940,7 @@ function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, execut
|
|
|
23810
23940
|
`project instruction source changed during projection: ${source.path}`
|
|
23811
23941
|
);
|
|
23812
23942
|
}
|
|
23813
|
-
const sourceContent =
|
|
23943
|
+
const sourceContent = readFileSync9(sourcePath, "utf8");
|
|
23814
23944
|
const sourceSha256 = createHash8("sha256").update(sourceContent, "utf8").digest("hex");
|
|
23815
23945
|
if (sourceSha256 !== source.sha256) {
|
|
23816
23946
|
throw instructionTopologyError(
|
|
@@ -23849,10 +23979,10 @@ function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, execut
|
|
|
23849
23979
|
assertProjectionTargetAncestors(targetPath, targetRoot);
|
|
23850
23980
|
const temporaryPath = `${targetPath}.mirrorx-${randomBytes2(12).toString("hex")}.tmp`;
|
|
23851
23981
|
try {
|
|
23852
|
-
|
|
23853
|
-
|
|
23982
|
+
writeFileSync7(temporaryPath, projectedContent, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
23983
|
+
renameSync6(temporaryPath, targetPath);
|
|
23854
23984
|
} finally {
|
|
23855
|
-
|
|
23985
|
+
rmSync5(temporaryPath, { force: true });
|
|
23856
23986
|
}
|
|
23857
23987
|
modelFacingFile = "AGENTS.md";
|
|
23858
23988
|
modelFacingBytes = Buffer.byteLength(projectedContent, "utf8");
|
|
@@ -23923,9 +24053,9 @@ function agentInstructionDeliveryAudit(bundle, delivery) {
|
|
|
23923
24053
|
}
|
|
23924
24054
|
|
|
23925
24055
|
// src/amaster-runtime-daemon/config-state.mjs
|
|
23926
|
-
import { existsSync as
|
|
24056
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync10, renameSync as renameSync7, rmSync as rmSync6, writeFileSync as writeFileSync8 } from "node:fs";
|
|
23927
24057
|
import { homedir as homedir2, hostname } from "node:os";
|
|
23928
|
-
import { dirname as
|
|
24058
|
+
import { dirname as dirname7, join as join9 } from "node:path";
|
|
23929
24059
|
var CAPABILITIES = [
|
|
23930
24060
|
"remote_registration",
|
|
23931
24061
|
"heartbeat",
|
|
@@ -23988,26 +24118,26 @@ function defaultMachineId() {
|
|
|
23988
24118
|
}
|
|
23989
24119
|
function runtimeHome(env) {
|
|
23990
24120
|
return expandHomePath(String(
|
|
23991
|
-
env.AMASTER_RUNTIME_STATE_HOME || env.AMASTER_RUNTIME_HOME ||
|
|
24121
|
+
env.AMASTER_RUNTIME_STATE_HOME || env.AMASTER_RUNTIME_HOME || join9(homedir2(), ".amaster-employee")
|
|
23992
24122
|
));
|
|
23993
24123
|
}
|
|
23994
24124
|
function stateFilePath(env) {
|
|
23995
|
-
return env.AMASTER_DAEMON_STATE_FILE ? expandHomePath(String(env.AMASTER_DAEMON_STATE_FILE)) :
|
|
24125
|
+
return env.AMASTER_DAEMON_STATE_FILE ? expandHomePath(String(env.AMASTER_DAEMON_STATE_FILE)) : join9(runtimeHome(env), "runtime-connector-state.json");
|
|
23996
24126
|
}
|
|
23997
24127
|
function corruptStatePath(path) {
|
|
23998
24128
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14);
|
|
23999
24129
|
const base = `${path}.corrupt-${timestamp}Z`;
|
|
24000
24130
|
let candidate = base;
|
|
24001
|
-
for (let suffix = 1;
|
|
24131
|
+
for (let suffix = 1; existsSync8(candidate); suffix += 1) {
|
|
24002
24132
|
candidate = `${base}.${suffix}`;
|
|
24003
24133
|
}
|
|
24004
24134
|
return candidate;
|
|
24005
24135
|
}
|
|
24006
24136
|
function readState(env) {
|
|
24007
24137
|
const path = stateFilePath(env);
|
|
24008
|
-
if (!
|
|
24138
|
+
if (!existsSync8(path)) return {};
|
|
24009
24139
|
try {
|
|
24010
|
-
const state = JSON.parse(
|
|
24140
|
+
const state = JSON.parse(readFileSync10(path, "utf8"));
|
|
24011
24141
|
if (!state || typeof state !== "object" || Array.isArray(state)) {
|
|
24012
24142
|
throw new TypeError("runtime connector state must be a JSON object");
|
|
24013
24143
|
}
|
|
@@ -24015,7 +24145,7 @@ function readState(env) {
|
|
|
24015
24145
|
} catch {
|
|
24016
24146
|
const quarantinePath = corruptStatePath(path);
|
|
24017
24147
|
try {
|
|
24018
|
-
|
|
24148
|
+
renameSync7(path, quarantinePath);
|
|
24019
24149
|
process.stderr.write(`AMaster runtime state was invalid and quarantined at ${quarantinePath}
|
|
24020
24150
|
`);
|
|
24021
24151
|
} catch (error) {
|
|
@@ -24029,17 +24159,17 @@ function readState(env) {
|
|
|
24029
24159
|
}
|
|
24030
24160
|
function writeState(env, state) {
|
|
24031
24161
|
const path = stateFilePath(env);
|
|
24032
|
-
mkdirSync6(
|
|
24162
|
+
mkdirSync6(dirname7(path), { recursive: true });
|
|
24033
24163
|
const temporaryPath = `${path}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
24034
24164
|
try {
|
|
24035
|
-
|
|
24165
|
+
writeFileSync8(temporaryPath, `${JSON.stringify(state, null, 2)}
|
|
24036
24166
|
`, {
|
|
24037
24167
|
flag: "wx",
|
|
24038
24168
|
mode: 384
|
|
24039
24169
|
});
|
|
24040
|
-
|
|
24170
|
+
renameSync7(temporaryPath, path);
|
|
24041
24171
|
} finally {
|
|
24042
|
-
|
|
24172
|
+
rmSync6(temporaryPath, { force: true });
|
|
24043
24173
|
}
|
|
24044
24174
|
}
|
|
24045
24175
|
function buildConfig(env = process.env, flags = {}) {
|
|
@@ -24051,10 +24181,10 @@ function buildConfig(env = process.env, flags = {}) {
|
|
|
24051
24181
|
const authHeader = String(flags.authHeader ?? env.AMASTER_CONNECTOR_AUTH_HEADER ?? "");
|
|
24052
24182
|
const home = runtimeHome(env);
|
|
24053
24183
|
const runtimeWorkspacesRoot = expandHomePath(
|
|
24054
|
-
String(flags.runtimeWorkspacesRoot ?? env.AMASTER_RUNTIME_WORKSPACES_ROOT ??
|
|
24184
|
+
String(flags.runtimeWorkspacesRoot ?? env.AMASTER_RUNTIME_WORKSPACES_ROOT ?? join9(home, "workspaces"))
|
|
24055
24185
|
);
|
|
24056
24186
|
const browserSessionStateRoot = expandHomePath(String(
|
|
24057
|
-
flags.browserSessionStateRoot ?? env.AMASTER_BROWSER_SESSION_STATE_ROOT ??
|
|
24187
|
+
flags.browserSessionStateRoot ?? env.AMASTER_BROWSER_SESSION_STATE_ROOT ?? join9(home, "browser-auth")
|
|
24058
24188
|
));
|
|
24059
24189
|
const piToolArgumentGuardModeValue = String(
|
|
24060
24190
|
flags.piToolArgumentGuardMode ?? env.AMASTER_PI_TOOL_ARGUMENT_GUARD_MODE ?? "shadow"
|
|
@@ -25906,7 +26036,7 @@ var bestEffortPostJson = bestEffortPostRuntimeConnectorJson;
|
|
|
25906
26036
|
|
|
25907
26037
|
// src/amaster-runtime-daemon/runtime-artifact-upload.mjs
|
|
25908
26038
|
import { createHash as createHash9 } from "node:crypto";
|
|
25909
|
-
import { closeSync as closeSync2, constants, fstatSync, lstatSync as lstatSync5, openSync as openSync2, readFileSync as
|
|
26039
|
+
import { closeSync as closeSync2, constants, fstatSync, lstatSync as lstatSync5, openSync as openSync2, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
25910
26040
|
import { isAbsolute as isAbsolute5, relative as relative4, resolve as resolve5 } from "node:path";
|
|
25911
26041
|
var SHA256_PATTERN3 = /^[a-f0-9]{64}$/;
|
|
25912
26042
|
function requiredString(value, name) {
|
|
@@ -25926,11 +26056,11 @@ function sameFileSnapshot(left, right) {
|
|
|
25926
26056
|
return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
25927
26057
|
}
|
|
25928
26058
|
function readOwnedWorkspaceFile(rootPath, sourceRelativePath, label = "Runtime workspace file", options = {}) {
|
|
25929
|
-
const root =
|
|
26059
|
+
const root = realpathSync5(resolve5(rootPath));
|
|
25930
26060
|
const relativePath = ownedRelativePath(sourceRelativePath);
|
|
25931
26061
|
const sourcePath = resolve5(root, relativePath);
|
|
25932
26062
|
const pathStat = lstatSync5(sourcePath);
|
|
25933
|
-
if (!pathStat.isFile() || pathStat.isSymbolicLink() || !pathWithin2(
|
|
26063
|
+
if (!pathStat.isFile() || pathStat.isSymbolicLink() || !pathWithin2(realpathSync5(sourcePath), root)) {
|
|
25934
26064
|
throw new Error(`${label} source is not an owned regular file`);
|
|
25935
26065
|
}
|
|
25936
26066
|
const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
@@ -25958,11 +26088,11 @@ function readOwnedWorkspaceFile(rootPath, sourceRelativePath, label = "Runtime w
|
|
|
25958
26088
|
);
|
|
25959
26089
|
}
|
|
25960
26090
|
}
|
|
25961
|
-
const body =
|
|
26091
|
+
const body = readFileSync11(descriptor);
|
|
25962
26092
|
options.afterRead?.({ sourcePath, descriptor });
|
|
25963
26093
|
const after = fstatSync(descriptor);
|
|
25964
26094
|
const pathAfter = lstatSync5(sourcePath);
|
|
25965
|
-
if (!sameFileSnapshot(before, after) || !sameFileSnapshot(pathAfter, after) || !pathAfter.isFile() || pathAfter.isSymbolicLink() || !pathWithin2(
|
|
26095
|
+
if (!sameFileSnapshot(before, after) || !sameFileSnapshot(pathAfter, after) || !pathAfter.isFile() || pathAfter.isSymbolicLink() || !pathWithin2(realpathSync5(sourcePath), root) || body.length !== after.size) {
|
|
25966
26096
|
throw new Error(`${label} source changed during the governed read`);
|
|
25967
26097
|
}
|
|
25968
26098
|
return { body, relativePath, stat: after };
|
|
@@ -26243,105 +26373,8 @@ function createRuntimeArtifactIngestQueue({ ingest, onError }) {
|
|
|
26243
26373
|
|
|
26244
26374
|
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
26245
26375
|
import { createHash as createHash11 } from "node:crypto";
|
|
26246
|
-
import { existsSync as existsSync9, mkdirSync as mkdirSync7, realpathSync as
|
|
26247
|
-
import { basename as basename4, join as
|
|
26248
|
-
|
|
26249
|
-
// src/amaster-runtime-daemon/workspace-manifest.mjs
|
|
26250
|
-
import { chownSync as chownSync3, existsSync as existsSync8, readFileSync as readFileSync11, renameSync as renameSync7, rmSync as rmSync6, statSync as statSync3, writeFileSync as writeFileSync8 } from "node:fs";
|
|
26251
|
-
import { basename as basename3, dirname as dirname7, join as join8 } from "node:path";
|
|
26252
|
-
var WORKSPACE_MANIFEST_FILENAME = ".amaster-runtime.json";
|
|
26253
|
-
function syncManifestDirOwnership(manifestPath, deps = {}) {
|
|
26254
|
-
const stat = deps.statSync ?? statSync3;
|
|
26255
|
-
const chown = deps.chownSync ?? chownSync3;
|
|
26256
|
-
const geteuid = deps.geteuid ?? (typeof process.geteuid === "function" ? process.geteuid.bind(process) : () => null);
|
|
26257
|
-
try {
|
|
26258
|
-
if (geteuid() !== 0) return false;
|
|
26259
|
-
const dirStat = stat(dirname7(manifestPath));
|
|
26260
|
-
if (dirStat.uid === 0 && dirStat.gid === 0) return false;
|
|
26261
|
-
chown(manifestPath, dirStat.uid, dirStat.gid);
|
|
26262
|
-
return true;
|
|
26263
|
-
} catch {
|
|
26264
|
-
return false;
|
|
26265
|
-
}
|
|
26266
|
-
}
|
|
26267
|
-
function nowIso() {
|
|
26268
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
26269
|
-
}
|
|
26270
|
-
function workspaceManifestPath(workspaceOrCwd) {
|
|
26271
|
-
if (!workspaceOrCwd) return null;
|
|
26272
|
-
if (typeof workspaceOrCwd === "string") return join8(workspaceOrCwd, WORKSPACE_MANIFEST_FILENAME);
|
|
26273
|
-
if (typeof workspaceOrCwd.cwd === "string") return join8(workspaceOrCwd.cwd, WORKSPACE_MANIFEST_FILENAME);
|
|
26274
|
-
return null;
|
|
26275
|
-
}
|
|
26276
|
-
function readWorkspaceManifest(manifestPath) {
|
|
26277
|
-
if (!manifestPath || !existsSync8(manifestPath)) return null;
|
|
26278
|
-
try {
|
|
26279
|
-
const parsed = JSON.parse(readFileSync11(manifestPath, "utf8"));
|
|
26280
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
26281
|
-
} catch {
|
|
26282
|
-
return null;
|
|
26283
|
-
}
|
|
26284
|
-
}
|
|
26285
|
-
function writeWorkspaceManifest(manifestPath, manifest, deps) {
|
|
26286
|
-
const tempPath = join8(
|
|
26287
|
-
dirname7(manifestPath),
|
|
26288
|
-
`.${basename3(manifestPath)}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
|
26289
|
-
);
|
|
26290
|
-
try {
|
|
26291
|
-
writeFileSync8(tempPath, `${JSON.stringify(manifest, null, 2)}
|
|
26292
|
-
`, { mode: 384 });
|
|
26293
|
-
renameSync7(tempPath, manifestPath);
|
|
26294
|
-
syncManifestDirOwnership(manifestPath, deps);
|
|
26295
|
-
} catch (err) {
|
|
26296
|
-
rmSync6(tempPath, { force: true });
|
|
26297
|
-
throw err;
|
|
26298
|
-
}
|
|
26299
|
-
return manifest;
|
|
26300
|
-
}
|
|
26301
|
-
function createWorkspaceManifest(workspace, input = {}) {
|
|
26302
|
-
const manifestPath = workspaceManifestPath(workspace);
|
|
26303
|
-
const createdAt = nowIso();
|
|
26304
|
-
const manifest = {
|
|
26305
|
-
version: 2,
|
|
26306
|
-
managed: true,
|
|
26307
|
-
sourceWorkspacePath: workspace.sourceWorkspacePath,
|
|
26308
|
-
managedCwd: workspace.cwd,
|
|
26309
|
-
executionWorkdir: workspace.cwd,
|
|
26310
|
-
executorKind: input.executorKind ?? null,
|
|
26311
|
-
executorHome: workspace.executorHome ?? null,
|
|
26312
|
-
commandId: input.commandId ?? null,
|
|
26313
|
-
generation: input.generation ?? null,
|
|
26314
|
-
runId: input.runId ?? null,
|
|
26315
|
-
issueId: input.issueId ?? null,
|
|
26316
|
-
workspaceKey: workspace.workspaceKey ?? null,
|
|
26317
|
-
issueKey: workspace.issueKey ?? null,
|
|
26318
|
-
runKey: workspace.runKey ?? null,
|
|
26319
|
-
createdAt,
|
|
26320
|
-
lastTouchedAt: createdAt,
|
|
26321
|
-
lastWorkspaceScanAt: null,
|
|
26322
|
-
artifactCandidateCount: 0,
|
|
26323
|
-
artifactCandidates: [],
|
|
26324
|
-
outboxPending: 0
|
|
26325
|
-
};
|
|
26326
|
-
return writeWorkspaceManifest(manifestPath, manifest);
|
|
26327
|
-
}
|
|
26328
|
-
function updateWorkspaceManifest(workspaceOrManifestPath, patch = {}) {
|
|
26329
|
-
const manifestPath = typeof workspaceOrManifestPath === "string" ? workspaceOrManifestPath : workspaceManifestPath(workspaceOrManifestPath);
|
|
26330
|
-
if (!manifestPath) return null;
|
|
26331
|
-
const current = readWorkspaceManifest(manifestPath) ?? {
|
|
26332
|
-
version: 2,
|
|
26333
|
-
managed: true,
|
|
26334
|
-
createdAt: nowIso()
|
|
26335
|
-
};
|
|
26336
|
-
const next = {
|
|
26337
|
-
...current,
|
|
26338
|
-
...patch,
|
|
26339
|
-
lastTouchedAt: nowIso()
|
|
26340
|
-
};
|
|
26341
|
-
return writeWorkspaceManifest(manifestPath, next);
|
|
26342
|
-
}
|
|
26343
|
-
|
|
26344
|
-
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
26376
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync7, realpathSync as realpathSync6, statSync as statSync4 } from "node:fs";
|
|
26377
|
+
import { basename as basename4, join as join10, isAbsolute as isAbsolute6, relative as relative5, resolve as resolve6 } from "node:path";
|
|
26345
26378
|
function pathWithin3(candidate, root) {
|
|
26346
26379
|
const rel = relative5(root, candidate);
|
|
26347
26380
|
return rel === "" || !rel.startsWith("..") && !isAbsolute6(rel);
|
|
@@ -26350,10 +26383,10 @@ function resolveWorkspaceCwd(config, command) {
|
|
|
26350
26383
|
const payload = asRecord(command.payload);
|
|
26351
26384
|
const requested = readString(payload.workspacePath);
|
|
26352
26385
|
const fallback = config.workspaceBindings[0] ?? process.cwd();
|
|
26353
|
-
const cwd =
|
|
26386
|
+
const cwd = realpathSync6(resolve6(expandHomePath(requested ?? fallback)));
|
|
26354
26387
|
const allowlist = config.workspaceBindings.flatMap((entry) => {
|
|
26355
26388
|
try {
|
|
26356
|
-
return [
|
|
26389
|
+
return [realpathSync6(resolve6(expandHomePath(entry)))];
|
|
26357
26390
|
} catch {
|
|
26358
26391
|
return [];
|
|
26359
26392
|
}
|
|
@@ -26398,7 +26431,7 @@ function workspaceLabel(sourceWorkspacePath, payload) {
|
|
|
26398
26431
|
function workspacesRoot(config) {
|
|
26399
26432
|
const root = resolve6(expandHomePath(config.runtimeWorkspacesRoot ?? "~/.amaster-employee/workspaces"));
|
|
26400
26433
|
mkdirSync7(root, { recursive: true });
|
|
26401
|
-
return
|
|
26434
|
+
return realpathSync6(root);
|
|
26402
26435
|
}
|
|
26403
26436
|
function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
26404
26437
|
const sourceWorkspacePath = resolveWorkspaceCwd(config, command);
|
|
@@ -26410,9 +26443,9 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
|
26410
26443
|
const workspaceKey = `${safeSegment(workspaceLabel(sourceWorkspacePath, payload), "workspace")}-${shortHash(sourceWorkspacePath)}`;
|
|
26411
26444
|
const issueKey = `${safeSegment(issueLabel(command, payload), "issue")}-${shortHash(issueId, 8)}`;
|
|
26412
26445
|
const runKey = `${safeSegment(runId, "run")}-${shortHash(runId, 8)}`;
|
|
26413
|
-
const runDir =
|
|
26414
|
-
const cwd =
|
|
26415
|
-
const executorHome =
|
|
26446
|
+
const runDir = join10(root, workspaceKey, issueKey, runKey);
|
|
26447
|
+
const cwd = join10(runDir, "workdir");
|
|
26448
|
+
const executorHome = join10(runDir, "executors", safeSegment(executorKind, "executor"));
|
|
26416
26449
|
mkdirSync7(cwd, { recursive: true });
|
|
26417
26450
|
mkdirSync7(executorHome, { recursive: true });
|
|
26418
26451
|
const workspace = {
|
|
@@ -26437,7 +26470,7 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
|
26437
26470
|
|
|
26438
26471
|
// src/amaster-runtime-daemon/workspace-gc.mjs
|
|
26439
26472
|
import { existsSync as existsSync10, readdirSync as readdirSync7, statSync as statSync5 } from "node:fs";
|
|
26440
|
-
import { join as
|
|
26473
|
+
import { join as join11, resolve as resolve7 } from "node:path";
|
|
26441
26474
|
function readIsoTime(value) {
|
|
26442
26475
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
26443
26476
|
const time = new Date(value).getTime();
|
|
@@ -26460,7 +26493,7 @@ function walkWorkdirs(root) {
|
|
|
26460
26493
|
}
|
|
26461
26494
|
for (const entry of entries) {
|
|
26462
26495
|
if (!entry.isDirectory()) continue;
|
|
26463
|
-
const fullPath =
|
|
26496
|
+
const fullPath = join11(current, entry.name);
|
|
26464
26497
|
if (entry.name === "workdir" && existsSync10(workspaceManifestPath(fullPath))) {
|
|
26465
26498
|
workdirs.push(fullPath);
|
|
26466
26499
|
continue;
|
|
@@ -26492,7 +26525,7 @@ function directorySizeBytes(path) {
|
|
|
26492
26525
|
continue;
|
|
26493
26526
|
}
|
|
26494
26527
|
for (const entry of entries) {
|
|
26495
|
-
stack.push(
|
|
26528
|
+
stack.push(join11(current, entry.name));
|
|
26496
26529
|
}
|
|
26497
26530
|
continue;
|
|
26498
26531
|
}
|
|
@@ -26578,7 +26611,7 @@ import {
|
|
|
26578
26611
|
unlinkSync as unlinkSync2,
|
|
26579
26612
|
writeFileSync as writeFileSync9
|
|
26580
26613
|
} from "node:fs";
|
|
26581
|
-
import { dirname as dirname8, extname, isAbsolute as isAbsolute7, join as
|
|
26614
|
+
import { dirname as dirname8, extname, isAbsolute as isAbsolute7, join as join12, parse as parse2, resolve as resolve8, sep as sep3 } from "node:path";
|
|
26582
26615
|
import { fileURLToPath } from "node:url";
|
|
26583
26616
|
var PRESET_TEMPLATE_MANIFEST_FILE = ".mirrorx-preset-templates.json";
|
|
26584
26617
|
var MAX_PRESET_TEMPLATE_FILES = 256;
|
|
@@ -26628,7 +26661,7 @@ function readManifest(manifestPath, { strict }) {
|
|
|
26628
26661
|
}
|
|
26629
26662
|
function verifiedBundleFiles(sourceDir, manifest) {
|
|
26630
26663
|
return manifest.files.map((entry) => {
|
|
26631
|
-
const sourcePath =
|
|
26664
|
+
const sourcePath = join12(sourceDir, entry.name);
|
|
26632
26665
|
const stat = lstatSync6(sourcePath);
|
|
26633
26666
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
26634
26667
|
throw new Error(`preset_template_bundle_file_unsafe: ${entry.name}`);
|
|
@@ -26643,7 +26676,7 @@ function verifiedBundleFiles(sourceDir, manifest) {
|
|
|
26643
26676
|
function removeRetiredPresetFiles(targetDir, previousManifest, nextNames) {
|
|
26644
26677
|
for (const entry of previousManifest.files) {
|
|
26645
26678
|
if (nextNames.has(entry.name)) continue;
|
|
26646
|
-
const targetPath =
|
|
26679
|
+
const targetPath = join12(targetDir, entry.name);
|
|
26647
26680
|
if (!existsSync11(targetPath)) continue;
|
|
26648
26681
|
const stat = lstatSync6(targetPath);
|
|
26649
26682
|
if (stat.isDirectory()) {
|
|
@@ -26658,7 +26691,7 @@ function materializeBundledPresetTemplates(input) {
|
|
|
26658
26691
|
if (sourceDir === targetDir || sourceDir.startsWith(`${targetDir}${sep3}`) || targetDir.startsWith(`${sourceDir}${sep3}`)) {
|
|
26659
26692
|
throw new Error("preset_template_source_target_overlap");
|
|
26660
26693
|
}
|
|
26661
|
-
const manifest = readManifest(
|
|
26694
|
+
const manifest = readManifest(join12(sourceDir, PRESET_TEMPLATE_MANIFEST_FILE), { strict: true });
|
|
26662
26695
|
const verifiedFiles = verifiedBundleFiles(sourceDir, manifest);
|
|
26663
26696
|
mkdirSync8(dirname8(targetDir), { recursive: true, mode: 493 });
|
|
26664
26697
|
const targetStat = lstatIfExists(targetDir);
|
|
@@ -26666,24 +26699,24 @@ function materializeBundledPresetTemplates(input) {
|
|
|
26666
26699
|
throw new Error("preset_template_target_root_unsafe");
|
|
26667
26700
|
}
|
|
26668
26701
|
mkdirSync8(targetDir, { recursive: true, mode: 493 });
|
|
26669
|
-
const previousManifest = readManifest(
|
|
26670
|
-
const stageDir = mkdtempSync(
|
|
26702
|
+
const previousManifest = readManifest(join12(targetDir, PRESET_TEMPLATE_MANIFEST_FILE), { strict: false });
|
|
26703
|
+
const stageDir = mkdtempSync(join12(dirname8(targetDir), ".mirrorx-preset-templates-"));
|
|
26671
26704
|
try {
|
|
26672
26705
|
for (const file of verifiedFiles) {
|
|
26673
|
-
const stagedPath =
|
|
26706
|
+
const stagedPath = join12(stageDir, file.name);
|
|
26674
26707
|
writeFileSync9(stagedPath, file.body, { mode: 292 });
|
|
26675
26708
|
chmodSync5(stagedPath, 292);
|
|
26676
|
-
renameSync8(stagedPath,
|
|
26709
|
+
renameSync8(stagedPath, join12(targetDir, file.name));
|
|
26677
26710
|
}
|
|
26678
26711
|
removeRetiredPresetFiles(targetDir, previousManifest, new Set(manifest.files.map((file) => file.name)));
|
|
26679
|
-
const stagedManifest =
|
|
26712
|
+
const stagedManifest = join12(stageDir, PRESET_TEMPLATE_MANIFEST_FILE);
|
|
26680
26713
|
writeFileSync9(stagedManifest, `${JSON.stringify({
|
|
26681
26714
|
schemaVersion: manifest.schemaVersion,
|
|
26682
26715
|
files: manifest.files
|
|
26683
26716
|
}, null, 2)}
|
|
26684
26717
|
`, { mode: 292 });
|
|
26685
26718
|
chmodSync5(stagedManifest, 292);
|
|
26686
|
-
renameSync8(stagedManifest,
|
|
26719
|
+
renameSync8(stagedManifest, join12(targetDir, PRESET_TEMPLATE_MANIFEST_FILE));
|
|
26687
26720
|
} finally {
|
|
26688
26721
|
rmSync7(stageDir, { recursive: true, force: true });
|
|
26689
26722
|
}
|
|
@@ -26712,7 +26745,7 @@ function materializeRuntimePresetTemplates(env = process.env, options = {}) {
|
|
|
26712
26745
|
|
|
26713
26746
|
// src/amaster-runtime-daemon/runtime-status-summary.mjs
|
|
26714
26747
|
import { existsSync as existsSync12, readdirSync as readdirSync9, statSync as statSync6 } from "node:fs";
|
|
26715
|
-
import { dirname as dirname9, join as
|
|
26748
|
+
import { dirname as dirname9, join as join13, resolve as resolve9 } from "node:path";
|
|
26716
26749
|
function runtimeStatusDirectoryEntries(path) {
|
|
26717
26750
|
try {
|
|
26718
26751
|
return readdirSync9(path, { withFileTypes: true });
|
|
@@ -26735,7 +26768,7 @@ function runtimeStatusDirectorySizeBytes(path) {
|
|
|
26735
26768
|
if (!stat || stat.isSymbolicLink()) continue;
|
|
26736
26769
|
if (stat.isDirectory()) {
|
|
26737
26770
|
for (const entry of runtimeStatusDirectoryEntries(current)) {
|
|
26738
|
-
stack.push(
|
|
26771
|
+
stack.push(join13(current, entry.name));
|
|
26739
26772
|
}
|
|
26740
26773
|
continue;
|
|
26741
26774
|
}
|
|
@@ -26752,7 +26785,7 @@ function walkRuntimeStatusManagedWorkdirs(root) {
|
|
|
26752
26785
|
if (!current) continue;
|
|
26753
26786
|
for (const entry of runtimeStatusDirectoryEntries(current)) {
|
|
26754
26787
|
if (!entry.isDirectory()) continue;
|
|
26755
|
-
const fullPath =
|
|
26788
|
+
const fullPath = join13(current, entry.name);
|
|
26756
26789
|
if (entry.name === "workdir" && existsSync12(workspaceManifestPath(fullPath))) {
|
|
26757
26790
|
workdirs.push(fullPath);
|
|
26758
26791
|
continue;
|
|
@@ -26794,7 +26827,7 @@ function summarizeRuntimeStatusRecentRun(workdir, manifest) {
|
|
|
26794
26827
|
}
|
|
26795
26828
|
function runtimeStatusOutboxDir(config) {
|
|
26796
26829
|
const statePath = config.AMASTER_DAEMON_STATE_FILE ?? config.daemonStateFile;
|
|
26797
|
-
return
|
|
26830
|
+
return join13(dirname9(stateFilePath({
|
|
26798
26831
|
AMASTER_DAEMON_STATE_FILE: statePath
|
|
26799
26832
|
})), "result-outbox");
|
|
26800
26833
|
}
|
|
@@ -26802,7 +26835,7 @@ function runtimeStatusRunCompletionDir(config) {
|
|
|
26802
26835
|
const explicit = config.AMASTER_RUN_COMPLETION_STATE_DIR ?? config.runCompletionStateDir;
|
|
26803
26836
|
if (typeof explicit === "string" && explicit.trim()) return resolve9(explicit);
|
|
26804
26837
|
const statePath = config.AMASTER_DAEMON_STATE_FILE ?? config.daemonStateFile;
|
|
26805
|
-
return
|
|
26838
|
+
return join13(dirname9(stateFilePath({
|
|
26806
26839
|
AMASTER_DAEMON_STATE_FILE: statePath
|
|
26807
26840
|
})), "run-completion-state");
|
|
26808
26841
|
}
|
|
@@ -26839,9 +26872,9 @@ function summarizeRuntimeLocalState(input) {
|
|
|
26839
26872
|
}
|
|
26840
26873
|
}
|
|
26841
26874
|
const pendingOutboxDir = runtimeStatusOutboxDir(config);
|
|
26842
|
-
const invalidOutboxDir =
|
|
26875
|
+
const invalidOutboxDir = join13(pendingOutboxDir, "invalid");
|
|
26843
26876
|
const pendingRunCompletionDir = runtimeStatusRunCompletionDir(config);
|
|
26844
|
-
const invalidRunCompletionDir =
|
|
26877
|
+
const invalidRunCompletionDir = join13(pendingRunCompletionDir, "invalid");
|
|
26845
26878
|
return {
|
|
26846
26879
|
managedWorkspacesRoot: root,
|
|
26847
26880
|
managedWorkdirCount: workdirs.length,
|
|
@@ -27454,7 +27487,7 @@ function readPiFinalContextAttestation(input) {
|
|
|
27454
27487
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
27455
27488
|
import { createHash as createHash14 } from "node:crypto";
|
|
27456
27489
|
import { existsSync as existsSync13, readdirSync as readdirSync10, readFileSync as readFileSync15, statSync as statSync7 } from "node:fs";
|
|
27457
|
-
import { basename as basename5, extname as extname2, isAbsolute as isAbsolute8, join as
|
|
27490
|
+
import { basename as basename5, extname as extname2, isAbsolute as isAbsolute8, join as join14, relative as relative6, resolve as resolve11 } from "node:path";
|
|
27458
27491
|
var WORKSPACE_RUNTIME_SERVICES_FILENAME = ".amaster-runtime-services.json";
|
|
27459
27492
|
var ARTIFACT_EXTENSIONS = /* @__PURE__ */ new Map([
|
|
27460
27493
|
[".md", "markdown"],
|
|
@@ -27572,7 +27605,7 @@ function scanArtifactCandidates(cwd, opts = {}) {
|
|
|
27572
27605
|
if (entry.name.startsWith(".") && entry.name !== ".amaster-runtime.json") {
|
|
27573
27606
|
if (entry.name === ".git") continue;
|
|
27574
27607
|
}
|
|
27575
|
-
const fullPath =
|
|
27608
|
+
const fullPath = join14(current, entry.name);
|
|
27576
27609
|
const relativePath = normalizeRelativePath(root, fullPath);
|
|
27577
27610
|
if (!isSafeRelativePath(relativePath)) continue;
|
|
27578
27611
|
if (basename5(relativePath) === ".amaster-runtime.json") continue;
|
|
@@ -27650,7 +27683,7 @@ function sanitizeRuntimeService(entry) {
|
|
|
27650
27683
|
};
|
|
27651
27684
|
}
|
|
27652
27685
|
function readRuntimeServicesSnapshot(cwd) {
|
|
27653
|
-
const snapshotPath =
|
|
27686
|
+
const snapshotPath = join14(resolve11(cwd), WORKSPACE_RUNTIME_SERVICES_FILENAME);
|
|
27654
27687
|
if (!existsSync13(snapshotPath)) return [];
|
|
27655
27688
|
try {
|
|
27656
27689
|
const parsed = JSON.parse(readFileSync15(snapshotPath, "utf8"));
|
|
@@ -27897,7 +27930,7 @@ import {
|
|
|
27897
27930
|
} from "node:fs";
|
|
27898
27931
|
import { createServer as createHttpServer } from "node:http";
|
|
27899
27932
|
import { connect as connectTcp, isIP } from "node:net";
|
|
27900
|
-
import { dirname as dirname10, join as
|
|
27933
|
+
import { dirname as dirname10, join as join15, relative as relative7, resolve as resolve12 } from "node:path";
|
|
27901
27934
|
var MARKER_NAME = ".amaster-browser-session.json";
|
|
27902
27935
|
var HUMAN_LEASE_INACTIVITY_MS = 30 * 60 * 1e3;
|
|
27903
27936
|
var HUMAN_LEASE_HARD_CAP_MS = 2 * 60 * 60 * 1e3;
|
|
@@ -28154,7 +28187,7 @@ function exactProfile(stateRoot, payload, { create = false } = {}) {
|
|
|
28154
28187
|
mkdirSync9(profilePath, { mode: 448 });
|
|
28155
28188
|
chmodSync6(profilePath, 448);
|
|
28156
28189
|
writeFileSync10(
|
|
28157
|
-
|
|
28190
|
+
join15(profilePath, MARKER_NAME),
|
|
28158
28191
|
`${JSON.stringify(expectedOwner(payload))}
|
|
28159
28192
|
`,
|
|
28160
28193
|
{ encoding: "utf8", mode: 384, flag: "wx" }
|
|
@@ -28165,7 +28198,7 @@ function exactProfile(stateRoot, payload, { create = false } = {}) {
|
|
|
28165
28198
|
}
|
|
28166
28199
|
let owner;
|
|
28167
28200
|
try {
|
|
28168
|
-
owner = JSON.parse(readFileSync16(
|
|
28201
|
+
owner = JSON.parse(readFileSync16(join15(profilePath, MARKER_NAME), "utf8"));
|
|
28169
28202
|
} catch {
|
|
28170
28203
|
throw brokerError("browser_session_profile_owner_invalid");
|
|
28171
28204
|
}
|
|
@@ -28450,7 +28483,7 @@ function createBrowserSessionBroker({
|
|
|
28450
28483
|
if (resolve12(payload.userDataDir) !== expectedPath) {
|
|
28451
28484
|
throw brokerError("browser_session_profile_path_invalid");
|
|
28452
28485
|
}
|
|
28453
|
-
const marker = JSON.parse(readFileSync16(
|
|
28486
|
+
const marker = JSON.parse(readFileSync16(join15(expectedPath, MARKER_NAME), "utf8"));
|
|
28454
28487
|
if (marker.version !== 1 || typeof marker.provider !== "string" || !marker.provider.trim() || marker.companyId !== payload.companyId || marker.bindingId !== payload.bindingId || marker.localOpaqueRef !== payload.localOpaqueRef || marker.origin !== payload.origin) {
|
|
28455
28488
|
throw brokerError("browser_session_profile_owner_mismatch");
|
|
28456
28489
|
}
|
|
@@ -28613,7 +28646,7 @@ function createSourceCompletionStopPolicy({
|
|
|
28613
28646
|
}
|
|
28614
28647
|
|
|
28615
28648
|
// src/amaster-runtime-daemon.mjs
|
|
28616
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
28649
|
+
var CONNECTOR_VERSION = "0.1.1-beta.125";
|
|
28617
28650
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
28618
28651
|
var SOURCE_ACQUISITION_CAPABILITY2 = source_acquisition_compatibility_default.profileVersion;
|
|
28619
28652
|
var daemonRequire = createRequire(import.meta.url);
|
|
@@ -28661,7 +28694,7 @@ function resultOutboxPendingCount(config) {
|
|
|
28661
28694
|
try {
|
|
28662
28695
|
let pending = 0;
|
|
28663
28696
|
for (const file of readdirSync11(dir).filter((name) => name.endsWith(".json"))) {
|
|
28664
|
-
if (readValidResultOutboxEntryOrQuarantine(config, file,
|
|
28697
|
+
if (readValidResultOutboxEntryOrQuarantine(config, file, join16(dir, file))) {
|
|
28665
28698
|
pending += 1;
|
|
28666
28699
|
}
|
|
28667
28700
|
}
|
|
@@ -28673,15 +28706,15 @@ function resultOutboxPendingCount(config) {
|
|
|
28673
28706
|
function runCompletionStateDir(config) {
|
|
28674
28707
|
const explicit = readString(process.env.AMASTER_RUN_COMPLETION_STATE_DIR);
|
|
28675
28708
|
if (explicit) return resolve13(expandHomePath(explicit));
|
|
28676
|
-
return
|
|
28709
|
+
return join16(dirname11(stateFilePath(process.env)), "run-completion-state");
|
|
28677
28710
|
}
|
|
28678
28711
|
function runCompletionStateInvalidDir(config) {
|
|
28679
|
-
return
|
|
28712
|
+
return join16(runCompletionStateDir(config), "invalid");
|
|
28680
28713
|
}
|
|
28681
28714
|
function quarantineInvalidRunCompletionState(config, filePath, reason) {
|
|
28682
28715
|
const invalidDir = runCompletionStateInvalidDir(config);
|
|
28683
28716
|
mkdirSync10(invalidDir, { recursive: true, mode: 448 });
|
|
28684
|
-
const destination =
|
|
28717
|
+
const destination = join16(invalidDir, basename6(filePath));
|
|
28685
28718
|
try {
|
|
28686
28719
|
renameSync9(filePath, destination);
|
|
28687
28720
|
} catch {
|
|
@@ -28738,7 +28771,7 @@ function resultOutboxActiveRunCommands(config) {
|
|
|
28738
28771
|
const outboxPending = resultOutboxPendingCount(config);
|
|
28739
28772
|
const entries = [];
|
|
28740
28773
|
for (const file of readdirSync11(dir).filter((name) => name.endsWith(".json")).sort()) {
|
|
28741
|
-
const entry = readValidResultOutboxEntryOrQuarantine(config, file,
|
|
28774
|
+
const entry = readValidResultOutboxEntryOrQuarantine(config, file, join16(dir, file));
|
|
28742
28775
|
if (!entry) continue;
|
|
28743
28776
|
const activeRun = asRecord(entry.activeRun);
|
|
28744
28777
|
const commandId = readString(activeRun.commandId) ?? readString(entry.commandId);
|
|
@@ -28773,7 +28806,7 @@ function resultOutboxFailedRunCommands(config) {
|
|
|
28773
28806
|
for (const file of readdirSync11(dir).filter((name) => name.endsWith(".json")).sort().slice(-100)) {
|
|
28774
28807
|
let entry;
|
|
28775
28808
|
try {
|
|
28776
|
-
entry = asRecord(JSON.parse(readFileSync17(
|
|
28809
|
+
entry = asRecord(JSON.parse(readFileSync17(join16(dir, file), "utf8")));
|
|
28777
28810
|
} catch {
|
|
28778
28811
|
continue;
|
|
28779
28812
|
}
|
|
@@ -28883,10 +28916,10 @@ function safeSkillRootSummary(kind, source, pathValue) {
|
|
|
28883
28916
|
try {
|
|
28884
28917
|
for (const name of readdirSync11(pathValue)) {
|
|
28885
28918
|
if (name.startsWith(".")) continue;
|
|
28886
|
-
const skillDir =
|
|
28919
|
+
const skillDir = join16(pathValue, name);
|
|
28887
28920
|
try {
|
|
28888
28921
|
if (!statSync9(skillDir).isDirectory()) continue;
|
|
28889
|
-
if (!existsSync15(
|
|
28922
|
+
if (!existsSync15(join16(skillDir, "SKILL.md"))) continue;
|
|
28890
28923
|
skillCount += 1;
|
|
28891
28924
|
if (skillCount >= MAX_PI_CAPABILITY_SOURCE_ENTRIES) {
|
|
28892
28925
|
truncated = true;
|
|
@@ -28937,7 +28970,7 @@ function objectKeyCount(value) {
|
|
|
28937
28970
|
return value && typeof value === "object" && !Array.isArray(value) ? Object.keys(value).length : 0;
|
|
28938
28971
|
}
|
|
28939
28972
|
function defaultPiCodingAgentDir() {
|
|
28940
|
-
return
|
|
28973
|
+
return join16(homedir3(), ".pi", "agent");
|
|
28941
28974
|
}
|
|
28942
28975
|
function piCapabilitySourcesDiagnostics() {
|
|
28943
28976
|
const configuredPiCodingAgentDir = safeExpandPath(process.env.PI_CODING_AGENT_DIR);
|
|
@@ -28946,14 +28979,14 @@ function piCapabilitySourcesDiagnostics() {
|
|
|
28946
28979
|
const configuredPiAgentHome = safeExpandPath(process.env.PI_AGENT_HOME);
|
|
28947
28980
|
const piAgentHome = configuredPiAgentHome ?? piCodingAgentDir;
|
|
28948
28981
|
const piAgentHomeSource = configuredPiAgentHome ? "PI_AGENT_HOME" : piCodingAgentDirSource;
|
|
28949
|
-
const userSkillsPath = piAgentHome ?
|
|
28982
|
+
const userSkillsPath = piAgentHome ? join16(piAgentHome, "skills") : null;
|
|
28950
28983
|
const configuredMarketplaceSkillsPath = safeExpandPath(
|
|
28951
28984
|
process.env.PI_AGENT_MARKETPLACE_SKILLS_DIR
|
|
28952
28985
|
);
|
|
28953
|
-
const marketplaceSkillsPath = configuredMarketplaceSkillsPath ?? (piAgentHome ?
|
|
28986
|
+
const marketplaceSkillsPath = configuredMarketplaceSkillsPath ?? (piAgentHome ? join16(piAgentHome, "marketplace", "skills") : null);
|
|
28954
28987
|
const builtinSkillsPath = safeExpandPath(process.env.PI_AGENT_BUILTIN_SKILLS_DIR) ?? safeExpandPath(process.env.AMASTER_BUILTIN_SKILLS);
|
|
28955
|
-
const mcpConfigPath = safeExpandPath(process.env.PI_AGENT_MCP_SERVERS_FILE) ?? (piAgentHome ?
|
|
28956
|
-
const settingsConfigPath = piCodingAgentDir ?
|
|
28988
|
+
const mcpConfigPath = safeExpandPath(process.env.PI_AGENT_MCP_SERVERS_FILE) ?? (piAgentHome ? join16(piAgentHome, "mcp.json") : null);
|
|
28989
|
+
const settingsConfigPath = piCodingAgentDir ? join16(piCodingAgentDir, "settings.json") : null;
|
|
28957
28990
|
const skillRoots = [
|
|
28958
28991
|
safeSkillRootSummary("user", `${piAgentHomeSource}/skills`, userSkillsPath),
|
|
28959
28992
|
safeSkillRootSummary(
|
|
@@ -29073,7 +29106,7 @@ function buildExecutorReadiness(config) {
|
|
|
29073
29106
|
function sourceAcquisitionPackageMetadata(packageName, location = "pi-config") {
|
|
29074
29107
|
const packageBase = location === "runtime" ? readString(process.env.PI_RUNTIME_ROOT) : readString(process.env.PI_CODING_AGENT_DIR ?? process.env.PI_AGENT_HOME);
|
|
29075
29108
|
if (!packageBase) return null;
|
|
29076
|
-
const packagePath =
|
|
29109
|
+
const packagePath = join16(
|
|
29077
29110
|
resolve13(expandHomePath(packageBase)),
|
|
29078
29111
|
...location === "runtime" ? [] : ["npm"],
|
|
29079
29112
|
"node_modules",
|
|
@@ -29538,7 +29571,7 @@ AMASTER_WORKSPACE_ALLOWLIST=${quoteShell(config.workspaceBindings.join(","))}
|
|
|
29538
29571
|
AMASTER_EXECUTORS=${quoteShell(executorEnv)}
|
|
29539
29572
|
AMASTER_CAPABILITIES=${quoteShell(config.capabilities.join(","))}
|
|
29540
29573
|
AMASTER_NETWORK_DOMAINS=${quoteShell(config.networkDomains.join(","))}
|
|
29541
|
-
AMASTER_DAEMON_STATE_FILE=${quoteShell(
|
|
29574
|
+
AMASTER_DAEMON_STATE_FILE=${quoteShell(join16(homedir3(), ".amaster-employee", "runtime-connector-state.json"))}
|
|
29542
29575
|
EOF
|
|
29543
29576
|
|
|
29544
29577
|
set -a
|
|
@@ -29966,7 +29999,7 @@ async function sourceAcquisitionRuntimeProfile(config, command) {
|
|
|
29966
29999
|
const stateRoot = resolve13(config.browserSessionStateRoot);
|
|
29967
30000
|
const userDataDir = resolve13(stateRoot, profileName2);
|
|
29968
30001
|
if (!pathWithin3(userDataDir, stateRoot)) throw new Error("source_acquisition_browser_profile_invalid");
|
|
29969
|
-
const markerPath =
|
|
30002
|
+
const markerPath = join16(userDataDir, ".amaster-browser-session.json");
|
|
29970
30003
|
if (!existsSync15(userDataDir) || lstatSync9(userDataDir).isSymbolicLink() || !lstatSync9(userDataDir).isDirectory() || !existsSync15(markerPath) || lstatSync9(markerPath).isSymbolicLink()) throw new Error("source_acquisition_browser_profile_invalid");
|
|
29971
30004
|
const marker = readJsonFile2(markerPath);
|
|
29972
30005
|
if (marker.version !== 1 || marker.companyId !== companyId || marker.bindingId !== bindingId || marker.localOpaqueRef !== localOpaqueRef || !readString(marker.provider) || !inspection.sourceOrigins.includes(marker.origin) || Object.keys(marker).length !== 6) {
|
|
@@ -30172,7 +30205,7 @@ function wikiTreePathForCommand(command, workspaceBindings) {
|
|
|
30172
30205
|
const candidates = [];
|
|
30173
30206
|
if (root.endsWith("paperclipai.plugin-llm-wiki")) candidates.push(root);
|
|
30174
30207
|
if (basename6(root) === "plugin-data" && companyId) {
|
|
30175
|
-
candidates.push(
|
|
30208
|
+
candidates.push(join16(root, companyId, "paperclipai.plugin-llm-wiki"));
|
|
30176
30209
|
}
|
|
30177
30210
|
for (const candidate of candidates) {
|
|
30178
30211
|
try {
|
|
@@ -30324,7 +30357,7 @@ function attachPiOutputReserve(profile, outputReserveTokens) {
|
|
|
30324
30357
|
if (!profile?.profileRoot || !Number.isSafeInteger(outputReserveTokens) || outputReserveTokens < 1) {
|
|
30325
30358
|
throw new Error("context_envelope_output_reserve_invalid");
|
|
30326
30359
|
}
|
|
30327
|
-
const extensionPath =
|
|
30360
|
+
const extensionPath = join16(profile.profileRoot, "context-output-reserve.js");
|
|
30328
30361
|
writeFileSync11(
|
|
30329
30362
|
extensionPath,
|
|
30330
30363
|
modelCallOutputContractExtensionSource(outputReserveTokens),
|
|
@@ -30351,13 +30384,13 @@ function attachPiFinalContextAttestor(profile, input) {
|
|
|
30351
30384
|
if (!projectInstruction || !/^[a-f0-9]{64}$/.test(readString(projectInstruction.sha256) ?? "")) {
|
|
30352
30385
|
throw new Error("model_context_attestation_unavailable: final AGENTS.md receipt is missing");
|
|
30353
30386
|
}
|
|
30354
|
-
const extensionPath =
|
|
30355
|
-
const projectInstructionExtensionPath =
|
|
30387
|
+
const extensionPath = join16(profile.profileRoot, "extensions", MANAGED_PI_FINAL_CONTEXT_ATTESTOR_FILENAME);
|
|
30388
|
+
const projectInstructionExtensionPath = join16(
|
|
30356
30389
|
profile.profileRoot,
|
|
30357
30390
|
"extensions",
|
|
30358
30391
|
MANAGED_PI_PROJECT_INSTRUCTION_FILENAME
|
|
30359
30392
|
);
|
|
30360
|
-
const receiptPath =
|
|
30393
|
+
const receiptPath = join16(profile.profileRoot, "tmp", "final-model-context-receipt.json");
|
|
30361
30394
|
const contract = {
|
|
30362
30395
|
receiptPath,
|
|
30363
30396
|
projectInstructionPath: resolve13(input.cwd, "AGENTS.md"),
|
|
@@ -30417,17 +30450,17 @@ function buildExecutorEnv(config, command, workspace) {
|
|
|
30417
30450
|
};
|
|
30418
30451
|
}
|
|
30419
30452
|
function preparePiModelCallProfile(commandId, baseEnv, options = {}) {
|
|
30420
|
-
const profileRoot = mkdtempSync2(
|
|
30421
|
-
const home =
|
|
30422
|
-
const sessionsDir =
|
|
30423
|
-
const tempDir =
|
|
30453
|
+
const profileRoot = mkdtempSync2(join16(tmpdir(), "amaster-pi-model-call-"));
|
|
30454
|
+
const home = join16(profileRoot, "home");
|
|
30455
|
+
const sessionsDir = join16(profileRoot, "sessions");
|
|
30456
|
+
const tempDir = join16(profileRoot, "tmp");
|
|
30424
30457
|
for (const directory of [home, sessionsDir, tempDir]) {
|
|
30425
30458
|
mkdirSync10(directory, { recursive: true, mode: 448 });
|
|
30426
30459
|
}
|
|
30427
30460
|
try {
|
|
30428
30461
|
const extensionArgs = [];
|
|
30429
30462
|
if (options.responseContract) {
|
|
30430
|
-
const extensionPath =
|
|
30463
|
+
const extensionPath = join16(profileRoot, "model-call-output-contract.js");
|
|
30431
30464
|
writeFileSync11(
|
|
30432
30465
|
extensionPath,
|
|
30433
30466
|
modelCallOutputContractExtensionSource(options.responseContract.maxOutputTokens),
|
|
@@ -30491,7 +30524,7 @@ function resolveNativeSessionRequest(command, workspace) {
|
|
|
30491
30524
|
let cwdMatched = false;
|
|
30492
30525
|
if (requestedCwd && sourceWorkspacePath) {
|
|
30493
30526
|
try {
|
|
30494
|
-
cwdMatched =
|
|
30527
|
+
cwdMatched = realpathSync7(requestedCwd) === realpathSync7(sourceWorkspacePath);
|
|
30495
30528
|
} catch {
|
|
30496
30529
|
cwdMatched = resolve13(requestedCwd) === resolve13(sourceWorkspacePath);
|
|
30497
30530
|
}
|
|
@@ -31097,7 +31130,7 @@ function sampleProcessGroupRssBytes(processGroupId) {
|
|
|
31097
31130
|
}
|
|
31098
31131
|
function realOrResolvedPath(value) {
|
|
31099
31132
|
try {
|
|
31100
|
-
return
|
|
31133
|
+
return realpathSync7(value);
|
|
31101
31134
|
} catch {
|
|
31102
31135
|
return resolve13(value);
|
|
31103
31136
|
}
|
|
@@ -31106,7 +31139,7 @@ var LSOF_COMMAND = process.platform === "darwin" && existsSync15("/usr/sbin/lsof
|
|
|
31106
31139
|
function processCwdForPid(pid) {
|
|
31107
31140
|
if (process.platform === "linux") {
|
|
31108
31141
|
try {
|
|
31109
|
-
return
|
|
31142
|
+
return realpathSync7(`/proc/${pid}/cwd`);
|
|
31110
31143
|
} catch {
|
|
31111
31144
|
return null;
|
|
31112
31145
|
}
|
|
@@ -31237,7 +31270,7 @@ function walkManagedWorkdirs(root) {
|
|
|
31237
31270
|
}
|
|
31238
31271
|
for (const entry of entries) {
|
|
31239
31272
|
if (!entry.isDirectory()) continue;
|
|
31240
|
-
const fullPath =
|
|
31273
|
+
const fullPath = join16(current, entry.name);
|
|
31241
31274
|
if (entry.name === "workdir" && existsSync15(workspaceManifestPath(fullPath))) {
|
|
31242
31275
|
workdirs.push(fullPath);
|
|
31243
31276
|
continue;
|
|
@@ -32970,10 +33003,10 @@ async function completeCommand(config, command, status, result3, error) {
|
|
|
32970
33003
|
function resultOutboxDir(config) {
|
|
32971
33004
|
const explicit = readString(process.env.AMASTER_RESULT_OUTBOX_DIR);
|
|
32972
33005
|
if (explicit) return resolve13(expandHomePath(explicit));
|
|
32973
|
-
return
|
|
33006
|
+
return join16(dirname11(stateFilePath(process.env)), "result-outbox");
|
|
32974
33007
|
}
|
|
32975
33008
|
function resultOutboxInvalidDir(config) {
|
|
32976
|
-
return
|
|
33009
|
+
return join16(resultOutboxDir(config), "invalid");
|
|
32977
33010
|
}
|
|
32978
33011
|
function writeResultOutboxEntry(config, entry) {
|
|
32979
33012
|
const dir = resultOutboxDir(config);
|
|
@@ -32985,13 +33018,13 @@ function writeResultOutboxEntry(config, entry) {
|
|
|
32985
33018
|
lastAttemptAt: null,
|
|
32986
33019
|
...entry
|
|
32987
33020
|
};
|
|
32988
|
-
writeFileSync11(
|
|
33021
|
+
writeFileSync11(join16(dir, resultOutboxFileName(entry.commandId)), `${JSON.stringify(body, null, 2)}
|
|
32989
33022
|
`, { mode: 384 });
|
|
32990
33023
|
}
|
|
32991
33024
|
function moveResultOutboxEntryToInvalid(config, file, fullPath, reason, detail, original) {
|
|
32992
33025
|
const invalidDir = resultOutboxInvalidDir(config);
|
|
32993
33026
|
mkdirSync10(invalidDir, { recursive: true });
|
|
32994
|
-
const invalidPath =
|
|
33027
|
+
const invalidPath = join16(invalidDir, file);
|
|
32995
33028
|
if (original === void 0) {
|
|
32996
33029
|
try {
|
|
32997
33030
|
renameSync9(fullPath, invalidPath);
|
|
@@ -33058,7 +33091,7 @@ function quarantineResultOutboxEntry(config, fullPath, file, entry, reason, err)
|
|
|
33058
33091
|
...typeof err?.httpStatus === "number" ? { httpStatus: err.httpStatus } : {},
|
|
33059
33092
|
lastError: truncateText(err instanceof Error ? err.message : String(err), 1e3)
|
|
33060
33093
|
};
|
|
33061
|
-
const invalidPath =
|
|
33094
|
+
const invalidPath = join16(invalidDir, file);
|
|
33062
33095
|
writeFileSync11(invalidPath, `${JSON.stringify(body, null, 2)}
|
|
33063
33096
|
`, { mode: 384 });
|
|
33064
33097
|
try {
|
|
@@ -33077,7 +33110,7 @@ async function flushResultOutbox(config) {
|
|
|
33077
33110
|
const files = readdirSync11(dir).filter((name) => name.endsWith(".json")).sort();
|
|
33078
33111
|
let completed = 0;
|
|
33079
33112
|
for (const file of files) {
|
|
33080
|
-
const fullPath =
|
|
33113
|
+
const fullPath = join16(dir, file);
|
|
33081
33114
|
const entry = readValidResultOutboxEntryOrQuarantine(config, file, fullPath);
|
|
33082
33115
|
if (!entry) continue;
|
|
33083
33116
|
try {
|
|
@@ -33274,7 +33307,7 @@ async function materializeIssueAttachments(config, command, workspace) {
|
|
|
33274
33307
|
runtimeAuth,
|
|
33275
33308
|
issueId
|
|
33276
33309
|
);
|
|
33277
|
-
const targetDir =
|
|
33310
|
+
const targetDir = join16(workspace.cwd, "input-attachments");
|
|
33278
33311
|
mkdirSync10(targetDir, { recursive: true });
|
|
33279
33312
|
const usedFilenames = /* @__PURE__ */ new Set();
|
|
33280
33313
|
const materialized = [];
|
|
@@ -33289,7 +33322,7 @@ async function materializeIssueAttachments(config, command, workspace) {
|
|
|
33289
33322
|
filename = `${stem}-${index + 1}${ext}`;
|
|
33290
33323
|
}
|
|
33291
33324
|
usedFilenames.add(filename);
|
|
33292
|
-
const targetPath =
|
|
33325
|
+
const targetPath = join16(targetDir, filename);
|
|
33293
33326
|
const body = await runtimeApiBuffer(runtimeAuth, contentPath);
|
|
33294
33327
|
writeFileSync11(targetPath, body);
|
|
33295
33328
|
const attachmentId = readString(attachment.id);
|
|
@@ -33365,7 +33398,7 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
33365
33398
|
if (manifest.version !== 1 || !Array.isArray(manifest.entries)) {
|
|
33366
33399
|
throw new Error("artifact_input_manifest_invalid: expected version 1 entries array");
|
|
33367
33400
|
}
|
|
33368
|
-
const targetRoot =
|
|
33401
|
+
const targetRoot = join16(workspace.cwd, "input-artifacts");
|
|
33369
33402
|
rmSync9(targetRoot, { recursive: true, force: true });
|
|
33370
33403
|
mkdirSync10(targetRoot, { recursive: true });
|
|
33371
33404
|
const usedPaths = /* @__PURE__ */ new Set();
|
|
@@ -33396,15 +33429,15 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
33396
33429
|
id: attachmentId,
|
|
33397
33430
|
originalFilename: readString(entry.originalFilename)
|
|
33398
33431
|
}, index);
|
|
33399
|
-
let relativePath =
|
|
33432
|
+
let relativePath = join16("input-artifacts", sourceDir, filename).split(/[\\/]+/).join("/");
|
|
33400
33433
|
if (usedPaths.has(relativePath)) {
|
|
33401
33434
|
const ext = extname3(filename);
|
|
33402
33435
|
const stem = ext ? filename.slice(0, -ext.length) : filename;
|
|
33403
33436
|
filename = `${stem}-${index + 1}${ext}`;
|
|
33404
|
-
relativePath =
|
|
33437
|
+
relativePath = join16("input-artifacts", sourceDir, filename).split(/[\\/]+/).join("/");
|
|
33405
33438
|
}
|
|
33406
33439
|
usedPaths.add(relativePath);
|
|
33407
|
-
const targetPath =
|
|
33440
|
+
const targetPath = join16(workspace.cwd, relativePath);
|
|
33408
33441
|
mkdirSync10(dirname11(targetPath), { recursive: true });
|
|
33409
33442
|
writeFileSync11(targetPath, body);
|
|
33410
33443
|
chmodSync7(targetPath, 292);
|
|
@@ -33426,7 +33459,7 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
33426
33459
|
version: 1,
|
|
33427
33460
|
entries: materialized.map(({ path: _path, relativePath, ...entry }) => ({ ...entry, path: relativePath }))
|
|
33428
33461
|
};
|
|
33429
|
-
const manifestPath =
|
|
33462
|
+
const manifestPath = join16(targetRoot, "artifact-input-manifest.json");
|
|
33430
33463
|
writeFileSync11(manifestPath, JSON.stringify(localManifest, null, 2) + "\n");
|
|
33431
33464
|
chmodSync7(manifestPath, 292);
|
|
33432
33465
|
updateWorkspaceManifest(workspaceManifestPath(workspace), { artifactInputManifest: localManifest });
|
|
@@ -33437,7 +33470,7 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
33437
33470
|
return materialized;
|
|
33438
33471
|
}
|
|
33439
33472
|
function issueCheckpointDir(workspace) {
|
|
33440
|
-
return
|
|
33473
|
+
return join16(dirname11(workspace.runDir), "checkpoint");
|
|
33441
33474
|
}
|
|
33442
33475
|
async function clearIssueCheckpoint(config, command, workspace, reason) {
|
|
33443
33476
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
@@ -33459,7 +33492,7 @@ function hashFileSha256(filePath) {
|
|
|
33459
33492
|
}
|
|
33460
33493
|
async function materializeIssueCheckpoint(config, command, workspace) {
|
|
33461
33494
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
33462
|
-
const manifestPath =
|
|
33495
|
+
const manifestPath = join16(checkpointDir, "manifest.json");
|
|
33463
33496
|
if (!existsSync15(manifestPath)) return [];
|
|
33464
33497
|
let manifest;
|
|
33465
33498
|
try {
|
|
@@ -33476,8 +33509,8 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
33476
33509
|
try {
|
|
33477
33510
|
const files = Array.isArray(manifest.files) ? manifest.files : [];
|
|
33478
33511
|
if (files.length > 20) throw new Error("issue checkpoint manifest exceeds the limit of 20 files");
|
|
33479
|
-
const filesRoot =
|
|
33480
|
-
const workspaceRoot =
|
|
33512
|
+
const filesRoot = realpathSync7(join16(checkpointDir, "files"));
|
|
33513
|
+
const workspaceRoot = realpathSync7(workspace.cwd);
|
|
33481
33514
|
const validated = [];
|
|
33482
33515
|
let totalBytes = 0;
|
|
33483
33516
|
for (const rawFile of files) {
|
|
@@ -33490,7 +33523,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
33490
33523
|
throw new Error(`issue checkpoint path escapes its workspace: ${relativePath}`);
|
|
33491
33524
|
}
|
|
33492
33525
|
if (!existsSync15(sourceCandidate)) throw new Error(`issue checkpoint file is missing: ${relativePath}`);
|
|
33493
|
-
const source =
|
|
33526
|
+
const source = realpathSync7(sourceCandidate);
|
|
33494
33527
|
if (!pathWithin3(source, filesRoot) || !statSync9(source).isFile()) {
|
|
33495
33528
|
throw new Error(`issue checkpoint source escapes its storage root: ${relativePath}`);
|
|
33496
33529
|
}
|
|
@@ -33515,7 +33548,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
33515
33548
|
if (err?.code !== "ENOENT") throw err;
|
|
33516
33549
|
}
|
|
33517
33550
|
mkdirSync10(dirname11(target), { recursive: true });
|
|
33518
|
-
const targetParent =
|
|
33551
|
+
const targetParent = realpathSync7(dirname11(target));
|
|
33519
33552
|
if (!pathWithin3(targetParent, workspaceRoot)) {
|
|
33520
33553
|
throw new Error(`issue checkpoint target escapes its workspace: ${relativePath}`);
|
|
33521
33554
|
}
|
|
@@ -33543,17 +33576,17 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
33543
33576
|
}
|
|
33544
33577
|
async function saveIssueCheckpoint(config, command, workspace, candidates) {
|
|
33545
33578
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
33546
|
-
const filesDir =
|
|
33579
|
+
const filesDir = join16(checkpointDir, "files");
|
|
33547
33580
|
rmSync9(checkpointDir, { recursive: true, force: true });
|
|
33548
33581
|
mkdirSync10(filesDir, { recursive: true });
|
|
33549
33582
|
const files = [];
|
|
33550
33583
|
let totalBytes = 0;
|
|
33551
|
-
const workspaceRoot =
|
|
33584
|
+
const workspaceRoot = realpathSync7(workspace.cwd);
|
|
33552
33585
|
for (const candidate of candidates.slice(0, 20)) {
|
|
33553
33586
|
const relativePath = safeCheckpointRelativePath(candidate.rawPath);
|
|
33554
33587
|
const source = readString(candidate.filePath);
|
|
33555
33588
|
if (!relativePath || !source || !existsSync15(source) || !statSync9(source).isFile()) continue;
|
|
33556
|
-
const ownedSource =
|
|
33589
|
+
const ownedSource = realpathSync7(source);
|
|
33557
33590
|
if (!pathWithin3(ownedSource, workspaceRoot)) {
|
|
33558
33591
|
throw new Error(`issue checkpoint source escapes its execution workspace: ${relativePath}`);
|
|
33559
33592
|
}
|
|
@@ -33579,7 +33612,7 @@ async function saveIssueCheckpoint(config, command, workspace, candidates) {
|
|
|
33579
33612
|
totalBytes,
|
|
33580
33613
|
files
|
|
33581
33614
|
};
|
|
33582
|
-
writeFileSync11(
|
|
33615
|
+
writeFileSync11(join16(checkpointDir, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
33583
33616
|
`);
|
|
33584
33617
|
await ingestLog(config, command, "system", "warn", `Saved ${files.length} required deliverable(s) for continuation recovery`, manifest);
|
|
33585
33618
|
return manifest;
|
|
@@ -33637,7 +33670,8 @@ async function executeRunCommand(config, command) {
|
|
|
33637
33670
|
const workspaceProjectInstructionReceipt = projectExternalWorkspaceProjectInstructions(
|
|
33638
33671
|
workspace.sourceWorkspacePath,
|
|
33639
33672
|
workspace.cwd,
|
|
33640
|
-
readString(asRecord(contextContract.instructions.files)["AGENTS.md"])
|
|
33673
|
+
readString(asRecord(contextContract.instructions.files)["AGENTS.md"]),
|
|
33674
|
+
{ managedWorkspacesRoot: config.runtimeWorkspacesRoot }
|
|
33641
33675
|
);
|
|
33642
33676
|
const finalAgentInstructionFiles = new Map(
|
|
33643
33677
|
materializedAgentInstructions.map((entry) => [entry.path, entry])
|
|
@@ -33729,7 +33763,7 @@ async function executeRunCommand(config, command) {
|
|
|
33729
33763
|
executorCommand: invocation.command,
|
|
33730
33764
|
executorHome: workspace.executorHome,
|
|
33731
33765
|
runDir: workspace.runDir,
|
|
33732
|
-
runtimeCacheRoot:
|
|
33766
|
+
runtimeCacheRoot: join16(dirname11(config.daemonStateFile), "cache"),
|
|
33733
33767
|
cwd,
|
|
33734
33768
|
runtimeAuth: commandRuntimeAuth(command),
|
|
33735
33769
|
nativeSession: asRecord(asRecord(command.payload).nativeSession),
|
package/dist/amaster-runtime.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { basename, dirname, join, resolve } from "node:path";
|
|
|
6
6
|
import { homedir, hostname } from "node:os";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
|
|
9
|
-
const CONNECTOR_VERSION = "0.1.1-beta.
|
|
9
|
+
const CONNECTOR_VERSION = "0.1.1-beta.125";
|
|
10
10
|
|
|
11
11
|
const CAPABILITIES = [
|
|
12
12
|
"remote_registration",
|