@amaster.ai/employee-runtime-connector 0.1.0-beta.21 → 0.1.0-beta.22
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 +54 -17
- package/dist/amaster-runtime.mjs +31 -4
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
// src/amaster-runtime-daemon.mjs
|
|
5
5
|
import { createHash as createHash6 } from "node:crypto";
|
|
6
|
-
import { chmodSync as chmodSync3, copyFileSync as copyFileSync2, existsSync as existsSync9, lstatSync as lstatSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync7, readdirSync as readdirSync6, realpathSync as realpathSync3, renameSync as
|
|
6
|
+
import { chmodSync as chmodSync3, copyFileSync as copyFileSync2, existsSync as existsSync9, lstatSync as lstatSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync7, readdirSync as readdirSync6, realpathSync as realpathSync3, renameSync as renameSync3, rmSync as rmSync5, statSync as statSync7, symlinkSync as symlinkSync2, unlinkSync, writeFileSync as writeFileSync5 } from "node:fs";
|
|
7
7
|
import { arch as arch3, homedir as homedir3, hostname as hostname2, platform as platform3 } from "node:os";
|
|
8
8
|
import { basename as basename6, delimiter as delimiter2, dirname as dirname6, extname as extname2, isAbsolute as isAbsolute6, join as join10, relative as relative6, resolve as resolve8 } from "node:path";
|
|
9
9
|
import { spawn, spawnSync as spawnSync5 } from "node:child_process";
|
|
@@ -2435,7 +2435,7 @@ function compileCommandPromptWithManifest(input, options = {}) {
|
|
|
2435
2435
|
}
|
|
2436
2436
|
|
|
2437
2437
|
// src/amaster-runtime-daemon/config-state.mjs
|
|
2438
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
2438
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, renameSync, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
2439
2439
|
import { homedir as homedir2, hostname } from "node:os";
|
|
2440
2440
|
import { dirname as dirname3, join as join4 } from "node:path";
|
|
2441
2441
|
|
|
@@ -2559,16 +2559,53 @@ function runtimeHome(env) {
|
|
|
2559
2559
|
function stateFilePath(env) {
|
|
2560
2560
|
return env.AMASTER_DAEMON_STATE_FILE ? expandHomePath(String(env.AMASTER_DAEMON_STATE_FILE)) : join4(runtimeHome(env), "runtime-connector-state.json");
|
|
2561
2561
|
}
|
|
2562
|
+
function corruptStatePath(path) {
|
|
2563
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14);
|
|
2564
|
+
const base = `${path}.corrupt-${timestamp}Z`;
|
|
2565
|
+
let candidate = base;
|
|
2566
|
+
for (let suffix = 1; existsSync3(candidate); suffix += 1) {
|
|
2567
|
+
candidate = `${base}.${suffix}`;
|
|
2568
|
+
}
|
|
2569
|
+
return candidate;
|
|
2570
|
+
}
|
|
2562
2571
|
function readState(env) {
|
|
2563
2572
|
const path = stateFilePath(env);
|
|
2564
2573
|
if (!existsSync3(path)) return {};
|
|
2565
|
-
|
|
2574
|
+
try {
|
|
2575
|
+
const state = JSON.parse(readFileSync3(path, "utf8"));
|
|
2576
|
+
if (!state || typeof state !== "object" || Array.isArray(state)) {
|
|
2577
|
+
throw new TypeError("runtime connector state must be a JSON object");
|
|
2578
|
+
}
|
|
2579
|
+
return state;
|
|
2580
|
+
} catch {
|
|
2581
|
+
const quarantinePath = corruptStatePath(path);
|
|
2582
|
+
try {
|
|
2583
|
+
renameSync(path, quarantinePath);
|
|
2584
|
+
process.stderr.write(`AMaster runtime state was invalid and quarantined at ${quarantinePath}
|
|
2585
|
+
`);
|
|
2586
|
+
} catch (error) {
|
|
2587
|
+
process.stderr.write(
|
|
2588
|
+
`AMaster runtime state was invalid but could not be quarantined (${error?.code ?? "unknown error"})
|
|
2589
|
+
`
|
|
2590
|
+
);
|
|
2591
|
+
}
|
|
2592
|
+
return {};
|
|
2593
|
+
}
|
|
2566
2594
|
}
|
|
2567
2595
|
function writeState(env, state) {
|
|
2568
2596
|
const path = stateFilePath(env);
|
|
2569
2597
|
mkdirSync3(dirname3(path), { recursive: true });
|
|
2570
|
-
|
|
2571
|
-
|
|
2598
|
+
const temporaryPath = `${path}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
2599
|
+
try {
|
|
2600
|
+
writeFileSync3(temporaryPath, `${JSON.stringify(state, null, 2)}
|
|
2601
|
+
`, {
|
|
2602
|
+
flag: "wx",
|
|
2603
|
+
mode: 384
|
|
2604
|
+
});
|
|
2605
|
+
renameSync(temporaryPath, path);
|
|
2606
|
+
} finally {
|
|
2607
|
+
rmSync3(temporaryPath, { force: true });
|
|
2608
|
+
}
|
|
2572
2609
|
}
|
|
2573
2610
|
function buildConfig(env = process.env, flags = {}) {
|
|
2574
2611
|
const serverUrl = String(flags.serverUrl ?? env.AMASTER_EMPLOYEE_SERVER_URL ?? "http://127.0.0.1:3100").replace(/\/+$/, "");
|
|
@@ -3843,7 +3880,7 @@ import { existsSync as existsSync5, mkdirSync as mkdirSync4, realpathSync as rea
|
|
|
3843
3880
|
import { basename as basename4, join as join6, isAbsolute as isAbsolute4, relative as relative4, resolve as resolve4 } from "node:path";
|
|
3844
3881
|
|
|
3845
3882
|
// src/amaster-runtime-daemon/workspace-manifest.mjs
|
|
3846
|
-
import { existsSync as existsSync4, readFileSync as readFileSync5, renameSync, rmSync as
|
|
3883
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5, renameSync as renameSync2, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
3847
3884
|
import { basename as basename3, dirname as dirname4, join as join5 } from "node:path";
|
|
3848
3885
|
var WORKSPACE_MANIFEST_FILENAME = ".amaster-runtime.json";
|
|
3849
3886
|
function nowIso() {
|
|
@@ -3872,9 +3909,9 @@ function writeWorkspaceManifest(manifestPath, manifest) {
|
|
|
3872
3909
|
try {
|
|
3873
3910
|
writeFileSync4(tempPath, `${JSON.stringify(manifest, null, 2)}
|
|
3874
3911
|
`, { mode: 384 });
|
|
3875
|
-
|
|
3912
|
+
renameSync2(tempPath, manifestPath);
|
|
3876
3913
|
} catch (err) {
|
|
3877
|
-
|
|
3914
|
+
rmSync4(tempPath, { force: true });
|
|
3878
3915
|
throw err;
|
|
3879
3916
|
}
|
|
3880
3917
|
return manifest;
|
|
@@ -4581,7 +4618,7 @@ function readWorkspaceStatus(cwd, opts = {}) {
|
|
|
4581
4618
|
}
|
|
4582
4619
|
|
|
4583
4620
|
// src/amaster-runtime-daemon.mjs
|
|
4584
|
-
var CONNECTOR_VERSION = "0.1.0-beta.
|
|
4621
|
+
var CONNECTOR_VERSION = "0.1.0-beta.22";
|
|
4585
4622
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
4586
4623
|
var MAX_CHECKPOINT_BYTES = 20 * 1024 * 1024;
|
|
4587
4624
|
var CHECKPOINT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -5534,7 +5571,7 @@ function writeJsonFileAtomic(filePath, value) {
|
|
|
5534
5571
|
const tmpPath = `${filePath}.tmp.${process.pid}.${Date.now()}`;
|
|
5535
5572
|
writeFileSync5(tmpPath, `${JSON.stringify(value, null, 2)}
|
|
5536
5573
|
`, { mode: 384 });
|
|
5537
|
-
|
|
5574
|
+
renameSync3(tmpPath, filePath);
|
|
5538
5575
|
}
|
|
5539
5576
|
function isPlainRecord(value) {
|
|
5540
5577
|
return value && typeof value === "object" && !Array.isArray(value);
|
|
@@ -6869,7 +6906,7 @@ function moveResultOutboxEntryToInvalid(config, file, fullPath, reason, detail,
|
|
|
6869
6906
|
const invalidPath = join10(invalidDir, file);
|
|
6870
6907
|
if (original === void 0) {
|
|
6871
6908
|
try {
|
|
6872
|
-
|
|
6909
|
+
renameSync3(fullPath, invalidPath);
|
|
6873
6910
|
} catch {
|
|
6874
6911
|
copyFileSync2(fullPath, invalidPath);
|
|
6875
6912
|
unlinkSync(fullPath);
|
|
@@ -7240,7 +7277,7 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
7240
7277
|
throw new Error("artifact_input_manifest_invalid: expected version 1 entries array");
|
|
7241
7278
|
}
|
|
7242
7279
|
const targetRoot = join10(workspace.cwd, "input-artifacts");
|
|
7243
|
-
|
|
7280
|
+
rmSync5(targetRoot, { recursive: true, force: true });
|
|
7244
7281
|
mkdirSync5(targetRoot, { recursive: true });
|
|
7245
7282
|
const usedPaths = /* @__PURE__ */ new Set();
|
|
7246
7283
|
const materialized = [];
|
|
@@ -7316,7 +7353,7 @@ function issueCheckpointDir(workspace) {
|
|
|
7316
7353
|
async function clearIssueCheckpoint(config, command, workspace, reason) {
|
|
7317
7354
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
7318
7355
|
if (!existsSync9(checkpointDir)) return false;
|
|
7319
|
-
|
|
7356
|
+
rmSync5(checkpointDir, { recursive: true, force: true });
|
|
7320
7357
|
await ingestLog(config, command, "system", "info", "Cleared issue continuation checkpoint", { reason });
|
|
7321
7358
|
return true;
|
|
7322
7359
|
}
|
|
@@ -7339,12 +7376,12 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
7339
7376
|
try {
|
|
7340
7377
|
manifest = asRecord(JSON.parse(readFileSync7(manifestPath, "utf8")));
|
|
7341
7378
|
} catch (err) {
|
|
7342
|
-
|
|
7379
|
+
rmSync5(checkpointDir, { recursive: true, force: true });
|
|
7343
7380
|
throw new Error(`invalid issue checkpoint manifest: ${err instanceof Error ? err.message : String(err)}`);
|
|
7344
7381
|
}
|
|
7345
7382
|
const expiresAt = Date.parse(readString(manifest.expiresAt) ?? "");
|
|
7346
7383
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() || readString(manifest.issueId) !== commandIssueId(command)) {
|
|
7347
|
-
|
|
7384
|
+
rmSync5(checkpointDir, { recursive: true, force: true });
|
|
7348
7385
|
return [];
|
|
7349
7386
|
}
|
|
7350
7387
|
try {
|
|
@@ -7418,7 +7455,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
7418
7455
|
async function saveIssueCheckpoint(config, command, workspace, candidates) {
|
|
7419
7456
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
7420
7457
|
const filesDir = join10(checkpointDir, "files");
|
|
7421
|
-
|
|
7458
|
+
rmSync5(checkpointDir, { recursive: true, force: true });
|
|
7422
7459
|
mkdirSync5(filesDir, { recursive: true });
|
|
7423
7460
|
const files = [];
|
|
7424
7461
|
let totalBytes = 0;
|
|
@@ -7441,7 +7478,7 @@ async function saveIssueCheckpoint(config, command, workspace, candidates) {
|
|
|
7441
7478
|
files.push({ path: relativePath, byteSize, sha256: hashFileSha256(ownedSource) });
|
|
7442
7479
|
}
|
|
7443
7480
|
if (files.length === 0) {
|
|
7444
|
-
|
|
7481
|
+
rmSync5(checkpointDir, { recursive: true, force: true });
|
|
7445
7482
|
return null;
|
|
7446
7483
|
}
|
|
7447
7484
|
const manifest = {
|
package/dist/amaster-runtime.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { spawn, spawnSync } from "node:child_process";
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { homedir, hostname } from "node:os";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
|
|
8
|
-
const CONNECTOR_VERSION = "0.1.0-beta.
|
|
8
|
+
const CONNECTOR_VERSION = "0.1.0-beta.22";
|
|
9
9
|
|
|
10
10
|
const CAPABILITIES = [
|
|
11
11
|
"remote_registration",
|
|
@@ -277,8 +277,26 @@ function readState(config) {
|
|
|
277
277
|
const statePath = config.AMASTER_DAEMON_STATE_FILE || join(configDir, "runtime-connector-state.json");
|
|
278
278
|
if (!existsSync(statePath)) return {};
|
|
279
279
|
try {
|
|
280
|
-
|
|
280
|
+
const state = JSON.parse(readFileSync(statePath, "utf8"));
|
|
281
|
+
if (!state || typeof state !== "object" || Array.isArray(state)) {
|
|
282
|
+
throw new TypeError("runtime connector state must be a JSON object");
|
|
283
|
+
}
|
|
284
|
+
return state;
|
|
281
285
|
} catch {
|
|
286
|
+
const timestamp = new Date().toISOString().replace(/\D/g, "").slice(0, 14);
|
|
287
|
+
const base = `${statePath}.corrupt-${timestamp}Z`;
|
|
288
|
+
let quarantinePath = base;
|
|
289
|
+
for (let suffix = 1; existsSync(quarantinePath); suffix += 1) {
|
|
290
|
+
quarantinePath = `${base}.${suffix}`;
|
|
291
|
+
}
|
|
292
|
+
try {
|
|
293
|
+
renameSync(statePath, quarantinePath);
|
|
294
|
+
process.stderr.write(`AMaster runtime state was invalid and quarantined at ${quarantinePath}\n`);
|
|
295
|
+
} catch (error) {
|
|
296
|
+
process.stderr.write(
|
|
297
|
+
`AMaster runtime state was invalid but could not be quarantined (${error?.code ?? "unknown error"})\n`,
|
|
298
|
+
);
|
|
299
|
+
}
|
|
282
300
|
return {};
|
|
283
301
|
}
|
|
284
302
|
}
|
|
@@ -286,7 +304,16 @@ function readState(config) {
|
|
|
286
304
|
function writeState(config, state) {
|
|
287
305
|
const statePath = withDefaults(config).AMASTER_DAEMON_STATE_FILE || join(configDir, "runtime-connector-state.json");
|
|
288
306
|
mkdirSync(dirname(statePath), { recursive: true });
|
|
289
|
-
|
|
307
|
+
const temporaryPath = `${statePath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
308
|
+
try {
|
|
309
|
+
writeFileSync(temporaryPath, `${JSON.stringify(state, null, 2)}\n`, {
|
|
310
|
+
flag: "wx",
|
|
311
|
+
mode: 0o600,
|
|
312
|
+
});
|
|
313
|
+
renameSync(temporaryPath, statePath);
|
|
314
|
+
} finally {
|
|
315
|
+
rmSync(temporaryPath, { force: true });
|
|
316
|
+
}
|
|
290
317
|
}
|
|
291
318
|
|
|
292
319
|
function readPidInfo() {
|