@botiverse/raft-daemon 0.72.8-play.20260713140653 → 0.72.12
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/{chunk-QCVK2BPO.js → chunk-LHJUHF42.js} +285 -427
- package/dist/cli/index.js +51 -3
- package/dist/core.js +1 -1
- package/dist/{dist-FTGVGDYA.js → dist-ME3NQ5JP.js} +47 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core.ts
|
|
2
|
-
import
|
|
2
|
+
import path23 from "path";
|
|
3
3
|
import os8 from "os";
|
|
4
4
|
import { randomUUID as randomUUID9 } from "crypto";
|
|
5
5
|
import { createRequire as createRequire3 } from "module";
|
|
@@ -4032,6 +4032,55 @@ var CANONICAL_MESSAGE_MANIFEST = Object.freeze({
|
|
|
4032
4032
|
excludedClientOnly: EXCLUDED_CLIENT_ONLY_MESSAGE_FIELDS
|
|
4033
4033
|
});
|
|
4034
4034
|
|
|
4035
|
+
// ../shared/src/canonicalMessageV2.ts
|
|
4036
|
+
var CANONICAL_MESSAGE_V2_SCHEMA_VERSION = 5;
|
|
4037
|
+
var CANONICAL_MESSAGE_V2_ENVELOPE_KIND = "normalized-message-v2";
|
|
4038
|
+
var CANONICAL_REACTION_PREVIEW_LIMIT = 3;
|
|
4039
|
+
var CANONICAL_REACTION_LIMIT = 30;
|
|
4040
|
+
var CANONICAL_MESSAGE_V2_MANIFEST = Object.freeze({
|
|
4041
|
+
schemaVersion: CANONICAL_MESSAGE_V2_SCHEMA_VERSION,
|
|
4042
|
+
envelopeKind: CANONICAL_MESSAGE_V2_ENVELOPE_KIND,
|
|
4043
|
+
legacyIngressManifestVersion: CANONICAL_MESSAGE_MANIFEST_VERSION,
|
|
4044
|
+
soleApplyEligible: true,
|
|
4045
|
+
reactions: Object.freeze({
|
|
4046
|
+
mergePolicy: "present-overwrite",
|
|
4047
|
+
maxItems: CANONICAL_REACTION_LIMIT,
|
|
4048
|
+
fields: Object.freeze(["count", "emoji", "previewK"]),
|
|
4049
|
+
previewFields: Object.freeze(["displayName", "id"]),
|
|
4050
|
+
previewLimit: CANONICAL_REACTION_PREVIEW_LIMIT,
|
|
4051
|
+
legacyCompatibilityPreviewPolicy: "empty-without-room-common-provenance",
|
|
4052
|
+
deterministicOrder: "emoji-code-unit/actor-id-code-unit"
|
|
4053
|
+
}),
|
|
4054
|
+
viewerOverlayFields: Object.freeze(["reactions.reactedByMe"]),
|
|
4055
|
+
readCacheRelations: Object.freeze(["Message.ReactionActors"]),
|
|
4056
|
+
forbiddenCanonicalPaths: Object.freeze([
|
|
4057
|
+
"reactions[].reactorIds",
|
|
4058
|
+
"reactions[].reactorNames"
|
|
4059
|
+
])
|
|
4060
|
+
});
|
|
4061
|
+
|
|
4062
|
+
// ../shared/src/discussionGraph.ts
|
|
4063
|
+
var DISCUSSION_RELATION_REGISTRY = Object.freeze({
|
|
4064
|
+
messageReactionActors: Object.freeze({
|
|
4065
|
+
rootKind: "message",
|
|
4066
|
+
relation: "reaction-actors",
|
|
4067
|
+
backing: "read-cache",
|
|
4068
|
+
consistency: "read-page",
|
|
4069
|
+
provenance: Object.freeze({ count: "shared-parent-fold", previewK: "shared-parent-fold" }),
|
|
4070
|
+
invalidation: "parent-scope-epoch",
|
|
4071
|
+
allowedCommands: Object.freeze(["set-interaction"])
|
|
4072
|
+
}),
|
|
4073
|
+
messageReplies: Object.freeze({
|
|
4074
|
+
rootKind: "message",
|
|
4075
|
+
relation: "replies",
|
|
4076
|
+
backing: "sync-scope",
|
|
4077
|
+
consistency: "sync-scope-window",
|
|
4078
|
+
provenance: Object.freeze({ replyCount: "shared-parent-fold" }),
|
|
4079
|
+
invalidation: "own-scope-rebaseline",
|
|
4080
|
+
allowedCommands: Object.freeze(["reply"])
|
|
4081
|
+
})
|
|
4082
|
+
});
|
|
4083
|
+
|
|
4035
4084
|
// ../shared/src/index.ts
|
|
4036
4085
|
var COMPUTER_CAPABILITY_SUPERVISOR_MUTATIONS = "computer:supervisor-mutations-v1";
|
|
4037
4086
|
var RUNTIME_CONFIG_VERSION = 1;
|
|
@@ -4558,9 +4607,9 @@ var TRIAL_DURATION_DAYS = (TRIAL_END_DATE.getTime() - TRIAL_START_DATE.getTime()
|
|
|
4558
4607
|
|
|
4559
4608
|
// src/agentProcessManager.ts
|
|
4560
4609
|
import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync6, readdirSync as readdirSync4, statSync, writeFileSync as writeFileSync4 } from "fs";
|
|
4561
|
-
import { readdir as
|
|
4610
|
+
import { readdir as readdir2, stat as stat2, readFile, rm as rm2, lstat, realpath, open } from "fs/promises";
|
|
4562
4611
|
import { createHash as createHash3, randomUUID as randomUUID6 } from "crypto";
|
|
4563
|
-
import
|
|
4612
|
+
import path14 from "path";
|
|
4564
4613
|
import { gzipSync } from "zlib";
|
|
4565
4614
|
import os6 from "os";
|
|
4566
4615
|
|
|
@@ -4866,8 +4915,8 @@ async function executeResponseRequest(url, init, {
|
|
|
4866
4915
|
}
|
|
4867
4916
|
|
|
4868
4917
|
// src/directUploadCapability.ts
|
|
4869
|
-
function joinUrl(base,
|
|
4870
|
-
return `${base.replace(/\/+$/, "")}${
|
|
4918
|
+
function joinUrl(base, path24) {
|
|
4919
|
+
return `${base.replace(/\/+$/, "")}${path24}`;
|
|
4871
4920
|
}
|
|
4872
4921
|
function jsonHeaders(apiKey) {
|
|
4873
4922
|
return {
|
|
@@ -4997,37 +5046,6 @@ import { existsSync as existsSync2, mkdirSync, readdirSync, readFileSync, rmSync
|
|
|
4997
5046
|
import { createRequire } from "module";
|
|
4998
5047
|
import path2 from "path";
|
|
4999
5048
|
|
|
5000
|
-
// src/gitIdentity.ts
|
|
5001
|
-
function resolveAgentGitIdentity(agentName) {
|
|
5002
|
-
const name = agentName.trim();
|
|
5003
|
-
if (!name) {
|
|
5004
|
-
throw new Error("Cannot provision git identity for an agent without a name");
|
|
5005
|
-
}
|
|
5006
|
-
return { name, email: `${name.toLowerCase()}@mail.build` };
|
|
5007
|
-
}
|
|
5008
|
-
function buildProvisionSignedGitEnv(agentName) {
|
|
5009
|
-
const identity = resolveAgentGitIdentity(agentName);
|
|
5010
|
-
return {
|
|
5011
|
-
GIT_AUTHOR_NAME: identity.name,
|
|
5012
|
-
GIT_AUTHOR_EMAIL: identity.email,
|
|
5013
|
-
GIT_COMMITTER_NAME: identity.name,
|
|
5014
|
-
GIT_COMMITTER_EMAIL: identity.email
|
|
5015
|
-
};
|
|
5016
|
-
}
|
|
5017
|
-
function withProvisionSignedGitEnv(config) {
|
|
5018
|
-
const identityEnv = buildProvisionSignedGitEnv(config.name);
|
|
5019
|
-
return {
|
|
5020
|
-
...config,
|
|
5021
|
-
envVars: { ...config.envVars ?? {}, ...identityEnv },
|
|
5022
|
-
...config.runtimeConfig ? {
|
|
5023
|
-
runtimeConfig: {
|
|
5024
|
-
...config.runtimeConfig,
|
|
5025
|
-
envVars: { ...config.runtimeConfig.envVars ?? {}, ...identityEnv }
|
|
5026
|
-
}
|
|
5027
|
-
} : {}
|
|
5028
|
-
};
|
|
5029
|
-
}
|
|
5030
|
-
|
|
5031
5049
|
// src/drivers/raftCliGuide.ts
|
|
5032
5050
|
var MESSAGE_HEREDOC_DELIMITER = "SLOCKMSG";
|
|
5033
5051
|
function describeSlockInstallation(audience) {
|
|
@@ -5588,15 +5606,6 @@ function listLegacySlockStatePaths(slockHome = resolveSlockHome(), homeDir = os.
|
|
|
5588
5606
|
return candidates.filter((candidate) => existsSync(candidate.path));
|
|
5589
5607
|
}
|
|
5590
5608
|
|
|
5591
|
-
// src/authEnv.ts
|
|
5592
|
-
var DAEMON_API_KEY_ENV = "SLOCK_MACHINE_API_KEY";
|
|
5593
|
-
var SLOCK_AGENT_TOKEN_ENV = "SLOCK_AGENT_TOKEN";
|
|
5594
|
-
function scrubDaemonChildEnv(env) {
|
|
5595
|
-
delete env[DAEMON_API_KEY_ENV];
|
|
5596
|
-
delete env[SLOCK_AGENT_TOKEN_ENV];
|
|
5597
|
-
return env;
|
|
5598
|
-
}
|
|
5599
|
-
|
|
5600
5609
|
// src/agentCredentialProxy.ts
|
|
5601
5610
|
import { randomBytes } from "crypto";
|
|
5602
5611
|
import http from "http";
|
|
@@ -7221,9 +7230,7 @@ var LOOPBACK_NO_PROXY = "127.0.0.1,localhost";
|
|
|
7221
7230
|
var CLI_TRANSPORT_TRACE_DIR_ENV = "SLOCK_CLI_TRANSPORT_TRACE_DIR";
|
|
7222
7231
|
var safePathPart = (value) => value.replace(/[^a-zA-Z0-9_.-]/g, "_");
|
|
7223
7232
|
var RAW_CREDENTIAL_ENV_DENYLIST = [
|
|
7224
|
-
"
|
|
7225
|
-
"SLOCK_AGENT_CREDENTIAL_KEY",
|
|
7226
|
-
"SLOCK_AGENT_CREDENTIAL_KEY_FILE"
|
|
7233
|
+
"SLOCK_AGENT_CREDENTIAL_KEY"
|
|
7227
7234
|
];
|
|
7228
7235
|
var WORKSPACE_CLI_TRANSPORT_FILENAMES = [
|
|
7229
7236
|
"agent-token",
|
|
@@ -7564,7 +7571,6 @@ set "SLOCK_AGENT_ACTIVE_CAPABILITIES=${DEFAULT_ACTIVE_CAPABILITIES}"\r
|
|
|
7564
7571
|
}
|
|
7565
7572
|
const wrapperPath = platform === "win32" ? path2.join(slockDir, "slock.cmd") : posixWrapper;
|
|
7566
7573
|
const launchRuntimeFields = runtimeConfigToLaunchFields(hydrateRuntimeConfig(ctx.config));
|
|
7567
|
-
const provisionSignedGitEnv = ctx.config.name?.trim() ? buildProvisionSignedGitEnv(ctx.config.name) : {};
|
|
7568
7574
|
const spawnEnv = {
|
|
7569
7575
|
...process.env,
|
|
7570
7576
|
FORCE_COLOR: "0",
|
|
@@ -7572,7 +7578,6 @@ set "SLOCK_AGENT_ACTIVE_CAPABILITIES=${DEFAULT_ACTIVE_CAPABILITIES}"\r
|
|
|
7572
7578
|
...extraEnv,
|
|
7573
7579
|
...platform === "win32" ? windowsUtf8Env() : {},
|
|
7574
7580
|
...runtimeContextEnv(ctx.config),
|
|
7575
|
-
...provisionSignedGitEnv,
|
|
7576
7581
|
[SLOCK_HOME_ENV]: slockHome,
|
|
7577
7582
|
SLOCK_AGENT_ID: ctx.agentId,
|
|
7578
7583
|
...ctx.launchId ? { SLOCK_AGENT_LAUNCH_ID: ctx.launchId } : {},
|
|
@@ -7580,7 +7585,7 @@ set "SLOCK_AGENT_ACTIVE_CAPABILITIES=${DEFAULT_ACTIVE_CAPABILITIES}"\r
|
|
|
7580
7585
|
SLOCK_SERVER_URL: ctx.config.serverUrl,
|
|
7581
7586
|
PATH: `${slockDir}${path2.delimiter}${process.env.PATH ?? ""}`
|
|
7582
7587
|
};
|
|
7583
|
-
|
|
7588
|
+
delete spawnEnv.SLOCK_AGENT_TOKEN;
|
|
7584
7589
|
for (const key of RAW_CREDENTIAL_ENV_DENYLIST) {
|
|
7585
7590
|
delete spawnEnv[key];
|
|
7586
7591
|
}
|
|
@@ -8188,7 +8193,7 @@ function requiresWindowsShell(command, platform = process.platform) {
|
|
|
8188
8193
|
}
|
|
8189
8194
|
function resolveCommandOnPath(command, deps = {}) {
|
|
8190
8195
|
const platform = deps.platform ?? process.platform;
|
|
8191
|
-
const env =
|
|
8196
|
+
const env = withWindowsUserEnvironment(deps.env ?? process.env, deps);
|
|
8192
8197
|
const execFileSyncFn = deps.execFileSyncFn ?? execFileSync;
|
|
8193
8198
|
const existsSyncFn = deps.existsSyncFn ?? existsSync3;
|
|
8194
8199
|
if (platform === "win32") {
|
|
@@ -8214,7 +8219,7 @@ function firstExistingPath(candidates, deps = {}) {
|
|
|
8214
8219
|
return null;
|
|
8215
8220
|
}
|
|
8216
8221
|
function readCommandVersion(command, args = [], deps = {}) {
|
|
8217
|
-
const env =
|
|
8222
|
+
const env = withWindowsUserEnvironment(deps.env ?? process.env, deps);
|
|
8218
8223
|
const execFileSyncFn = deps.execFileSyncFn ?? execFileSync;
|
|
8219
8224
|
try {
|
|
8220
8225
|
const output = normalizeExecOutput(execFileSyncFn(command, [...args, "--version"], {
|
|
@@ -8688,7 +8693,7 @@ function codexNotificationDiagnosticEvent(message) {
|
|
|
8688
8693
|
return null;
|
|
8689
8694
|
}
|
|
8690
8695
|
const sessionId = codexMessageThreadId(message);
|
|
8691
|
-
const
|
|
8696
|
+
const path24 = boundedString(params.path);
|
|
8692
8697
|
return {
|
|
8693
8698
|
kind: "runtime_diagnostic",
|
|
8694
8699
|
severity: "warning",
|
|
@@ -8696,7 +8701,7 @@ function codexNotificationDiagnosticEvent(message) {
|
|
|
8696
8701
|
itemType: message.method,
|
|
8697
8702
|
message: diagnosticMessage,
|
|
8698
8703
|
...details ? { details } : {},
|
|
8699
|
-
...
|
|
8704
|
+
...path24 ? { path: path24 } : {},
|
|
8700
8705
|
...params.range !== void 0 ? { range: params.range } : {},
|
|
8701
8706
|
payloadBytes: payloadBytes(params),
|
|
8702
8707
|
...sessionId ? { sessionId } : {}
|
|
@@ -10418,11 +10423,11 @@ function detectCursorModels(runCommand = runCursorModelsCommand) {
|
|
|
10418
10423
|
return parseCursorModelsOutput(String(result.stdout || ""));
|
|
10419
10424
|
}
|
|
10420
10425
|
function buildCursorModelProbeEnv(deps = {}) {
|
|
10421
|
-
return
|
|
10426
|
+
return withWindowsUserEnvironment({
|
|
10422
10427
|
...deps.env ?? process.env,
|
|
10423
10428
|
FORCE_COLOR: "0",
|
|
10424
10429
|
NO_COLOR: "1"
|
|
10425
|
-
}, deps)
|
|
10430
|
+
}, deps);
|
|
10426
10431
|
}
|
|
10427
10432
|
function runCursorModelsCommand() {
|
|
10428
10433
|
return spawnSync("cursor-agent", ["models"], {
|
|
@@ -10478,7 +10483,7 @@ function resolveGeminiSpawn(commandArgs, deps = {}) {
|
|
|
10478
10483
|
}
|
|
10479
10484
|
const execFileSyncFn = deps.execFileSyncFn ?? execFileSync3;
|
|
10480
10485
|
const existsSyncFn = deps.existsSyncFn ?? existsSync5;
|
|
10481
|
-
const env =
|
|
10486
|
+
const env = deps.env ?? process.env;
|
|
10482
10487
|
const winPath = path8.win32;
|
|
10483
10488
|
let geminiEntry = null;
|
|
10484
10489
|
try {
|
|
@@ -10615,15 +10620,12 @@ var GeminiDriver = class {
|
|
|
10615
10620
|
// src/drivers/kimi.ts
|
|
10616
10621
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
10617
10622
|
import { spawn as spawn7 } from "child_process";
|
|
10618
|
-
import {
|
|
10623
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
10619
10624
|
import os4 from "os";
|
|
10620
10625
|
import path9 from "path";
|
|
10621
10626
|
var KIMI_WIRE_PROTOCOL_VERSION = "1.3";
|
|
10622
10627
|
var KIMI_SYSTEM_PROMPT_FILE = ".slock-kimi-system.md";
|
|
10623
10628
|
var KIMI_AGENT_FILE = ".slock-kimi-agent.yaml";
|
|
10624
|
-
var KIMI_GENERATED_CONFIG_FILE = ".slock-kimi-config.toml";
|
|
10625
|
-
var SLOCK_KIMI_CONFIG_CONTENT_ENV = "SLOCK_KIMI_CONFIG_CONTENT";
|
|
10626
|
-
var SLOCK_KIMI_CONFIG_FILE_ENV = "SLOCK_KIMI_CONFIG_FILE";
|
|
10627
10629
|
function parseToolArguments(raw) {
|
|
10628
10630
|
if (typeof raw !== "string") return raw;
|
|
10629
10631
|
try {
|
|
@@ -10632,73 +10634,6 @@ function parseToolArguments(raw) {
|
|
|
10632
10634
|
return raw;
|
|
10633
10635
|
}
|
|
10634
10636
|
}
|
|
10635
|
-
function readKimiConfigSource(home = os4.homedir(), env = process.env) {
|
|
10636
|
-
const inlineConfig = env[SLOCK_KIMI_CONFIG_CONTENT_ENV];
|
|
10637
|
-
if (inlineConfig && inlineConfig.trim()) {
|
|
10638
|
-
return {
|
|
10639
|
-
raw: inlineConfig,
|
|
10640
|
-
explicitPath: null,
|
|
10641
|
-
sourcePath: SLOCK_KIMI_CONFIG_CONTENT_ENV
|
|
10642
|
-
};
|
|
10643
|
-
}
|
|
10644
|
-
const explicitPath = env[SLOCK_KIMI_CONFIG_FILE_ENV];
|
|
10645
|
-
const configPath = explicitPath && explicitPath.trim() ? explicitPath : path9.join(home, ".kimi", "config.toml");
|
|
10646
|
-
try {
|
|
10647
|
-
return {
|
|
10648
|
-
raw: readFileSync3(configPath, "utf8"),
|
|
10649
|
-
explicitPath: explicitPath && explicitPath.trim() ? explicitPath : null,
|
|
10650
|
-
sourcePath: configPath
|
|
10651
|
-
};
|
|
10652
|
-
} catch {
|
|
10653
|
-
return {
|
|
10654
|
-
raw: null,
|
|
10655
|
-
explicitPath: explicitPath && explicitPath.trim() ? explicitPath : null,
|
|
10656
|
-
sourcePath: configPath
|
|
10657
|
-
};
|
|
10658
|
-
}
|
|
10659
|
-
}
|
|
10660
|
-
function buildKimiSpawnEnv(env = process.env) {
|
|
10661
|
-
const spawnEnv = { ...env, FORCE_COLOR: "0", NO_COLOR: "1" };
|
|
10662
|
-
delete spawnEnv[SLOCK_KIMI_CONFIG_CONTENT_ENV];
|
|
10663
|
-
delete spawnEnv[SLOCK_KIMI_CONFIG_FILE_ENV];
|
|
10664
|
-
return scrubDaemonChildEnv(spawnEnv);
|
|
10665
|
-
}
|
|
10666
|
-
function buildKimiEffectiveEnv(ctx, overrideEnv) {
|
|
10667
|
-
return {
|
|
10668
|
-
...process.env,
|
|
10669
|
-
...ctx.config.envVars || {},
|
|
10670
|
-
...overrideEnv || {}
|
|
10671
|
-
};
|
|
10672
|
-
}
|
|
10673
|
-
function buildKimiLaunchOptions(ctx, opts = {}) {
|
|
10674
|
-
const env = buildKimiEffectiveEnv(ctx, opts.env);
|
|
10675
|
-
const source = readKimiConfigSource(opts.home ?? os4.homedir(), env);
|
|
10676
|
-
const args = [];
|
|
10677
|
-
let configFilePath = null;
|
|
10678
|
-
let configContent = null;
|
|
10679
|
-
if (source.explicitPath) {
|
|
10680
|
-
configFilePath = source.explicitPath;
|
|
10681
|
-
} else if (source.raw !== null && source.sourcePath === SLOCK_KIMI_CONFIG_CONTENT_ENV) {
|
|
10682
|
-
configFilePath = path9.join(ctx.workingDirectory, KIMI_GENERATED_CONFIG_FILE);
|
|
10683
|
-
configContent = source.raw;
|
|
10684
|
-
if (opts.writeGeneratedConfig !== false) {
|
|
10685
|
-
writeFileSync3(configFilePath, source.raw, { encoding: "utf8", mode: 384 });
|
|
10686
|
-
chmodSync(configFilePath, 384);
|
|
10687
|
-
}
|
|
10688
|
-
}
|
|
10689
|
-
if (configFilePath) {
|
|
10690
|
-
args.push("--config-file", configFilePath);
|
|
10691
|
-
}
|
|
10692
|
-
if (ctx.config.model && ctx.config.model !== "default") {
|
|
10693
|
-
args.push("--model", ctx.config.model);
|
|
10694
|
-
}
|
|
10695
|
-
return {
|
|
10696
|
-
args,
|
|
10697
|
-
env: buildKimiSpawnEnv(env),
|
|
10698
|
-
configFilePath,
|
|
10699
|
-
configContent
|
|
10700
|
-
};
|
|
10701
|
-
}
|
|
10702
10637
|
function resolveKimiSpawn(commandArgs, deps = {}) {
|
|
10703
10638
|
return {
|
|
10704
10639
|
command: resolveCommandOnPath("kimi", deps) ?? "kimi",
|
|
@@ -10722,25 +10657,7 @@ var KimiDriver = class {
|
|
|
10722
10657
|
};
|
|
10723
10658
|
model = {
|
|
10724
10659
|
detectedModelsVerifiedAs: "launchable",
|
|
10725
|
-
toLaunchSpec: (modelId
|
|
10726
|
-
if (!ctx) return { args: ["--model", modelId] };
|
|
10727
|
-
const launchCtx = {
|
|
10728
|
-
...ctx,
|
|
10729
|
-
config: {
|
|
10730
|
-
...ctx.config,
|
|
10731
|
-
model: modelId
|
|
10732
|
-
}
|
|
10733
|
-
};
|
|
10734
|
-
const launch = buildKimiLaunchOptions(launchCtx, {
|
|
10735
|
-
home: opts?.home,
|
|
10736
|
-
writeGeneratedConfig: false
|
|
10737
|
-
});
|
|
10738
|
-
return {
|
|
10739
|
-
args: launch.args,
|
|
10740
|
-
env: launch.env,
|
|
10741
|
-
configFiles: launch.configFilePath ? [launch.configFilePath] : void 0
|
|
10742
|
-
};
|
|
10743
|
-
}
|
|
10660
|
+
toLaunchSpec: (modelId) => ({ args: ["--model", modelId] })
|
|
10744
10661
|
};
|
|
10745
10662
|
supportsStdinNotification = true;
|
|
10746
10663
|
busyDeliveryMode = "direct";
|
|
@@ -10764,23 +10681,21 @@ var KimiDriver = class {
|
|
|
10764
10681
|
` system_prompt_path: ./${KIMI_SYSTEM_PROMPT_FILE}`,
|
|
10765
10682
|
""
|
|
10766
10683
|
].join("\n"), "utf8");
|
|
10767
|
-
const launch = buildKimiLaunchOptions(ctx);
|
|
10768
10684
|
const args = [
|
|
10769
10685
|
"--wire",
|
|
10770
10686
|
"--yolo",
|
|
10771
10687
|
"--agent-file",
|
|
10772
10688
|
agentFilePath,
|
|
10773
10689
|
"--session",
|
|
10774
|
-
this.sessionId
|
|
10775
|
-
...launch.args
|
|
10690
|
+
this.sessionId
|
|
10776
10691
|
];
|
|
10777
10692
|
const launchRuntimeFields = runtimeConfigToLaunchFields(hydrateRuntimeConfig(ctx.config));
|
|
10778
10693
|
if (launchRuntimeFields.model && launchRuntimeFields.model !== "default") {
|
|
10779
10694
|
args.push("--model", launchRuntimeFields.model);
|
|
10780
10695
|
}
|
|
10781
10696
|
const spawnEnv = (await prepareCliTransport(ctx, { NO_COLOR: "1" })).spawnEnv;
|
|
10782
|
-
const
|
|
10783
|
-
const proc = spawn7(
|
|
10697
|
+
const launch = resolveKimiSpawn(args);
|
|
10698
|
+
const proc = spawn7(launch.command, launch.args, {
|
|
10784
10699
|
cwd: ctx.workingDirectory,
|
|
10785
10700
|
stdio: ["pipe", "pipe", "pipe"],
|
|
10786
10701
|
env: spawnEnv,
|
|
@@ -10788,7 +10703,7 @@ var KimiDriver = class {
|
|
|
10788
10703
|
// and has an 8191-character command-line limit. Kimi's official
|
|
10789
10704
|
// installer/uv entrypoint is an executable, so launch it directly and
|
|
10790
10705
|
// keep prompts on stdin / files instead of routing through cmd.exe.
|
|
10791
|
-
shell:
|
|
10706
|
+
shell: launch.shell
|
|
10792
10707
|
});
|
|
10793
10708
|
proc.stdin?.write(JSON.stringify({
|
|
10794
10709
|
jsonrpc: "2.0",
|
|
@@ -10901,9 +10816,14 @@ var KimiDriver = class {
|
|
|
10901
10816
|
return detectKimiModels();
|
|
10902
10817
|
}
|
|
10903
10818
|
};
|
|
10904
|
-
function detectKimiModels(home = os4.homedir()
|
|
10905
|
-
const
|
|
10906
|
-
|
|
10819
|
+
function detectKimiModels(home = os4.homedir()) {
|
|
10820
|
+
const configPath = path9.join(home, ".kimi", "config.toml");
|
|
10821
|
+
let raw;
|
|
10822
|
+
try {
|
|
10823
|
+
raw = readFileSync3(configPath, "utf8");
|
|
10824
|
+
} catch {
|
|
10825
|
+
return null;
|
|
10826
|
+
}
|
|
10907
10827
|
const models = [];
|
|
10908
10828
|
const sectionRe = /^\s*\[models(?:\.([^\]]+)|"\.[^"]+"|\."[^"]+")\s*\]\s*$/gm;
|
|
10909
10829
|
const lineRe = /^\s*\[models\.(.+?)\s*\]\s*$/gm;
|
|
@@ -10929,7 +10849,6 @@ import { mkdirSync as mkdirSync2, readFileSync as readFileSync4 } from "fs";
|
|
|
10929
10849
|
import path10 from "path";
|
|
10930
10850
|
import { createRequire as createRequire2 } from "module";
|
|
10931
10851
|
import {
|
|
10932
|
-
LocalKaos,
|
|
10933
10852
|
createKimiHarness,
|
|
10934
10853
|
resolveKimiHome
|
|
10935
10854
|
} from "@botiverse/kimi-code-sdk";
|
|
@@ -11095,7 +11014,6 @@ So instead of \`raft message send ...\`, run \`${wrapperPath} message send ...\`
|
|
|
11095
11014
|
}
|
|
11096
11015
|
async function createKimiAgentSessionForContext(ctx, sessionId, deps = {}) {
|
|
11097
11016
|
const createHarnessImpl = deps.createHarness ?? createKimiHarness;
|
|
11098
|
-
const createKaosImpl = deps.createKaos ?? LocalKaos.create;
|
|
11099
11017
|
const prepareTransportImpl = deps.prepareTransport ?? prepareCliTransport;
|
|
11100
11018
|
const sessionDir = buildKimiSessionDir(ctx.workingDirectory);
|
|
11101
11019
|
mkdirSync2(sessionDir, { recursive: true });
|
|
@@ -11114,10 +11032,8 @@ async function createKimiAgentSessionForContext(ctx, sessionId, deps = {}) {
|
|
|
11114
11032
|
});
|
|
11115
11033
|
const launchRuntimeFields = runtimeConfigToLaunchFields(hydrateRuntimeConfig(ctx.config));
|
|
11116
11034
|
const roleAdditional = composeStandingRoleAdditional(ctx.standingPrompt, wrapperPath);
|
|
11117
|
-
const kaos = (await createKaosImpl()).withEnv(buildProvisionSignedGitEnv(ctx.config.name));
|
|
11118
11035
|
const sessionFields = {
|
|
11119
11036
|
workDir: ctx.workingDirectory,
|
|
11120
|
-
kaos,
|
|
11121
11037
|
...launchRuntimeFields.model && launchRuntimeFields.model !== "default" ? { model: launchRuntimeFields.model } : {},
|
|
11122
11038
|
...roleAdditional ? { roleAdditional } : {}
|
|
11123
11039
|
};
|
|
@@ -11592,7 +11508,7 @@ function runOpenCodeModelsCommand(home, deps = {}) {
|
|
|
11592
11508
|
const platform = deps.platform ?? process.platform;
|
|
11593
11509
|
const spawnSyncFn = deps.spawnSyncFn ?? spawnSync2;
|
|
11594
11510
|
const result = spawnSyncFn("opencode", ["models"], {
|
|
11595
|
-
env:
|
|
11511
|
+
env: { ...process.env, HOME: home, FORCE_COLOR: "0", NO_COLOR: "1" },
|
|
11596
11512
|
encoding: "utf8",
|
|
11597
11513
|
timeout: 5e3,
|
|
11598
11514
|
shell: platform === "win32"
|
|
@@ -11905,7 +11821,11 @@ function buildBuiltInAgentDir(workingDirectory) {
|
|
|
11905
11821
|
async function buildPiSpawnEnv(ctx) {
|
|
11906
11822
|
return (await prepareCliTransport(ctx, { NO_COLOR: "1" })).spawnEnv;
|
|
11907
11823
|
}
|
|
11908
|
-
function
|
|
11824
|
+
function seedPiSessionAuthStorage(authStorage, runtimeConfig) {
|
|
11825
|
+
if (runtimeConfig.runtime === "pi" && runtimeConfig.provider?.kind === "pi-builtin") {
|
|
11826
|
+
authStorage.setRuntimeApiKey(runtimeConfig.provider.providerId, runtimeConfig.provider.apiKey);
|
|
11827
|
+
return;
|
|
11828
|
+
}
|
|
11909
11829
|
if (runtimeConfig.runtime !== "builtin") return;
|
|
11910
11830
|
if (runtimeConfig.provider.kind === "preset") {
|
|
11911
11831
|
authStorage.setRuntimeApiKey(runtimeConfig.provider.providerId, runtimeConfig.provider.apiKey);
|
|
@@ -11918,11 +11838,12 @@ function seedBuiltInAuthStorage(authStorage, runtimeConfig) {
|
|
|
11918
11838
|
}
|
|
11919
11839
|
}
|
|
11920
11840
|
function buildPiSessionCreateEnvPatch(runtimeConfig, envVars) {
|
|
11921
|
-
if (
|
|
11922
|
-
const providerApiKeyEnvNames = /* @__PURE__ */ new Set([
|
|
11841
|
+
if (!envVars) return null;
|
|
11842
|
+
const providerApiKeyEnvNames = runtimeConfig.runtime === "builtin" ? /* @__PURE__ */ new Set([
|
|
11923
11843
|
...Object.values(BUILTIN_RUNTIME_PROVIDER_ENV_KEYS),
|
|
11924
11844
|
...Object.values(BUILTIN_RUNTIME_GATEWAY_PROVIDER_ENV_KEYS)
|
|
11925
|
-
]);
|
|
11845
|
+
]) : runtimeConfig.runtime === "pi" && runtimeConfig.provider?.kind === "pi-builtin" ? /* @__PURE__ */ new Set([PI_BUILTIN_PROVIDER_ENV_KEYS[runtimeConfig.provider.providerId]]) : /* @__PURE__ */ new Set();
|
|
11846
|
+
if (providerApiKeyEnvNames.size === 0) return envVars;
|
|
11926
11847
|
const filtered = Object.fromEntries(
|
|
11927
11848
|
Object.entries(envVars).filter(([key]) => !providerApiKeyEnvNames.has(key))
|
|
11928
11849
|
);
|
|
@@ -12280,7 +12201,7 @@ async function createPiAgentSessionForContext(ctx, sessionId, opts = {}) {
|
|
|
12280
12201
|
const agentDir = opts.agentDir ?? spawnEnv.PI_CODING_AGENT_DIR ?? getAgentDir();
|
|
12281
12202
|
mkdirSync3(agentDir, { recursive: true });
|
|
12282
12203
|
const authStorage = AuthStorage.create(path12.join(agentDir, "auth.json"));
|
|
12283
|
-
|
|
12204
|
+
seedPiSessionAuthStorage(authStorage, runtimeConfig);
|
|
12284
12205
|
const settingsManager = SettingsManager.create(ctx.workingDirectory, agentDir);
|
|
12285
12206
|
const providerEnvScope = opts.isolateHostProviderEnv ? BUILTIN_BLOCKED_HOST_PROVIDER_ENV_KEYS : void 0;
|
|
12286
12207
|
const sessionCreateEnvPatch = buildPiSessionCreateEnvPatch(runtimeConfig, launchRuntimeFields.envVars);
|
|
@@ -12403,22 +12324,17 @@ async function createPiAgentSessionForContext(ctx, sessionId, opts = {}) {
|
|
|
12403
12324
|
throw error;
|
|
12404
12325
|
}
|
|
12405
12326
|
}
|
|
12327
|
+
var piPromptsInFlight = 0;
|
|
12406
12328
|
var PiSdkRuntimeSession = class {
|
|
12407
|
-
constructor(ctx, setCurrentSessionId, sessionFactory = createPiAgentSessionForContext
|
|
12329
|
+
constructor(ctx, setCurrentSessionId, sessionFactory = createPiAgentSessionForContext) {
|
|
12408
12330
|
this.ctx = ctx;
|
|
12409
12331
|
this.setCurrentSessionId = setCurrentSessionId;
|
|
12410
12332
|
this.sessionFactory = sessionFactory;
|
|
12411
12333
|
this.mappingState = createPiSdkEventMappingState(ctx.config.sessionId || null);
|
|
12412
|
-
const runtimeConfig = hydrateRuntimeConfig(ctx.config);
|
|
12413
|
-
const launchRuntimeFields = runtimeConfigToLaunchFields(runtimeConfig);
|
|
12414
|
-
this.sdkCallEnvPatch = buildPiSessionCreateEnvPatch(runtimeConfig, launchRuntimeFields.envVars);
|
|
12415
|
-
this.sdkCallEnvRemoveFirst = opts.isolateHostProviderEnv ? BUILTIN_BLOCKED_HOST_PROVIDER_ENV_KEYS : void 0;
|
|
12416
12334
|
}
|
|
12417
12335
|
descriptor = PI_RUNTIME_SESSION_DESCRIPTOR;
|
|
12418
12336
|
events = new EventEmitter2();
|
|
12419
12337
|
mappingState;
|
|
12420
|
-
sdkCallEnvPatch;
|
|
12421
|
-
sdkCallEnvRemoveFirst;
|
|
12422
12338
|
session = null;
|
|
12423
12339
|
unsubscribe = null;
|
|
12424
12340
|
started = false;
|
|
@@ -12551,10 +12467,41 @@ var PiSdkRuntimeSession = class {
|
|
|
12551
12467
|
return !this.didClose && this.session === session && !session.isStreaming;
|
|
12552
12468
|
}
|
|
12553
12469
|
deferSdkCall(invoke) {
|
|
12470
|
+
const queuedAt = currentTimeMs();
|
|
12554
12471
|
setImmediate(() => {
|
|
12555
12472
|
if (this.didClose) return;
|
|
12473
|
+
const span = this.ctx.tracer?.startSpan("daemon.pi.prompt", {
|
|
12474
|
+
surface: "daemon",
|
|
12475
|
+
kind: "internal",
|
|
12476
|
+
attrs: {
|
|
12477
|
+
agentId: this.ctx.agentId,
|
|
12478
|
+
launchId: this.ctx.launchId || void 0,
|
|
12479
|
+
runtime: this.ctx.config.runtime
|
|
12480
|
+
}
|
|
12481
|
+
});
|
|
12482
|
+
const startedAt = currentTimeMs();
|
|
12483
|
+
piPromptsInFlight += 1;
|
|
12484
|
+
span?.addEvent("daemon.pi.prompt.start", {
|
|
12485
|
+
agentId: this.ctx.agentId,
|
|
12486
|
+
queued_ms: startedAt - queuedAt,
|
|
12487
|
+
prompts_in_flight: piPromptsInFlight
|
|
12488
|
+
});
|
|
12489
|
+
let settled = false;
|
|
12490
|
+
const settle = (status) => {
|
|
12491
|
+
if (settled) return;
|
|
12492
|
+
settled = true;
|
|
12493
|
+
piPromptsInFlight -= 1;
|
|
12494
|
+
span?.end(status, {
|
|
12495
|
+
attrs: {
|
|
12496
|
+
queued_ms: startedAt - queuedAt,
|
|
12497
|
+
duration_ms: currentTimeMs() - startedAt,
|
|
12498
|
+
prompts_in_flight_after: piPromptsInFlight
|
|
12499
|
+
}
|
|
12500
|
+
});
|
|
12501
|
+
};
|
|
12556
12502
|
try {
|
|
12557
|
-
void
|
|
12503
|
+
void invoke().then(() => settle("ok")).catch((error) => {
|
|
12504
|
+
settle("error");
|
|
12558
12505
|
if (this.didClose) return;
|
|
12559
12506
|
this.events.emit("runtime_event", {
|
|
12560
12507
|
kind: "error",
|
|
@@ -12562,6 +12509,7 @@ var PiSdkRuntimeSession = class {
|
|
|
12562
12509
|
});
|
|
12563
12510
|
});
|
|
12564
12511
|
} catch (error) {
|
|
12512
|
+
settle("error");
|
|
12565
12513
|
if (this.didClose) return;
|
|
12566
12514
|
this.events.emit("runtime_event", {
|
|
12567
12515
|
kind: "error",
|
|
@@ -12687,7 +12635,7 @@ var BuiltInDriver = class extends PiDriver {
|
|
|
12687
12635
|
exposeLaunchTraceEvidence: true,
|
|
12688
12636
|
exposeLaunchEnvToTools: false,
|
|
12689
12637
|
isolateHostProviderEnv: true
|
|
12690
|
-
})
|
|
12638
|
+
}));
|
|
12691
12639
|
}
|
|
12692
12640
|
buildSystemPrompt(config, _agentId) {
|
|
12693
12641
|
return buildCliTransportSystemPrompt(config, {
|
|
@@ -13079,120 +13027,6 @@ async function deleteWorkspaceDirectory(dataDir, directoryName) {
|
|
|
13079
13027
|
}
|
|
13080
13028
|
}
|
|
13081
13029
|
|
|
13082
|
-
// src/workspaceGitIdentity.ts
|
|
13083
|
-
import { execFile } from "child_process";
|
|
13084
|
-
import { readdir as readdir2, realpath } from "fs/promises";
|
|
13085
|
-
import path14 from "path";
|
|
13086
|
-
import { promisify } from "util";
|
|
13087
|
-
var execFileAsync = promisify(execFile);
|
|
13088
|
-
var DISCOVERY_SKIP_DIRECTORIES = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
13089
|
-
var RepositoryOwnershipError = class extends Error {
|
|
13090
|
-
};
|
|
13091
|
-
async function runGit(repoPath, args) {
|
|
13092
|
-
const { stdout } = await execFileAsync("git", ["-C", repoPath, ...args], {
|
|
13093
|
-
encoding: "utf8"
|
|
13094
|
-
});
|
|
13095
|
-
return stdout.trim();
|
|
13096
|
-
}
|
|
13097
|
-
function isPathInside(rootPath, candidatePath) {
|
|
13098
|
-
const relative = path14.relative(rootPath, candidatePath);
|
|
13099
|
-
return relative === "" || !relative.startsWith(`..${path14.sep}`) && relative !== ".." && !path14.isAbsolute(relative);
|
|
13100
|
-
}
|
|
13101
|
-
async function inspectGitRepository(repoPath, ownedRootPath) {
|
|
13102
|
-
try {
|
|
13103
|
-
const [gitDirOutput, commonDirOutput] = await Promise.all([
|
|
13104
|
-
runGit(repoPath, ["rev-parse", "--absolute-git-dir"]),
|
|
13105
|
-
runGit(repoPath, ["rev-parse", "--git-common-dir"])
|
|
13106
|
-
]);
|
|
13107
|
-
const [canonicalRepoPath, gitDir, commonDir] = await Promise.all([
|
|
13108
|
-
realpath(repoPath),
|
|
13109
|
-
realpath(gitDirOutput),
|
|
13110
|
-
realpath(
|
|
13111
|
-
path14.isAbsolute(commonDirOutput) ? commonDirOutput : path14.resolve(repoPath, commonDirOutput)
|
|
13112
|
-
)
|
|
13113
|
-
]);
|
|
13114
|
-
if (!isPathInside(ownedRootPath, canonicalRepoPath) || !isPathInside(ownedRootPath, gitDir) || !isPathInside(ownedRootPath, commonDir)) {
|
|
13115
|
-
throw new RepositoryOwnershipError(
|
|
13116
|
-
`Refusing to provision git identity outside the agent-owned workspace: ${repoPath}`
|
|
13117
|
-
);
|
|
13118
|
-
}
|
|
13119
|
-
return { repoPath, linkedWorktree: gitDir !== commonDir };
|
|
13120
|
-
} catch (error) {
|
|
13121
|
-
if (error.code === "ENOENT") {
|
|
13122
|
-
throw new Error("git is required to provision repository identity", { cause: error });
|
|
13123
|
-
}
|
|
13124
|
-
if (error instanceof RepositoryOwnershipError) {
|
|
13125
|
-
throw error;
|
|
13126
|
-
}
|
|
13127
|
-
return null;
|
|
13128
|
-
}
|
|
13129
|
-
}
|
|
13130
|
-
async function discoverWorkspaceGitRepositories(workspacePath) {
|
|
13131
|
-
const repositories = [];
|
|
13132
|
-
const pending = [workspacePath];
|
|
13133
|
-
while (pending.length > 0) {
|
|
13134
|
-
const currentPath = pending.pop();
|
|
13135
|
-
const entries = await readdir2(currentPath, { withFileTypes: true });
|
|
13136
|
-
if (entries.some((entry) => entry.name === ".git")) {
|
|
13137
|
-
repositories.push(currentPath);
|
|
13138
|
-
}
|
|
13139
|
-
for (const entry of entries) {
|
|
13140
|
-
if (!entry.isDirectory() || DISCOVERY_SKIP_DIRECTORIES.has(entry.name)) {
|
|
13141
|
-
continue;
|
|
13142
|
-
}
|
|
13143
|
-
pending.push(path14.join(currentPath, entry.name));
|
|
13144
|
-
}
|
|
13145
|
-
}
|
|
13146
|
-
return repositories.sort();
|
|
13147
|
-
}
|
|
13148
|
-
async function reconcileWorkspaceGitIdentity(workspacePath, agentName) {
|
|
13149
|
-
const identity = resolveAgentGitIdentity(agentName);
|
|
13150
|
-
const ownedRootPath = await realpath(workspacePath);
|
|
13151
|
-
const repositories = await discoverWorkspaceGitRepositories(workspacePath);
|
|
13152
|
-
const result = {
|
|
13153
|
-
discovered: repositories.length,
|
|
13154
|
-
configuredStandalone: 0,
|
|
13155
|
-
configuredLinkedWorktree: 0,
|
|
13156
|
-
skippedInvalid: 0
|
|
13157
|
-
};
|
|
13158
|
-
const layouts = [];
|
|
13159
|
-
for (const repoPath of repositories) {
|
|
13160
|
-
const layout = await inspectGitRepository(repoPath, ownedRootPath);
|
|
13161
|
-
if (!layout) {
|
|
13162
|
-
result.skippedInvalid += 1;
|
|
13163
|
-
continue;
|
|
13164
|
-
}
|
|
13165
|
-
layouts.push(layout);
|
|
13166
|
-
}
|
|
13167
|
-
for (const layout of layouts) {
|
|
13168
|
-
const { repoPath } = layout;
|
|
13169
|
-
if (layout.linkedWorktree) {
|
|
13170
|
-
await runGit(repoPath, ["config", "--local", "extensions.worktreeConfig", "true"]);
|
|
13171
|
-
await runGit(repoPath, ["config", "--worktree", "user.name", identity.name]);
|
|
13172
|
-
await runGit(repoPath, ["config", "--worktree", "user.email", identity.email]);
|
|
13173
|
-
result.configuredLinkedWorktree += 1;
|
|
13174
|
-
continue;
|
|
13175
|
-
}
|
|
13176
|
-
await runGit(repoPath, ["config", "--local", "user.name", identity.name]);
|
|
13177
|
-
await runGit(repoPath, ["config", "--local", "user.email", identity.email]);
|
|
13178
|
-
result.configuredStandalone += 1;
|
|
13179
|
-
}
|
|
13180
|
-
return result;
|
|
13181
|
-
}
|
|
13182
|
-
async function provisionWorkspaceGitIdentity(workspacePath, agentId, agentName) {
|
|
13183
|
-
const result = await reconcileWorkspaceGitIdentity(workspacePath, agentName);
|
|
13184
|
-
if (result.discovered > 0) {
|
|
13185
|
-
logger.info(
|
|
13186
|
-
`[Agent ${agentId}] Git identity provisioned for ${result.configuredStandalone} standalone repositories and ${result.configuredLinkedWorktree} linked worktrees`
|
|
13187
|
-
);
|
|
13188
|
-
}
|
|
13189
|
-
if (result.skippedInvalid > 0) {
|
|
13190
|
-
logger.warn(
|
|
13191
|
-
`[Agent ${agentId}] Skipped ${result.skippedInvalid} invalid git repository markers while provisioning identity`
|
|
13192
|
-
);
|
|
13193
|
-
}
|
|
13194
|
-
}
|
|
13195
|
-
|
|
13196
13030
|
// src/agentStartCoordinator.ts
|
|
13197
13031
|
var AgentStartCoordinator = class {
|
|
13198
13032
|
starting = /* @__PURE__ */ new Set();
|
|
@@ -14696,7 +14530,7 @@ function isWorkspaceNeverVisibleHiddenEntry(name) {
|
|
|
14696
14530
|
return WORKSPACE_NEVER_VISIBLE_HIDDEN_NAMES.has(name) || name.startsWith(".slock-");
|
|
14697
14531
|
}
|
|
14698
14532
|
function workspacePathParts(relativePath) {
|
|
14699
|
-
return relativePath.split(
|
|
14533
|
+
return relativePath.split(path14.sep).filter(Boolean);
|
|
14700
14534
|
}
|
|
14701
14535
|
function isWorkspaceHiddenPath(relativePath) {
|
|
14702
14536
|
return workspacePathParts(relativePath).some((part) => part.startsWith("."));
|
|
@@ -14823,29 +14657,29 @@ function allowedTranscriptRootsForRuntime(runtime, homeDir, workspaceDir) {
|
|
|
14823
14657
|
const roots = [workspaceDir];
|
|
14824
14658
|
switch (runtime) {
|
|
14825
14659
|
case "claude":
|
|
14826
|
-
roots.push(
|
|
14660
|
+
roots.push(path14.join(homeDir, ".claude"));
|
|
14827
14661
|
break;
|
|
14828
14662
|
case "codex":
|
|
14829
|
-
roots.push(homeDir,
|
|
14663
|
+
roots.push(homeDir, path14.join(homeDir, ".codex"));
|
|
14830
14664
|
break;
|
|
14831
14665
|
case "kimi":
|
|
14832
14666
|
case "kimi-sdk":
|
|
14833
|
-
roots.push(
|
|
14667
|
+
roots.push(path14.join(homeDir, ".kimi"));
|
|
14834
14668
|
break;
|
|
14835
14669
|
case "pi":
|
|
14836
|
-
roots.push(
|
|
14670
|
+
roots.push(path14.join(homeDir, ".pi"), path14.join(homeDir, ".pi", "agent"));
|
|
14837
14671
|
break;
|
|
14838
14672
|
}
|
|
14839
14673
|
return roots;
|
|
14840
14674
|
}
|
|
14841
14675
|
async function isPathWithinAllowedRoots(filePath, roots) {
|
|
14842
|
-
const real = await
|
|
14676
|
+
const real = await realpath(filePath).catch(() => null);
|
|
14843
14677
|
if (!real) return false;
|
|
14844
14678
|
for (const root of roots) {
|
|
14845
|
-
const realRoot = await
|
|
14679
|
+
const realRoot = await realpath(root).catch(() => null);
|
|
14846
14680
|
if (!realRoot) continue;
|
|
14847
|
-
const rel =
|
|
14848
|
-
if (!rel.startsWith("..") && !
|
|
14681
|
+
const rel = path14.relative(realRoot, real);
|
|
14682
|
+
if (!rel.startsWith("..") && !path14.isAbsolute(rel)) return true;
|
|
14849
14683
|
}
|
|
14850
14684
|
return false;
|
|
14851
14685
|
}
|
|
@@ -14892,12 +14726,12 @@ function findSessionJsonl(root, predicate) {
|
|
|
14892
14726
|
for (const entry of entries) {
|
|
14893
14727
|
if (++visited > maxEntries) return null;
|
|
14894
14728
|
if (!entry.isFile() || !predicate(entry.name)) continue;
|
|
14895
|
-
return
|
|
14729
|
+
return path14.join(dir, entry.name);
|
|
14896
14730
|
}
|
|
14897
14731
|
for (const entry of entries) {
|
|
14898
14732
|
if (++visited > maxEntries) return null;
|
|
14899
14733
|
if (!entry.isDirectory()) continue;
|
|
14900
|
-
const found = visit(
|
|
14734
|
+
const found = visit(path14.join(dir, entry.name), depth - 1);
|
|
14901
14735
|
if (found) return found;
|
|
14902
14736
|
}
|
|
14903
14737
|
return null;
|
|
@@ -14905,7 +14739,7 @@ function findSessionJsonl(root, predicate) {
|
|
|
14905
14739
|
return visit(root, maxDepth);
|
|
14906
14740
|
}
|
|
14907
14741
|
function findKimiSdkSessionDir(sessionId, agentId, homeDir) {
|
|
14908
|
-
const indexPath =
|
|
14742
|
+
const indexPath = path14.join(homeDir, ".kimi", "session_index.jsonl");
|
|
14909
14743
|
try {
|
|
14910
14744
|
const index = readFileSync6(indexPath, "utf8");
|
|
14911
14745
|
for (const line of index.split("\n")) {
|
|
@@ -14920,12 +14754,12 @@ function findKimiSdkSessionDir(sessionId, agentId, homeDir) {
|
|
|
14920
14754
|
}
|
|
14921
14755
|
} catch {
|
|
14922
14756
|
}
|
|
14923
|
-
const sessionsRoot =
|
|
14757
|
+
const sessionsRoot = path14.join(homeDir, ".kimi", "sessions");
|
|
14924
14758
|
try {
|
|
14925
14759
|
const prefix = agentId ? `wd_${agentId}_` : `wd_`;
|
|
14926
14760
|
for (const entry of readdirSync4(sessionsRoot, { withFileTypes: true })) {
|
|
14927
14761
|
if (!entry.isDirectory() || !entry.name.startsWith(prefix)) continue;
|
|
14928
|
-
const candidate =
|
|
14762
|
+
const candidate = path14.join(sessionsRoot, entry.name, `session_${sessionId}`);
|
|
14929
14763
|
if (existsSync8(candidate)) return candidate;
|
|
14930
14764
|
}
|
|
14931
14765
|
} catch {
|
|
@@ -14934,16 +14768,16 @@ function findKimiSdkSessionDir(sessionId, agentId, homeDir) {
|
|
|
14934
14768
|
}
|
|
14935
14769
|
function findPiSessionFile2(sessionId, workingDirectory, homeDir) {
|
|
14936
14770
|
if (workingDirectory) {
|
|
14937
|
-
const piSessionsDir =
|
|
14771
|
+
const piSessionsDir = path14.join(workingDirectory, ".pi-sessions");
|
|
14938
14772
|
try {
|
|
14939
|
-
const files = readdirSync4(piSessionsDir, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".jsonl")).map((e) => ({ name: e.name, path:
|
|
14773
|
+
const files = readdirSync4(piSessionsDir, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".jsonl")).map((e) => ({ name: e.name, path: path14.join(piSessionsDir, e.name), stat: statSync(path14.join(piSessionsDir, e.name)) })).filter((f) => f.stat.isFile() && f.name.includes(sessionId)).sort((a, b) => b.stat.mtimeMs - a.stat.mtimeMs);
|
|
14940
14774
|
if (files[0]) return files[0].path;
|
|
14941
14775
|
} catch {
|
|
14942
14776
|
}
|
|
14943
14777
|
}
|
|
14944
14778
|
const legacyRoots = [
|
|
14945
|
-
|
|
14946
|
-
|
|
14779
|
+
path14.join(homeDir, ".pi", "agent"),
|
|
14780
|
+
path14.join(homeDir, ".pi")
|
|
14947
14781
|
];
|
|
14948
14782
|
for (const root of legacyRoots) {
|
|
14949
14783
|
const found = findSessionJsonl(root, (filename) => filename.endsWith(".jsonl") && filename.includes(sessionId));
|
|
@@ -14957,9 +14791,9 @@ function safeSessionFilename(value) {
|
|
|
14957
14791
|
}
|
|
14958
14792
|
function writeRuntimeSessionHandoff(runtime, sessionId, fallbackDir, join, resolve) {
|
|
14959
14793
|
try {
|
|
14960
|
-
const dir =
|
|
14794
|
+
const dir = path14.join(fallbackDir, ".slock", "runtime-sessions");
|
|
14961
14795
|
mkdirSync4(dir, { recursive: true });
|
|
14962
|
-
const filePath =
|
|
14796
|
+
const filePath = path14.join(dir, `${runtime}-${safeSessionFilename(sessionId)}.jsonl`);
|
|
14963
14797
|
const searchedPaths = resolve?.searchedPaths ?? [];
|
|
14964
14798
|
writeFileSync4(filePath, JSON.stringify({
|
|
14965
14799
|
type: "runtime_session_handoff",
|
|
@@ -15014,7 +14848,7 @@ function resolveRuntimeSessionRef(runtime, sessionId, homeDir = os6.homedir(), f
|
|
|
15014
14848
|
const searchedPaths = [];
|
|
15015
14849
|
if (runtime === "claude") {
|
|
15016
14850
|
lookupMethod = "claude_jsonl";
|
|
15017
|
-
const claudeRoot =
|
|
14851
|
+
const claudeRoot = path14.join(homeDir, ".claude", "projects");
|
|
15018
14852
|
searchedPaths.push(claudeRoot);
|
|
15019
14853
|
resolvedPath = findSessionJsonl(claudeRoot, (filename) => filename === `${sessionId}.jsonl`);
|
|
15020
14854
|
} else if (runtime === "codex") {
|
|
@@ -16386,7 +16220,7 @@ var AgentProcessManager = class _AgentProcessManager {
|
|
|
16386
16220
|
this.sendToServer = sendToServer;
|
|
16387
16221
|
this.daemonApiKey = daemonApiKey;
|
|
16388
16222
|
this.serverUrl = opts.serverUrl;
|
|
16389
|
-
this.slockHome = opts.slockHome ?
|
|
16223
|
+
this.slockHome = opts.slockHome ? path14.resolve(opts.slockHome) : resolveSlockHome();
|
|
16390
16224
|
this.dataDir = opts.dataDir || resolveSlockHomePath("agents", this.slockHome);
|
|
16391
16225
|
this.runtimeSessionHomeDir = opts.runtimeSessionHomeDir || os6.homedir();
|
|
16392
16226
|
this.driverResolver = opts.driverResolver || getDriver;
|
|
@@ -17701,7 +17535,7 @@ var AgentProcessManager = class _AgentProcessManager {
|
|
|
17701
17535
|
let pendingStartRebind;
|
|
17702
17536
|
const originalLaunchId = launchId || null;
|
|
17703
17537
|
try {
|
|
17704
|
-
const agentDataDir =
|
|
17538
|
+
const agentDataDir = path14.join(this.dataDir, agentId);
|
|
17705
17539
|
const initialRuntimeConfig = withLocalRuntimeContext(config, agentId, agentDataDir);
|
|
17706
17540
|
await initializeAgentWorkspace(
|
|
17707
17541
|
agentDataDir,
|
|
@@ -17730,7 +17564,6 @@ var AgentProcessManager = class _AgentProcessManager {
|
|
|
17730
17564
|
wakeMessageTransient = pendingStartRebind.wakeMessageTransient === true;
|
|
17731
17565
|
}
|
|
17732
17566
|
}
|
|
17733
|
-
await provisionWorkspaceGitIdentity(agentDataDir, agentId, config.name);
|
|
17734
17567
|
this.enterNoProcessResidency(
|
|
17735
17568
|
"starting_process",
|
|
17736
17569
|
this.noProcessResidencyIdentity(agentId, config, launchId, this.startLaunchSource(config, wakeMessage, resumePrompt)),
|
|
@@ -18499,7 +18332,7 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
18499
18332
|
);
|
|
18500
18333
|
}
|
|
18501
18334
|
}
|
|
18502
|
-
return
|
|
18335
|
+
return effectiveConfig;
|
|
18503
18336
|
}
|
|
18504
18337
|
async requestManagedRunnerCredentialOnce(agentId, config) {
|
|
18505
18338
|
const url = new URL(`/internal/computer/runners/${encodeURIComponent(agentId)}/credentials`, this.serverUrl);
|
|
@@ -19238,7 +19071,7 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19238
19071
|
return true;
|
|
19239
19072
|
}
|
|
19240
19073
|
async resetWorkspace(agentId) {
|
|
19241
|
-
const agentDataDir =
|
|
19074
|
+
const agentDataDir = path14.join(this.dataDir, agentId);
|
|
19242
19075
|
try {
|
|
19243
19076
|
await rm2(agentDataDir, { recursive: true, force: true });
|
|
19244
19077
|
logger.info(`[Agent ${agentId}] Workspace reset complete (${agentDataDir})`);
|
|
@@ -19320,7 +19153,7 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19320
19153
|
return result;
|
|
19321
19154
|
}
|
|
19322
19155
|
buildRuntimeProfileReport(agentId, config, sessionId, launchId, observedRuntimeHomeDir, processInstanceId) {
|
|
19323
|
-
const workspacePath =
|
|
19156
|
+
const workspacePath = path14.join(this.dataDir, agentId);
|
|
19324
19157
|
const runtimeHomeDir = observedRuntimeHomeDir || resolveRuntimeHomeDir(config, this.runtimeSessionHomeDir, workspacePath, { agentId, slockHome: this.slockHome });
|
|
19325
19158
|
return {
|
|
19326
19159
|
agentId,
|
|
@@ -19656,7 +19489,7 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19656
19489
|
}
|
|
19657
19490
|
// Workspace file browsing
|
|
19658
19491
|
async getFileTree(agentId, dirPath, includeHidden = false) {
|
|
19659
|
-
const agentDir =
|
|
19492
|
+
const agentDir = path14.join(this.dataDir, agentId);
|
|
19660
19493
|
try {
|
|
19661
19494
|
await stat2(agentDir);
|
|
19662
19495
|
} catch {
|
|
@@ -19664,11 +19497,11 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19664
19497
|
}
|
|
19665
19498
|
let targetDir = agentDir;
|
|
19666
19499
|
if (dirPath) {
|
|
19667
|
-
const resolved =
|
|
19668
|
-
if (!resolved.startsWith(agentDir +
|
|
19500
|
+
const resolved = path14.resolve(agentDir, dirPath);
|
|
19501
|
+
if (!resolved.startsWith(agentDir + path14.sep) && resolved !== agentDir) {
|
|
19669
19502
|
return [];
|
|
19670
19503
|
}
|
|
19671
|
-
const relativePath =
|
|
19504
|
+
const relativePath = path14.relative(agentDir, resolved);
|
|
19672
19505
|
if (isWorkspaceNeverVisibleHiddenPath(relativePath)) {
|
|
19673
19506
|
return [];
|
|
19674
19507
|
}
|
|
@@ -19680,18 +19513,18 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19680
19513
|
return this.listDirectoryChildren(targetDir, agentDir, includeHidden);
|
|
19681
19514
|
}
|
|
19682
19515
|
async readFile(agentId, filePath) {
|
|
19683
|
-
const agentDir =
|
|
19684
|
-
const resolved =
|
|
19685
|
-
if (!resolved.startsWith(agentDir +
|
|
19516
|
+
const agentDir = path14.join(this.dataDir, agentId);
|
|
19517
|
+
const resolved = path14.resolve(agentDir, filePath);
|
|
19518
|
+
if (!resolved.startsWith(agentDir + path14.sep) && resolved !== agentDir) {
|
|
19686
19519
|
throw new Error("Access denied");
|
|
19687
19520
|
}
|
|
19688
|
-
const relativePath =
|
|
19521
|
+
const relativePath = path14.relative(agentDir, resolved);
|
|
19689
19522
|
if (isWorkspaceNeverVisibleHiddenPath(relativePath) || isWorkspaceSecretFilePath(relativePath)) {
|
|
19690
19523
|
throw new Error("Preview is disabled for sensitive workspace files");
|
|
19691
19524
|
}
|
|
19692
19525
|
const info = await stat2(resolved);
|
|
19693
19526
|
if (info.isDirectory()) throw new Error("Cannot read a directory");
|
|
19694
|
-
const ext =
|
|
19527
|
+
const ext = path14.extname(resolved).toLowerCase();
|
|
19695
19528
|
if (WORKSPACE_TEXT_EXTENSIONS.has(ext) || ext === "") {
|
|
19696
19529
|
if (info.size > WORKSPACE_TEXT_FILE_MAX_BYTES) throw new Error("File too large");
|
|
19697
19530
|
const content = await readFile(resolved, "utf-8");
|
|
@@ -19742,7 +19575,7 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19742
19575
|
};
|
|
19743
19576
|
}
|
|
19744
19577
|
const runtime = config.runtime;
|
|
19745
|
-
const workspaceDir =
|
|
19578
|
+
const workspaceDir = path14.join(this.dataDir, agentId);
|
|
19746
19579
|
const homeDir = agent?.runtime.currentRuntimeHomeDir || ensureRuntimeHomeDir(config, this.runtimeSessionHomeDir, workspaceDir, { agentId, slockHome: this.slockHome });
|
|
19747
19580
|
if (!actualSessionId) {
|
|
19748
19581
|
return {
|
|
@@ -19783,7 +19616,7 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19783
19616
|
let redacted = false;
|
|
19784
19617
|
if (ref.reachable && ref.path) {
|
|
19785
19618
|
try {
|
|
19786
|
-
const resolved =
|
|
19619
|
+
const resolved = path14.resolve(ref.path);
|
|
19787
19620
|
const allowedRoots = allowedTranscriptRootsForRuntime(runtime, homeDir, workspaceDir);
|
|
19788
19621
|
if (!await isPathWithinAllowedRoots(resolved, allowedRoots)) {
|
|
19789
19622
|
throw new Error("resolved session path is outside allowed runtime directories");
|
|
@@ -19794,7 +19627,7 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19794
19627
|
throw new Error("symbolic links are not allowed");
|
|
19795
19628
|
}
|
|
19796
19629
|
if (info.isDirectory()) {
|
|
19797
|
-
targetPath =
|
|
19630
|
+
targetPath = path14.join(resolved, "state.json");
|
|
19798
19631
|
}
|
|
19799
19632
|
if (!await isPathWithinAllowedRoots(targetPath, allowedRoots)) {
|
|
19800
19633
|
throw new Error("resolved session state path is outside allowed runtime directories");
|
|
@@ -19906,17 +19739,17 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19906
19739
|
const idle = this.lifecycleRecords.getRestartSnapshot(agentId);
|
|
19907
19740
|
const config = agent?.config ?? idle?.config ?? null;
|
|
19908
19741
|
const runtime = runtimeHint || config?.runtime || "claude";
|
|
19909
|
-
const workspaceDir =
|
|
19742
|
+
const workspaceDir = path14.join(this.dataDir, agentId);
|
|
19910
19743
|
const hostHome = os6.homedir();
|
|
19911
19744
|
const home = agent?.runtime.currentRuntimeHomeDir || (config ? ensureRuntimeHomeDir(config, hostHome, workspaceDir, { agentId, slockHome: this.slockHome }) : runtime === "codex" ? resolveCodexHomeRootFromEnv(process.env, { defaultHomeDir: hostHome, cwd: workspaceDir }) : hostHome);
|
|
19912
19745
|
const paths = _AgentProcessManager.SKILL_PATHS[runtime] || _AgentProcessManager.SKILL_PATHS.claude;
|
|
19913
19746
|
const globalDirs = runtime === "codex" ? [
|
|
19914
|
-
|
|
19915
|
-
|
|
19916
|
-
|
|
19917
|
-
...hasConfiguredCodexHome(config) ? [] : [
|
|
19918
|
-
] : paths.global.map((p) =>
|
|
19919
|
-
const workspaceDirs = paths.workspace.map((p) =>
|
|
19747
|
+
path14.join(home, "skills"),
|
|
19748
|
+
path14.join(home, "skills", ".system"),
|
|
19749
|
+
path14.join(home, ".agents", "skills"),
|
|
19750
|
+
...hasConfiguredCodexHome(config) ? [] : [path14.join(hostHome, ".agents", "skills")]
|
|
19751
|
+
] : paths.global.map((p) => path14.join(home, p));
|
|
19752
|
+
const workspaceDirs = paths.workspace.map((p) => path14.join(workspaceDir, p));
|
|
19920
19753
|
const globalResults = await Promise.all(
|
|
19921
19754
|
globalDirs.map((dir) => this.scanSkillsDir(dir))
|
|
19922
19755
|
);
|
|
@@ -19943,14 +19776,14 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19943
19776
|
async scanSkillsDir(dir) {
|
|
19944
19777
|
let entries;
|
|
19945
19778
|
try {
|
|
19946
|
-
entries = await
|
|
19779
|
+
entries = await readdir2(dir, { withFileTypes: true });
|
|
19947
19780
|
} catch {
|
|
19948
19781
|
return [];
|
|
19949
19782
|
}
|
|
19950
19783
|
const skills = [];
|
|
19951
19784
|
for (const entry of entries) {
|
|
19952
19785
|
if (entry.isDirectory() || entry.isSymbolicLink()) {
|
|
19953
|
-
const skillMd =
|
|
19786
|
+
const skillMd = path14.join(dir, entry.name, "SKILL.md");
|
|
19954
19787
|
try {
|
|
19955
19788
|
const content = await readFile(skillMd, "utf-8");
|
|
19956
19789
|
const skill = this.parseSkillMd(entry.name, content);
|
|
@@ -19961,7 +19794,7 @@ Use \`raft message read\` to catch up on the channels listed above, then stop. R
|
|
|
19961
19794
|
} else if (entry.name.endsWith(".md")) {
|
|
19962
19795
|
const cmdName = entry.name.replace(/\.md$/, "");
|
|
19963
19796
|
try {
|
|
19964
|
-
const content = await readFile(
|
|
19797
|
+
const content = await readFile(path14.join(dir, entry.name), "utf-8");
|
|
19965
19798
|
const skill = this.parseSkillMd(cmdName, content);
|
|
19966
19799
|
skill.sourcePath = dir;
|
|
19967
19800
|
skills.push(skill);
|
|
@@ -22029,7 +21862,7 @@ ${RESPONSE_TARGET_HINT}`);
|
|
|
22029
21862
|
async listDirectoryChildren(dir, rootDir, includeHidden = false) {
|
|
22030
21863
|
let entries;
|
|
22031
21864
|
try {
|
|
22032
|
-
entries = await
|
|
21865
|
+
entries = await readdir2(dir, { withFileTypes: true });
|
|
22033
21866
|
} catch {
|
|
22034
21867
|
return [];
|
|
22035
21868
|
}
|
|
@@ -22043,8 +21876,8 @@ ${RESPONSE_TARGET_HINT}`);
|
|
|
22043
21876
|
const isHidden = entry.name.startsWith(".");
|
|
22044
21877
|
if (entry.name === "node_modules") continue;
|
|
22045
21878
|
if (isHidden && (!includeHidden || isWorkspaceNeverVisibleHiddenEntry(entry.name))) continue;
|
|
22046
|
-
const fullPath =
|
|
22047
|
-
const relativePath =
|
|
21879
|
+
const fullPath = path14.join(dir, entry.name);
|
|
21880
|
+
const relativePath = path14.relative(rootDir, fullPath);
|
|
22048
21881
|
let info;
|
|
22049
21882
|
try {
|
|
22050
21883
|
info = await stat2(fullPath);
|
|
@@ -22513,7 +22346,7 @@ var ReminderCache = class {
|
|
|
22513
22346
|
import { createHash as createHash4, randomUUID as randomUUID7 } from "crypto";
|
|
22514
22347
|
import { mkdirSync as mkdirSync5, readFileSync as readFileSync7, rmSync as rmSync3, statSync as statSync2, writeFileSync as writeFileSync5 } from "fs";
|
|
22515
22348
|
import os7 from "os";
|
|
22516
|
-
import
|
|
22349
|
+
import path15 from "path";
|
|
22517
22350
|
var INCOMPLETE_LOCK_STALE_MS = 3e4;
|
|
22518
22351
|
var DaemonMachineLockConflictError = class extends Error {
|
|
22519
22352
|
code = "DAEMON_MACHINE_LOCK_HELD";
|
|
@@ -22535,7 +22368,7 @@ function resolveDefaultMachineStateRoot() {
|
|
|
22535
22368
|
return resolveSlockHomePath("machines");
|
|
22536
22369
|
}
|
|
22537
22370
|
function ownerPath(lockDir) {
|
|
22538
|
-
return
|
|
22371
|
+
return path15.join(lockDir, "owner.json");
|
|
22539
22372
|
}
|
|
22540
22373
|
function readOwner(lockDir) {
|
|
22541
22374
|
try {
|
|
@@ -22565,8 +22398,8 @@ function acquireDaemonMachineLock(options) {
|
|
|
22565
22398
|
const rootDir = options.rootDir ?? resolveDefaultMachineStateRoot();
|
|
22566
22399
|
const fingerprint = apiKeyFingerprint(options.apiKey);
|
|
22567
22400
|
const lockId = getDaemonMachineLockId(options.apiKey);
|
|
22568
|
-
const machineDir =
|
|
22569
|
-
const lockDir =
|
|
22401
|
+
const machineDir = path15.join(rootDir, lockId);
|
|
22402
|
+
const lockDir = path15.join(machineDir, "daemon.lock");
|
|
22570
22403
|
const token = randomUUID7();
|
|
22571
22404
|
mkdirSync5(machineDir, { recursive: true });
|
|
22572
22405
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
@@ -22627,7 +22460,7 @@ function acquireDaemonMachineLock(options) {
|
|
|
22627
22460
|
|
|
22628
22461
|
// ../trace-client/src/localTraceSink.ts
|
|
22629
22462
|
import { appendFileSync, mkdirSync as mkdirSync6, readdirSync as readdirSync5, rmSync as rmSync4, statSync as statSync3, writeFileSync as writeFileSync6 } from "fs";
|
|
22630
|
-
import
|
|
22463
|
+
import path16 from "path";
|
|
22631
22464
|
var DEFAULT_MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
22632
22465
|
var DEFAULT_MAX_FILE_AGE_MS = 5 * 60 * 1e3;
|
|
22633
22466
|
var DEFAULT_MAX_FILES = 8;
|
|
@@ -22672,7 +22505,7 @@ var LocalRotatingTraceSink = class {
|
|
|
22672
22505
|
currentSize = 0;
|
|
22673
22506
|
sequence = 0;
|
|
22674
22507
|
constructor(options) {
|
|
22675
|
-
this.traceDir =
|
|
22508
|
+
this.traceDir = path16.join(options.machineDir, "traces");
|
|
22676
22509
|
this.maxFileBytes = Math.max(1024, Math.floor(options.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES));
|
|
22677
22510
|
const baseAgeMs = Math.max(1e3, Math.floor(options.maxFileAgeMs ?? DEFAULT_MAX_FILE_AGE_MS));
|
|
22678
22511
|
const ageJitterMs = Math.max(0, Math.floor(options.maxFileAgeJitterMs ?? 0));
|
|
@@ -22702,7 +22535,7 @@ var LocalRotatingTraceSink = class {
|
|
|
22702
22535
|
const nowMs = this.nowMsProvider();
|
|
22703
22536
|
const shouldRotateForAge = this.currentFileOpenedAtMs !== null && nowMs - this.currentFileOpenedAtMs >= this.maxFileAgeMs;
|
|
22704
22537
|
if (!this.currentFile || this.currentSize + nextBytes > this.maxFileBytes || shouldRotateForAge) {
|
|
22705
|
-
this.currentFile =
|
|
22538
|
+
this.currentFile = path16.join(
|
|
22706
22539
|
this.traceDir,
|
|
22707
22540
|
`daemon-trace-${safeTimestamp(nowMs)}-${process.pid}-${String(this.sequence++).padStart(4, "0")}.jsonl`
|
|
22708
22541
|
);
|
|
@@ -22717,7 +22550,7 @@ var LocalRotatingTraceSink = class {
|
|
|
22717
22550
|
const excess = files.length - this.maxFiles;
|
|
22718
22551
|
if (excess <= 0) return;
|
|
22719
22552
|
for (const file of files.slice(0, excess)) {
|
|
22720
|
-
rmSync4(
|
|
22553
|
+
rmSync4(path16.join(this.traceDir, file), { force: true });
|
|
22721
22554
|
}
|
|
22722
22555
|
}
|
|
22723
22556
|
};
|
|
@@ -22893,8 +22726,8 @@ function createTraceClient(options) {
|
|
|
22893
22726
|
// src/traceBundleUpload.ts
|
|
22894
22727
|
import { createHash as createHash6, randomUUID as randomUUID8 } from "crypto";
|
|
22895
22728
|
import { gzipSync as gzipSync2 } from "zlib";
|
|
22896
|
-
import { mkdir as mkdir2, readFile as readFile2, readdir as
|
|
22897
|
-
import
|
|
22729
|
+
import { mkdir as mkdir2, readFile as readFile2, readdir as readdir3, stat as stat3, writeFile as writeFile2 } from "fs/promises";
|
|
22730
|
+
import path17 from "path";
|
|
22898
22731
|
var TRACE_UPLOAD_SCOPE = "daemon-trace-bundle:create";
|
|
22899
22732
|
var DEFAULT_UPLOAD_INTERVAL_MS = 5 * 60 * 1e3;
|
|
22900
22733
|
var DEFAULT_MIN_FILE_AGE_MS = 60 * 1e3;
|
|
@@ -22977,10 +22810,10 @@ var DaemonTraceBundleUploader = class {
|
|
|
22977
22810
|
}, nextMs);
|
|
22978
22811
|
}
|
|
22979
22812
|
async findUploadCandidates() {
|
|
22980
|
-
const traceDir =
|
|
22813
|
+
const traceDir = path17.join(this.options.machineDir, "traces");
|
|
22981
22814
|
let names;
|
|
22982
22815
|
try {
|
|
22983
|
-
names = await
|
|
22816
|
+
names = await readdir3(traceDir);
|
|
22984
22817
|
} catch {
|
|
22985
22818
|
return [];
|
|
22986
22819
|
}
|
|
@@ -22989,8 +22822,8 @@ var DaemonTraceBundleUploader = class {
|
|
|
22989
22822
|
const currentFile = this.options.currentFileProvider?.();
|
|
22990
22823
|
const candidates = [];
|
|
22991
22824
|
for (const name of names.filter((entry) => entry.startsWith("daemon-trace-") && entry.endsWith(".jsonl")).sort()) {
|
|
22992
|
-
const file =
|
|
22993
|
-
if (currentFile &&
|
|
22825
|
+
const file = path17.join(traceDir, name);
|
|
22826
|
+
if (currentFile && path17.resolve(file) === path17.resolve(currentFile)) continue;
|
|
22994
22827
|
if (await this.isUploaded(file)) continue;
|
|
22995
22828
|
try {
|
|
22996
22829
|
const info = await stat3(file);
|
|
@@ -23068,8 +22901,8 @@ var DaemonTraceBundleUploader = class {
|
|
|
23068
22901
|
}
|
|
23069
22902
|
}
|
|
23070
22903
|
uploadStatePath(file) {
|
|
23071
|
-
const stateDir =
|
|
23072
|
-
return
|
|
22904
|
+
const stateDir = path17.join(this.options.machineDir, "trace-uploads");
|
|
22905
|
+
return path17.join(stateDir, `${path17.basename(file)}.uploaded.json`);
|
|
23073
22906
|
}
|
|
23074
22907
|
async isUploaded(file) {
|
|
23075
22908
|
try {
|
|
@@ -23081,9 +22914,9 @@ var DaemonTraceBundleUploader = class {
|
|
|
23081
22914
|
}
|
|
23082
22915
|
async markUploaded(file, metadata) {
|
|
23083
22916
|
const stateFile = this.uploadStatePath(file);
|
|
23084
|
-
await mkdir2(
|
|
22917
|
+
await mkdir2(path17.dirname(stateFile), { recursive: true, mode: 448 });
|
|
23085
22918
|
await writeFile2(stateFile, `${JSON.stringify({
|
|
23086
|
-
file:
|
|
22919
|
+
file: path17.basename(file),
|
|
23087
22920
|
uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
23088
22921
|
...metadata
|
|
23089
22922
|
}, null, 2)}
|
|
@@ -23102,7 +22935,7 @@ function readPositiveIntegerEnv2(name, fallback) {
|
|
|
23102
22935
|
|
|
23103
22936
|
// src/computerMigrationGuard.ts
|
|
23104
22937
|
import { existsSync as existsSync9, readdirSync as readdirSync6, readFileSync as readFileSync9 } from "fs";
|
|
23105
|
-
import
|
|
22938
|
+
import path18 from "path";
|
|
23106
22939
|
|
|
23107
22940
|
// src/legacySupervisor.ts
|
|
23108
22941
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
@@ -23289,7 +23122,7 @@ function daemonApiKeyFingerprint(apiKey) {
|
|
|
23289
23122
|
return getDaemonMachineLockId(apiKey).slice("machine-".length);
|
|
23290
23123
|
}
|
|
23291
23124
|
function findAdoptedComputerForLegacyFingerprint(slockHome, legacyApiKeyFingerprint) {
|
|
23292
|
-
const serversDir =
|
|
23125
|
+
const serversDir = path18.join(slockHome, "computer", "servers");
|
|
23293
23126
|
if (!existsSync9(serversDir)) return null;
|
|
23294
23127
|
let serverDirs;
|
|
23295
23128
|
try {
|
|
@@ -23298,7 +23131,7 @@ function findAdoptedComputerForLegacyFingerprint(slockHome, legacyApiKeyFingerpr
|
|
|
23298
23131
|
return null;
|
|
23299
23132
|
}
|
|
23300
23133
|
for (const serverId of serverDirs) {
|
|
23301
|
-
const attachmentPath =
|
|
23134
|
+
const attachmentPath = path18.join(serversDir, serverId, "runner.state.json");
|
|
23302
23135
|
let raw;
|
|
23303
23136
|
try {
|
|
23304
23137
|
raw = readFileSync9(attachmentPath, "utf8");
|
|
@@ -23849,7 +23682,7 @@ function onceDrain(res) {
|
|
|
23849
23682
|
import { createHash as createHash9 } from "crypto";
|
|
23850
23683
|
import { createReadStream as createReadStream2, createWriteStream } from "fs";
|
|
23851
23684
|
import { lstat as lstat3, mkdir as mkdir3, readlink as readlink2, rm as rm3, symlink } from "fs/promises";
|
|
23852
|
-
import
|
|
23685
|
+
import path20 from "path";
|
|
23853
23686
|
import { Transform } from "stream";
|
|
23854
23687
|
import { pipeline } from "stream/promises";
|
|
23855
23688
|
import { createGunzip, createGzip } from "zlib";
|
|
@@ -23858,8 +23691,8 @@ import { extract, pack } from "tar-stream";
|
|
|
23858
23691
|
// src/agentMigrationExport.ts
|
|
23859
23692
|
import { createHash as createHash8 } from "crypto";
|
|
23860
23693
|
import { createReadStream } from "fs";
|
|
23861
|
-
import { lstat as lstat2, readdir as
|
|
23862
|
-
import
|
|
23694
|
+
import { lstat as lstat2, readdir as readdir4, readFile as readFile3, readlink } from "fs/promises";
|
|
23695
|
+
import path19 from "path";
|
|
23863
23696
|
var AGENT_MIGRATION_BUNDLE_SCHEMA_VERSION = "agent-bundle/v1";
|
|
23864
23697
|
var REGENERABLE_DIRECTORY_NAMES = [
|
|
23865
23698
|
".cache",
|
|
@@ -23883,8 +23716,8 @@ var SECRET_FILE_NAMES = /* @__PURE__ */ new Set([
|
|
|
23883
23716
|
]);
|
|
23884
23717
|
var ENV_KEY_PATTERN = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/;
|
|
23885
23718
|
async function buildAgentMigrationExportManifest(input) {
|
|
23886
|
-
const slockHome =
|
|
23887
|
-
const workspace =
|
|
23719
|
+
const slockHome = path19.resolve(input.slockHome);
|
|
23720
|
+
const workspace = path19.resolve(input.workspacePath ?? path19.join(slockHome, "agents", input.agentId));
|
|
23888
23721
|
const proposedIncludes = normalizeProposalPaths(input.cooperativeManifest?.include, workspace, "include");
|
|
23889
23722
|
const proposedRegenerableExcludes = normalizeProposalPaths(input.cooperativeManifest?.exclude_regenerable, workspace, "exclude_regenerable");
|
|
23890
23723
|
const cleanedProposal = normalizeProposalPaths(input.cooperativeManifest?.cleaned, workspace, "cleaned");
|
|
@@ -23945,10 +23778,10 @@ async function buildAgentMigrationExportManifest(input) {
|
|
|
23945
23778
|
};
|
|
23946
23779
|
}
|
|
23947
23780
|
async function walkWorkspace(root, relativeDir, proposedRegenerableExcludes, state, opts) {
|
|
23948
|
-
const absoluteDir =
|
|
23781
|
+
const absoluteDir = path19.join(root, relativeDir);
|
|
23949
23782
|
let entries;
|
|
23950
23783
|
try {
|
|
23951
|
-
entries = await
|
|
23784
|
+
entries = await readdir4(absoluteDir, { withFileTypes: true });
|
|
23952
23785
|
} catch {
|
|
23953
23786
|
state.unreachable.push({
|
|
23954
23787
|
path: relativeDir || ".",
|
|
@@ -23959,7 +23792,7 @@ async function walkWorkspace(root, relativeDir, proposedRegenerableExcludes, sta
|
|
|
23959
23792
|
}
|
|
23960
23793
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
23961
23794
|
for (const entry of entries) {
|
|
23962
|
-
const relativePath = toPosixPath(
|
|
23795
|
+
const relativePath = toPosixPath(path19.join(relativeDir, entry.name));
|
|
23963
23796
|
if (entry.isDirectory()) {
|
|
23964
23797
|
if (!opts.forceIncludeRegenerable && isRegenerablePath(relativePath)) {
|
|
23965
23798
|
if (state.explicitIncludePaths.has(relativePath)) {
|
|
@@ -23986,7 +23819,7 @@ async function walkWorkspace(root, relativeDir, proposedRegenerableExcludes, sta
|
|
|
23986
23819
|
async function includeWorkspacePath(workspaceRelativePath, state, opts) {
|
|
23987
23820
|
const normalizedRelativePath = normalizeRelativePath(workspaceRelativePath);
|
|
23988
23821
|
if (state.seenWorkspacePaths.has(normalizedRelativePath)) return;
|
|
23989
|
-
const sourcePath =
|
|
23822
|
+
const sourcePath = path19.join(state.workspace, normalizedRelativePath);
|
|
23990
23823
|
let stat5;
|
|
23991
23824
|
try {
|
|
23992
23825
|
stat5 = await lstat2(sourcePath);
|
|
@@ -24003,7 +23836,7 @@ async function includeWorkspacePath(workspaceRelativePath, state, opts) {
|
|
|
24003
23836
|
state.excludedRegenerable.push({
|
|
24004
23837
|
path: normalizedRelativePath,
|
|
24005
23838
|
reason: "cooperative_exclude_regenerable",
|
|
24006
|
-
regenerableHint: `${
|
|
23839
|
+
regenerableHint: `${path19.basename(normalizedRelativePath)} is treated as rebuildable/installable state and is not bundled by default`
|
|
24007
23840
|
});
|
|
24008
23841
|
return;
|
|
24009
23842
|
}
|
|
@@ -24050,8 +23883,8 @@ async function includeWorkspacePath(workspaceRelativePath, state, opts) {
|
|
|
24050
23883
|
async function buildCrossTreeRefs(refs) {
|
|
24051
23884
|
const result = [];
|
|
24052
23885
|
for (const ref of refs) {
|
|
24053
|
-
const sourcePath =
|
|
24054
|
-
const bundlePath = `runtime/${safeBundleSegment(ref.runtime)}/${safeBundleSegment(ref.label)}/${safeBundleSegment(
|
|
23886
|
+
const sourcePath = path19.resolve(ref.path);
|
|
23887
|
+
const bundlePath = `runtime/${safeBundleSegment(ref.runtime)}/${safeBundleSegment(ref.label)}/${safeBundleSegment(path19.basename(sourcePath) || "session")}`;
|
|
24055
23888
|
const entry = {
|
|
24056
23889
|
runtime: ref.runtime,
|
|
24057
23890
|
label: ref.label,
|
|
@@ -24084,7 +23917,7 @@ async function sha256File(filePath) {
|
|
|
24084
23917
|
return hash.digest("hex");
|
|
24085
23918
|
}
|
|
24086
23919
|
async function detectSecretShapes(sourcePath, relativePath) {
|
|
24087
|
-
const basename =
|
|
23920
|
+
const basename = path19.basename(relativePath);
|
|
24088
23921
|
const lowerBasename = basename.toLowerCase();
|
|
24089
23922
|
const shapes = /* @__PURE__ */ new Set();
|
|
24090
23923
|
if (SECRET_FILE_NAMES.has(lowerBasename) || lowerBasename.startsWith(".env.")) {
|
|
@@ -24117,9 +23950,9 @@ function normalizeProposalPaths(paths, workspace, source) {
|
|
|
24117
23950
|
for (const value of paths) {
|
|
24118
23951
|
const trimmed = value.trim();
|
|
24119
23952
|
if (!trimmed) continue;
|
|
24120
|
-
if (
|
|
24121
|
-
const relative =
|
|
24122
|
-
if (relative.startsWith("..") ||
|
|
23953
|
+
if (path19.isAbsolute(trimmed)) {
|
|
23954
|
+
const relative = path19.relative(workspace, trimmed);
|
|
23955
|
+
if (relative.startsWith("..") || path19.isAbsolute(relative)) {
|
|
24123
23956
|
refusals.push({
|
|
24124
23957
|
path: trimmed,
|
|
24125
23958
|
reason: "outside_workspace",
|
|
@@ -24151,8 +23984,8 @@ function normalizeProposalPaths(paths, workspace, source) {
|
|
|
24151
23984
|
return { paths: [...new Set(result)], refusals };
|
|
24152
23985
|
}
|
|
24153
23986
|
function normalizeRelativePath(value) {
|
|
24154
|
-
const normalized =
|
|
24155
|
-
if (!normalized || normalized === "." || normalized.startsWith("..") ||
|
|
23987
|
+
const normalized = path19.normalize(value).replace(/^[\\/]+/, "");
|
|
23988
|
+
if (!normalized || normalized === "." || normalized.startsWith("..") || path19.isAbsolute(normalized)) {
|
|
24156
23989
|
throw new Error(`unsafe migration export path: ${value}`);
|
|
24157
23990
|
}
|
|
24158
23991
|
return toPosixPath(normalized);
|
|
@@ -24171,7 +24004,7 @@ function safeBundleSegment(value) {
|
|
|
24171
24004
|
return value.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "unknown";
|
|
24172
24005
|
}
|
|
24173
24006
|
function toPosixPath(value) {
|
|
24174
|
-
return value.split(
|
|
24007
|
+
return value.split(path19.sep).join("/");
|
|
24175
24008
|
}
|
|
24176
24009
|
function sortBundleEntries(entries) {
|
|
24177
24010
|
return [...entries].sort((a, b) => a.bundlePath.localeCompare(b.bundlePath));
|
|
@@ -24200,7 +24033,7 @@ var AgentMigrationObjectStoreBundleTooLargeError = class extends Error {
|
|
|
24200
24033
|
};
|
|
24201
24034
|
async function buildAgentMigrationObjectStoreBundle(input) {
|
|
24202
24035
|
assertPositiveMaxBytes(input.maxBytes);
|
|
24203
|
-
const workspacePath =
|
|
24036
|
+
const workspacePath = path20.resolve(input.workspacePath);
|
|
24204
24037
|
const manifest = await buildAgentMigrationExportManifest({
|
|
24205
24038
|
agentId: input.agentId,
|
|
24206
24039
|
slockHome: input.slockHome,
|
|
@@ -24233,8 +24066,8 @@ async function buildAgentMigrationObjectStoreBundle(input) {
|
|
|
24233
24066
|
}
|
|
24234
24067
|
async function stageAgentMigrationObjectStoreBundle(input) {
|
|
24235
24068
|
assertPositiveMaxBytes(input.maxBytes);
|
|
24236
|
-
const stagingWorkspacePath =
|
|
24237
|
-
|
|
24069
|
+
const stagingWorkspacePath = path20.join(
|
|
24070
|
+
path20.resolve(input.slockHome),
|
|
24238
24071
|
"migrations",
|
|
24239
24072
|
sanitizePathSegment(input.sessionId),
|
|
24240
24073
|
"workspace"
|
|
@@ -24306,7 +24139,7 @@ async function writeArchive(tarPack, manifestBuffer, manifest, workspacePath) {
|
|
|
24306
24139
|
throw new Error("MIGRATION_OBJECT_STORE_UNSUPPORTED_ENTRY");
|
|
24307
24140
|
}
|
|
24308
24141
|
const relativePath = normalizeWorkspaceRelativePath(entry.workspaceRelativePath);
|
|
24309
|
-
const sourcePath =
|
|
24142
|
+
const sourcePath = path20.resolve(entry.sourcePath);
|
|
24310
24143
|
const archivePath = `${ARCHIVE_WORKSPACE_PREFIX}${relativePath}`;
|
|
24311
24144
|
if (entry.kind === "symlink") {
|
|
24312
24145
|
await writeBufferedEntry(tarPack, {
|
|
@@ -24356,8 +24189,8 @@ async function handleArchiveEntry(input) {
|
|
|
24356
24189
|
const expected = input.getExpectedEntries().get(relativePath);
|
|
24357
24190
|
if (!expected) throw new Error(`MIGRATION_OBJECT_STORE_ARCHIVE_ENTRY_UNEXPECTED:${relativePath}`);
|
|
24358
24191
|
input.extractedEntries.add(relativePath);
|
|
24359
|
-
const targetPath =
|
|
24360
|
-
await mkdir3(
|
|
24192
|
+
const targetPath = path20.join(input.stagingWorkspacePath, relativePath);
|
|
24193
|
+
await mkdir3(path20.dirname(targetPath), { recursive: true });
|
|
24361
24194
|
if (expected.kind === "symlink") {
|
|
24362
24195
|
if (input.header.type !== "symlink" || input.header.linkname !== expected.linkTarget) {
|
|
24363
24196
|
throw new Error(`MIGRATION_OBJECT_STORE_LINK_TARGET_MISMATCH:${relativePath}`);
|
|
@@ -24474,8 +24307,8 @@ function encodeAccountingPath(value) {
|
|
|
24474
24307
|
return encoded;
|
|
24475
24308
|
}
|
|
24476
24309
|
function normalizeWorkspaceRelativePath(relativePath) {
|
|
24477
|
-
const normalized =
|
|
24478
|
-
if (normalized === "." || normalized.startsWith("../") || normalized === ".." ||
|
|
24310
|
+
const normalized = path20.posix.normalize(relativePath.replaceAll("\\", "/"));
|
|
24311
|
+
if (normalized === "." || normalized.startsWith("../") || normalized === ".." || path20.isAbsolute(normalized)) {
|
|
24479
24312
|
throw new Error("MIGRATION_OBJECT_STORE_UNSAFE_PATH");
|
|
24480
24313
|
}
|
|
24481
24314
|
return normalized;
|
|
@@ -24536,15 +24369,15 @@ function sanitizePathSegment(value) {
|
|
|
24536
24369
|
import { createHash as createHash10 } from "crypto";
|
|
24537
24370
|
import { createReadStream as createReadStream3 } from "fs";
|
|
24538
24371
|
import { access as access2, cp, lstat as lstat4, mkdir as mkdir4, readlink as readlink3, rename, writeFile as writeFile3 } from "fs/promises";
|
|
24539
|
-
import
|
|
24372
|
+
import path21 from "path";
|
|
24540
24373
|
async function buildAgentMigrationAdoptPlan(input) {
|
|
24541
|
-
const slockHome =
|
|
24374
|
+
const slockHome = path21.resolve(input.slockHome);
|
|
24542
24375
|
let manifest;
|
|
24543
24376
|
if (input.sourceKind === "orphan_directory" && !input.manifest) {
|
|
24544
24377
|
manifest = await buildAgentMigrationExportManifest({
|
|
24545
24378
|
agentId: input.agentId,
|
|
24546
24379
|
slockHome,
|
|
24547
|
-
workspacePath:
|
|
24380
|
+
workspacePath: path21.resolve(input.orphanWorkspacePath),
|
|
24548
24381
|
mode: "forensic",
|
|
24549
24382
|
now: input.now
|
|
24550
24383
|
});
|
|
@@ -24557,11 +24390,11 @@ async function buildAgentMigrationAdoptPlan(input) {
|
|
|
24557
24390
|
manifest,
|
|
24558
24391
|
expectedAgentId: input.sourceKind === "orphan_directory" ? input.agentId : manifest.agentId
|
|
24559
24392
|
});
|
|
24560
|
-
const sourceWorkspacePath =
|
|
24393
|
+
const sourceWorkspacePath = path21.resolve(
|
|
24561
24394
|
input.sourceKind === "staged_bundle" ? input.stagingWorkspacePath : input.orphanWorkspacePath
|
|
24562
24395
|
);
|
|
24563
|
-
const finalWorkspacePath =
|
|
24564
|
-
const reportPath =
|
|
24396
|
+
const finalWorkspacePath = path21.resolve(input.finalWorkspacePath ?? path21.join(slockHome, "agents", manifest.agentId));
|
|
24397
|
+
const reportPath = path21.resolve(input.reportPath ?? path21.join(
|
|
24565
24398
|
slockHome,
|
|
24566
24399
|
"migrations",
|
|
24567
24400
|
sanitizePathSegment2(input.generation.grantKey),
|
|
@@ -24686,7 +24519,7 @@ async function verifyManifestFileEntry(sourceWorkspacePath, entry) {
|
|
|
24686
24519
|
throw new Error("MIGRATION_MANIFEST_ENTRY_NOT_WORKSPACE");
|
|
24687
24520
|
}
|
|
24688
24521
|
const relative = normalizeWorkspaceRelativePath2(entry.workspaceRelativePath);
|
|
24689
|
-
const entryPath =
|
|
24522
|
+
const entryPath = path21.join(sourceWorkspacePath, relative);
|
|
24690
24523
|
const info = await lstat4(entryPath).catch(() => null);
|
|
24691
24524
|
if (!info) throw new Error("MIGRATION_MANIFEST_FILE_MISSING");
|
|
24692
24525
|
if (entry.kind === "symlink") {
|
|
@@ -24705,14 +24538,14 @@ async function verifyManifestFileEntry(sourceWorkspacePath, entry) {
|
|
|
24705
24538
|
}
|
|
24706
24539
|
}
|
|
24707
24540
|
function normalizeWorkspaceRelativePath2(relativePath) {
|
|
24708
|
-
const normalized =
|
|
24709
|
-
if (normalized === "." || normalized.startsWith("../") || normalized === ".." ||
|
|
24541
|
+
const normalized = path21.posix.normalize(relativePath.replaceAll("\\", "/"));
|
|
24542
|
+
if (normalized === "." || normalized.startsWith("../") || normalized === ".." || path21.isAbsolute(normalized)) {
|
|
24710
24543
|
throw new Error("MIGRATION_MANIFEST_UNSAFE_PATH");
|
|
24711
24544
|
}
|
|
24712
24545
|
return normalized;
|
|
24713
24546
|
}
|
|
24714
24547
|
async function assertFinalWorkspaceAvailable(sourceWorkspacePath, finalWorkspacePath) {
|
|
24715
|
-
if (
|
|
24548
|
+
if (path21.resolve(sourceWorkspacePath) === path21.resolve(finalWorkspacePath)) return;
|
|
24716
24549
|
try {
|
|
24717
24550
|
await access2(finalWorkspacePath);
|
|
24718
24551
|
throw new Error("MIGRATION_WORKSPACE_ALREADY_EXISTS");
|
|
@@ -24721,9 +24554,9 @@ async function assertFinalWorkspaceAvailable(sourceWorkspacePath, finalWorkspace
|
|
|
24721
24554
|
}
|
|
24722
24555
|
}
|
|
24723
24556
|
async function placeWorkspace(sourceWorkspacePath, finalWorkspacePath) {
|
|
24724
|
-
if (
|
|
24557
|
+
if (path21.resolve(sourceWorkspacePath) === path21.resolve(finalWorkspacePath)) return;
|
|
24725
24558
|
const stagingPath = `${finalWorkspacePath}.migration-${process.pid}-${Date.now()}`;
|
|
24726
|
-
await mkdir4(
|
|
24559
|
+
await mkdir4(path21.dirname(finalWorkspacePath), { recursive: true });
|
|
24727
24560
|
await cp(sourceWorkspacePath, stagingPath, {
|
|
24728
24561
|
recursive: true,
|
|
24729
24562
|
dereference: false,
|
|
@@ -24736,7 +24569,7 @@ async function placeWorkspace(sourceWorkspacePath, finalWorkspacePath) {
|
|
|
24736
24569
|
async function writeArrivalReport(reportPath, report) {
|
|
24737
24570
|
const payload = `${canonicalJson3(report)}
|
|
24738
24571
|
`;
|
|
24739
|
-
await mkdir4(
|
|
24572
|
+
await mkdir4(path21.dirname(reportPath), { recursive: true });
|
|
24740
24573
|
await writeFile3(reportPath, payload, { mode: 384 });
|
|
24741
24574
|
return sha256Buffer3(Buffer.from(payload, "utf8"));
|
|
24742
24575
|
}
|
|
@@ -24767,8 +24600,8 @@ function sanitizePathSegment2(value) {
|
|
|
24767
24600
|
}
|
|
24768
24601
|
|
|
24769
24602
|
// src/secretFile.ts
|
|
24770
|
-
import { chmodSync
|
|
24771
|
-
import
|
|
24603
|
+
import { chmodSync, mkdirSync as mkdirSync7, readFileSync as readFileSync10, writeFileSync as writeFileSync7 } from "fs";
|
|
24604
|
+
import path22 from "path";
|
|
24772
24605
|
function readSecretFileSync(filePath) {
|
|
24773
24606
|
return readFileSync10(filePath, "utf8").trim();
|
|
24774
24607
|
}
|
|
@@ -24861,6 +24694,17 @@ var DAEMON_CORE_TRACE_ATTR_CONTRACTS = {
|
|
|
24861
24694
|
},
|
|
24862
24695
|
endAttrs: ["outcome", "models_count", "default_model_present", "verified_as", "error_class"]
|
|
24863
24696
|
},
|
|
24697
|
+
// task #510: per-prompt span. `prompts_in_flight` is the cross-agent concurrency
|
|
24698
|
+
// observable — under the old process-env-patch lock it could never exceed 1
|
|
24699
|
+
// (every Pi prompt serialized process-wide); > 1 proves the queue is gone.
|
|
24700
|
+
// `queued_ms` is the queued -> prompt-start wait that users experienced as the
|
|
24701
|
+
// 60-165s stall.
|
|
24702
|
+
"daemon.pi.prompt": {
|
|
24703
|
+
spanAttrs: ["agentId", "launchId", "runtime", "queued_ms", "duration_ms", "prompts_in_flight_after"],
|
|
24704
|
+
eventAttrs: {
|
|
24705
|
+
"daemon.pi.prompt.start": ["agentId", "queued_ms", "prompts_in_flight"]
|
|
24706
|
+
}
|
|
24707
|
+
},
|
|
24864
24708
|
"daemon.pi.session.create": {
|
|
24865
24709
|
spanAttrs: ["agentId", "launchId", "runtime", "model", "session_id_present", "requested_model"],
|
|
24866
24710
|
eventAttrs: {
|
|
@@ -25041,13 +24885,13 @@ function readDaemonVersion(moduleUrl = import.meta.url) {
|
|
|
25041
24885
|
}
|
|
25042
24886
|
}
|
|
25043
24887
|
function resolveSlockCliPath(moduleUrl = import.meta.url) {
|
|
25044
|
-
const thisDir =
|
|
25045
|
-
const bundledDistPath =
|
|
24888
|
+
const thisDir = path23.dirname(fileURLToPath(moduleUrl));
|
|
24889
|
+
const bundledDistPath = path23.resolve(thisDir, "cli", "index.js");
|
|
25046
24890
|
try {
|
|
25047
24891
|
accessSync(bundledDistPath);
|
|
25048
24892
|
return bundledDistPath;
|
|
25049
24893
|
} catch {
|
|
25050
|
-
const workspaceDistPath =
|
|
24894
|
+
const workspaceDistPath = path23.resolve(thisDir, "..", "..", "cli", "dist", "index.js");
|
|
25051
24895
|
accessSync(workspaceDistPath);
|
|
25052
24896
|
return workspaceDistPath;
|
|
25053
24897
|
}
|
|
@@ -25061,7 +24905,7 @@ function resolveSlockCliPathOrEmpty(moduleUrl = import.meta.url) {
|
|
|
25061
24905
|
}
|
|
25062
24906
|
async function runBundledSlockCli(argv) {
|
|
25063
24907
|
process.argv = [process.execPath, "slock", ...argv];
|
|
25064
|
-
await import("./dist-
|
|
24908
|
+
await import("./dist-ME3NQ5JP.js");
|
|
25065
24909
|
}
|
|
25066
24910
|
function detectRuntimes(tracer = noopTracer) {
|
|
25067
24911
|
const ids = [];
|
|
@@ -25289,7 +25133,7 @@ var DaemonCore = class {
|
|
|
25289
25133
|
}
|
|
25290
25134
|
resolveMachineStateRoot() {
|
|
25291
25135
|
if (this.options.machineStateDir) return this.options.machineStateDir;
|
|
25292
|
-
if (this.options.dataDir) return
|
|
25136
|
+
if (this.options.dataDir) return path23.join(path23.dirname(this.options.dataDir), "machines");
|
|
25293
25137
|
return resolveDefaultMachineStateRoot();
|
|
25294
25138
|
}
|
|
25295
25139
|
shouldEnableLocalTrace() {
|
|
@@ -25317,7 +25161,7 @@ var DaemonCore = class {
|
|
|
25317
25161
|
sinks: [this.localTraceSink]
|
|
25318
25162
|
}));
|
|
25319
25163
|
this.agentManager.setTracer(this.tracer);
|
|
25320
|
-
this.agentManager.setCliTransportTraceDir(
|
|
25164
|
+
this.agentManager.setCliTransportTraceDir(path23.join(machineDir, "traces"));
|
|
25321
25165
|
}
|
|
25322
25166
|
installTraceBundleUploader(machineDir) {
|
|
25323
25167
|
if (!this.shouldEnableLocalTrace()) return;
|
|
@@ -25641,11 +25485,11 @@ var DaemonCore = class {
|
|
|
25641
25485
|
const built = await buildAgentMigrationObjectStoreBundle({
|
|
25642
25486
|
agentId: lease.agentId,
|
|
25643
25487
|
slockHome: this.slockHome,
|
|
25644
|
-
workspacePath:
|
|
25488
|
+
workspacePath: path23.join(this.agentsDataDir, lease.agentId),
|
|
25645
25489
|
maxBytes: lease.maxBytes
|
|
25646
25490
|
});
|
|
25647
|
-
const spoolDirectory = await mkdtemp(
|
|
25648
|
-
const spoolPath =
|
|
25491
|
+
const spoolDirectory = await mkdtemp(path23.join(os8.tmpdir(), "raft-agent-migration-upload-"));
|
|
25492
|
+
const spoolPath = path23.join(spoolDirectory, "bundle.tar.gz");
|
|
25649
25493
|
let archiveBytes = 0;
|
|
25650
25494
|
let uploadStatus = 0;
|
|
25651
25495
|
try {
|
|
@@ -25708,7 +25552,7 @@ var DaemonCore = class {
|
|
|
25708
25552
|
sourceKind: "staged_bundle",
|
|
25709
25553
|
slockHome: this.slockHome,
|
|
25710
25554
|
stagingWorkspacePath: staged.stagingWorkspacePath,
|
|
25711
|
-
finalWorkspacePath:
|
|
25555
|
+
finalWorkspacePath: path23.join(this.agentsDataDir, lease.agentId),
|
|
25712
25556
|
manifest: staged.manifest,
|
|
25713
25557
|
manifestSha256: staged.manifestSha256,
|
|
25714
25558
|
generation: {
|
|
@@ -26430,9 +26274,9 @@ var DaemonCore = class {
|
|
|
26430
26274
|
});
|
|
26431
26275
|
}
|
|
26432
26276
|
emitReadyIfConnected() {
|
|
26433
|
-
if (this.connection.connected) this.emitReady();
|
|
26277
|
+
if (this.connection.connected) void this.emitReady();
|
|
26434
26278
|
}
|
|
26435
|
-
emitReady() {
|
|
26279
|
+
async emitReady() {
|
|
26436
26280
|
const { ids: runtimes, versions: runtimeVersions, diagnostics: runtimeDiagnostics = {} } = this.runtimeDetector();
|
|
26437
26281
|
const runtimeInfo = runtimes.map((id) => runtimeVersions[id] ? `${id} (${runtimeVersions[id]})` : id);
|
|
26438
26282
|
logger.info(`[Daemon] Detected runtimes: ${runtimeInfo.join(", ") || "none"}`);
|
|
@@ -26442,6 +26286,15 @@ var DaemonCore = class {
|
|
|
26442
26286
|
const runningAgentIds = this.agentManager.getRunningAgentIds();
|
|
26443
26287
|
const idleAgentSessions = this.agentManager.getIdleAgentSessionIds();
|
|
26444
26288
|
const runtimeProfileReports = this.agentManager.getAgentRuntimeProfileReports();
|
|
26289
|
+
let lifecycleAcks = this.options.getComputerLifecycleAcks?.() ?? [];
|
|
26290
|
+
if (this.options.getComputerLifecycleReadyAcks) {
|
|
26291
|
+
try {
|
|
26292
|
+
lifecycleAcks = await this.options.getComputerLifecycleReadyAcks();
|
|
26293
|
+
} catch (error) {
|
|
26294
|
+
logger.warn(`[Daemon] Computer lifecycle attestation skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
26295
|
+
lifecycleAcks = [];
|
|
26296
|
+
}
|
|
26297
|
+
}
|
|
26445
26298
|
this.connection.send({
|
|
26446
26299
|
type: "ready",
|
|
26447
26300
|
capabilities: [
|
|
@@ -26458,7 +26311,7 @@ var DaemonCore = class {
|
|
|
26458
26311
|
daemonVersion: this.daemonVersion,
|
|
26459
26312
|
...this.computerVersion ? { computerVersion: this.computerVersion } : {},
|
|
26460
26313
|
migrationTransport: this.getMigrationTransportReady(),
|
|
26461
|
-
...this.options.getComputerLifecycleAcks ? { lifecycleAcks
|
|
26314
|
+
...this.options.getComputerLifecycleAcks || this.options.getComputerLifecycleReadyAcks ? { lifecycleAcks } : {}
|
|
26462
26315
|
});
|
|
26463
26316
|
this.recordDaemonTrace("daemon.ready.sent", {
|
|
26464
26317
|
runtimes_count: runtimes.length,
|
|
@@ -26479,20 +26332,25 @@ var DaemonCore = class {
|
|
|
26479
26332
|
logger.warn(`[Daemon] opencli wrapper refresh skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
26480
26333
|
}
|
|
26481
26334
|
}
|
|
26482
|
-
this.emitReady();
|
|
26335
|
+
void this.emitReady();
|
|
26483
26336
|
const runningAgentIds = this.agentManager.getRunningAgentIds();
|
|
26484
26337
|
const idleAgentSessions = this.agentManager.getIdleAgentSessionIds();
|
|
26485
26338
|
const runtimeProfileReports = this.agentManager.getAgentRuntimeProfileReports();
|
|
26486
26339
|
if (this.options.onComputerUpgradeReconcile) {
|
|
26487
26340
|
void Promise.resolve().then(
|
|
26488
|
-
() => this.options.onComputerUpgradeReconcile(
|
|
26489
|
-
|
|
26490
|
-
|
|
26491
|
-
|
|
26492
|
-
|
|
26493
|
-
|
|
26494
|
-
|
|
26495
|
-
|
|
26341
|
+
() => this.options.onComputerUpgradeReconcile(
|
|
26342
|
+
(done) => {
|
|
26343
|
+
this.connection.send({ type: "computer:upgrade:done", ...done });
|
|
26344
|
+
this.recordDaemonTrace("daemon.computer_upgrade.reconciled", {
|
|
26345
|
+
request_id: done.requestId,
|
|
26346
|
+
ok: done.ok,
|
|
26347
|
+
...done.newVersion ? { new_version: done.newVersion } : {}
|
|
26348
|
+
});
|
|
26349
|
+
},
|
|
26350
|
+
(progress) => {
|
|
26351
|
+
this.connection.send({ type: "computer:upgrade:progress", ...progress });
|
|
26352
|
+
}
|
|
26353
|
+
)
|
|
26496
26354
|
).catch((err) => {
|
|
26497
26355
|
logger.error(
|
|
26498
26356
|
`[Daemon] computer upgrade reconcile failed: ${err instanceof Error ? err.message : String(err)}`
|