@alan-ai-hq/agent-manager-linux-x64 0.1.195 → 0.1.197
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/alan-agent.cjs +1427 -999
- package/alan-holder.cjs +1047 -619
- package/package.json +1 -1
package/alan-holder.cjs
CHANGED
|
@@ -24807,6 +24807,13 @@ var init_agent_message_envelope = __esm({
|
|
|
24807
24807
|
}
|
|
24808
24808
|
});
|
|
24809
24809
|
|
|
24810
|
+
// ../shared/src/agent/memory-repos-prompt.ts
|
|
24811
|
+
var init_memory_repos_prompt = __esm({
|
|
24812
|
+
"../shared/src/agent/memory-repos-prompt.ts"() {
|
|
24813
|
+
"use strict";
|
|
24814
|
+
}
|
|
24815
|
+
});
|
|
24816
|
+
|
|
24810
24817
|
// ../shared/src/agent/pilot-prompt.ts
|
|
24811
24818
|
function splitPilotPrompt(prompt) {
|
|
24812
24819
|
const index = prompt.indexOf(PILOT_LIVE_STATE_HEADING);
|
|
@@ -24831,6 +24838,7 @@ Your brief is your durable memory: the goal, persona, working agreements and the
|
|
|
24831
24838
|
- On your first turn, introduce yourself with a tentative responsibility inferred from your name and any context the person supplied. Treat that inference as a suggestion, not an agreed role. For an ambiguous name such as Alex, ask what they want help with instead of inventing a job.
|
|
24832
24839
|
- Ask one short contextual question per turn, with two or three concrete choices and room for a free-text answer. Begin with responsibility and scope, then naturally explore personality (for example, supportive versus candid and critical), autonomy (propose work versus take initiative), and when to ask permission. Skip questions the person has already answered; do not turn this into a fixed questionnaire.
|
|
24833
24840
|
- For example, a pilot named "Prasad's Manager" could suggest organizing tasks, tracking priorities and blockers, and coordinating with other pilots, then ask which of those to focus on first. Use available team context to make suggestions relevant; do not invent facts about the person's work.
|
|
24841
|
+
- Start your brief with a \`Tagline: <two or three words>\` line naming what you do, such as \`Tagline: Release coordination\`; the person sees it under your name. Keep it current when your role changes.
|
|
24834
24842
|
- Save answers and unresolved questions in your brief as you go with \`update_pilot_brief\`. Clearly distinguish proposed traits from agreed working agreements; do not save your own suggestions as accepted preferences.
|
|
24835
24843
|
- Once the role and working style are clear, summarize the responsibility, personality, autonomy, and permission boundaries in a short proposed agreement and ask whether it feels right. Save the confirmed agreement and keep working from it. Revisit it when preferences change; do not repeat onboarding on every turn.
|
|
24836
24844
|
- When the person gives you a concrete task, start working on it without requiring onboarding or agreement confirmation first. Ask only for essential missing information, and learn optional preferences naturally as you work. A request to start authorizes that task, not unrelated ongoing or recurring work. Autonomy preferences never override tool permissions or required approvals.
|
|
@@ -24851,6 +24859,7 @@ Your brief is your durable memory: the goal, persona, working agreements and the
|
|
|
24851
24859
|
|
|
24852
24860
|
## Talking to the person
|
|
24853
24861
|
|
|
24862
|
+
- Every time you tell someone you will deliver something, use \`record_commitment\` with a due time and close it with \`close_commitment\` once sent.
|
|
24854
24863
|
- Lead with the outcome, then stop: one to three sentences is the default; length must be earned by the task. Report results, not process \u2014 no restating the request, no "Here's what I did", no narrating steps or tools.
|
|
24855
24864
|
- Say only what is new, decided, blocked or needed; drop rejected options and what they already know. When nothing changed, stay silent: a no-op update is worse than none.
|
|
24856
24865
|
- Decide and proceed on reversible work. An \`ask_person\` becomes a "Needs you" entry that stays until they answer, so spend it only on a decision you cannot make; if a sensible reversible default exists, take it and say what you chose. One question, two to four short options with one recommended, a line on why; do not ask again while it is open. A session under you can propose an ask; it reaches the person only after you approve it with \`review_ask\`, so approve one that meets this bar and decline the rest with a reason.
|
|
@@ -25296,6 +25305,8 @@ Choose tools by the evidence or action the request needs, whether the agent runs
|
|
|
25296
25305
|
|
|
25297
25306
|
Git and GitHub: in an Alan cloud sandbox, repositories are already cloned where the context block says, and \`git\` and \`gh\` are already authenticated. Use them for all repository and GitHub work (fetch, commit, push, \`gh pr create/view/edit/checks\`, \`gh issue\`, \`gh api\`); this is the intended path, not a bypass of Alan MCP. Never change git config, remotes, credential helpers or tokens, never print credentials, and never re-clone an existing checkout. Alan links pull requests you open automatically. If git or gh reports \`github_not_connected\`, call \`request_github_connection\` and end the turn; for any other authentication failure, report the exact error as a blocker.
|
|
25298
25307
|
|
|
25308
|
+
For GitHub PR actions, use \`request_github_pr_ready_for_review\`, \`request_github_pr_reviewers\`, \`request_github_pr_branch_update\`, or \`request_github_pr_merge\` instead of executing them with gh or asking the user to do them manually. These tools show a confirmation card; the UI performs the action on Confirm. End your turn and wait for the reply. Do not claim success before the action succeeds.
|
|
25309
|
+
|
|
25299
25310
|
If the cloud environment has no repository and the work needs code, ask which one with slack_ask (a menu from list_repositories with scope connectable) in Slack, or ask in chat; then call add_team_repository, which checks it out and returns its path.
|
|
25300
25311
|
|
|
25301
25312
|
An empty search result is not a permission denial. Continue gathering evidence from relevant permitted sources rather than refusing the request because one source cannot answer. Distinguish observed facts from inference and name remaining evidence gaps.
|
|
@@ -25587,6 +25598,7 @@ var init_agent2 = __esm({
|
|
|
25587
25598
|
init_gated_mcp_tools();
|
|
25588
25599
|
init_generated_images();
|
|
25589
25600
|
init_mcp_config();
|
|
25601
|
+
init_memory_repos_prompt();
|
|
25590
25602
|
init_opencode_zen_entitlement();
|
|
25591
25603
|
init_pilot_prompt();
|
|
25592
25604
|
init_pilot_title();
|
|
@@ -27070,8 +27082,8 @@ function retryNoticeReason(text4) {
|
|
|
27070
27082
|
const kind = classifyProviderTerminalText(trimmed4)?.errorKind;
|
|
27071
27083
|
const known = kind === void 0 ? void 0 : RETRY_REASONS.get(kind);
|
|
27072
27084
|
if (known) return known;
|
|
27073
|
-
const
|
|
27074
|
-
return
|
|
27085
|
+
const plain2 = plainReason(trimmed4);
|
|
27086
|
+
return plain2 === "" ? void 0 : plain2;
|
|
27075
27087
|
}
|
|
27076
27088
|
var RETRY_REASONS, MAX_REASON_CHARS, DEVELOPER_HINT;
|
|
27077
27089
|
var init_retry_reason = __esm({
|
|
@@ -31274,12 +31286,74 @@ var init_catalog = __esm({
|
|
|
31274
31286
|
}
|
|
31275
31287
|
});
|
|
31276
31288
|
|
|
31289
|
+
// ../agent-core/src/providers/alan-code/catalog-cache.ts
|
|
31290
|
+
function cacheFile(directory, access6) {
|
|
31291
|
+
const scope = (0, import_node_crypto9.createHash)("sha256").update(`${access6.apiOrigin}
|
|
31292
|
+
${access6.conversationId}`).digest("hex").slice(0, 24);
|
|
31293
|
+
return (0, import_node_path14.join)(directory, `catalog-${scope}.json`);
|
|
31294
|
+
}
|
|
31295
|
+
function parseStored(text4) {
|
|
31296
|
+
try {
|
|
31297
|
+
const record3 = asRecord(JSON.parse(text4));
|
|
31298
|
+
return typeof record3?.savedAtMs === "number" ? { savedAtMs: record3.savedAtMs, models: record3.models } : void 0;
|
|
31299
|
+
} catch {
|
|
31300
|
+
return void 0;
|
|
31301
|
+
}
|
|
31302
|
+
}
|
|
31303
|
+
async function readCached(file2, nowMs, requestedModel) {
|
|
31304
|
+
const text4 = await (0, import_promises14.readFile)(file2, "utf8").catch(() => void 0);
|
|
31305
|
+
const stored = text4 === void 0 ? void 0 : parseStored(text4);
|
|
31306
|
+
if (stored === void 0 || nowMs - stored.savedAtMs > CATALOG_CACHE_MAX_AGE_MS) return void 0;
|
|
31307
|
+
const models = parseAlanCodeCatalog({ models: stored.models });
|
|
31308
|
+
if (models.length === 0) return void 0;
|
|
31309
|
+
const wanted = requestedModel?.trim();
|
|
31310
|
+
if (wanted && !models.some((model2) => model2.id === stripAlanCodeProviderPrefix(wanted)))
|
|
31311
|
+
return void 0;
|
|
31312
|
+
return models;
|
|
31313
|
+
}
|
|
31314
|
+
async function writeCached(file2, models, nowMs) {
|
|
31315
|
+
await (0, import_promises14.mkdir)((0, import_node_path14.join)(file2, ".."), { recursive: true, mode: 448 });
|
|
31316
|
+
const temporary = `${file2}.${(0, import_node_crypto9.randomUUID)()}.tmp`;
|
|
31317
|
+
await (0, import_promises14.writeFile)(temporary, JSON.stringify({ savedAtMs: nowMs, models }), { mode: 384 });
|
|
31318
|
+
await (0, import_promises14.rename)(temporary, file2);
|
|
31319
|
+
}
|
|
31320
|
+
function cachedAlanCodeCatalog(options) {
|
|
31321
|
+
return async (access6) => {
|
|
31322
|
+
const file2 = cacheFile(options.directory, access6);
|
|
31323
|
+
const refresh = async () => {
|
|
31324
|
+
const models = await options.fetchLive(access6);
|
|
31325
|
+
if (models.length > 0) await writeCached(file2, models, options.clock.now());
|
|
31326
|
+
return models;
|
|
31327
|
+
};
|
|
31328
|
+
const cached2 = await readCached(file2, options.clock.now(), options.requestedModel);
|
|
31329
|
+
if (cached2 === void 0) return refresh();
|
|
31330
|
+
refresh().catch(
|
|
31331
|
+
(error62) => options.log.warn("alan_code.catalog_refresh_failed", {
|
|
31332
|
+
error: error62 instanceof Error ? error62.message : String(error62)
|
|
31333
|
+
})
|
|
31334
|
+
);
|
|
31335
|
+
return cached2;
|
|
31336
|
+
};
|
|
31337
|
+
}
|
|
31338
|
+
var import_node_crypto9, import_promises14, import_node_path14, CATALOG_CACHE_MAX_AGE_MS;
|
|
31339
|
+
var init_catalog_cache = __esm({
|
|
31340
|
+
"../agent-core/src/providers/alan-code/catalog-cache.ts"() {
|
|
31341
|
+
"use strict";
|
|
31342
|
+
import_node_crypto9 = require("node:crypto");
|
|
31343
|
+
import_promises14 = require("node:fs/promises");
|
|
31344
|
+
import_node_path14 = require("node:path");
|
|
31345
|
+
init_kernel2();
|
|
31346
|
+
init_models2();
|
|
31347
|
+
CATALOG_CACHE_MAX_AGE_MS = 24 * 60 * 6e4;
|
|
31348
|
+
}
|
|
31349
|
+
});
|
|
31350
|
+
|
|
31277
31351
|
// ../agent-core/src/providers/alan-code/engine.ts
|
|
31278
31352
|
function alanCodeEngineBinary(platform) {
|
|
31279
31353
|
return platform === "win32" ? "opencode.exe" : "opencode";
|
|
31280
31354
|
}
|
|
31281
31355
|
function packagedAlanCodeEnginePath(bundle, platform) {
|
|
31282
|
-
return (0,
|
|
31356
|
+
return (0, import_node_path15.join)((0, import_node_path15.dirname)(bundle), "..", "engine", alanCodeEngineBinary(platform));
|
|
31283
31357
|
}
|
|
31284
31358
|
function isRunnableFile(path21, platform) {
|
|
31285
31359
|
try {
|
|
@@ -31299,12 +31373,12 @@ function resolveAlanCodeEngine(lookup) {
|
|
|
31299
31373
|
if (packaged !== void 0) return { command: packaged, source: "packaged" };
|
|
31300
31374
|
return { command: ALAN_CODE_ENGINE_COMMAND, source: "path" };
|
|
31301
31375
|
}
|
|
31302
|
-
var import_node_fs14,
|
|
31376
|
+
var import_node_fs14, import_node_path15, ALAN_CODE_ENGINE_PATH_ENV, ALAN_CODE_ENGINE_COMMAND, ALAN_CODE_ENGINE_NAME, WINDOWS_RUNNABLE_EXTENSION;
|
|
31303
31377
|
var init_engine = __esm({
|
|
31304
31378
|
"../agent-core/src/providers/alan-code/engine.ts"() {
|
|
31305
31379
|
"use strict";
|
|
31306
31380
|
import_node_fs14 = require("node:fs");
|
|
31307
|
-
|
|
31381
|
+
import_node_path15 = require("node:path");
|
|
31308
31382
|
ALAN_CODE_ENGINE_PATH_ENV = "ALAN_CODE_ENGINE_PATH";
|
|
31309
31383
|
ALAN_CODE_ENGINE_COMMAND = "opencode";
|
|
31310
31384
|
ALAN_CODE_ENGINE_NAME = {
|
|
@@ -31328,15 +31402,15 @@ var init_code_mode = __esm({
|
|
|
31328
31402
|
|
|
31329
31403
|
// ../agent-core/src/mcp/env-digest.ts
|
|
31330
31404
|
function envDigest(env) {
|
|
31331
|
-
const hash2 = (0,
|
|
31405
|
+
const hash2 = (0, import_node_crypto10.createHash)("sha256");
|
|
31332
31406
|
for (const key of Object.keys(env).sort()) hash2.update(`${key}\0${env[key]}\0`);
|
|
31333
31407
|
return hash2.digest("hex");
|
|
31334
31408
|
}
|
|
31335
|
-
var
|
|
31409
|
+
var import_node_crypto10;
|
|
31336
31410
|
var init_env_digest = __esm({
|
|
31337
31411
|
"../agent-core/src/mcp/env-digest.ts"() {
|
|
31338
31412
|
"use strict";
|
|
31339
|
-
|
|
31413
|
+
import_node_crypto10 = require("node:crypto");
|
|
31340
31414
|
}
|
|
31341
31415
|
});
|
|
31342
31416
|
|
|
@@ -31354,7 +31428,7 @@ function selectExternalMcpServers(spec) {
|
|
|
31354
31428
|
return selected;
|
|
31355
31429
|
}
|
|
31356
31430
|
function headerEnvName(server, header) {
|
|
31357
|
-
const fingerprint = (0,
|
|
31431
|
+
const fingerprint = (0, import_node_crypto11.createHash)("sha256").update(`${server}\0${header}`).digest("hex").slice(0, 12);
|
|
31358
31432
|
return `ALAN_MCP_HEADER_${fingerprint.toUpperCase()}`;
|
|
31359
31433
|
}
|
|
31360
31434
|
function deliverRemote(name, server, env) {
|
|
@@ -31401,11 +31475,11 @@ function planExternalMcpDelivery(spec, cliEnv) {
|
|
|
31401
31475
|
}
|
|
31402
31476
|
return delivery;
|
|
31403
31477
|
}
|
|
31404
|
-
var
|
|
31478
|
+
var import_node_crypto11;
|
|
31405
31479
|
var init_external2 = __esm({
|
|
31406
31480
|
"../agent-core/src/mcp/external.ts"() {
|
|
31407
31481
|
"use strict";
|
|
31408
|
-
|
|
31482
|
+
import_node_crypto11 = require("node:crypto");
|
|
31409
31483
|
init_agent2();
|
|
31410
31484
|
}
|
|
31411
31485
|
});
|
|
@@ -31457,26 +31531,26 @@ var init_names = __esm({
|
|
|
31457
31531
|
|
|
31458
31532
|
// ../agent-core/src/mcp/secret-file.ts
|
|
31459
31533
|
async function writeSecretFile(name, contents) {
|
|
31460
|
-
const dir = await (0,
|
|
31461
|
-
const path21 = (0,
|
|
31534
|
+
const dir = await (0, import_promises15.mkdtemp)((0, import_node_path16.join)((0, import_node_os2.tmpdir)(), "alan-mcp-"));
|
|
31535
|
+
const path21 = (0, import_node_path16.join)(dir, name);
|
|
31462
31536
|
const remove = async () => {
|
|
31463
|
-
await (0,
|
|
31537
|
+
await (0, import_promises15.rm)(dir, { recursive: true, force: true });
|
|
31464
31538
|
};
|
|
31465
31539
|
try {
|
|
31466
|
-
await (0,
|
|
31540
|
+
await (0, import_promises15.writeFile)(path21, contents, { mode: 384, flag: "wx" });
|
|
31467
31541
|
} catch (error62) {
|
|
31468
31542
|
await remove();
|
|
31469
31543
|
throw error62;
|
|
31470
31544
|
}
|
|
31471
31545
|
return { path: path21, remove, [Symbol.asyncDispose]: remove };
|
|
31472
31546
|
}
|
|
31473
|
-
var
|
|
31547
|
+
var import_promises15, import_node_os2, import_node_path16;
|
|
31474
31548
|
var init_secret_file = __esm({
|
|
31475
31549
|
"../agent-core/src/mcp/secret-file.ts"() {
|
|
31476
31550
|
"use strict";
|
|
31477
|
-
|
|
31551
|
+
import_promises15 = require("node:fs/promises");
|
|
31478
31552
|
import_node_os2 = require("node:os");
|
|
31479
|
-
|
|
31553
|
+
import_node_path16 = require("node:path");
|
|
31480
31554
|
}
|
|
31481
31555
|
});
|
|
31482
31556
|
|
|
@@ -31772,68 +31846,6 @@ async function callWebSearch(query, signal) {
|
|
|
31772
31846
|
}
|
|
31773
31847
|
});
|
|
31774
31848
|
|
|
31775
|
-
// ../agent-core/src/providers/alan-code/catalog-cache.ts
|
|
31776
|
-
function cacheFile(directory, access6) {
|
|
31777
|
-
const scope = (0, import_node_crypto11.createHash)("sha256").update(`${access6.apiOrigin}
|
|
31778
|
-
${access6.conversationId}`).digest("hex").slice(0, 24);
|
|
31779
|
-
return (0, import_node_path16.join)(directory, `catalog-${scope}.json`);
|
|
31780
|
-
}
|
|
31781
|
-
function parseStored(text4) {
|
|
31782
|
-
try {
|
|
31783
|
-
const record3 = asRecord(JSON.parse(text4));
|
|
31784
|
-
return typeof record3?.savedAtMs === "number" ? { savedAtMs: record3.savedAtMs, models: record3.models } : void 0;
|
|
31785
|
-
} catch {
|
|
31786
|
-
return void 0;
|
|
31787
|
-
}
|
|
31788
|
-
}
|
|
31789
|
-
async function readCached(file2, nowMs, requestedModel) {
|
|
31790
|
-
const text4 = await (0, import_promises15.readFile)(file2, "utf8").catch(() => void 0);
|
|
31791
|
-
const stored = text4 === void 0 ? void 0 : parseStored(text4);
|
|
31792
|
-
if (stored === void 0 || nowMs - stored.savedAtMs > CATALOG_CACHE_MAX_AGE_MS) return void 0;
|
|
31793
|
-
const models = parseAlanCodeCatalog({ models: stored.models });
|
|
31794
|
-
if (models.length === 0) return void 0;
|
|
31795
|
-
const wanted = requestedModel?.trim();
|
|
31796
|
-
if (wanted && !models.some((model2) => model2.id === stripAlanCodeProviderPrefix(wanted)))
|
|
31797
|
-
return void 0;
|
|
31798
|
-
return models;
|
|
31799
|
-
}
|
|
31800
|
-
async function writeCached(file2, models, nowMs) {
|
|
31801
|
-
await (0, import_promises15.mkdir)((0, import_node_path16.join)(file2, ".."), { recursive: true, mode: 448 });
|
|
31802
|
-
const temporary = `${file2}.${(0, import_node_crypto11.randomUUID)()}.tmp`;
|
|
31803
|
-
await (0, import_promises15.writeFile)(temporary, JSON.stringify({ savedAtMs: nowMs, models }), { mode: 384 });
|
|
31804
|
-
await (0, import_promises15.rename)(temporary, file2);
|
|
31805
|
-
}
|
|
31806
|
-
function cachedAlanCodeCatalog(options) {
|
|
31807
|
-
return async (access6) => {
|
|
31808
|
-
const file2 = cacheFile(options.directory, access6);
|
|
31809
|
-
const refresh = async () => {
|
|
31810
|
-
const models = await options.fetchLive(access6);
|
|
31811
|
-
if (models.length > 0) await writeCached(file2, models, options.clock.now());
|
|
31812
|
-
return models;
|
|
31813
|
-
};
|
|
31814
|
-
const cached2 = await readCached(file2, options.clock.now(), options.requestedModel);
|
|
31815
|
-
if (cached2 === void 0) return refresh();
|
|
31816
|
-
refresh().catch(
|
|
31817
|
-
(error62) => options.log.warn("alan_code.catalog_refresh_failed", {
|
|
31818
|
-
error: error62 instanceof Error ? error62.message : String(error62)
|
|
31819
|
-
})
|
|
31820
|
-
);
|
|
31821
|
-
return cached2;
|
|
31822
|
-
};
|
|
31823
|
-
}
|
|
31824
|
-
var import_node_crypto11, import_promises15, import_node_path16, CATALOG_CACHE_MAX_AGE_MS;
|
|
31825
|
-
var init_catalog_cache = __esm({
|
|
31826
|
-
"../agent-core/src/providers/alan-code/catalog-cache.ts"() {
|
|
31827
|
-
"use strict";
|
|
31828
|
-
import_node_crypto11 = require("node:crypto");
|
|
31829
|
-
import_promises15 = require("node:fs/promises");
|
|
31830
|
-
import_node_path16 = require("node:path");
|
|
31831
|
-
init_kernel2();
|
|
31832
|
-
init_models2();
|
|
31833
|
-
CATALOG_CACHE_MAX_AGE_MS = 24 * 60 * 6e4;
|
|
31834
|
-
}
|
|
31835
|
-
});
|
|
31836
|
-
|
|
31837
31849
|
// ../agent-core/src/providers/alan-code/engine-dependencies.ts
|
|
31838
31850
|
async function readJsonRecord(file2) {
|
|
31839
31851
|
const text4 = await (0, import_promises16.readFile)(file2, "utf8").catch(() => null);
|
|
@@ -32118,6 +32130,7 @@ var init_alan_code = __esm({
|
|
|
32118
32130
|
"use strict";
|
|
32119
32131
|
init_baseline_prompt_generated();
|
|
32120
32132
|
init_catalog();
|
|
32133
|
+
init_catalog_cache();
|
|
32121
32134
|
init_config();
|
|
32122
32135
|
init_engine();
|
|
32123
32136
|
init_engine_plugin();
|
|
@@ -40501,7 +40514,6 @@ var init_grammar_system = __esm({
|
|
|
40501
40514
|
ALAN_NOTICE_KEY = "alan_tools_unavailable";
|
|
40502
40515
|
ALAN_TOOL_PREFIX = `mcp__${MANAGED_MCP_SERVER_NAME}__`;
|
|
40503
40516
|
ALAN_SERVER_UNREADY_REASON = /* @__PURE__ */ new Map([
|
|
40504
|
-
["starting", "the Alan server was still connecting when the session started"],
|
|
40505
40517
|
["needs_auth", "the Alan server needs sign-in"],
|
|
40506
40518
|
["failed", "the Alan server failed to connect"]
|
|
40507
40519
|
]);
|
|
@@ -43747,11 +43759,11 @@ function isFieldType(value2) {
|
|
|
43747
43759
|
}
|
|
43748
43760
|
function enumChoices(schema) {
|
|
43749
43761
|
const names2 = asArray(schema?.enumNames).map(asString);
|
|
43750
|
-
const
|
|
43762
|
+
const plain2 = asArray(schema?.enum).flatMap((raw, index) => {
|
|
43751
43763
|
const value2 = asString(raw);
|
|
43752
43764
|
return value2 ? [{ label: names2[index] || value2, value: value2 }] : [];
|
|
43753
43765
|
});
|
|
43754
|
-
if (
|
|
43766
|
+
if (plain2.length > 0) return plain2;
|
|
43755
43767
|
return [...asArray(schema?.oneOf), ...asArray(schema?.anyOf)].flatMap(
|
|
43756
43768
|
(raw) => {
|
|
43757
43769
|
const option2 = asRecord(raw);
|
|
@@ -47422,6 +47434,44 @@ var init_alan_code2 = __esm({
|
|
|
47422
47434
|
}
|
|
47423
47435
|
});
|
|
47424
47436
|
|
|
47437
|
+
// src/capabilities/providers/harness-catalog.ts
|
|
47438
|
+
async function liveHarnessModels(access6, requestedModel) {
|
|
47439
|
+
const authorization = await access6.authorization();
|
|
47440
|
+
if (authorization === void 0) return [];
|
|
47441
|
+
const load = cachedAlanCodeCatalog({
|
|
47442
|
+
directory: CATALOG_DIRECTORY,
|
|
47443
|
+
requestedModel,
|
|
47444
|
+
fetchLive: fetchAlanCodeModels,
|
|
47445
|
+
clock: systemClock2,
|
|
47446
|
+
log: silentLog2
|
|
47447
|
+
});
|
|
47448
|
+
return load({
|
|
47449
|
+
apiOrigin: access6.apiOrigin,
|
|
47450
|
+
authorization,
|
|
47451
|
+
conversationId: access6.conversationId
|
|
47452
|
+
}).catch(() => []);
|
|
47453
|
+
}
|
|
47454
|
+
function harnessModelInputModalities(models) {
|
|
47455
|
+
return new Map(models.map((model2) => [model2.id, model2.modalities.input]));
|
|
47456
|
+
}
|
|
47457
|
+
var import_node_os4, import_node_path33, CATALOG_DIRECTORY, silentLog2;
|
|
47458
|
+
var init_harness_catalog = __esm({
|
|
47459
|
+
"src/capabilities/providers/harness-catalog.ts"() {
|
|
47460
|
+
"use strict";
|
|
47461
|
+
import_node_os4 = require("node:os");
|
|
47462
|
+
import_node_path33 = require("node:path");
|
|
47463
|
+
init_src();
|
|
47464
|
+
init_alan_code();
|
|
47465
|
+
CATALOG_DIRECTORY = (0, import_node_path33.join)(alanCodeEngineRoot((0, import_node_os4.homedir)()), "catalog");
|
|
47466
|
+
silentLog2 = {
|
|
47467
|
+
debug: () => void 0,
|
|
47468
|
+
info: () => void 0,
|
|
47469
|
+
warn: () => void 0,
|
|
47470
|
+
error: () => void 0
|
|
47471
|
+
};
|
|
47472
|
+
}
|
|
47473
|
+
});
|
|
47474
|
+
|
|
47425
47475
|
// src/capabilities/providers/managed.ts
|
|
47426
47476
|
async function readManagedProviderVersion(file2, backendKind) {
|
|
47427
47477
|
try {
|
|
@@ -47450,6 +47500,7 @@ var init_providers = __esm({
|
|
|
47450
47500
|
"use strict";
|
|
47451
47501
|
init_alan_code2();
|
|
47452
47502
|
init_commands();
|
|
47503
|
+
init_harness_catalog();
|
|
47453
47504
|
init_managed2();
|
|
47454
47505
|
}
|
|
47455
47506
|
});
|
|
@@ -54797,7 +54848,7 @@ async function inspectSkillPackage(packageRoot, options = {}) {
|
|
|
54797
54848
|
inspectedFiles.sort(comparePackageFiles);
|
|
54798
54849
|
const parsedMetadata = parseSkillMetadata(
|
|
54799
54850
|
inspectedFiles.find((file2) => file2.manifest.path === "SKILL.md")?.bytes,
|
|
54800
|
-
options.expectedName === void 0 ? (0,
|
|
54851
|
+
options.expectedName === void 0 ? (0, import_node_path34.basename)(root) : options.expectedName
|
|
54801
54852
|
);
|
|
54802
54853
|
const manifestFiles = inspectedFiles.map((file2) => file2.manifest);
|
|
54803
54854
|
const diagnostics = [
|
|
@@ -54820,7 +54871,7 @@ async function inspectSkillPackage(packageRoot, options = {}) {
|
|
|
54820
54871
|
};
|
|
54821
54872
|
}
|
|
54822
54873
|
async function requirePackageRoot(packageRoot) {
|
|
54823
|
-
const root = await (0, import_promises28.realpath)((0,
|
|
54874
|
+
const root = await (0, import_promises28.realpath)((0, import_node_path34.resolve)(packageRoot)).catch(() => null);
|
|
54824
54875
|
if (!root) {
|
|
54825
54876
|
throw new SkillPackageError("INVALID_PACKAGE_ROOT", "Skill package directory does not exist");
|
|
54826
54877
|
}
|
|
@@ -54852,7 +54903,7 @@ async function walkPackage(root, ignoredPaths) {
|
|
|
54852
54903
|
async function walkDirectory(directory) {
|
|
54853
54904
|
const entries2 = await (0, import_promises28.readdir)(directory, { withFileTypes: true });
|
|
54854
54905
|
for (const entry2 of entries2) {
|
|
54855
|
-
const absolutePath = (0,
|
|
54906
|
+
const absolutePath = (0, import_node_path34.resolve)(directory, entry2.name);
|
|
54856
54907
|
const normalizedPath = normalizeRelativePath(root, absolutePath);
|
|
54857
54908
|
if (isIgnored(normalizedPath, entry2.name, entry2.isDirectory(), ignored3)) continue;
|
|
54858
54909
|
const entryStat = await (0, import_promises28.lstat)(absolutePath);
|
|
@@ -54924,12 +54975,12 @@ function globToRegExp(pattern) {
|
|
|
54924
54975
|
return new RegExp(`${source}(?:/.*)?$`);
|
|
54925
54976
|
}
|
|
54926
54977
|
function normalizeRelativePath(root, absolutePath) {
|
|
54927
|
-
const nativeRelativePath = (0,
|
|
54928
|
-
if (!nativeRelativePath || nativeRelativePath.startsWith(`..${
|
|
54978
|
+
const nativeRelativePath = (0, import_node_path34.relative)(root, absolutePath);
|
|
54979
|
+
if (!nativeRelativePath || nativeRelativePath.startsWith(`..${import_node_path34.sep}`) || nativeRelativePath === "..") {
|
|
54929
54980
|
throw new SkillPackageError("INVALID_PATH", "Skill package path escapes its root");
|
|
54930
54981
|
}
|
|
54931
|
-
const normalized2 = nativeRelativePath.split(
|
|
54932
|
-
if (normalized2.includes("\0") || normalized2.includes("\uFFFD") ||
|
|
54982
|
+
const normalized2 = nativeRelativePath.split(import_node_path34.sep).join("/").normalize("NFC");
|
|
54983
|
+
if (normalized2.includes("\0") || normalized2.includes("\uFFFD") || import_node_path34.posix.isAbsolute(normalized2)) {
|
|
54933
54984
|
throw new SkillPackageError("INVALID_PATH", `Invalid Skill package path: ${normalized2}`);
|
|
54934
54985
|
}
|
|
54935
54986
|
return normalized2;
|
|
@@ -54976,7 +55027,7 @@ function requireSafeFile(path21, size, normalizedPaths) {
|
|
|
54976
55027
|
}
|
|
54977
55028
|
}
|
|
54978
55029
|
function isSecretPath(path21) {
|
|
54979
|
-
const name =
|
|
55030
|
+
const name = import_node_path34.posix.basename(path21).toLowerCase();
|
|
54980
55031
|
if (SECRET_BASENAMES.has(name) || name.startsWith(".env.")) return true;
|
|
54981
55032
|
return name.endsWith(".private-key.pem") || name.endsWith(".private-key.key");
|
|
54982
55033
|
}
|
|
@@ -54999,11 +55050,11 @@ function classifyFileKind(path21) {
|
|
|
54999
55050
|
if (path21.startsWith("scripts/")) return "script";
|
|
55000
55051
|
if (path21.startsWith("references/")) return "reference";
|
|
55001
55052
|
if (path21.startsWith("assets/")) return "asset";
|
|
55002
|
-
if (/^(?:licen[cs]e|copying|notice)(?:\.|$)/i.test(
|
|
55053
|
+
if (/^(?:licen[cs]e|copying|notice)(?:\.|$)/i.test(import_node_path34.posix.basename(path21))) return "license";
|
|
55003
55054
|
return "other";
|
|
55004
55055
|
}
|
|
55005
55056
|
function classifyPreview(path21, bytes2) {
|
|
55006
|
-
const extension =
|
|
55057
|
+
const extension = import_node_path34.posix.extname(path21).toLowerCase();
|
|
55007
55058
|
if (IMAGE_EXTENSIONS2.has(extension)) return "image";
|
|
55008
55059
|
if (bytes2.includes(0)) return "binary";
|
|
55009
55060
|
if (MARKDOWN_EXTENSIONS.has(extension)) return "markdown";
|
|
@@ -55123,7 +55174,7 @@ function normalizePackageReference(value2) {
|
|
|
55123
55174
|
}
|
|
55124
55175
|
const withoutSuffix = trimmed4.split(/[?#]/, 1)[0];
|
|
55125
55176
|
if (!withoutSuffix) return null;
|
|
55126
|
-
const normalized2 =
|
|
55177
|
+
const normalized2 = import_node_path34.posix.normalize(withoutSuffix).replace(/^\.\//, "").normalize("NFC");
|
|
55127
55178
|
if (normalized2 === ".." || normalized2.startsWith("../")) return null;
|
|
55128
55179
|
return normalized2;
|
|
55129
55180
|
}
|
|
@@ -55162,14 +55213,14 @@ function uint642(value2) {
|
|
|
55162
55213
|
buffer.writeBigUInt64BE(BigInt(value2));
|
|
55163
55214
|
return buffer;
|
|
55164
55215
|
}
|
|
55165
|
-
var import_node_buffer, import_node_crypto24, import_promises28,
|
|
55216
|
+
var import_node_buffer, import_node_crypto24, import_promises28, import_node_path34, import_yaml, TREE_HASH_PREFIX, ALWAYS_IGNORED_DIRECTORIES, ALWAYS_IGNORED_FILES, MARKDOWN_EXTENSIONS, IMAGE_EXTENSIONS2, CODE_EXTENSIONS, TEXT_EXTENSIONS, SECRET_BASENAMES, MARKDOWN_LINK_TARGET;
|
|
55166
55217
|
var init_skill_package = __esm({
|
|
55167
55218
|
"../shared/src/node/skill-package.ts"() {
|
|
55168
55219
|
"use strict";
|
|
55169
55220
|
import_node_buffer = require("node:buffer");
|
|
55170
55221
|
import_node_crypto24 = require("node:crypto");
|
|
55171
55222
|
import_promises28 = require("node:fs/promises");
|
|
55172
|
-
|
|
55223
|
+
import_node_path34 = require("node:path");
|
|
55173
55224
|
import_yaml = __toESM(require_dist(), 1);
|
|
55174
55225
|
init_contracts();
|
|
55175
55226
|
init_domain();
|
|
@@ -55261,21 +55312,21 @@ var init_alan_skill_identity = __esm({
|
|
|
55261
55312
|
|
|
55262
55313
|
// src/capabilities/skills/store.ts
|
|
55263
55314
|
function skillsLayout(stateDir, home) {
|
|
55264
|
-
const root = (0,
|
|
55315
|
+
const root = (0, import_node_path35.join)(stateDir, "skills");
|
|
55265
55316
|
return {
|
|
55266
55317
|
root,
|
|
55267
|
-
installedFile: (0,
|
|
55268
|
-
retiredFile: (0,
|
|
55269
|
-
localFile: (0,
|
|
55270
|
-
versionsDir: (0,
|
|
55271
|
-
tmpDir: (0,
|
|
55272
|
-
pluginDir: (0,
|
|
55273
|
-
pluginSkillsDir: (0,
|
|
55274
|
-
nativeDir: home === void 0 || home === "" ? null : (0,
|
|
55318
|
+
installedFile: (0, import_node_path35.join)(root, "installed.json"),
|
|
55319
|
+
retiredFile: (0, import_node_path35.join)(root, "retired.json"),
|
|
55320
|
+
localFile: (0, import_node_path35.join)(root, "local.json"),
|
|
55321
|
+
versionsDir: (0, import_node_path35.join)(root, "versions"),
|
|
55322
|
+
tmpDir: (0, import_node_path35.join)(root, "tmp"),
|
|
55323
|
+
pluginDir: (0, import_node_path35.join)(root, "alan-plugin"),
|
|
55324
|
+
pluginSkillsDir: (0, import_node_path35.join)(root, "alan-plugin", "skills"),
|
|
55325
|
+
nativeDir: home === void 0 || home === "" ? null : (0, import_node_path35.join)(home, ".agents", "skills")
|
|
55275
55326
|
};
|
|
55276
55327
|
}
|
|
55277
55328
|
function packageDirectory(layout, versionId) {
|
|
55278
|
-
return (0,
|
|
55329
|
+
return (0, import_node_path35.join)(layout.versionsDir, versionId);
|
|
55279
55330
|
}
|
|
55280
55331
|
async function readInstalledSkills(layout) {
|
|
55281
55332
|
const read4 = await readJsonFile(layout.installedFile, installedFileSchema);
|
|
@@ -55303,7 +55354,7 @@ async function resolveLocalSkill(local, invocation) {
|
|
|
55303
55354
|
}
|
|
55304
55355
|
async function hasSkillFile(directory) {
|
|
55305
55356
|
try {
|
|
55306
|
-
return (await (0, import_promises29.stat)((0,
|
|
55357
|
+
return (await (0, import_promises29.stat)((0, import_node_path35.join)(directory, "SKILL.md"))).isFile();
|
|
55307
55358
|
} catch {
|
|
55308
55359
|
return false;
|
|
55309
55360
|
}
|
|
@@ -55321,7 +55372,7 @@ async function isIntact(layout, skill) {
|
|
|
55321
55372
|
async function resolveNativeBuiltIn(layout, invocation, baked) {
|
|
55322
55373
|
const slug = invocation.displayName;
|
|
55323
55374
|
if (layout.nativeDir === null || invocation.skillId !== alanSkillId(slug)) return null;
|
|
55324
|
-
const directory = (0,
|
|
55375
|
+
const directory = (0, import_node_path35.join)(layout.nativeDir, slug);
|
|
55325
55376
|
try {
|
|
55326
55377
|
const inspected = await inspectSkillPackage(directory, { expectedName: slug });
|
|
55327
55378
|
if (baked === "exact" && alanSkillVersionId(slug, inspected.contentHash) !== invocation.versionId)
|
|
@@ -55359,7 +55410,7 @@ async function resolveSkillInvocations(layout, invocations, baked = "any") {
|
|
|
55359
55410
|
}
|
|
55360
55411
|
async function folderCandidates(folder) {
|
|
55361
55412
|
const entries2 = await (0, import_promises29.readdir)(folder, { withFileTypes: true }).catch(() => []);
|
|
55362
|
-
return entries2.filter((entry2) => entry2.isDirectory() || entry2.isSymbolicLink()).map((entry2) => ({ directory: (0,
|
|
55413
|
+
return entries2.filter((entry2) => entry2.isDirectory() || entry2.isSymbolicLink()).map((entry2) => ({ directory: (0, import_node_path35.join)(folder, entry2.name) }));
|
|
55363
55414
|
}
|
|
55364
55415
|
async function nativeCandidates(layout) {
|
|
55365
55416
|
return layout.nativeDir === null ? [] : folderCandidates(layout.nativeDir);
|
|
@@ -55403,12 +55454,12 @@ async function inspectIndexedSkill(directory, contentHash) {
|
|
|
55403
55454
|
return null;
|
|
55404
55455
|
}
|
|
55405
55456
|
}
|
|
55406
|
-
var import_promises29,
|
|
55457
|
+
var import_promises29, import_node_path35, installedFileSchema, localSkillsFileSchema, INDEX_CONCURRENCY;
|
|
55407
55458
|
var init_store = __esm({
|
|
55408
55459
|
"src/capabilities/skills/store.ts"() {
|
|
55409
55460
|
"use strict";
|
|
55410
55461
|
import_promises29 = require("node:fs/promises");
|
|
55411
|
-
|
|
55462
|
+
import_node_path35 = require("node:path");
|
|
55412
55463
|
init_alan_skill_identity();
|
|
55413
55464
|
init_skill_package();
|
|
55414
55465
|
init_runtime_v2();
|
|
@@ -55435,14 +55486,14 @@ var init_store = __esm({
|
|
|
55435
55486
|
|
|
55436
55487
|
// src/capabilities/skills/native-index.ts
|
|
55437
55488
|
function installedSkillFolders(layout) {
|
|
55438
|
-
return (0, import_node_fs20.existsSync)((0,
|
|
55489
|
+
return (0, import_node_fs20.existsSync)((0, import_node_path36.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
|
|
55439
55490
|
}
|
|
55440
|
-
var import_node_fs20,
|
|
55491
|
+
var import_node_fs20, import_node_path36, ALAN_SKILLS_PLUGIN_NAME, PLUGIN_MANIFEST;
|
|
55441
55492
|
var init_native_index = __esm({
|
|
55442
55493
|
"src/capabilities/skills/native-index.ts"() {
|
|
55443
55494
|
"use strict";
|
|
55444
55495
|
import_node_fs20 = require("node:fs");
|
|
55445
|
-
|
|
55496
|
+
import_node_path36 = require("node:path");
|
|
55446
55497
|
ALAN_SKILLS_PLUGIN_NAME = "alan";
|
|
55447
55498
|
PLUGIN_MANIFEST = `${JSON.stringify(
|
|
55448
55499
|
{
|
|
@@ -55473,15 +55524,15 @@ function stripWin32Namespace(path21) {
|
|
|
55473
55524
|
}
|
|
55474
55525
|
function comparablePath(path21, platform) {
|
|
55475
55526
|
if (platform === "win32") {
|
|
55476
|
-
const normalized3 =
|
|
55527
|
+
const normalized3 = import_node_path37.win32.normalize(stripWin32Namespace(path21).replaceAll("/", "\\"));
|
|
55477
55528
|
const trimmed4 = normalized3.length > 3 || !/^[a-z]:\\$/i.test(normalized3) ? normalized3.replace(/\\+$/, "") : normalized3;
|
|
55478
55529
|
return trimmed4.toLowerCase();
|
|
55479
55530
|
}
|
|
55480
|
-
const normalized2 =
|
|
55531
|
+
const normalized2 = import_node_path37.posix.normalize(path21);
|
|
55481
55532
|
return normalized2.length > 1 ? normalized2.replace(/\/+$/, "") : normalized2;
|
|
55482
55533
|
}
|
|
55483
55534
|
function isAbsoluteFor(path21, platform) {
|
|
55484
|
-
return platform === "win32" ?
|
|
55535
|
+
return platform === "win32" ? import_node_path37.win32.isAbsolute(path21) : import_node_path37.posix.isAbsolute(path21);
|
|
55485
55536
|
}
|
|
55486
55537
|
function isWithin(root, candidate, platform) {
|
|
55487
55538
|
const separator = platform === "win32" ? "\\" : "/";
|
|
@@ -55490,11 +55541,11 @@ function isWithin(root, candidate, platform) {
|
|
|
55490
55541
|
if (child === parent) return true;
|
|
55491
55542
|
return child.startsWith(parent.endsWith(separator) ? parent : `${parent}${separator}`);
|
|
55492
55543
|
}
|
|
55493
|
-
var
|
|
55544
|
+
var import_node_path37;
|
|
55494
55545
|
var init_paths2 = __esm({
|
|
55495
55546
|
"src/capabilities/workspace/paths.ts"() {
|
|
55496
55547
|
"use strict";
|
|
55497
|
-
|
|
55548
|
+
import_node_path37 = require("node:path");
|
|
55498
55549
|
}
|
|
55499
55550
|
});
|
|
55500
55551
|
|
|
@@ -55515,8 +55566,8 @@ async function isApprovedPath(path21, roots, platform) {
|
|
|
55515
55566
|
const resolved = await realpathOrNull(path21);
|
|
55516
55567
|
for (const root of roots) {
|
|
55517
55568
|
const resolvedRoot = await realpathOrNull(root) ?? root;
|
|
55518
|
-
const
|
|
55519
|
-
if (
|
|
55569
|
+
const inside = resolved === null ? isWithin(root, path21, platform) || isWithin(resolvedRoot, path21, platform) : isWithin(resolvedRoot, resolved, platform);
|
|
55570
|
+
if (inside) return true;
|
|
55520
55571
|
}
|
|
55521
55572
|
return false;
|
|
55522
55573
|
}
|
|
@@ -55641,7 +55692,7 @@ function openRepositoryLocks(options) {
|
|
|
55641
55692
|
});
|
|
55642
55693
|
const folder = async (commonDir) => {
|
|
55643
55694
|
const key = repositoryLockKey(commonDir, platform);
|
|
55644
|
-
const dir = (0,
|
|
55695
|
+
const dir = (0, import_node_path38.join)(options.dir, key);
|
|
55645
55696
|
await (0, import_promises31.mkdir)(dir, { recursive: true, mode: 448 });
|
|
55646
55697
|
return { key, dir };
|
|
55647
55698
|
};
|
|
@@ -55663,7 +55714,7 @@ function openRepositoryLocks(options) {
|
|
|
55663
55714
|
const entries2 = await (0, import_promises31.readdir)(dir);
|
|
55664
55715
|
for (const entry2 of entries2) {
|
|
55665
55716
|
if (!entry2.startsWith(RUN_FILE_PREFIX)) continue;
|
|
55666
|
-
const holder = await heldBy((0,
|
|
55717
|
+
const holder = await heldBy((0, import_node_path38.join)(dir, entry2));
|
|
55667
55718
|
if (holder !== null) return holder;
|
|
55668
55719
|
}
|
|
55669
55720
|
return null;
|
|
@@ -55671,7 +55722,7 @@ function openRepositoryLocks(options) {
|
|
|
55671
55722
|
return {
|
|
55672
55723
|
tryExclusive: async (commonDir, operationId) => {
|
|
55673
55724
|
const { key, dir } = await folder(commonDir);
|
|
55674
|
-
const path21 = (0,
|
|
55725
|
+
const path21 = (0, import_node_path38.join)(dir, EXCLUSIVE_FILE);
|
|
55675
55726
|
const owner = await self(operationId);
|
|
55676
55727
|
if (!await createExclusive(path21, owner)) {
|
|
55677
55728
|
const holder = await heldBy(path21);
|
|
@@ -55690,10 +55741,10 @@ function openRepositoryLocks(options) {
|
|
|
55690
55741
|
tryShared: async (commonDir, runId) => {
|
|
55691
55742
|
const { key, dir } = await folder(commonDir);
|
|
55692
55743
|
const file2 = `${RUN_FILE_PREFIX}${(0, import_node_crypto26.createHash)("sha256").update(runId).digest("hex").slice(0, 32)}.json`;
|
|
55693
|
-
const path21 = (0,
|
|
55744
|
+
const path21 = (0, import_node_path38.join)(dir, file2);
|
|
55694
55745
|
const owner = await self(runId);
|
|
55695
55746
|
await writeJsonFileAtomic(path21, owner);
|
|
55696
|
-
const operation = await heldBy((0,
|
|
55747
|
+
const operation = await heldBy((0, import_node_path38.join)(dir, EXCLUSIVE_FILE));
|
|
55697
55748
|
if (operation !== null) {
|
|
55698
55749
|
await removeIfSame(path21, owner);
|
|
55699
55750
|
return { kind: "busy", holder: operation };
|
|
@@ -55702,13 +55753,13 @@ function openRepositoryLocks(options) {
|
|
|
55702
55753
|
}
|
|
55703
55754
|
};
|
|
55704
55755
|
}
|
|
55705
|
-
var import_node_crypto26, import_promises31,
|
|
55756
|
+
var import_node_crypto26, import_promises31, import_node_path38, LOCK_FORMAT, EXCLUSIVE_FILE, RUN_FILE_PREFIX, UNREADABLE_GRACE_MS, ownerSchema;
|
|
55706
55757
|
var init_locks = __esm({
|
|
55707
55758
|
"src/capabilities/workspace/locks.ts"() {
|
|
55708
55759
|
"use strict";
|
|
55709
55760
|
import_node_crypto26 = require("node:crypto");
|
|
55710
55761
|
import_promises31 = require("node:fs/promises");
|
|
55711
|
-
|
|
55762
|
+
import_node_path38 = require("node:path");
|
|
55712
55763
|
init_zod();
|
|
55713
55764
|
init_kernel();
|
|
55714
55765
|
init_platform();
|
|
@@ -67732,8 +67783,8 @@ function tailMargin(text4, limits) {
|
|
|
67732
67783
|
const start = Math.max(byteStart, lineStart);
|
|
67733
67784
|
return start === 0 ? text4 : decoder.decode(bytes2.subarray(start));
|
|
67734
67785
|
}
|
|
67735
|
-
function lines(newlines,
|
|
67736
|
-
return newlines + (
|
|
67786
|
+
function lines(newlines, terminated2) {
|
|
67787
|
+
return newlines + (terminated2 ? 0 : 1);
|
|
67737
67788
|
}
|
|
67738
67789
|
function utf8ByteLength(content2) {
|
|
67739
67790
|
if (runtimeBuffer)
|
|
@@ -68179,8 +68230,8 @@ function numberCheck(mode, min, max, xmin, xmax, multipleOf) {
|
|
|
68179
68230
|
return false;
|
|
68180
68231
|
return v >= min && v <= max && v > xmin && v < xmax && (multipleOf === void 0 || isMultiple(v, multipleOf));
|
|
68181
68232
|
};
|
|
68182
|
-
const
|
|
68183
|
-
if (mode === 0 || mode === 3 || multipleOf !== void 0 || !
|
|
68233
|
+
const plain2 = typeof min === "number" && typeof max === "number" && typeof xmin === "number" && typeof xmax === "number";
|
|
68234
|
+
if (mode === 0 || mode === 3 || multipleOf !== void 0 || !plain2)
|
|
68184
68235
|
return check3;
|
|
68185
68236
|
return leaf(mode === 2 ? 10 : 11, new Bounds(min, max, xmin, xmax), check3);
|
|
68186
68237
|
}
|
|
@@ -69366,9 +69417,9 @@ function isolateAnnotations(check3) {
|
|
|
69366
69417
|
return true;
|
|
69367
69418
|
};
|
|
69368
69419
|
}
|
|
69369
|
-
function annotateAll(
|
|
69420
|
+
function annotateAll(plain2, parts3) {
|
|
69370
69421
|
return (v, a) => {
|
|
69371
|
-
if (!
|
|
69422
|
+
if (!plain2(v))
|
|
69372
69423
|
return false;
|
|
69373
69424
|
for (let i = 0; i < parts3.length; i++)
|
|
69374
69425
|
if (!parts3[i](v, a))
|
|
@@ -69900,11 +69951,11 @@ var init_compiler = __esm({
|
|
|
69900
69951
|
else
|
|
69901
69952
|
rest[k] = node2[k];
|
|
69902
69953
|
}
|
|
69903
|
-
const
|
|
69954
|
+
const plain2 = this.plain(rest, base);
|
|
69904
69955
|
const parts3 = [];
|
|
69905
69956
|
if (annotates)
|
|
69906
69957
|
this.annotatingParts(node2, base, parts3);
|
|
69907
|
-
const all = parts3.length === 0 ? ignoreAnnotations(
|
|
69958
|
+
const all = parts3.length === 0 ? ignoreAnnotations(plain2) : annotateAll(plain2, parts3);
|
|
69908
69959
|
const own2 = node2.unevaluatedProperties !== void 0 || node2.unevaluatedItems !== void 0 ? isolateAnnotations(all) : all;
|
|
69909
69960
|
return this.dynamic && this.r.isResource(node2, base) ? scopedAnnotating(this.scope, base, own2) : own2;
|
|
69910
69961
|
}
|
|
@@ -70409,10 +70460,10 @@ function compileCheck(schema, options) {
|
|
|
70409
70460
|
return compiler(schema, options).root();
|
|
70410
70461
|
}
|
|
70411
70462
|
function compiler(schema, options) {
|
|
70412
|
-
const
|
|
70463
|
+
const plain2 = new Compiler(schema, options, false);
|
|
70413
70464
|
try {
|
|
70414
|
-
|
|
70415
|
-
return
|
|
70465
|
+
plain2.root();
|
|
70466
|
+
return plain2;
|
|
70416
70467
|
} catch (error62) {
|
|
70417
70468
|
if (error62 !== RESTART)
|
|
70418
70469
|
throw error62;
|
|
@@ -75055,62 +75106,305 @@ function segmentArguments(segment) {
|
|
|
75055
75106
|
const start = words.findIndex((word) => !ASSIGNMENT2.test(word.text));
|
|
75056
75107
|
return start === -1 ? [] : words.slice(start);
|
|
75057
75108
|
}
|
|
75058
|
-
function inside(cwd, target) {
|
|
75059
|
-
if (target.startsWith("~")) return false;
|
|
75060
|
-
const relative7 = import_node_path38.default.relative(cwd, import_node_path38.default.resolve(cwd, target));
|
|
75061
|
-
return relative7 === "" || !relative7.startsWith("..") && !import_node_path38.default.isAbsolute(relative7);
|
|
75062
|
-
}
|
|
75063
75109
|
function flag(flagText, letters, long) {
|
|
75064
75110
|
if (flagText === long) return true;
|
|
75065
75111
|
return SHORT_FLAG.test(flagText) && letters.test(flagText);
|
|
75066
75112
|
}
|
|
75067
|
-
|
|
75068
|
-
|
|
75069
|
-
|
|
75070
|
-
|
|
75071
|
-
const
|
|
75072
|
-
if (
|
|
75073
|
-
|
|
75113
|
+
function plain(word) {
|
|
75114
|
+
return !word.expands && !word.glob && !word.redirect;
|
|
75115
|
+
}
|
|
75116
|
+
function killTargets(args) {
|
|
75117
|
+
const first = args[0];
|
|
75118
|
+
if (first === void 0 || !plain(first)) return args;
|
|
75119
|
+
if (["-l", "-L", "--list", "--table"].includes(first.text)) return [];
|
|
75120
|
+
let start = 0;
|
|
75121
|
+
if (["-s", "-n", "--signal"].includes(first.text)) start = 2;
|
|
75122
|
+
else if (/^--signal=/.test(first.text) || args.length > 1 && SIGNAL_FLAG.test(first.text))
|
|
75123
|
+
start = 1;
|
|
75124
|
+
if (args[start]?.text === "--") start++;
|
|
75125
|
+
return args.slice(start);
|
|
75126
|
+
}
|
|
75127
|
+
function finderQueries(command, args) {
|
|
75128
|
+
if (!args.every(plain)) return void 0;
|
|
75129
|
+
const words = args.map((word) => word.text);
|
|
75130
|
+
if (command === "pkill") return [words.filter((word) => !SIGNAL_FLAG.test(word))];
|
|
75131
|
+
const names2 = words.filter((word) => !word.startsWith("-"));
|
|
75132
|
+
const flags = words.filter((word) => word.startsWith("-"));
|
|
75133
|
+
if (!flags.every((word) => KILLALL_FLAG.test(word))) return void 0;
|
|
75134
|
+
return names2.map((name) => ["-x", name]);
|
|
75135
|
+
}
|
|
75136
|
+
async function substitutedPids(source, options) {
|
|
75137
|
+
const match = KILL_SUBSTITUTION.exec(source);
|
|
75138
|
+
const inner = match?.[1] ?? match?.[2];
|
|
75139
|
+
if (inner === void 0) return void 0;
|
|
75140
|
+
const parts3 = split(inner);
|
|
75141
|
+
const [only2] = parts3;
|
|
75142
|
+
if (parts3.length !== 1 || only2 === void 0 || only2.unsafe) return void 0;
|
|
75143
|
+
const words = segmentArguments(only2);
|
|
75144
|
+
const [program, ...rest] = words.map((word) => word.text);
|
|
75145
|
+
if (program === void 0 || !words.every(plain)) return void 0;
|
|
75146
|
+
if (program === "jobs" && rest.join(" ") === "-p") return [];
|
|
75147
|
+
if (!FINDERS.has(program)) return void 0;
|
|
75148
|
+
return (options.findPids ?? findPidsWithProcess)(program, rest);
|
|
75149
|
+
}
|
|
75150
|
+
function strangerOf(pids, owned) {
|
|
75151
|
+
return pids.find((pid) => !owned.has(pid));
|
|
75152
|
+
}
|
|
75153
|
+
async function killGuard(segment, args, owned, options) {
|
|
75154
|
+
const substituted = await substitutedPids(segment.source, options);
|
|
75155
|
+
if (substituted !== void 0) {
|
|
75156
|
+
const stranger = strangerOf(substituted, owned);
|
|
75157
|
+
return stranger === void 0 ? void 0 : `kill ${stranger} targets a process this session did not start`;
|
|
75158
|
+
}
|
|
75159
|
+
for (const word of args) {
|
|
75160
|
+
if (OWN_JOB.test(word.text)) continue;
|
|
75161
|
+
if (!plain(word) || !PID.test(word.text)) return "kill needs process IDs this session started";
|
|
75162
|
+
if (!owned.has(Number(word.text)))
|
|
75163
|
+
return `kill ${word.text} targets a process this session did not start`;
|
|
75164
|
+
}
|
|
75165
|
+
return void 0;
|
|
75166
|
+
}
|
|
75167
|
+
async function matchGuard(command, args, owned, options) {
|
|
75168
|
+
const unknown3 = `${command} also signals processes this session did not start`;
|
|
75169
|
+
const queries = finderQueries(command, args);
|
|
75170
|
+
if (queries === void 0) return unknown3;
|
|
75171
|
+
for (const query of queries) {
|
|
75172
|
+
const pids = await (options.findPids ?? findPidsWithProcess)("pgrep", query);
|
|
75173
|
+
if (pids === void 0) return unknown3;
|
|
75174
|
+
const stranger = strangerOf(pids, owned);
|
|
75175
|
+
if (stranger !== void 0)
|
|
75176
|
+
return `${command} matches process ${stranger}, which this session did not start`;
|
|
75177
|
+
}
|
|
75178
|
+
return void 0;
|
|
75179
|
+
}
|
|
75180
|
+
async function killerGuard(command, segment, args, options) {
|
|
75181
|
+
const targets = command === "kill" ? killTargets(args) : args;
|
|
75182
|
+
if (command === "kill") {
|
|
75183
|
+
if (targets.some((word) => GROUP_PID.test(word.text)))
|
|
75184
|
+
return "kill may signal a process group or processes this session did not start";
|
|
75185
|
+
if (targets.length === 0) return void 0;
|
|
75186
|
+
} else if (args.every((word) => word.text.startsWith("-"))) return void 0;
|
|
75074
75187
|
const owned = await options.ownedPids();
|
|
75075
|
-
|
|
75076
|
-
return
|
|
75188
|
+
if (owned === void 0) return void 0;
|
|
75189
|
+
return command === "kill" ? killGuard(segment, targets, owned, options) : matchGuard(command, args, owned, options);
|
|
75190
|
+
}
|
|
75191
|
+
async function realTarget(target, followLast) {
|
|
75192
|
+
const start = followLast ? target : import_node_path39.default.dirname(target);
|
|
75193
|
+
const tail2 = followLast ? "" : import_node_path39.default.basename(target);
|
|
75194
|
+
const missing2 = [];
|
|
75195
|
+
for (let existing = start; ; existing = import_node_path39.default.dirname(existing)) {
|
|
75196
|
+
try {
|
|
75197
|
+
return import_node_path39.default.join(await (0, import_promises32.realpath)(existing), ...missing2.reverse(), tail2);
|
|
75198
|
+
} catch {
|
|
75199
|
+
if (import_node_path39.default.dirname(existing) === existing) return target;
|
|
75200
|
+
missing2.push(import_node_path39.default.basename(existing));
|
|
75201
|
+
}
|
|
75202
|
+
}
|
|
75077
75203
|
}
|
|
75078
|
-
function
|
|
75079
|
-
|
|
75080
|
-
|
|
75081
|
-
|
|
75204
|
+
function tempRoot() {
|
|
75205
|
+
return process.env.TMPDIR?.trim() || import_node_os5.default.tmpdir();
|
|
75206
|
+
}
|
|
75207
|
+
function expandTemp(word, inheritedTemp) {
|
|
75208
|
+
if (!word.expands) return word.text;
|
|
75209
|
+
const temp = inheritedTemp ? process.env.TMPDIR : void 0;
|
|
75210
|
+
const expanded = temp && import_node_path39.default.isAbsolute(temp) && !/[\s*?[]/.test(temp) ? word.text.replace(/^\$(?:TMPDIR|\{TMPDIR\})(?=\/|$)/, () => temp) : word.text;
|
|
75211
|
+
return expanded.includes("$") ? void 0 : expanded;
|
|
75212
|
+
}
|
|
75213
|
+
function within2(root, target) {
|
|
75214
|
+
const relative7 = import_node_path39.default.relative(root, target);
|
|
75215
|
+
return relative7.startsWith("..") || import_node_path39.default.isAbsolute(relative7) ? void 0 : relative7;
|
|
75216
|
+
}
|
|
75217
|
+
async function outsidePath(absolute, followLast, work, tempRoots) {
|
|
75218
|
+
const real = await realTarget(absolute, followLast);
|
|
75219
|
+
if (within2(work, real) !== void 0) return false;
|
|
75220
|
+
for (const root of tempRoots) {
|
|
75221
|
+
const relative7 = within2(await realTarget(root, true), real);
|
|
75222
|
+
const first = relative7?.split(import_node_path39.default.sep)[0] ?? "";
|
|
75223
|
+
if (first !== "" && first !== ".." && !GLOB_CHARS.test(first)) return false;
|
|
75224
|
+
}
|
|
75225
|
+
return true;
|
|
75226
|
+
}
|
|
75227
|
+
async function reachesOutside(word, location, work, tempRoots) {
|
|
75228
|
+
const text4 = expandTemp(word, location.inheritedTemp);
|
|
75229
|
+
if (text4 === void 0 || text4.startsWith("~")) return true;
|
|
75230
|
+
const followLast = /[\\/]$/.test(text4);
|
|
75231
|
+
if (import_node_path39.default.isAbsolute(text4)) return outsidePath(import_node_path39.default.resolve(text4), followLast, work, tempRoots);
|
|
75232
|
+
if (location.directories === void 0) return true;
|
|
75233
|
+
for (const directory of location.directories) {
|
|
75234
|
+
if (await outsidePath(import_node_path39.default.resolve(directory, text4), followLast, work, tempRoots)) return true;
|
|
75235
|
+
}
|
|
75236
|
+
return false;
|
|
75237
|
+
}
|
|
75238
|
+
async function removeGuard(args, location, options) {
|
|
75239
|
+
const endOfOptions = args.findIndex((word) => word.text === "--");
|
|
75240
|
+
const beforeMarker = endOfOptions === -1 ? args : args.slice(0, endOfOptions);
|
|
75241
|
+
const recursive3 = beforeMarker.some((word) => flag(word.text, /[rR]/, "--recursive"));
|
|
75242
|
+
const forced = beforeMarker.some((word) => flag(word.text, /f/, "--force"));
|
|
75082
75243
|
if (!recursive3 || !forced) return void 0;
|
|
75083
|
-
const
|
|
75084
|
-
|
|
75085
|
-
);
|
|
75244
|
+
const targets = beforeMarker.filter((word) => !word.text.startsWith("-"));
|
|
75245
|
+
if (endOfOptions !== -1) targets.push(...args.slice(endOfOptions + 1));
|
|
75246
|
+
const work = await realTarget(options.cwd, true);
|
|
75247
|
+
const roots = [import_node_os5.default.tmpdir(), tempRoot(), "/tmp", "/var/tmp", ...options.tempDirs ?? []];
|
|
75248
|
+
const outside = [];
|
|
75249
|
+
for (const word of targets) {
|
|
75250
|
+
if (await reachesOutside(word, location, work, roots)) outside.push(word);
|
|
75251
|
+
}
|
|
75086
75252
|
return outside.length === 0 ? void 0 : `rm -rf reaches outside the work folder: ${outside.map((word) => word.text).join(" ")}`;
|
|
75087
75253
|
}
|
|
75088
|
-
function installGuard(
|
|
75089
|
-
|
|
75090
|
-
if (
|
|
75091
|
-
|
|
75092
|
-
return args.some((arg) => INSTALLS.has(arg)) ? `${command} installs globally` : void 0;
|
|
75254
|
+
function installGuard(command, args) {
|
|
75255
|
+
if (!PACKAGE_MANAGERS.has(command)) return void 0;
|
|
75256
|
+
if (!args.some((arg) => GLOBAL_FLAGS.has(arg.text))) return void 0;
|
|
75257
|
+
return args.some((arg) => INSTALLS.has(arg.text)) ? `${command} installs globally` : void 0;
|
|
75093
75258
|
}
|
|
75094
|
-
|
|
75095
|
-
|
|
75096
|
-
if (command === void 0) return void 0;
|
|
75097
|
-
if (PRIVILEGED.has(command.text)) return `${command.text} runs the command as another user`;
|
|
75098
|
-
if (KILLERS.has(command.text)) return killerGuard(command.text, args, options);
|
|
75099
|
-
if (command.text === "rm") return removeGuard(segment, options.cwd);
|
|
75100
|
-
return installGuard(segment);
|
|
75259
|
+
function commandName(word) {
|
|
75260
|
+
return import_node_path39.default.posix.basename(word.text).replace(/\.exe$/i, "");
|
|
75101
75261
|
}
|
|
75102
|
-
|
|
75262
|
+
function envCommand(args) {
|
|
75263
|
+
let index = 0;
|
|
75264
|
+
let flags = true;
|
|
75265
|
+
for (const word of args) {
|
|
75266
|
+
if (!plain(word)) return null;
|
|
75267
|
+
if (flags && word.text === "--") flags = false;
|
|
75268
|
+
else if (flags && ["-", "-i", "--ignore-environment"].includes(word.text)) {
|
|
75269
|
+
index++;
|
|
75270
|
+
continue;
|
|
75271
|
+
} else if (!ASSIGNMENT2.test(word.text)) {
|
|
75272
|
+
return flags && word.text.startsWith("-") ? null : args.slice(index);
|
|
75273
|
+
} else flags = false;
|
|
75274
|
+
index++;
|
|
75275
|
+
}
|
|
75276
|
+
return [];
|
|
75277
|
+
}
|
|
75278
|
+
function timeoutCommand(args) {
|
|
75279
|
+
let index = 0;
|
|
75280
|
+
for (; index < args.length; index++) {
|
|
75281
|
+
const word = args[index];
|
|
75282
|
+
if (word === void 0 || !plain(word)) return null;
|
|
75283
|
+
if (word.text === "--") return args.slice(index + 2);
|
|
75284
|
+
if (!word.text.startsWith("-")) return args.slice(index + 1);
|
|
75285
|
+
if (["-k", "-s", "--kill-after", "--signal"].includes(word.text)) index++;
|
|
75286
|
+
else if (!/^(--(foreground|preserve-status|verbose)|--(kill-after|signal)=.+|-v)$/.test(word.text))
|
|
75287
|
+
return null;
|
|
75288
|
+
}
|
|
75289
|
+
return [];
|
|
75290
|
+
}
|
|
75291
|
+
function wrappedArgs(name, args) {
|
|
75292
|
+
const first = args[0]?.text;
|
|
75293
|
+
if (name === "command") {
|
|
75294
|
+
if (first === "-v" || first === "-V") return [];
|
|
75295
|
+
if (first === "-p") return args.slice(args[1]?.text === "--" ? 2 : 1);
|
|
75296
|
+
}
|
|
75297
|
+
if (name === "env") return envCommand(args);
|
|
75298
|
+
if (name === "timeout") return timeoutCommand(args);
|
|
75299
|
+
if (["nohup", "command", "builtin", "exec", "nice", "time"].includes(name)) {
|
|
75300
|
+
if (first === "--") return args.slice(1);
|
|
75301
|
+
return first?.startsWith("-") ? null : args;
|
|
75302
|
+
}
|
|
75303
|
+
return void 0;
|
|
75304
|
+
}
|
|
75305
|
+
function inlineScript(args) {
|
|
75306
|
+
for (const [index, word] of args.entries()) {
|
|
75307
|
+
if (!plain(word)) return null;
|
|
75308
|
+
if (!word.text.startsWith("-") || word.text === "--") return void 0;
|
|
75309
|
+
if (/^-[A-Za-z]*c[A-Za-z]*$/.test(word.text)) return args[index + 1] ?? null;
|
|
75310
|
+
}
|
|
75311
|
+
return void 0;
|
|
75312
|
+
}
|
|
75313
|
+
function indirectTarget(word) {
|
|
75314
|
+
const name = commandName(word);
|
|
75315
|
+
return PRIVILEGED.has(name) || KILLERS.has(name) || SHELLS.has(name) || PACKAGE_MANAGERS.has(name) || name === "rm" || name === "find" || wrappedArgs(name, []) !== void 0;
|
|
75316
|
+
}
|
|
75317
|
+
async function inspectSegment(segment, words, location, options, depth) {
|
|
75318
|
+
let remaining = words;
|
|
75319
|
+
let inheritedTemp = location.inheritedTemp;
|
|
75320
|
+
let command = remaining[0];
|
|
75321
|
+
while (command !== void 0) {
|
|
75322
|
+
const name = commandName(command);
|
|
75323
|
+
const args = remaining.slice(1);
|
|
75324
|
+
const wrapped = wrappedArgs(name, args);
|
|
75325
|
+
if (wrapped === null || !plain(command) && wrapped !== void 0)
|
|
75326
|
+
return `${name} runs a command that could not be checked`;
|
|
75327
|
+
if (wrapped === void 0)
|
|
75328
|
+
return inspectCommand(name, segment, args, { ...location, inheritedTemp }, options, depth);
|
|
75329
|
+
if (name === "env") inheritedTemp = false;
|
|
75330
|
+
remaining = wrapped;
|
|
75331
|
+
command = remaining[0];
|
|
75332
|
+
}
|
|
75333
|
+
return void 0;
|
|
75334
|
+
}
|
|
75335
|
+
async function inspectCommand(name, segment, args, location, options, depth) {
|
|
75336
|
+
if (PRIVILEGED.has(name)) return `${name} runs the command as another user`;
|
|
75337
|
+
if (KILLERS.has(name)) return killerGuard(name, segment, args, options);
|
|
75338
|
+
if (name === "rm") return removeGuard(args, location, options);
|
|
75339
|
+
if (name === "find" && args.some((word) => word.text === "-delete"))
|
|
75340
|
+
return "find -delete removes files recursively";
|
|
75341
|
+
if (name === "xargs" && args.some(indirectTarget))
|
|
75342
|
+
return "xargs supplies arguments to a command that needs approval";
|
|
75343
|
+
if (!SHELLS.has(name)) return installGuard(name, args);
|
|
75344
|
+
const script = inlineScript(args);
|
|
75345
|
+
if (script === void 0) return void 0;
|
|
75346
|
+
if (script === null || !plain(script) || depth >= MAX_INLINE_DEPTH)
|
|
75347
|
+
return `${name} runs a script that could not be checked`;
|
|
75348
|
+
return inspectScript(script.text, location, options, depth + 1);
|
|
75349
|
+
}
|
|
75350
|
+
function directoriesAfter(words, current) {
|
|
75351
|
+
let command = words[0];
|
|
75352
|
+
let args = words.slice(1);
|
|
75353
|
+
while (command?.text === "command" || command?.text === "builtin") {
|
|
75354
|
+
const wrapped = wrappedArgs(command.text, args);
|
|
75355
|
+
command = wrapped?.[0];
|
|
75356
|
+
args = wrapped?.slice(1) ?? [];
|
|
75357
|
+
}
|
|
75358
|
+
if (command?.text === "popd") return void 0;
|
|
75359
|
+
if (command?.text !== "cd" && command?.text !== "pushd") return current;
|
|
75360
|
+
const target = args[args[0]?.text === "--" ? 1 : 0];
|
|
75361
|
+
if (current === void 0 || target === void 0 || !plain(target) || /^[~+-]/.test(target.text))
|
|
75362
|
+
return void 0;
|
|
75363
|
+
const possible = /* @__PURE__ */ new Set([...current, ...current.map((cwd) => import_node_path39.default.resolve(cwd, target.text))]);
|
|
75364
|
+
return possible.size <= MAX_POSSIBLE_DIRECTORIES ? [...possible] : void 0;
|
|
75365
|
+
}
|
|
75366
|
+
function changesTemp(segment) {
|
|
75367
|
+
return segment.words.some((word) => word.text === "TMPDIR" || word.text.startsWith("TMPDIR="));
|
|
75368
|
+
}
|
|
75369
|
+
async function inspectScript(command, start, options, depth) {
|
|
75370
|
+
let { directories, inheritedTemp } = start;
|
|
75103
75371
|
for (const segment of split(command)) {
|
|
75104
|
-
const
|
|
75372
|
+
const ungrouped = segment.source.replace(/^(?:\(\s*|\{\s+)+/, "");
|
|
75373
|
+
if (ungrouped !== segment.source) {
|
|
75374
|
+
directories = void 0;
|
|
75375
|
+
inheritedTemp = false;
|
|
75376
|
+
}
|
|
75377
|
+
const current = ungrouped === segment.source ? segment : split(ungrouped)[0] ?? segment;
|
|
75378
|
+
const words = segmentArguments(current);
|
|
75379
|
+
inheritedTemp &&= !changesTemp(current);
|
|
75380
|
+
const reason = await inspectSegment(
|
|
75381
|
+
current,
|
|
75382
|
+
words,
|
|
75383
|
+
{ directories, inheritedTemp },
|
|
75384
|
+
options,
|
|
75385
|
+
depth
|
|
75386
|
+
);
|
|
75105
75387
|
if (reason !== void 0) return reason;
|
|
75388
|
+
directories = directoriesAfter(words, directories);
|
|
75106
75389
|
}
|
|
75107
75390
|
return void 0;
|
|
75108
75391
|
}
|
|
75109
|
-
|
|
75392
|
+
async function guardedCommand(command, options) {
|
|
75393
|
+
return inspectScript(
|
|
75394
|
+
command,
|
|
75395
|
+
{ directories: [options.workdir ?? options.cwd], inheritedTemp: true },
|
|
75396
|
+
options,
|
|
75397
|
+
0
|
|
75398
|
+
);
|
|
75399
|
+
}
|
|
75400
|
+
var import_node_child_process12, import_promises32, import_node_os5, import_node_path39, PRIVILEGED, KILLERS, PACKAGE_MANAGERS, INSTALLS, GLOBAL_FLAGS, ASSIGNMENT2, PID, GROUP_PID, SHORT_FLAG, SHELLS, MAX_INLINE_DEPTH, MAX_POSSIBLE_DIRECTORIES, FINDERS, OWN_JOB, SIGNAL_FLAG, KILLALL_FLAG, KILL_SUBSTITUTION, GLOB_CHARS, FINDER_TIMEOUT_MS, FINDER_NO_MATCH, findPidsWithProcess;
|
|
75110
75401
|
var init_bash_guard = __esm({
|
|
75111
75402
|
"../alan-engine/src/tools/bash-guard.ts"() {
|
|
75112
75403
|
"use strict";
|
|
75113
|
-
|
|
75404
|
+
import_node_child_process12 = require("node:child_process");
|
|
75405
|
+
import_promises32 = require("node:fs/promises");
|
|
75406
|
+
import_node_os5 = __toESM(require("node:os"), 1);
|
|
75407
|
+
import_node_path39 = __toESM(require("node:path"), 1);
|
|
75114
75408
|
init_bash_approval();
|
|
75115
75409
|
PRIVILEGED = /* @__PURE__ */ new Set(["sudo", "doas"]);
|
|
75116
75410
|
KILLERS = /* @__PURE__ */ new Set(["kill", "pkill", "killall"]);
|
|
@@ -75119,7 +75413,28 @@ var init_bash_guard = __esm({
|
|
|
75119
75413
|
GLOBAL_FLAGS = /* @__PURE__ */ new Set(["-g", "--global", "--location=global", "global"]);
|
|
75120
75414
|
ASSIGNMENT2 = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
75121
75415
|
PID = /^\d+$/;
|
|
75416
|
+
GROUP_PID = /^(?:0+|-\d+)$/;
|
|
75122
75417
|
SHORT_FLAG = /^-[A-Za-z]+$/;
|
|
75418
|
+
SHELLS = /* @__PURE__ */ new Set(["bash", "dash", "ksh", "sh", "zsh"]);
|
|
75419
|
+
MAX_INLINE_DEPTH = 8;
|
|
75420
|
+
MAX_POSSIBLE_DIRECTORIES = 8;
|
|
75421
|
+
FINDERS = /* @__PURE__ */ new Set(["pgrep", "pidof", "lsof"]);
|
|
75422
|
+
OWN_JOB = /^(\$!|\$\{!\}|%.*)$/;
|
|
75423
|
+
SIGNAL_FLAG = /^-(\d+|[A-Z][A-Z0-9]+)$/;
|
|
75424
|
+
KILLALL_FLAG = /^-([qvwe]|\d+|[A-Z][A-Z0-9]+)$/;
|
|
75425
|
+
KILL_SUBSTITUTION = /^\s*kill\s+(?:-\S+\s+)*"?(?:\$\((.+)\)|`([^`]+)`)"?\s*$/;
|
|
75426
|
+
GLOB_CHARS = /[*?[]/;
|
|
75427
|
+
FINDER_TIMEOUT_MS = 2e3;
|
|
75428
|
+
FINDER_NO_MATCH = 1;
|
|
75429
|
+
findPidsWithProcess = (program, args) => new Promise((resolve14) => {
|
|
75430
|
+
(0, import_node_child_process12.execFile)(program, [...args], { timeout: FINDER_TIMEOUT_MS }, (error62, stdout) => {
|
|
75431
|
+
const failed = error62 !== null && error62.code !== FINDER_NO_MATCH;
|
|
75432
|
+
if (failed || typeof stdout !== "string") return resolve14(void 0);
|
|
75433
|
+
resolve14(
|
|
75434
|
+
stdout.split(/\s+/).filter((pid) => PID.test(pid)).map(Number)
|
|
75435
|
+
);
|
|
75436
|
+
});
|
|
75437
|
+
});
|
|
75123
75438
|
}
|
|
75124
75439
|
});
|
|
75125
75440
|
|
|
@@ -75252,19 +75567,19 @@ async function guard(call, run3) {
|
|
|
75252
75567
|
}
|
|
75253
75568
|
}
|
|
75254
75569
|
function resolvePath2(cwd, target) {
|
|
75255
|
-
const expanded = target === "~" || target.startsWith("~/") ?
|
|
75256
|
-
return
|
|
75570
|
+
const expanded = target === "~" || target.startsWith("~/") ? import_node_path40.default.join((0, import_node_os6.homedir)(), target.slice(1)) : target;
|
|
75571
|
+
return import_node_path40.default.isAbsolute(expanded) ? import_node_path40.default.normalize(expanded) : import_node_path40.default.resolve(cwd, expanded);
|
|
75257
75572
|
}
|
|
75258
75573
|
function relativeTitle(cwd, target) {
|
|
75259
|
-
return
|
|
75574
|
+
return import_node_path40.default.relative(cwd, target) || ".";
|
|
75260
75575
|
}
|
|
75261
75576
|
async function canonicalPath(target) {
|
|
75262
75577
|
try {
|
|
75263
|
-
return await (0,
|
|
75578
|
+
return await (0, import_promises33.realpath)(target);
|
|
75264
75579
|
} catch {
|
|
75265
|
-
const parent =
|
|
75580
|
+
const parent = import_node_path40.default.dirname(target);
|
|
75266
75581
|
if (parent === target) return target;
|
|
75267
|
-
return
|
|
75582
|
+
return import_node_path40.default.join(await canonicalPath(parent), import_node_path40.default.basename(target));
|
|
75268
75583
|
}
|
|
75269
75584
|
}
|
|
75270
75585
|
async function withFileLock(target, run3) {
|
|
@@ -75284,13 +75599,13 @@ async function withFileLock(target, run3) {
|
|
|
75284
75599
|
if (queues.get(key) === tail2) queues.delete(key);
|
|
75285
75600
|
}
|
|
75286
75601
|
}
|
|
75287
|
-
var
|
|
75602
|
+
var import_promises33, import_node_os6, import_node_path40, ToolFailure, queues;
|
|
75288
75603
|
var init_shared2 = __esm({
|
|
75289
75604
|
"../alan-engine/src/tools/shared.ts"() {
|
|
75290
75605
|
"use strict";
|
|
75291
|
-
|
|
75292
|
-
|
|
75293
|
-
|
|
75606
|
+
import_promises33 = require("node:fs/promises");
|
|
75607
|
+
import_node_os6 = require("node:os");
|
|
75608
|
+
import_node_path40 = __toESM(require("node:path"), 1);
|
|
75294
75609
|
ToolFailure = class extends Error {
|
|
75295
75610
|
};
|
|
75296
75611
|
queues = /* @__PURE__ */ new Map();
|
|
@@ -75581,30 +75896,33 @@ var init_edit_replace = __esm({
|
|
|
75581
75896
|
});
|
|
75582
75897
|
|
|
75583
75898
|
// ../alan-engine/src/tools/session-processes.ts
|
|
75899
|
+
function registerSessionGroup(pid) {
|
|
75900
|
+
if (pid !== void 0) sessionGroups.add(pid);
|
|
75901
|
+
}
|
|
75584
75902
|
function parseRows(stdout) {
|
|
75585
75903
|
return stdout.split("\n").flatMap((line) => {
|
|
75586
|
-
const [pid, parent] = line.trim().split(/\s+/);
|
|
75587
|
-
if (pid === void 0 || parent === void 0) return [];
|
|
75588
|
-
if (
|
|
75589
|
-
return [{ pid: Number(pid), parent: Number(parent) }];
|
|
75904
|
+
const [pid, parent, group] = line.trim().split(/\s+/);
|
|
75905
|
+
if (pid === void 0 || parent === void 0 || group === void 0) return [];
|
|
75906
|
+
if (!PID2.test(pid) || !PID2.test(parent) || !PID2.test(group)) return [];
|
|
75907
|
+
return [{ pid: Number(pid), parent: Number(parent), group: Number(group) }];
|
|
75590
75908
|
});
|
|
75591
75909
|
}
|
|
75592
75910
|
function processTable() {
|
|
75593
75911
|
return new Promise((resolve14) => {
|
|
75594
|
-
(0,
|
|
75912
|
+
(0, import_node_child_process13.execFile)("ps", ["-Ao", "pid=,ppid=,pgid="], { timeout: PS_TIMEOUT_MS }, (error62, stdout) => {
|
|
75595
75913
|
resolve14(error62 === null && typeof stdout === "string" ? stdout : "");
|
|
75596
75914
|
});
|
|
75597
75915
|
});
|
|
75598
75916
|
}
|
|
75599
|
-
|
|
75917
|
+
function descendantsOf(rows, root) {
|
|
75600
75918
|
const children = /* @__PURE__ */ new Map();
|
|
75601
|
-
for (const row of
|
|
75919
|
+
for (const row of rows) {
|
|
75602
75920
|
const siblings = children.get(row.parent);
|
|
75603
75921
|
if (siblings === void 0) children.set(row.parent, [row.pid]);
|
|
75604
75922
|
else siblings.push(row.pid);
|
|
75605
75923
|
}
|
|
75606
75924
|
const owned = /* @__PURE__ */ new Set();
|
|
75607
|
-
const pending = [
|
|
75925
|
+
const pending = [root];
|
|
75608
75926
|
while (pending.length > 0) {
|
|
75609
75927
|
const pid = pending.pop();
|
|
75610
75928
|
if (pid === void 0) break;
|
|
@@ -75616,12 +75934,27 @@ async function sessionPids() {
|
|
|
75616
75934
|
}
|
|
75617
75935
|
return owned;
|
|
75618
75936
|
}
|
|
75619
|
-
|
|
75937
|
+
async function sessionPids(platform = process.platform) {
|
|
75938
|
+
if (platform === "win32") return void 0;
|
|
75939
|
+
const rows = parseRows(await processTable());
|
|
75940
|
+
const owned = descendantsOf(rows, process.pid);
|
|
75941
|
+
const live = new Set(rows.map((row) => row.group));
|
|
75942
|
+
for (const group of sessionGroups) {
|
|
75943
|
+
if (!live.has(group)) sessionGroups.delete(group);
|
|
75944
|
+
}
|
|
75945
|
+
for (const row of rows) {
|
|
75946
|
+
if (sessionGroups.has(row.group)) owned.add(row.pid);
|
|
75947
|
+
}
|
|
75948
|
+
return owned;
|
|
75949
|
+
}
|
|
75950
|
+
var import_node_child_process13, PS_TIMEOUT_MS, PID2, sessionGroups;
|
|
75620
75951
|
var init_session_processes = __esm({
|
|
75621
75952
|
"../alan-engine/src/tools/session-processes.ts"() {
|
|
75622
75953
|
"use strict";
|
|
75623
|
-
|
|
75954
|
+
import_node_child_process13 = require("node:child_process");
|
|
75624
75955
|
PS_TIMEOUT_MS = 2e3;
|
|
75956
|
+
PID2 = /^\d+$/;
|
|
75957
|
+
sessionGroups = /* @__PURE__ */ new Set();
|
|
75625
75958
|
}
|
|
75626
75959
|
});
|
|
75627
75960
|
|
|
@@ -75796,6 +76129,9 @@ var init_interactions = __esm({
|
|
|
75796
76129
|
await watch.stop();
|
|
75797
76130
|
}
|
|
75798
76131
|
}
|
|
76132
|
+
async withdraw(key) {
|
|
76133
|
+
await this.#withdraw(key);
|
|
76134
|
+
}
|
|
75799
76135
|
async #withdraw(key) {
|
|
75800
76136
|
const toolCallId = await this.#session().commit(async (tx) => {
|
|
75801
76137
|
const doc = await tx.doc(InteractionsDoc);
|
|
@@ -75869,7 +76205,7 @@ function text2(args, key) {
|
|
|
75869
76205
|
return typeof value2 === "string" ? value2 : "";
|
|
75870
76206
|
}
|
|
75871
76207
|
function resolveIn(cwd, target) {
|
|
75872
|
-
return
|
|
76208
|
+
return import_node_path41.default.isAbsolute(target) ? import_node_path41.default.normalize(target) : import_node_path41.default.resolve(cwd, target);
|
|
75873
76209
|
}
|
|
75874
76210
|
function commandMatches(pattern, segment) {
|
|
75875
76211
|
const prefix2 = pattern.endsWith(" *") ? pattern.slice(0, -2) : pattern.trim();
|
|
@@ -75922,7 +76258,7 @@ function replacementsOf(args) {
|
|
|
75922
76258
|
}
|
|
75923
76259
|
async function editDiff(cwd, tool, args) {
|
|
75924
76260
|
const filepath = resolveIn(cwd, text2(args, "filePath"));
|
|
75925
|
-
const before = await (0,
|
|
76261
|
+
const before = await (0, import_promises34.readFile)(filepath, "utf8").catch(() => "");
|
|
75926
76262
|
try {
|
|
75927
76263
|
if (tool === "write") return unifiedDiff(filepath, before, text2(args, "content"));
|
|
75928
76264
|
const edits = replacementsOf(args);
|
|
@@ -75937,7 +76273,21 @@ async function editDiff(cwd, tool, args) {
|
|
|
75937
76273
|
function summaryOf2(cwd, kind, tool, args) {
|
|
75938
76274
|
if (kind === "command") return text2(args, "command");
|
|
75939
76275
|
const filepath = resolveIn(cwd, text2(args, "filePath"));
|
|
75940
|
-
return `${tool} ${
|
|
76276
|
+
return `${tool} ${import_node_path41.default.relative(cwd, filepath) || filepath}`;
|
|
76277
|
+
}
|
|
76278
|
+
async function parkWithin(hub, draft, context, guard2, timeoutMs) {
|
|
76279
|
+
if (guard2 === void 0 || timeoutMs === void 0) return hub.park(draft, context);
|
|
76280
|
+
let expired = false;
|
|
76281
|
+
const timer = setTimeout(() => {
|
|
76282
|
+
expired = true;
|
|
76283
|
+
void hub.withdraw(draft.key);
|
|
76284
|
+
}, timeoutMs);
|
|
76285
|
+
try {
|
|
76286
|
+
const answer2 = await hub.park(draft, context);
|
|
76287
|
+
return expired ? "timeout" : answer2;
|
|
76288
|
+
} finally {
|
|
76289
|
+
clearTimeout(timer);
|
|
76290
|
+
}
|
|
75941
76291
|
}
|
|
75942
76292
|
function createApprovalsExtension(options) {
|
|
75943
76293
|
const { cwd, policy, hub } = options;
|
|
@@ -75952,7 +76302,12 @@ function createApprovalsExtension(options) {
|
|
|
75952
76302
|
if (policy.mode === "deny-writes") return { block: DENY_WRITES_MESSAGE };
|
|
75953
76303
|
const args = jsonObjectOf(copyJson(call.arguments));
|
|
75954
76304
|
const command = text2(args, "command");
|
|
75955
|
-
const
|
|
76305
|
+
const workdir = text2(args, "workdir");
|
|
76306
|
+
const guard2 = kind === "command" ? await guardedCommand(command, {
|
|
76307
|
+
cwd,
|
|
76308
|
+
workdir: workdir ? resolvePath2(cwd, workdir) : cwd,
|
|
76309
|
+
ownedPids: sessionPids
|
|
76310
|
+
}) : void 0;
|
|
75956
76311
|
if (guard2 !== void 0 && policy.guards === "block") {
|
|
75957
76312
|
return { block: `${guard2}. This session cannot ask for approval, so it did not run.` };
|
|
75958
76313
|
}
|
|
@@ -75978,7 +76333,9 @@ function createApprovalsExtension(options) {
|
|
|
75978
76333
|
grants: kind === "edit" ? [EDIT_GRANT] : commandGrants(command),
|
|
75979
76334
|
questions: null
|
|
75980
76335
|
};
|
|
75981
|
-
const answer2 = await hub
|
|
76336
|
+
const answer2 = await parkWithin(hub, draft, context, guard2, policy.parkTimeoutMs);
|
|
76337
|
+
if (answer2 === "timeout")
|
|
76338
|
+
return { block: `${guard2}. Nobody answered in time, so it did not run.` };
|
|
75982
76339
|
if (answer2.kind === "allow") return void 0;
|
|
75983
76340
|
const reason = answer2.kind === "deny" ? answer2.reason : null;
|
|
75984
76341
|
return {
|
|
@@ -75989,12 +76346,12 @@ function createApprovalsExtension(options) {
|
|
|
75989
76346
|
]
|
|
75990
76347
|
});
|
|
75991
76348
|
}
|
|
75992
|
-
var
|
|
76349
|
+
var import_promises34, import_node_path41, APPROVALS_EXTENSION_NAME, EDIT_TOOLS2, COMMAND_TOOLS, EDIT_GRANT, MAX_INPUT_TEXT, DENY_WRITES_MESSAGE;
|
|
75993
76350
|
var init_approvals = __esm({
|
|
75994
76351
|
"../alan-engine/src/engine/approvals.ts"() {
|
|
75995
76352
|
"use strict";
|
|
75996
|
-
|
|
75997
|
-
|
|
76353
|
+
import_promises34 = require("node:fs/promises");
|
|
76354
|
+
import_node_path41 = __toESM(require("node:path"), 1);
|
|
75998
76355
|
init_json2();
|
|
75999
76356
|
init_dist3();
|
|
76000
76357
|
init_bash_approval();
|
|
@@ -76002,6 +76359,7 @@ var init_approvals = __esm({
|
|
|
76002
76359
|
init_diff();
|
|
76003
76360
|
init_edit_replace();
|
|
76004
76361
|
init_session_processes();
|
|
76362
|
+
init_shared2();
|
|
76005
76363
|
init_interactions();
|
|
76006
76364
|
APPROVALS_EXTENSION_NAME = "alan-approvals";
|
|
76007
76365
|
EDIT_TOOLS2 = /* @__PURE__ */ new Set(["write", "edit"]);
|
|
@@ -76017,18 +76375,18 @@ function thinkingLevelForEffort(effort) {
|
|
|
76017
76375
|
if (effort === null || effort === void 0) return null;
|
|
76018
76376
|
return EFFORT_THINKING[effort.trim().toLowerCase()] ?? null;
|
|
76019
76377
|
}
|
|
76020
|
-
function alanCatalogEntry(seed) {
|
|
76378
|
+
function alanCatalogEntry(seed, inputModalities) {
|
|
76021
76379
|
return {
|
|
76022
76380
|
id: seed.id,
|
|
76023
76381
|
name: seed.name,
|
|
76024
76382
|
contextWindow: seed.contextWindow,
|
|
76025
76383
|
maxOutputTokens: seed.maxOutputTokens,
|
|
76026
|
-
inputModalities: ["text"],
|
|
76384
|
+
inputModalities: inputModalities ?? ["text"],
|
|
76027
76385
|
...seed.reasoning === true ? { reasoning: true, thinkingLevelMap: { ...ALAN_REASONING_LEVELS } } : {}
|
|
76028
76386
|
};
|
|
76029
76387
|
}
|
|
76030
|
-
function seedAlanCatalog() {
|
|
76031
|
-
return HARNESS_MODEL_SEEDS.filter((seed) => seed.enabled).toSorted((a, b) => a.sortOrder - b.sortOrder).map(alanCatalogEntry);
|
|
76388
|
+
function seedAlanCatalog(liveModalities) {
|
|
76389
|
+
return HARNESS_MODEL_SEEDS.filter((seed) => seed.enabled).toSorted((a, b) => a.sortOrder - b.sortOrder).map((seed) => alanCatalogEntry(seed, liveModalities?.get(seed.id)));
|
|
76032
76390
|
}
|
|
76033
76391
|
var ALAN_PROVIDER_ID, DEFAULT_ALAN_MODEL_ID, ALAN_REASONING_LEVELS, EFFORT_THINKING;
|
|
76034
76392
|
var init_catalog2 = __esm({
|
|
@@ -84774,7 +85132,7 @@ function processAlive(pid) {
|
|
|
84774
85132
|
}
|
|
84775
85133
|
async function lockOwner(path21) {
|
|
84776
85134
|
try {
|
|
84777
|
-
const pid = Number.parseInt((await (0,
|
|
85135
|
+
const pid = Number.parseInt((await (0, import_promises35.readFile)(path21, "utf8")).trim(), 10);
|
|
84778
85136
|
return Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
84779
85137
|
} catch {
|
|
84780
85138
|
return void 0;
|
|
@@ -84785,12 +85143,12 @@ function isExists(error62) {
|
|
|
84785
85143
|
}
|
|
84786
85144
|
async function createLock(path21) {
|
|
84787
85145
|
const staged = `${path21}.${process.pid}.${(0, import_node_crypto27.randomUUID)().slice(0, 8)}`;
|
|
84788
|
-
await (0,
|
|
85146
|
+
await (0, import_promises35.writeFile)(staged, `${process.pid}
|
|
84789
85147
|
`, "utf8");
|
|
84790
85148
|
try {
|
|
84791
|
-
await (0,
|
|
85149
|
+
await (0, import_promises35.link)(staged, path21);
|
|
84792
85150
|
} finally {
|
|
84793
|
-
await (0,
|
|
85151
|
+
await (0, import_promises35.rm)(staged, { force: true });
|
|
84794
85152
|
}
|
|
84795
85153
|
}
|
|
84796
85154
|
async function acquireSessionLock(path21) {
|
|
@@ -84803,7 +85161,7 @@ async function acquireSessionLock(path21) {
|
|
|
84803
85161
|
release: async () => {
|
|
84804
85162
|
if (released) return;
|
|
84805
85163
|
released = true;
|
|
84806
|
-
await (0,
|
|
85164
|
+
await (0, import_promises35.rm)(path21, { force: true });
|
|
84807
85165
|
}
|
|
84808
85166
|
};
|
|
84809
85167
|
} catch (error62) {
|
|
@@ -84811,17 +85169,17 @@ async function acquireSessionLock(path21) {
|
|
|
84811
85169
|
const owner = await lockOwner(path21);
|
|
84812
85170
|
if (owner !== void 0 && processAlive(owner)) throw new SessionLockedError(path21, owner);
|
|
84813
85171
|
if (attempt > 0) throw new SessionLockedError(path21, owner);
|
|
84814
|
-
await (0,
|
|
85172
|
+
await (0, import_promises35.rm)(path21, { force: true });
|
|
84815
85173
|
}
|
|
84816
85174
|
}
|
|
84817
85175
|
throw new SessionLockedError(path21, void 0);
|
|
84818
85176
|
}
|
|
84819
|
-
var import_node_crypto27,
|
|
85177
|
+
var import_node_crypto27, import_promises35, SessionLockedError;
|
|
84820
85178
|
var init_lock = __esm({
|
|
84821
85179
|
"../alan-engine/src/engine/lock.ts"() {
|
|
84822
85180
|
"use strict";
|
|
84823
85181
|
import_node_crypto27 = require("node:crypto");
|
|
84824
|
-
|
|
85182
|
+
import_promises35 = require("node:fs/promises");
|
|
84825
85183
|
SessionLockedError = class extends Error {
|
|
84826
85184
|
lockPath;
|
|
84827
85185
|
ownerPid;
|
|
@@ -84839,24 +85197,24 @@ var init_lock = __esm({
|
|
|
84839
85197
|
|
|
84840
85198
|
// ../alan-engine/src/engine/rules.ts
|
|
84841
85199
|
async function exists2(target) {
|
|
84842
|
-
return (0,
|
|
85200
|
+
return (0, import_promises36.stat)(target).then(
|
|
84843
85201
|
() => true,
|
|
84844
85202
|
() => false
|
|
84845
85203
|
);
|
|
84846
85204
|
}
|
|
84847
85205
|
async function findGitRoot(cwd) {
|
|
84848
|
-
let dir =
|
|
85206
|
+
let dir = import_node_path42.default.resolve(cwd);
|
|
84849
85207
|
for (; ; ) {
|
|
84850
|
-
if (await exists2(
|
|
84851
|
-
const parent =
|
|
85208
|
+
if (await exists2(import_node_path42.default.join(dir, ".git"))) return dir;
|
|
85209
|
+
const parent = import_node_path42.default.dirname(dir);
|
|
84852
85210
|
if (parent === dir) return void 0;
|
|
84853
85211
|
dir = parent;
|
|
84854
85212
|
}
|
|
84855
85213
|
}
|
|
84856
85214
|
async function ruleFileIn(dir) {
|
|
84857
85215
|
for (const name of RULE_FILE_NAMES) {
|
|
84858
|
-
const file2 =
|
|
84859
|
-
const text4 = await (0,
|
|
85216
|
+
const file2 = import_node_path42.default.join(dir, name);
|
|
85217
|
+
const text4 = await (0, import_promises36.readFile)(file2, "utf8").catch(() => void 0);
|
|
84860
85218
|
if (text4 === void 0 || text4.trim() === "") continue;
|
|
84861
85219
|
const truncatedChars = Math.max(0, text4.length - MAX_RULE_FILE_CHARS);
|
|
84862
85220
|
return { path: file2, content: text4.slice(0, MAX_RULE_FILE_CHARS), truncatedChars };
|
|
@@ -84865,7 +85223,7 @@ async function ruleFileIn(dir) {
|
|
|
84865
85223
|
}
|
|
84866
85224
|
async function loadProjectRules(cwd) {
|
|
84867
85225
|
const root = await findGitRoot(cwd);
|
|
84868
|
-
const dirs = [...new Set([root,
|
|
85226
|
+
const dirs = [...new Set([root, import_node_path42.default.resolve(cwd)].filter((dir) => dir !== void 0))];
|
|
84869
85227
|
const files = [];
|
|
84870
85228
|
for (const dir of dirs) {
|
|
84871
85229
|
const file2 = await ruleFileIn(dir);
|
|
@@ -84894,12 +85252,12 @@ ${file2.content.trimEnd()}${note}`;
|
|
|
84894
85252
|
async function projectInstructions(cwd) {
|
|
84895
85253
|
return renderProjectRules(await loadProjectRules(cwd));
|
|
84896
85254
|
}
|
|
84897
|
-
var
|
|
85255
|
+
var import_promises36, import_node_path42, RULE_FILE_NAMES, MAX_RULE_FILE_CHARS;
|
|
84898
85256
|
var init_rules2 = __esm({
|
|
84899
85257
|
"../alan-engine/src/engine/rules.ts"() {
|
|
84900
85258
|
"use strict";
|
|
84901
|
-
|
|
84902
|
-
|
|
85259
|
+
import_promises36 = require("node:fs/promises");
|
|
85260
|
+
import_node_path42 = __toESM(require("node:path"), 1);
|
|
84903
85261
|
RULE_FILE_NAMES = ["AGENTS.md", "CLAUDE.md"];
|
|
84904
85262
|
MAX_RULE_FILE_CHARS = 16e3;
|
|
84905
85263
|
}
|
|
@@ -85146,14 +85504,14 @@ function sameEntry(a, b) {
|
|
|
85146
85504
|
}
|
|
85147
85505
|
function ancestorsOf(path21) {
|
|
85148
85506
|
const result = [];
|
|
85149
|
-
for (let current = (0,
|
|
85507
|
+
for (let current = (0, import_node_path43.dirname)(path21); ; current = (0, import_node_path43.dirname)(current)) {
|
|
85150
85508
|
result.push(current);
|
|
85151
|
-
if ((0,
|
|
85509
|
+
if ((0, import_node_path43.dirname)(current) === current)
|
|
85152
85510
|
return result;
|
|
85153
85511
|
}
|
|
85154
85512
|
}
|
|
85155
85513
|
function isWithin2(path21, ancestor) {
|
|
85156
|
-
return path21 === ancestor || path21.startsWith(ancestor.endsWith(
|
|
85514
|
+
return path21 === ancestor || path21.startsWith(ancestor.endsWith(import_node_path43.sep) ? ancestor : ancestor + import_node_path43.sep);
|
|
85157
85515
|
}
|
|
85158
85516
|
function excluded(target, name) {
|
|
85159
85517
|
return target.hidden && name.startsWith(".") || target.names.has(name);
|
|
@@ -85163,7 +85521,7 @@ async function anyUnreliable(paths) {
|
|
|
85163
85521
|
return false;
|
|
85164
85522
|
for (const path21 of paths) {
|
|
85165
85523
|
for (const candidate of [path21, ...ancestorsOf(path21)]) {
|
|
85166
|
-
const info = await (0,
|
|
85524
|
+
const info = await (0, import_promises37.statfs)(candidate).catch(() => void 0);
|
|
85167
85525
|
if (info === void 0)
|
|
85168
85526
|
continue;
|
|
85169
85527
|
if (UNRELIABLE_FILE_SYSTEMS.has(info.type))
|
|
@@ -85173,14 +85531,14 @@ async function anyUnreliable(paths) {
|
|
|
85173
85531
|
}
|
|
85174
85532
|
return false;
|
|
85175
85533
|
}
|
|
85176
|
-
var import_node_crypto28, import_node_fs21,
|
|
85534
|
+
var import_node_crypto28, import_node_fs21, import_promises37, import_node_path43, DEBOUNCE_MS, FSEVENTS_SETTLE_MS, DEFAULT_POLL_MS, DEFAULT_MAX_DIRECTORIES, OVERFLOW, HASH_MAX_BYTES, HASH_RECENT_MS, UNRELIABLE_FILE_SYSTEMS, BudgetExceeded, NodeFileWatcher;
|
|
85177
85535
|
var init_node_watch = __esm({
|
|
85178
85536
|
"../../node_modules/@earendil-works/pi-durable/dist/env/node-watch.js"() {
|
|
85179
85537
|
"use strict";
|
|
85180
85538
|
import_node_crypto28 = require("node:crypto");
|
|
85181
85539
|
import_node_fs21 = require("node:fs");
|
|
85182
|
-
|
|
85183
|
-
|
|
85540
|
+
import_promises37 = require("node:fs/promises");
|
|
85541
|
+
import_node_path43 = require("node:path");
|
|
85184
85542
|
init_env();
|
|
85185
85543
|
DEBOUNCE_MS = 50;
|
|
85186
85544
|
FSEVENTS_SETTLE_MS = 500;
|
|
@@ -85392,7 +85750,7 @@ var init_node_watch = __esm({
|
|
|
85392
85750
|
const record3 = async (path21, stats) => {
|
|
85393
85751
|
let hash2;
|
|
85394
85752
|
if (this.#mode === "polling" && stats.isFile() && stats.size <= HASH_MAX_BYTES && Date.now() - stats.mtimeMs < HASH_RECENT_MS) {
|
|
85395
|
-
hash2 = await (0,
|
|
85753
|
+
hash2 = await (0, import_promises37.readFile)(path21).then((content2) => (0, import_node_crypto28.createHash)("sha256").update(content2).digest("hex"), () => void 0);
|
|
85396
85754
|
}
|
|
85397
85755
|
snapshot.set(path21, entryOf(stats, hash2));
|
|
85398
85756
|
};
|
|
@@ -85403,7 +85761,7 @@ var init_node_watch = __esm({
|
|
|
85403
85761
|
traversed.add(key);
|
|
85404
85762
|
let names2;
|
|
85405
85763
|
try {
|
|
85406
|
-
names2 = await (0,
|
|
85764
|
+
names2 = await (0, import_promises37.readdir)(directory);
|
|
85407
85765
|
} catch (error62) {
|
|
85408
85766
|
if (directory === target.path && isDenied(error62))
|
|
85409
85767
|
throw error62;
|
|
@@ -85414,10 +85772,10 @@ var init_node_watch = __esm({
|
|
|
85414
85772
|
for (const name of names2) {
|
|
85415
85773
|
if (excluded(target, name))
|
|
85416
85774
|
continue;
|
|
85417
|
-
const path21 = `${directory.endsWith(
|
|
85775
|
+
const path21 = `${directory.endsWith(import_node_path43.sep) ? directory : directory + import_node_path43.sep}${name}`;
|
|
85418
85776
|
let kind = listed.get(path21);
|
|
85419
85777
|
if (kind === void 0) {
|
|
85420
|
-
const stats = await (0,
|
|
85778
|
+
const stats = await (0, import_promises37.lstat)(path21).catch(() => void 0);
|
|
85421
85779
|
if (stats === void 0)
|
|
85422
85780
|
continue;
|
|
85423
85781
|
kind = entryOf(stats).kind;
|
|
@@ -85435,20 +85793,20 @@ var init_node_watch = __esm({
|
|
|
85435
85793
|
for (const ancestor of ancestorsOf(target.path)) {
|
|
85436
85794
|
if (snapshot.has(ancestor))
|
|
85437
85795
|
continue;
|
|
85438
|
-
const stats2 = await (0,
|
|
85796
|
+
const stats2 = await (0, import_promises37.lstat)(ancestor).catch(() => void 0);
|
|
85439
85797
|
if (stats2 !== void 0)
|
|
85440
85798
|
snapshot.set(ancestor, { ...entryOf(stats2), size: 0, mtimeMs: 0 });
|
|
85441
85799
|
}
|
|
85442
85800
|
let stats;
|
|
85443
85801
|
try {
|
|
85444
|
-
stats = await (0,
|
|
85802
|
+
stats = await (0, import_promises37.stat)(target.path);
|
|
85445
85803
|
} catch (error62) {
|
|
85446
85804
|
if (isDenied(error62))
|
|
85447
85805
|
throw error62;
|
|
85448
85806
|
continue;
|
|
85449
85807
|
}
|
|
85450
85808
|
await record3(target.path, stats);
|
|
85451
|
-
if (stats.isFile() && (await (0,
|
|
85809
|
+
if (stats.isFile() && (await (0, import_promises37.lstat)(target.path).catch(() => void 0))?.isSymbolicLink()) {
|
|
85452
85810
|
linkedFiles.add(target.path);
|
|
85453
85811
|
}
|
|
85454
85812
|
if (stats.isDirectory()) {
|
|
@@ -85532,7 +85890,7 @@ var init_node_watch = __esm({
|
|
|
85532
85890
|
#onEvent(directory, filename) {
|
|
85533
85891
|
if (this.#stopped)
|
|
85534
85892
|
return;
|
|
85535
|
-
const path21 = filename === void 0 ? directory : `${directory.endsWith(
|
|
85893
|
+
const path21 = filename === void 0 ? directory : `${directory.endsWith(import_node_path43.sep) ? directory : directory + import_node_path43.sep}${filename}`;
|
|
85536
85894
|
const relevant = this.#inScope(path21);
|
|
85537
85895
|
if (relevant)
|
|
85538
85896
|
this.#events.add(this.#reported(path21));
|
|
@@ -85552,7 +85910,7 @@ var init_node_watch = __esm({
|
|
|
85552
85910
|
return true;
|
|
85553
85911
|
if (!isWithin2(path21, target.path) || path21 === target.path)
|
|
85554
85912
|
continue;
|
|
85555
|
-
const components = (0,
|
|
85913
|
+
const components = (0, import_node_path43.relative)(target.path, path21).split(import_node_path43.sep);
|
|
85556
85914
|
if (!target.recursive && components.length > 1)
|
|
85557
85915
|
continue;
|
|
85558
85916
|
if (components.some((name) => excluded(target, name)))
|
|
@@ -85581,16 +85939,16 @@ function resolveTimeoutMs(timeout2) {
|
|
|
85581
85939
|
function resolvePath3(cwd, path21) {
|
|
85582
85940
|
let normalized2 = path21;
|
|
85583
85941
|
if (normalized2 === "~") {
|
|
85584
|
-
normalized2 = (0,
|
|
85942
|
+
normalized2 = (0, import_node_os7.homedir)();
|
|
85585
85943
|
} else if (normalized2.startsWith("~/") || process.platform === "win32" && normalized2.startsWith("~\\")) {
|
|
85586
|
-
normalized2 = (0,
|
|
85944
|
+
normalized2 = (0, import_node_path44.join)((0, import_node_os7.homedir)(), normalized2.slice(2));
|
|
85587
85945
|
} else if (normalized2.startsWith("file://")) {
|
|
85588
85946
|
try {
|
|
85589
85947
|
normalized2 = (0, import_node_url5.fileURLToPath)(normalized2);
|
|
85590
85948
|
} catch {
|
|
85591
85949
|
}
|
|
85592
85950
|
}
|
|
85593
|
-
return (0,
|
|
85951
|
+
return (0, import_node_path44.isAbsolute)(normalized2) ? (0, import_node_path44.resolve)(normalized2) : (0, import_node_path44.resolve)(cwd, normalized2);
|
|
85594
85952
|
}
|
|
85595
85953
|
function fileKindFromStats(stats) {
|
|
85596
85954
|
if (stats.isFile())
|
|
@@ -85606,7 +85964,7 @@ function fileInfoFromStats(path21, stats) {
|
|
|
85606
85964
|
if (!kind)
|
|
85607
85965
|
return err(new FileError("invalid", "Unsupported file type", path21));
|
|
85608
85966
|
return ok({
|
|
85609
|
-
name: (0,
|
|
85967
|
+
name: (0, import_node_path44.basename)(path21),
|
|
85610
85968
|
path: path21,
|
|
85611
85969
|
kind,
|
|
85612
85970
|
size: stats.size,
|
|
@@ -85647,7 +86005,7 @@ function abortResult(signal, path21) {
|
|
|
85647
86005
|
}
|
|
85648
86006
|
async function pathExists(path21) {
|
|
85649
86007
|
try {
|
|
85650
|
-
await (0,
|
|
86008
|
+
await (0, import_promises38.access)(path21, import_node_fs22.constants.F_OK);
|
|
85651
86009
|
return true;
|
|
85652
86010
|
} catch {
|
|
85653
86011
|
return false;
|
|
@@ -85658,7 +86016,7 @@ async function runCommand(command, args, timeoutMs) {
|
|
|
85658
86016
|
let stdout = "";
|
|
85659
86017
|
let child;
|
|
85660
86018
|
try {
|
|
85661
|
-
child = (0,
|
|
86019
|
+
child = (0, import_node_child_process14.spawn)(command, args, {
|
|
85662
86020
|
stdio: ["ignore", "pipe", "ignore"],
|
|
85663
86021
|
windowsHide: true
|
|
85664
86022
|
});
|
|
@@ -85692,12 +86050,12 @@ async function findBashOnPath() {
|
|
|
85692
86050
|
return firstMatch && await pathExists(firstMatch) ? firstMatch : null;
|
|
85693
86051
|
}
|
|
85694
86052
|
function isLegacyWslBashPath(path21) {
|
|
85695
|
-
const normalized2 =
|
|
86053
|
+
const normalized2 = import_node_path44.win32.normalize(path21).toLowerCase();
|
|
85696
86054
|
const systemRoot = process.env.SystemRoot;
|
|
85697
86055
|
if (systemRoot) {
|
|
85698
86056
|
if (!/^[a-z]:[\\/]/i.test(systemRoot))
|
|
85699
86057
|
return false;
|
|
85700
|
-
return ["System32", "Sysnative"].some((directory) => normalized2 ===
|
|
86058
|
+
return ["System32", "Sysnative"].some((directory) => normalized2 === import_node_path44.win32.join(systemRoot, directory, "bash.exe").toLowerCase());
|
|
85701
86059
|
}
|
|
85702
86060
|
return /^[a-z]:\\windows\\(?:system32|sysnative)\\bash\.exe$/.test(normalized2);
|
|
85703
86061
|
}
|
|
@@ -85757,7 +86115,7 @@ function getShellEnv(baseEnv, extraEnv, inheritEnv = true) {
|
|
|
85757
86115
|
function killProcessTree2(pid) {
|
|
85758
86116
|
if (process.platform === "win32") {
|
|
85759
86117
|
try {
|
|
85760
|
-
const child = (0,
|
|
86118
|
+
const child = (0, import_node_child_process14.spawn)((0, import_node_path44.join)(process.env.SystemRoot || "C:\\Windows", "System32", "taskkill.exe"), ["/F", "/T", "/PID", String(pid)], {
|
|
85761
86119
|
stdio: "ignore",
|
|
85762
86120
|
detached: true,
|
|
85763
86121
|
windowsHide: true
|
|
@@ -85867,16 +86225,16 @@ function closedResult(what, path21) {
|
|
|
85867
86225
|
function symlinkRefused(path21, cause) {
|
|
85868
86226
|
return new FileError("invalid", "Refusing to follow a symbolic link", path21, cause);
|
|
85869
86227
|
}
|
|
85870
|
-
var
|
|
86228
|
+
var import_node_child_process14, import_node_crypto29, import_node_fs22, import_promises38, import_node_os7, import_node_path44, import_node_url5, MAX_TIMEOUT_MS, MAX_TIMEOUT_SECONDS, EXIT_STDIO_GRACE_MS, SPILL_HIGH_WATER_MARK, BINARY_READ_CHUNK, NodeTextLineReader, NodeBinaryReader, NodeDirReader, NodeExecutionEnv;
|
|
85871
86229
|
var init_node = __esm({
|
|
85872
86230
|
"../../node_modules/@earendil-works/pi-durable/dist/env/node.js"() {
|
|
85873
86231
|
"use strict";
|
|
85874
|
-
|
|
86232
|
+
import_node_child_process14 = require("node:child_process");
|
|
85875
86233
|
import_node_crypto29 = require("node:crypto");
|
|
85876
86234
|
import_node_fs22 = require("node:fs");
|
|
85877
|
-
|
|
85878
|
-
|
|
85879
|
-
|
|
86235
|
+
import_promises38 = require("node:fs/promises");
|
|
86236
|
+
import_node_os7 = require("node:os");
|
|
86237
|
+
import_node_path44 = require("node:path");
|
|
85880
86238
|
import_node_url5 = require("node:url");
|
|
85881
86239
|
init_decode2();
|
|
85882
86240
|
init_env();
|
|
@@ -86068,10 +86426,10 @@ var init_node = __esm({
|
|
|
86068
86426
|
const loopAbort = abortResult(context.abortSignal, this.path);
|
|
86069
86427
|
if (loopAbort)
|
|
86070
86428
|
return loopAbort;
|
|
86071
|
-
const entryPath = (0,
|
|
86429
|
+
const entryPath = (0, import_node_path44.resolve)(this.path, entry2.name);
|
|
86072
86430
|
let stats;
|
|
86073
86431
|
try {
|
|
86074
|
-
stats = await (0,
|
|
86432
|
+
stats = await (0, import_promises38.lstat)(entryPath);
|
|
86075
86433
|
} catch (error62) {
|
|
86076
86434
|
if (isNodeError2(error62) && error62.code === "ENOENT")
|
|
86077
86435
|
continue;
|
|
@@ -86127,7 +86485,7 @@ var init_node = __esm({
|
|
|
86127
86485
|
return ok(resolvePath3(this.cwd, path21));
|
|
86128
86486
|
}
|
|
86129
86487
|
async joinPath(parts3, _context) {
|
|
86130
|
-
return ok((0,
|
|
86488
|
+
return ok((0, import_node_path44.join)(...parts3));
|
|
86131
86489
|
}
|
|
86132
86490
|
async exec(command, options, context) {
|
|
86133
86491
|
const signal = context.abortSignal;
|
|
@@ -86157,7 +86515,7 @@ var init_node = __esm({
|
|
|
86157
86515
|
args = rest;
|
|
86158
86516
|
}
|
|
86159
86517
|
try {
|
|
86160
|
-
await (0,
|
|
86518
|
+
await (0, import_promises38.access)(cwd, import_node_fs22.constants.F_OK);
|
|
86161
86519
|
} catch (error62) {
|
|
86162
86520
|
const cause = toError3(error62);
|
|
86163
86521
|
return err(new ExecutionError("spawn_error", `Working directory does not exist: ${cwd}
|
|
@@ -86275,7 +86633,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86275
86633
|
});
|
|
86276
86634
|
};
|
|
86277
86635
|
try {
|
|
86278
|
-
child = (0,
|
|
86636
|
+
child = (0, import_node_child_process14.spawn)(program, args, {
|
|
86279
86637
|
cwd,
|
|
86280
86638
|
detached: process.platform !== "win32",
|
|
86281
86639
|
env: getShellEnv(this.shellEnv, options?.env, options?.inheritEnv),
|
|
@@ -86347,7 +86705,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86347
86705
|
settle4(err(spillError));
|
|
86348
86706
|
return;
|
|
86349
86707
|
}
|
|
86350
|
-
const exitCode = code ?? (exitSignal ? 128 + (
|
|
86708
|
+
const exitCode = code ?? (exitSignal ? 128 + (import_node_os7.constants.signals[exitSignal] ?? 0) : 1);
|
|
86351
86709
|
settle4(ok({ exitCode, ...spillPath === void 0 ? {} : { spillPath } }));
|
|
86352
86710
|
}, (error62) => settle4(err(new ExecutionError("spawn_error", error62.message, error62))));
|
|
86353
86711
|
});
|
|
@@ -86358,7 +86716,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86358
86716
|
if (aborted2)
|
|
86359
86717
|
return aborted2;
|
|
86360
86718
|
try {
|
|
86361
|
-
const file2 = await (0,
|
|
86719
|
+
const file2 = await (0, import_promises38.open)(resolved, "r");
|
|
86362
86720
|
const afterOpenAbort = abortResult(context.abortSignal, resolved);
|
|
86363
86721
|
if (afterOpenAbort) {
|
|
86364
86722
|
await file2.close().catch(() => void 0);
|
|
@@ -86376,7 +86734,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86376
86734
|
if (aborted2)
|
|
86377
86735
|
return aborted2;
|
|
86378
86736
|
try {
|
|
86379
|
-
return ok(await (0,
|
|
86737
|
+
return ok(await (0, import_promises38.readFile)(resolved, { encoding: "utf8", signal }));
|
|
86380
86738
|
} catch (error62) {
|
|
86381
86739
|
return err(toFileError(error62, resolved));
|
|
86382
86740
|
}
|
|
@@ -86409,7 +86767,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86409
86767
|
if (aborted2)
|
|
86410
86768
|
return aborted2;
|
|
86411
86769
|
try {
|
|
86412
|
-
return ok(await (0,
|
|
86770
|
+
return ok(await (0, import_promises38.readFile)(resolved, { signal }));
|
|
86413
86771
|
} catch (error62) {
|
|
86414
86772
|
return err(toFileError(error62, resolved));
|
|
86415
86773
|
}
|
|
@@ -86424,14 +86782,14 @@ Cannot execute bash commands.`, cause));
|
|
|
86424
86782
|
try {
|
|
86425
86783
|
let flags = import_node_fs22.constants.O_RDONLY;
|
|
86426
86784
|
if (process.platform === "win32") {
|
|
86427
|
-
if (noFollow && (await (0,
|
|
86785
|
+
if (noFollow && (await (0, import_promises38.lstat)(resolved)).isSymbolicLink())
|
|
86428
86786
|
return err(symlinkRefused(resolved));
|
|
86429
86787
|
} else {
|
|
86430
86788
|
flags |= import_node_fs22.constants.O_NONBLOCK;
|
|
86431
86789
|
if (noFollow)
|
|
86432
86790
|
flags |= import_node_fs22.constants.O_NOFOLLOW;
|
|
86433
86791
|
}
|
|
86434
|
-
file2 = await (0,
|
|
86792
|
+
file2 = await (0, import_promises38.open)(resolved, flags);
|
|
86435
86793
|
const stats = await file2.stat();
|
|
86436
86794
|
if (!stats.isFile()) {
|
|
86437
86795
|
await file2.close().catch(() => void 0);
|
|
@@ -86458,11 +86816,11 @@ Cannot execute bash commands.`, cause));
|
|
|
86458
86816
|
if (aborted2)
|
|
86459
86817
|
return aborted2;
|
|
86460
86818
|
try {
|
|
86461
|
-
await (0,
|
|
86819
|
+
await (0, import_promises38.mkdir)((0, import_node_path44.resolve)(resolved, ".."), { recursive: true });
|
|
86462
86820
|
const afterMkdirAbort = abortResult(signal, resolved);
|
|
86463
86821
|
if (afterMkdirAbort)
|
|
86464
86822
|
return afterMkdirAbort;
|
|
86465
|
-
await (0,
|
|
86823
|
+
await (0, import_promises38.writeFile)(resolved, content2, { signal });
|
|
86466
86824
|
return ok(void 0);
|
|
86467
86825
|
} catch (error62) {
|
|
86468
86826
|
return err(toFileError(error62, resolved));
|
|
@@ -86475,11 +86833,11 @@ Cannot execute bash commands.`, cause));
|
|
|
86475
86833
|
if (aborted2)
|
|
86476
86834
|
return aborted2;
|
|
86477
86835
|
try {
|
|
86478
|
-
await (0,
|
|
86836
|
+
await (0, import_promises38.mkdir)((0, import_node_path44.resolve)(resolved, ".."), { recursive: true });
|
|
86479
86837
|
const afterMkdirAbort = abortResult(signal, resolved);
|
|
86480
86838
|
if (afterMkdirAbort)
|
|
86481
86839
|
return afterMkdirAbort;
|
|
86482
|
-
await (0,
|
|
86840
|
+
await (0, import_promises38.appendFile)(resolved, content2);
|
|
86483
86841
|
const afterAppendAbort = abortResult(signal, resolved);
|
|
86484
86842
|
return afterAppendAbort ?? ok(void 0);
|
|
86485
86843
|
} catch (error62) {
|
|
@@ -86497,7 +86855,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86497
86855
|
}
|
|
86498
86856
|
let file2;
|
|
86499
86857
|
try {
|
|
86500
|
-
file2 = await (0,
|
|
86858
|
+
file2 = await (0, import_promises38.open)(resolved, "r+");
|
|
86501
86859
|
await file2.truncate(size);
|
|
86502
86860
|
const afterTruncateAbort = abortResult(signal, resolved);
|
|
86503
86861
|
return afterTruncateAbort ?? ok(void 0);
|
|
@@ -86515,7 +86873,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86515
86873
|
return aborted2;
|
|
86516
86874
|
let file2;
|
|
86517
86875
|
try {
|
|
86518
|
-
file2 = await (0,
|
|
86876
|
+
file2 = await (0, import_promises38.open)(resolved, "r+");
|
|
86519
86877
|
if ((await file2.stat()).isDirectory())
|
|
86520
86878
|
return err(new FileError("is_directory", "Is a directory", resolved));
|
|
86521
86879
|
await file2.sync();
|
|
@@ -86534,7 +86892,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86534
86892
|
if (aborted2)
|
|
86535
86893
|
return aborted2;
|
|
86536
86894
|
try {
|
|
86537
|
-
await (0,
|
|
86895
|
+
await (0, import_promises38.rename)(source, destination);
|
|
86538
86896
|
return ok(void 0);
|
|
86539
86897
|
} catch (error62) {
|
|
86540
86898
|
return err(toFileError(error62, source));
|
|
@@ -86546,7 +86904,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86546
86904
|
if (aborted2)
|
|
86547
86905
|
return aborted2;
|
|
86548
86906
|
try {
|
|
86549
|
-
return fileInfoFromStats(resolved, await (0,
|
|
86907
|
+
return fileInfoFromStats(resolved, await (0, import_promises38.lstat)(resolved));
|
|
86550
86908
|
} catch (error62) {
|
|
86551
86909
|
return err(toFileError(error62, resolved));
|
|
86552
86910
|
}
|
|
@@ -86558,15 +86916,15 @@ Cannot execute bash commands.`, cause));
|
|
|
86558
86916
|
if (aborted2)
|
|
86559
86917
|
return aborted2;
|
|
86560
86918
|
try {
|
|
86561
|
-
const entries2 = await (0,
|
|
86919
|
+
const entries2 = await (0, import_promises38.readdir)(resolved, { withFileTypes: true });
|
|
86562
86920
|
const infos = [];
|
|
86563
86921
|
for (const entry2 of entries2) {
|
|
86564
86922
|
const loopAbort = abortResult(signal, resolved);
|
|
86565
86923
|
if (loopAbort)
|
|
86566
86924
|
return loopAbort;
|
|
86567
|
-
const entryPath = (0,
|
|
86925
|
+
const entryPath = (0, import_node_path44.resolve)(resolved, entry2.name);
|
|
86568
86926
|
try {
|
|
86569
|
-
const info = fileInfoFromStats(entryPath, await (0,
|
|
86927
|
+
const info = fileInfoFromStats(entryPath, await (0, import_promises38.lstat)(entryPath));
|
|
86570
86928
|
if (info.ok)
|
|
86571
86929
|
infos.push(info.value);
|
|
86572
86930
|
} catch (error62) {
|
|
@@ -86584,7 +86942,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86584
86942
|
if (aborted2)
|
|
86585
86943
|
return aborted2;
|
|
86586
86944
|
try {
|
|
86587
|
-
const dir = await (0,
|
|
86945
|
+
const dir = await (0, import_promises38.opendir)(resolved);
|
|
86588
86946
|
const afterOpenAbort = abortResult(context.abortSignal, resolved);
|
|
86589
86947
|
if (afterOpenAbort) {
|
|
86590
86948
|
await dir.close().catch(() => void 0);
|
|
@@ -86601,7 +86959,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86601
86959
|
if (aborted2)
|
|
86602
86960
|
return aborted2;
|
|
86603
86961
|
try {
|
|
86604
|
-
return ok(await (0,
|
|
86962
|
+
return ok(await (0, import_promises38.realpath)(resolved));
|
|
86605
86963
|
} catch (error62) {
|
|
86606
86964
|
return err(toFileError(error62, resolved));
|
|
86607
86965
|
}
|
|
@@ -86620,7 +86978,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86620
86978
|
if (aborted2)
|
|
86621
86979
|
return aborted2;
|
|
86622
86980
|
try {
|
|
86623
|
-
await (0,
|
|
86981
|
+
await (0, import_promises38.mkdir)(resolved, { recursive: options?.recursive ?? true });
|
|
86624
86982
|
return ok(void 0);
|
|
86625
86983
|
} catch (error62) {
|
|
86626
86984
|
return err(toFileError(error62, resolved));
|
|
@@ -86632,7 +86990,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86632
86990
|
if (aborted2)
|
|
86633
86991
|
return aborted2;
|
|
86634
86992
|
try {
|
|
86635
|
-
await (0,
|
|
86993
|
+
await (0, import_promises38.rm)(resolved, { recursive: options?.recursive ?? false, force: options?.force ?? false });
|
|
86636
86994
|
return ok(void 0);
|
|
86637
86995
|
} catch (error62) {
|
|
86638
86996
|
return err(toFileError(error62, resolved));
|
|
@@ -86644,7 +87002,7 @@ Cannot execute bash commands.`, cause));
|
|
|
86644
87002
|
return aborted2;
|
|
86645
87003
|
try {
|
|
86646
87004
|
prefix2 ??= "tmp-";
|
|
86647
|
-
return ok(await (0,
|
|
87005
|
+
return ok(await (0, import_promises38.mkdtemp)((0, import_node_path44.join)((0, import_node_os7.tmpdir)(), prefix2)));
|
|
86648
87006
|
} catch (error62) {
|
|
86649
87007
|
return err(toFileError(error62));
|
|
86650
87008
|
}
|
|
@@ -86653,9 +87011,9 @@ Cannot execute bash commands.`, cause));
|
|
|
86653
87011
|
const dir = await this.createTempDir("tmp-", context);
|
|
86654
87012
|
if (!dir.ok)
|
|
86655
87013
|
return dir;
|
|
86656
|
-
const filePath = (0,
|
|
87014
|
+
const filePath = (0, import_node_path44.join)(dir.value, `${options?.prefix ?? ""}${(0, import_node_crypto29.randomUUID)()}${options?.suffix ?? ""}`);
|
|
86657
87015
|
try {
|
|
86658
|
-
await (0,
|
|
87016
|
+
await (0, import_promises38.writeFile)(filePath, "");
|
|
86659
87017
|
return ok(filePath);
|
|
86660
87018
|
} catch (error62) {
|
|
86661
87019
|
return err(toFileError(error62, filePath));
|
|
@@ -86930,6 +87288,9 @@ var init_alan = __esm({
|
|
|
86930
87288
|
"subscribe_session",
|
|
86931
87289
|
"list_subscriptions",
|
|
86932
87290
|
"cancel_subscription",
|
|
87291
|
+
"record_commitment",
|
|
87292
|
+
"list_commitments",
|
|
87293
|
+
"close_commitment",
|
|
86933
87294
|
"update_pilot_brief",
|
|
86934
87295
|
"ask_person",
|
|
86935
87296
|
"review_ask",
|
|
@@ -88864,7 +89225,7 @@ function stripBearer(authorization) {
|
|
|
88864
89225
|
return authorization.replace(/^Bearer\s+/i, "").trim();
|
|
88865
89226
|
}
|
|
88866
89227
|
async function readAlanCredentialFile(path21) {
|
|
88867
|
-
const parsed = JSON.parse(await (0,
|
|
89228
|
+
const parsed = JSON.parse(await (0, import_promises39.readFile)(path21, "utf8"));
|
|
88868
89229
|
if (typeof parsed !== "object" || parsed === null) {
|
|
88869
89230
|
throw new Error(`Alan credential file is not a JSON object: ${path21}`);
|
|
88870
89231
|
}
|
|
@@ -88883,11 +89244,11 @@ function alanCredentialSource(explicit, env = process.env) {
|
|
|
88883
89244
|
if (file2 === void 0) return { apiKey: void 0 };
|
|
88884
89245
|
return () => readAlanCredentialFile(file2);
|
|
88885
89246
|
}
|
|
88886
|
-
var
|
|
89247
|
+
var import_promises39, DEFAULT_ALAN_API_URL;
|
|
88887
89248
|
var init_credentials = __esm({
|
|
88888
89249
|
"../alan-engine/src/model/credentials.ts"() {
|
|
88889
89250
|
"use strict";
|
|
88890
|
-
|
|
89251
|
+
import_promises39 = require("node:fs/promises");
|
|
88891
89252
|
init_credential_source();
|
|
88892
89253
|
DEFAULT_ALAN_API_URL = "https://api.tryalan.ai";
|
|
88893
89254
|
}
|
|
@@ -89116,8 +89477,8 @@ function defaultProviderAuthContext() {
|
|
|
89116
89477
|
const fs = await importNodeModule("node:fs/promises");
|
|
89117
89478
|
let resolved = path21;
|
|
89118
89479
|
if (resolved.startsWith("~")) {
|
|
89119
|
-
const
|
|
89120
|
-
resolved =
|
|
89480
|
+
const os4 = await importNodeModule("node:os");
|
|
89481
|
+
resolved = os4.homedir() + resolved.slice(1);
|
|
89121
89482
|
}
|
|
89122
89483
|
await fs.access(resolved);
|
|
89123
89484
|
return true;
|
|
@@ -113000,12 +113361,12 @@ function resolveBashShell(options) {
|
|
|
113000
113361
|
(value2) => !!value2
|
|
113001
113362
|
);
|
|
113002
113363
|
const candidates2 = roots.flatMap((root) => [
|
|
113003
|
-
|
|
113004
|
-
|
|
113364
|
+
import_node_path45.default.win32.join(root, "Git", "bin", "bash.exe"),
|
|
113365
|
+
import_node_path45.default.win32.join(root, "Programs", "Git", "bin", "bash.exe")
|
|
113005
113366
|
]);
|
|
113006
113367
|
for (const directory of (env.PATH ?? "").split(";")) {
|
|
113007
|
-
candidates2.push(
|
|
113008
|
-
candidates2.push(
|
|
113368
|
+
candidates2.push(import_node_path45.default.win32.join(directory, "bash.exe"));
|
|
113369
|
+
candidates2.push(import_node_path45.default.win32.join(directory, "..", "bin", "bash.exe"));
|
|
113009
113370
|
}
|
|
113010
113371
|
const found = candidates2.find(
|
|
113011
113372
|
(candidate) => !candidate.toLowerCase().includes("\\windows\\system32\\") && exists5(candidate)
|
|
@@ -113019,12 +113380,12 @@ function resolveBashShell(options) {
|
|
|
113019
113380
|
function bashShell() {
|
|
113020
113381
|
return resolveBashShell({ platform: process.platform, env: process.env, exists: import_node_fs23.existsSync });
|
|
113021
113382
|
}
|
|
113022
|
-
var import_node_fs23,
|
|
113383
|
+
var import_node_fs23, import_node_path45;
|
|
113023
113384
|
var init_bash_shell = __esm({
|
|
113024
113385
|
"../alan-engine/src/tools/bash-shell.ts"() {
|
|
113025
113386
|
"use strict";
|
|
113026
113387
|
import_node_fs23 = require("node:fs");
|
|
113027
|
-
|
|
113388
|
+
import_node_path45 = __toESM(require("node:path"), 1);
|
|
113028
113389
|
}
|
|
113029
113390
|
});
|
|
113030
113391
|
|
|
@@ -113048,7 +113409,7 @@ function stampOf(info) {
|
|
|
113048
113409
|
return { mtimeMs: info.mtimeMs, size: info.size };
|
|
113049
113410
|
}
|
|
113050
113411
|
async function recordFileStamp(context, filepath, info) {
|
|
113051
|
-
const current = info ?? await (0,
|
|
113412
|
+
const current = info ?? await (0, import_promises40.stat)(filepath);
|
|
113052
113413
|
await context.fileReads.record(filepath, stampOf(current));
|
|
113053
113414
|
}
|
|
113054
113415
|
async function assertUnchangedSinceRead(context, filepath, info) {
|
|
@@ -113058,11 +113419,11 @@ async function assertUnchangedSinceRead(context, filepath, info) {
|
|
|
113058
113419
|
throw new ToolFailure(modifiedSinceReadMessage(filepath));
|
|
113059
113420
|
}
|
|
113060
113421
|
}
|
|
113061
|
-
var
|
|
113422
|
+
var import_promises40, FileReadsDoc;
|
|
113062
113423
|
var init_file_reads = __esm({
|
|
113063
113424
|
"../alan-engine/src/tools/file-reads.ts"() {
|
|
113064
113425
|
"use strict";
|
|
113065
|
-
|
|
113426
|
+
import_promises40 = require("node:fs/promises");
|
|
113066
113427
|
init_dist3();
|
|
113067
113428
|
init_shared2();
|
|
113068
113429
|
FileReadsDoc = defineDoc({
|
|
@@ -113359,7 +113720,7 @@ function spawnShellTree(shell, env, start, platform = process.platform) {
|
|
|
113359
113720
|
}
|
|
113360
113721
|
function run2(file2, args) {
|
|
113361
113722
|
return new Promise((resolve14) => {
|
|
113362
|
-
(0,
|
|
113723
|
+
(0, import_node_child_process15.execFile)(file2, args, { windowsHide: true }, (error62, stdout) => {
|
|
113363
113724
|
resolve14({ ok: !error62, stdout: typeof stdout === "string" ? stdout : "" });
|
|
113364
113725
|
});
|
|
113365
113726
|
});
|
|
@@ -113420,11 +113781,11 @@ function drainAfterExit(child, drainMs = EXIT_DRAIN_MS) {
|
|
|
113420
113781
|
}
|
|
113421
113782
|
};
|
|
113422
113783
|
}
|
|
113423
|
-
var
|
|
113784
|
+
var import_node_child_process15, import_node_crypto30, PROCESS_TREE_ENV, shellTrees, LIST_SHELL_TREE, SHELL_TREE_ROUNDS, EXIT_DRAIN_MS;
|
|
113424
113785
|
var init_process_tree2 = __esm({
|
|
113425
113786
|
"../alan-engine/src/tools/process-tree.ts"() {
|
|
113426
113787
|
"use strict";
|
|
113427
|
-
|
|
113788
|
+
import_node_child_process15 = require("node:child_process");
|
|
113428
113789
|
import_node_crypto30 = require("node:crypto");
|
|
113429
113790
|
PROCESS_TREE_ENV = "ALAN_PROCESS_TREE";
|
|
113430
113791
|
shellTrees = /* @__PURE__ */ new WeakMap();
|
|
@@ -119853,9 +120214,9 @@ function killGroup2(child, signal) {
|
|
|
119853
120214
|
killProcessTree3(child, signal);
|
|
119854
120215
|
}
|
|
119855
120216
|
async function saveFullOutput(text4) {
|
|
119856
|
-
await (0,
|
|
119857
|
-
const file2 =
|
|
119858
|
-
await (0,
|
|
120217
|
+
await (0, import_promises41.mkdir)(OUTPUT_DIR, { recursive: true });
|
|
120218
|
+
const file2 = import_node_path46.default.join(OUTPUT_DIR, `tool_${(0, import_node_crypto31.randomUUID)()}`);
|
|
120219
|
+
await (0, import_promises41.writeFile)(file2, text4, "utf8");
|
|
119859
120220
|
return file2;
|
|
119860
120221
|
}
|
|
119861
120222
|
function runCommand2(io, args, cwd, timeout2) {
|
|
@@ -119864,13 +120225,14 @@ function runCommand2(io, args, cwd, timeout2) {
|
|
|
119864
120225
|
const child = spawnShellTree(
|
|
119865
120226
|
shell,
|
|
119866
120227
|
process.env,
|
|
119867
|
-
(env) => (0,
|
|
120228
|
+
(env) => (0, import_node_child_process16.spawn)(shell, ["-c", args.command], {
|
|
119868
120229
|
cwd,
|
|
119869
120230
|
env,
|
|
119870
120231
|
stdio: ["ignore", "pipe", "pipe"],
|
|
119871
120232
|
detached: process.platform !== "win32"
|
|
119872
120233
|
})
|
|
119873
120234
|
);
|
|
120235
|
+
if (process.platform !== "win32") registerSessionGroup(child.pid);
|
|
119874
120236
|
let raw = "";
|
|
119875
120237
|
let last = "";
|
|
119876
120238
|
let ending = "exit";
|
|
@@ -119943,7 +120305,7 @@ Use bash_output with this ID to read new output and kill_shell to stop it.`;
|
|
|
119943
120305
|
}
|
|
119944
120306
|
async function execute(context, io, args, options) {
|
|
119945
120307
|
const cwd = args.workdir ? resolvePath2(context.cwd, args.workdir) : context.cwd;
|
|
119946
|
-
const workdirInfo = await (0,
|
|
120308
|
+
const workdirInfo = await (0, import_promises41.stat)(cwd).catch(() => void 0);
|
|
119947
120309
|
if (!workdirInfo?.isDirectory())
|
|
119948
120310
|
throw new ToolFailure(`Working directory does not exist: ${cwd}`);
|
|
119949
120311
|
if (args.run_in_background === true) {
|
|
@@ -120001,27 +120363,28 @@ function createBashTool(cwd, shells, options = {}) {
|
|
|
120001
120363
|
execute: (args, api, context) => runDurable({ cwd, shells }, api, context, (tool, io) => execute(tool, io, args, options))
|
|
120002
120364
|
});
|
|
120003
120365
|
}
|
|
120004
|
-
var
|
|
120366
|
+
var import_node_child_process16, import_node_crypto31, import_promises41, import_node_os8, import_node_path46, MAX_METADATA_LENGTH, DETAILS_INTERVAL_MS, KILL_GRACE_MS, OUTPUT_RELEASED_NOTE, OUTPUT_DIR, HEAD_CHARS, TAIL_CHARS, HEAD_LINES, TAIL_LINES;
|
|
120005
120367
|
var init_bash = __esm({
|
|
120006
120368
|
"../alan-engine/src/tools/bash.ts"() {
|
|
120007
120369
|
"use strict";
|
|
120008
|
-
|
|
120370
|
+
import_node_child_process16 = require("node:child_process");
|
|
120009
120371
|
import_node_crypto31 = require("node:crypto");
|
|
120010
|
-
|
|
120011
|
-
|
|
120012
|
-
|
|
120372
|
+
import_promises41 = require("node:fs/promises");
|
|
120373
|
+
import_node_os8 = __toESM(require("node:os"), 1);
|
|
120374
|
+
import_node_path46 = __toESM(require("node:path"), 1);
|
|
120013
120375
|
init_dist3();
|
|
120014
120376
|
init_bash_shell();
|
|
120015
120377
|
init_durable();
|
|
120016
120378
|
init_metadata();
|
|
120017
120379
|
init_process_tree2();
|
|
120380
|
+
init_session_processes();
|
|
120018
120381
|
init_shared2();
|
|
120019
120382
|
init_workspace_tool();
|
|
120020
120383
|
MAX_METADATA_LENGTH = 3e4;
|
|
120021
120384
|
DETAILS_INTERVAL_MS = 200;
|
|
120022
120385
|
KILL_GRACE_MS = 3e3;
|
|
120023
120386
|
OUTPUT_RELEASED_NOTE = "The command exited, but a process it started kept its output open, so output after the exit was not captured. That process may still be running; start servers and watchers with run_in_background.";
|
|
120024
|
-
OUTPUT_DIR =
|
|
120387
|
+
OUTPUT_DIR = import_node_path46.default.join(import_node_os8.default.tmpdir(), "alan-engine-tool-output");
|
|
120025
120388
|
HEAD_CHARS = 3e3;
|
|
120026
120389
|
TAIL_CHARS = 7e3;
|
|
120027
120390
|
HEAD_LINES = 900;
|
|
@@ -120033,14 +120396,14 @@ var init_bash = __esm({
|
|
|
120033
120396
|
function newShellId() {
|
|
120034
120397
|
return `shell_${(0, import_node_crypto32.randomBytes)(4).toString("hex")}`;
|
|
120035
120398
|
}
|
|
120036
|
-
var
|
|
120399
|
+
var import_node_child_process17, import_node_crypto32, import_node_fs24, import_node_path47, UNREAD_LIMIT_CHARS, RETAINED_FINISHED, UnknownBackgroundShell, BackgroundShells;
|
|
120037
120400
|
var init_background_shells = __esm({
|
|
120038
120401
|
"../alan-engine/src/tools/background-shells.ts"() {
|
|
120039
120402
|
"use strict";
|
|
120040
|
-
|
|
120403
|
+
import_node_child_process17 = require("node:child_process");
|
|
120041
120404
|
import_node_crypto32 = require("node:crypto");
|
|
120042
120405
|
import_node_fs24 = require("node:fs");
|
|
120043
|
-
|
|
120406
|
+
import_node_path47 = __toESM(require("node:path"), 1);
|
|
120044
120407
|
init_bash();
|
|
120045
120408
|
init_process_tree2();
|
|
120046
120409
|
UNREAD_LIMIT_CHARS = 100 * 1024;
|
|
@@ -120072,7 +120435,7 @@ var init_background_shells = __esm({
|
|
|
120072
120435
|
if (this.#closed) throw new Error("The session is closing; background shells cannot start");
|
|
120073
120436
|
const id = newShellId();
|
|
120074
120437
|
(0, import_node_fs24.mkdirSync)(OUTPUT_DIR, { recursive: true });
|
|
120075
|
-
const outputPath =
|
|
120438
|
+
const outputPath = import_node_path47.default.join(OUTPUT_DIR, `background_${id}`);
|
|
120076
120439
|
const file2 = (0, import_node_fs24.createWriteStream)(outputPath, { encoding: "utf8" });
|
|
120077
120440
|
file2.on("error", () => void 0);
|
|
120078
120441
|
const info = {
|
|
@@ -120109,7 +120472,7 @@ var init_background_shells = __esm({
|
|
|
120109
120472
|
const child = spawnShellTree(
|
|
120110
120473
|
shellPath,
|
|
120111
120474
|
process.env,
|
|
120112
|
-
(env) => (0,
|
|
120475
|
+
(env) => (0, import_node_child_process17.spawn)(shellPath, ["-c", request3.command], {
|
|
120113
120476
|
cwd: request3.cwd,
|
|
120114
120477
|
env,
|
|
120115
120478
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -120307,27 +120670,27 @@ function withLineEnding(edit, ending) {
|
|
|
120307
120670
|
};
|
|
120308
120671
|
}
|
|
120309
120672
|
async function applyEdit(context, io, filepath, args) {
|
|
120310
|
-
const info = await (0,
|
|
120673
|
+
const info = await (0, import_promises42.stat)(filepath).catch(() => void 0);
|
|
120311
120674
|
const [first] = args.edits;
|
|
120312
120675
|
if (first !== void 0 && first.oldString === "" && args.edits.length === 1) {
|
|
120313
120676
|
if (info) throw new ToolFailure(EMPTY_OLD_STRING_MESSAGE);
|
|
120314
120677
|
io.abortSignal?.throwIfAborted();
|
|
120315
|
-
await (0,
|
|
120316
|
-
await (0,
|
|
120678
|
+
await (0, import_promises42.mkdir)(import_node_path48.default.dirname(filepath), { recursive: true });
|
|
120679
|
+
await (0, import_promises42.writeFile)(filepath, first.newString, "utf8");
|
|
120317
120680
|
await recordFileStamp(context, filepath);
|
|
120318
120681
|
return { before: "", after: first.newString };
|
|
120319
120682
|
}
|
|
120320
120683
|
if (!info) throw new ToolFailure(`File ${filepath} not found`);
|
|
120321
120684
|
if (info.isDirectory()) throw new ToolFailure(`Path is a directory, not a file: ${filepath}`);
|
|
120322
120685
|
await assertUnchangedSinceRead(context, filepath, info);
|
|
120323
|
-
const before = await (0,
|
|
120686
|
+
const before = await (0, import_promises42.readFile)(filepath, "utf8");
|
|
120324
120687
|
const ending = detectLineEnding(before);
|
|
120325
120688
|
const after = applyReplacements(
|
|
120326
120689
|
before,
|
|
120327
120690
|
args.edits.map((edit) => withLineEnding(edit, ending))
|
|
120328
120691
|
);
|
|
120329
120692
|
io.abortSignal?.throwIfAborted();
|
|
120330
|
-
await (0,
|
|
120693
|
+
await (0, import_promises42.writeFile)(filepath, after, "utf8");
|
|
120331
120694
|
await recordFileStamp(context, filepath);
|
|
120332
120695
|
return { before, after };
|
|
120333
120696
|
}
|
|
@@ -120355,12 +120718,12 @@ function createEditTool(cwd) {
|
|
|
120355
120718
|
execute: (args, api, context) => runDurable({ cwd, shells: void 0 }, api, context, (tool, io) => execute2(tool, io, args))
|
|
120356
120719
|
});
|
|
120357
120720
|
}
|
|
120358
|
-
var
|
|
120721
|
+
var import_promises42, import_node_path48, editTool;
|
|
120359
120722
|
var init_edit2 = __esm({
|
|
120360
120723
|
"../alan-engine/src/tools/edit.ts"() {
|
|
120361
120724
|
"use strict";
|
|
120362
|
-
|
|
120363
|
-
|
|
120725
|
+
import_promises42 = require("node:fs/promises");
|
|
120726
|
+
import_node_path48 = __toESM(require("node:path"), 1);
|
|
120364
120727
|
init_dist3();
|
|
120365
120728
|
init_diff();
|
|
120366
120729
|
init_durable();
|
|
@@ -120389,7 +120752,7 @@ function typeScriptProblem(source) {
|
|
|
120389
120752
|
}
|
|
120390
120753
|
function pythonProblem(filepath) {
|
|
120391
120754
|
return new Promise((resolve14) => {
|
|
120392
|
-
(0,
|
|
120755
|
+
(0, import_node_child_process18.execFile)(
|
|
120393
120756
|
"python3",
|
|
120394
120757
|
["-c", PY_PARSE, filepath],
|
|
120395
120758
|
{ timeout: SYNTAX_TIMEOUT_MS },
|
|
@@ -120402,10 +120765,10 @@ function pythonProblem(filepath) {
|
|
|
120402
120765
|
});
|
|
120403
120766
|
}
|
|
120404
120767
|
async function syntaxProblem(filepath) {
|
|
120405
|
-
const extension =
|
|
120768
|
+
const extension = import_node_path49.default.extname(filepath).toLowerCase();
|
|
120406
120769
|
if (extension === ".py") return pythonProblem(filepath);
|
|
120407
120770
|
if (!TS_EXTENSIONS.has(extension) && extension !== ".json") return void 0;
|
|
120408
|
-
const source = await (0,
|
|
120771
|
+
const source = await (0, import_promises43.readFile)(filepath, "utf8").catch(() => void 0);
|
|
120409
120772
|
if (source === void 0) return void 0;
|
|
120410
120773
|
if (extension !== ".json") return typeScriptProblem(source);
|
|
120411
120774
|
try {
|
|
@@ -120457,14 +120820,14 @@ function withBudgetReminder(tools) {
|
|
|
120457
120820
|
})
|
|
120458
120821
|
);
|
|
120459
120822
|
}
|
|
120460
|
-
var
|
|
120823
|
+
var import_node_child_process18, import_promises43, import_node_module, import_node_path49, TOOL_EXPERIMENTS, SYNTAX_TIMEOUT_MS, TS_EXTENSIONS, PY_PARSE, BUDGET_FIRST_REMINDER, BUDGET_REMINDER_EVERY;
|
|
120461
120824
|
var init_experiments = __esm({
|
|
120462
120825
|
"../alan-engine/src/tools/experiments.ts"() {
|
|
120463
120826
|
"use strict";
|
|
120464
|
-
|
|
120465
|
-
|
|
120827
|
+
import_node_child_process18 = require("node:child_process");
|
|
120828
|
+
import_promises43 = require("node:fs/promises");
|
|
120466
120829
|
import_node_module = require("node:module");
|
|
120467
|
-
|
|
120830
|
+
import_node_path49 = __toESM(require("node:path"), 1);
|
|
120468
120831
|
TOOL_EXPERIMENTS = [
|
|
120469
120832
|
"no-exit-code",
|
|
120470
120833
|
"no-head-tail",
|
|
@@ -120755,9 +121118,9 @@ function isExecutable3(file2) {
|
|
|
120755
121118
|
function findRipgrep() {
|
|
120756
121119
|
if (ripgrepPath !== void 0) return ripgrepPath ?? void 0;
|
|
120757
121120
|
const binary = process.platform === "win32" ? "rg.exe" : "rg";
|
|
120758
|
-
for (const dir of (process.env.PATH ?? "").split(
|
|
121121
|
+
for (const dir of (process.env.PATH ?? "").split(import_node_path50.default.delimiter)) {
|
|
120759
121122
|
if (!dir) continue;
|
|
120760
|
-
const candidate =
|
|
121123
|
+
const candidate = import_node_path50.default.join(dir, binary);
|
|
120761
121124
|
if (isExecutable3(candidate)) {
|
|
120762
121125
|
ripgrepPath = candidate;
|
|
120763
121126
|
return candidate;
|
|
@@ -120771,7 +121134,7 @@ function normalizeRelative(line) {
|
|
|
120771
121134
|
}
|
|
120772
121135
|
function runRipgrep(binary, run3) {
|
|
120773
121136
|
return new Promise((resolve14, reject2) => {
|
|
120774
|
-
const child = (0,
|
|
121137
|
+
const child = (0, import_node_child_process19.spawn)(binary, ["--no-require-git", ...run3.args], {
|
|
120775
121138
|
cwd: run3.cwd,
|
|
120776
121139
|
stdio: ["ignore", "pipe", "pipe"]
|
|
120777
121140
|
});
|
|
@@ -120816,7 +121179,7 @@ function runRipgrep(binary, run3) {
|
|
|
120816
121179
|
});
|
|
120817
121180
|
}
|
|
120818
121181
|
async function readIgnoreRules(root) {
|
|
120819
|
-
const text4 = await (0,
|
|
121182
|
+
const text4 = await (0, import_promises44.readFile)(import_node_path50.default.join(root, ".gitignore"), "utf8").catch(() => "");
|
|
120820
121183
|
const rules = [];
|
|
120821
121184
|
for (const raw of text4.split(/\r?\n/)) {
|
|
120822
121185
|
const line = raw.trim();
|
|
@@ -120838,7 +121201,7 @@ async function* walkFiles(root, options) {
|
|
|
120838
121201
|
while (stack.length > 0) {
|
|
120839
121202
|
options.signal?.throwIfAborted();
|
|
120840
121203
|
const relativeDir = stack.pop() ?? "";
|
|
120841
|
-
const entries2 = await (0,
|
|
121204
|
+
const entries2 = await (0, import_promises44.readdir)(import_node_path50.default.join(root, relativeDir), { withFileTypes: true }).catch(
|
|
120842
121205
|
() => []
|
|
120843
121206
|
);
|
|
120844
121207
|
entries2.sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -120861,14 +121224,14 @@ async function* walkFiles(root, options) {
|
|
|
120861
121224
|
for (let i = directories.length - 1; i >= 0; i--) stack.push(directories[i]);
|
|
120862
121225
|
}
|
|
120863
121226
|
}
|
|
120864
|
-
var
|
|
121227
|
+
var import_node_child_process19, import_node_fs25, import_promises44, import_node_path50, import_node_readline, ALWAYS_SKIPPED, ripgrepPath;
|
|
120865
121228
|
var init_search2 = __esm({
|
|
120866
121229
|
"../alan-engine/src/tools/search.ts"() {
|
|
120867
121230
|
"use strict";
|
|
120868
|
-
|
|
121231
|
+
import_node_child_process19 = require("node:child_process");
|
|
120869
121232
|
import_node_fs25 = require("node:fs");
|
|
120870
|
-
|
|
120871
|
-
|
|
121233
|
+
import_promises44 = require("node:fs/promises");
|
|
121234
|
+
import_node_path50 = __toESM(require("node:path"), 1);
|
|
120872
121235
|
import_node_readline = require("node:readline");
|
|
120873
121236
|
init_glob_match();
|
|
120874
121237
|
init_shared2();
|
|
@@ -120899,7 +121262,7 @@ async function findFiles(root, pattern, signal) {
|
|
|
120899
121262
|
}
|
|
120900
121263
|
async function execute3(context, io, args) {
|
|
120901
121264
|
const search = resolvePath2(context.cwd, args.path ?? ".");
|
|
120902
|
-
const info = await (0,
|
|
121265
|
+
const info = await (0, import_promises45.stat)(search).catch(() => void 0);
|
|
120903
121266
|
if (info?.isFile()) throw new ToolFailure(`glob path must be a directory: ${search}`);
|
|
120904
121267
|
if (!info) throw new ToolFailure(`Directory not found: ${search}`);
|
|
120905
121268
|
const files = await findFiles(search, args.pattern, io.abortSignal);
|
|
@@ -120907,7 +121270,7 @@ async function execute3(context, io, args) {
|
|
|
120907
121270
|
const output2 = [];
|
|
120908
121271
|
if (files.length === 0) output2.push("No files found");
|
|
120909
121272
|
else {
|
|
120910
|
-
output2.push(...files.map((file2) =>
|
|
121273
|
+
output2.push(...files.map((file2) => import_node_path51.default.resolve(search, file2)));
|
|
120911
121274
|
if (truncated2) {
|
|
120912
121275
|
output2.push("");
|
|
120913
121276
|
output2.push(
|
|
@@ -120927,12 +121290,12 @@ function createGlobTool(cwd) {
|
|
|
120927
121290
|
execute: (args, api, context) => runDurable({ cwd, shells: void 0 }, api, context, (tool, io) => execute3(tool, io, args))
|
|
120928
121291
|
});
|
|
120929
121292
|
}
|
|
120930
|
-
var
|
|
121293
|
+
var import_promises45, import_node_path51, LIMIT, globTool;
|
|
120931
121294
|
var init_glob = __esm({
|
|
120932
121295
|
"../alan-engine/src/tools/glob.ts"() {
|
|
120933
121296
|
"use strict";
|
|
120934
|
-
|
|
120935
|
-
|
|
121297
|
+
import_promises45 = require("node:fs/promises");
|
|
121298
|
+
import_node_path51 = __toESM(require("node:path"), 1);
|
|
120936
121299
|
init_dist3();
|
|
120937
121300
|
init_durable();
|
|
120938
121301
|
init_glob_match();
|
|
@@ -120961,7 +121324,7 @@ function isPdf(bytes2) {
|
|
|
120961
121324
|
return Buffer.from(bytes2.subarray(0, 5)).toString("latin1") === "%PDF-";
|
|
120962
121325
|
}
|
|
120963
121326
|
function isBinaryFile(filepath, bytes2) {
|
|
120964
|
-
if (BINARY_EXTENSIONS.has(
|
|
121327
|
+
if (BINARY_EXTENSIONS.has(import_node_path52.default.extname(filepath).toLowerCase())) return true;
|
|
120965
121328
|
if (bytes2.length === 0) return false;
|
|
120966
121329
|
let nonPrintable = 0;
|
|
120967
121330
|
for (const byte of bytes2) {
|
|
@@ -120972,7 +121335,7 @@ function isBinaryFile(filepath, bytes2) {
|
|
|
120972
121335
|
}
|
|
120973
121336
|
async function readSample(filepath, size) {
|
|
120974
121337
|
if (size === 0) return new Uint8Array();
|
|
120975
|
-
const handle = await (0,
|
|
121338
|
+
const handle = await (0, import_promises46.open)(filepath, "r");
|
|
120976
121339
|
try {
|
|
120977
121340
|
const buffer = Buffer.alloc(Math.min(SAMPLE_BYTES, size));
|
|
120978
121341
|
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
@@ -120982,10 +121345,10 @@ async function readSample(filepath, size) {
|
|
|
120982
121345
|
}
|
|
120983
121346
|
}
|
|
120984
121347
|
async function missing(filepath) {
|
|
120985
|
-
const dir =
|
|
120986
|
-
const base =
|
|
120987
|
-
const suggestions = await (0,
|
|
120988
|
-
(items) => items.filter((item) => item.toLowerCase().includes(base) || base.includes(item.toLowerCase())).map((item) =>
|
|
121348
|
+
const dir = import_node_path52.default.dirname(filepath);
|
|
121349
|
+
const base = import_node_path52.default.basename(filepath).toLowerCase();
|
|
121350
|
+
const suggestions = await (0, import_promises46.readdir)(dir).then(
|
|
121351
|
+
(items) => items.filter((item) => item.toLowerCase().includes(base) || base.includes(item.toLowerCase())).map((item) => import_node_path52.default.join(dir, item)).slice(0, 3)
|
|
120989
121352
|
).catch(() => []);
|
|
120990
121353
|
if (suggestions.length > 0) {
|
|
120991
121354
|
throw new ToolFailure(
|
|
@@ -120998,12 +121361,12 @@ ${suggestions.join("\n")}`
|
|
|
120998
121361
|
throw new ToolFailure(`File not found: ${filepath}`);
|
|
120999
121362
|
}
|
|
121000
121363
|
async function listDirectory(dirpath) {
|
|
121001
|
-
const entries2 = await (0,
|
|
121364
|
+
const entries2 = await (0, import_promises46.readdir)(dirpath, { withFileTypes: true });
|
|
121002
121365
|
const names2 = await Promise.all(
|
|
121003
121366
|
entries2.map(async (entry2) => {
|
|
121004
121367
|
if (entry2.isDirectory()) return `${entry2.name}/`;
|
|
121005
121368
|
if (!entry2.isSymbolicLink()) return entry2.name;
|
|
121006
|
-
const target = await (0,
|
|
121369
|
+
const target = await (0, import_promises46.stat)(import_node_path52.default.join(dirpath, entry2.name)).catch(() => void 0);
|
|
121007
121370
|
return target?.isDirectory() ? `${entry2.name}/` : entry2.name;
|
|
121008
121371
|
})
|
|
121009
121372
|
);
|
|
@@ -121087,7 +121450,7 @@ async function readImage(io, filepath, title, mimeType, size) {
|
|
|
121087
121450
|
details: { title, preview: message2, truncated: false }
|
|
121088
121451
|
};
|
|
121089
121452
|
}
|
|
121090
|
-
const data = (await (0,
|
|
121453
|
+
const data = (await (0, import_promises46.readFile)(filepath)).toString("base64");
|
|
121091
121454
|
const message = "Image read successfully";
|
|
121092
121455
|
return {
|
|
121093
121456
|
output: [
|
|
@@ -121142,7 +121505,7 @@ async function readText2(filepath, title, args, call) {
|
|
|
121142
121505
|
async function execute4(context, io, args) {
|
|
121143
121506
|
const filepath = resolvePath2(context.cwd, args.filePath);
|
|
121144
121507
|
const title = relativeTitle(context.cwd, filepath);
|
|
121145
|
-
const info = await (0,
|
|
121508
|
+
const info = await (0, import_promises46.stat)(filepath).catch(() => void 0);
|
|
121146
121509
|
if (!info) return missing(filepath);
|
|
121147
121510
|
if (info.isDirectory()) return readDirectory(filepath, title, args);
|
|
121148
121511
|
const sample = await readSample(filepath, info.size);
|
|
@@ -121168,13 +121531,13 @@ function createReadTool(cwd) {
|
|
|
121168
121531
|
execute: (args, api, context) => runDurable({ cwd, shells: void 0 }, api, context, (tool, io) => execute4(tool, io, args))
|
|
121169
121532
|
});
|
|
121170
121533
|
}
|
|
121171
|
-
var import_node_fs26,
|
|
121534
|
+
var import_node_fs26, import_promises46, import_node_path52, import_node_readline2, DEFAULT_READ_LIMIT, MAX_LINE_LENGTH, MAX_LINE_SUFFIX, MAX_BYTES, MAX_BYTES_LABEL, SAMPLE_BYTES, MAX_IMAGE_BYTES2, BINARY_EXTENSIONS, readTool2;
|
|
121172
121535
|
var init_read2 = __esm({
|
|
121173
121536
|
"../alan-engine/src/tools/read.ts"() {
|
|
121174
121537
|
"use strict";
|
|
121175
121538
|
import_node_fs26 = require("node:fs");
|
|
121176
|
-
|
|
121177
|
-
|
|
121539
|
+
import_promises46 = require("node:fs/promises");
|
|
121540
|
+
import_node_path52 = __toESM(require("node:path"), 1);
|
|
121178
121541
|
import_node_readline2 = require("node:readline");
|
|
121179
121542
|
init_dist3();
|
|
121180
121543
|
init_durable();
|
|
@@ -121260,7 +121623,7 @@ async function searchWithRipgrep(binary, root, target, args, signal) {
|
|
|
121260
121623
|
}
|
|
121261
121624
|
if (!isRipgrepMatch(parsed)) continue;
|
|
121262
121625
|
matches.push({
|
|
121263
|
-
path:
|
|
121626
|
+
path: import_node_path53.default.resolve(root, normalizeRelative(parsed.data.path.text)),
|
|
121264
121627
|
line: parsed.data.line_number,
|
|
121265
121628
|
text: clip(parsed.data.lines.text)
|
|
121266
121629
|
});
|
|
@@ -121268,9 +121631,9 @@ async function searchWithRipgrep(binary, root, target, args, signal) {
|
|
|
121268
121631
|
return matches;
|
|
121269
121632
|
}
|
|
121270
121633
|
async function searchFile(file2, regex, matches) {
|
|
121271
|
-
const info = await (0,
|
|
121634
|
+
const info = await (0, import_promises47.stat)(file2).catch(() => void 0);
|
|
121272
121635
|
if (!info?.isFile() || info.size > MAX_FALLBACK_FILE_BYTES) return;
|
|
121273
|
-
const buffer = await (0,
|
|
121636
|
+
const buffer = await (0, import_promises47.readFile)(file2).catch(() => void 0);
|
|
121274
121637
|
if (!buffer || isBinaryFile(file2, buffer.subarray(0, 4096))) return;
|
|
121275
121638
|
const lines2 = buffer.toString("utf8").split("\n");
|
|
121276
121639
|
for (let index = 0; index < lines2.length && matches.length < LIMIT2; index++) {
|
|
@@ -121296,7 +121659,7 @@ async function searchWithWalk(root, single, args, signal) {
|
|
|
121296
121659
|
const include = args.include ? createGlobMatcher(args.include) : void 0;
|
|
121297
121660
|
for await (const relative7 of walkFiles(root, { hidden: true, exclude: [], signal })) {
|
|
121298
121661
|
if (include && !include.matches(relative7)) continue;
|
|
121299
|
-
await searchFile(
|
|
121662
|
+
await searchFile(import_node_path53.default.join(root, relative7), regex, matches);
|
|
121300
121663
|
if (matches.length >= LIMIT2) break;
|
|
121301
121664
|
}
|
|
121302
121665
|
return matches;
|
|
@@ -121322,13 +121685,13 @@ function formatGrep(matches) {
|
|
|
121322
121685
|
async function execute5(context, io, args) {
|
|
121323
121686
|
if (!args.pattern) throw new ToolFailure("pattern is required");
|
|
121324
121687
|
const requested = resolvePath2(context.cwd, args.path ?? ".");
|
|
121325
|
-
const info = await (0,
|
|
121688
|
+
const info = await (0, import_promises47.stat)(requested).catch(() => void 0);
|
|
121326
121689
|
if (!info) throw new ToolFailure(`Path not found: ${requested}`);
|
|
121327
|
-
const root = info.isDirectory() ? requested :
|
|
121690
|
+
const root = info.isDirectory() ? requested : import_node_path53.default.dirname(requested);
|
|
121328
121691
|
const single = info.isDirectory() ? void 0 : requested;
|
|
121329
121692
|
const binary = findRipgrep();
|
|
121330
121693
|
const signal = io.abortSignal;
|
|
121331
|
-
const matches = binary ? await searchWithRipgrep(binary, root, single ?
|
|
121694
|
+
const matches = binary ? await searchWithRipgrep(binary, root, single ? import_node_path53.default.basename(single) : ".", args, signal) : await searchWithWalk(root, single, args, signal);
|
|
121332
121695
|
if (matches.length === 0)
|
|
121333
121696
|
return textResult2("No files found", { title: args.pattern, matches: 0, truncated: false });
|
|
121334
121697
|
return textResult2(formatGrep(matches), {
|
|
@@ -121343,12 +121706,12 @@ function createGrepTool(cwd) {
|
|
|
121343
121706
|
execute: (args, api, context) => runDurable({ cwd, shells: void 0 }, api, context, (tool, io) => execute5(tool, io, args))
|
|
121344
121707
|
});
|
|
121345
121708
|
}
|
|
121346
|
-
var
|
|
121709
|
+
var import_promises47, import_node_path53, LIMIT2, MAX_LINE_LENGTH2, MAX_FALLBACK_FILE_BYTES, grepTool;
|
|
121347
121710
|
var init_grep = __esm({
|
|
121348
121711
|
"../alan-engine/src/tools/grep.ts"() {
|
|
121349
121712
|
"use strict";
|
|
121350
|
-
|
|
121351
|
-
|
|
121713
|
+
import_promises47 = require("node:fs/promises");
|
|
121714
|
+
import_node_path53 = __toESM(require("node:path"), 1);
|
|
121352
121715
|
init_type_guards();
|
|
121353
121716
|
init_dist3();
|
|
121354
121717
|
init_durable();
|
|
@@ -121393,19 +121756,19 @@ function renderTree(root, files) {
|
|
|
121393
121756
|
const dirs = /* @__PURE__ */ new Set(["."]);
|
|
121394
121757
|
const filesByDir = /* @__PURE__ */ new Map();
|
|
121395
121758
|
for (const file2 of files) {
|
|
121396
|
-
const dir =
|
|
121759
|
+
const dir = import_node_path54.default.posix.dirname(file2);
|
|
121397
121760
|
const parts3 = dir === "." ? [] : dir.split("/");
|
|
121398
121761
|
for (let i = 1; i <= parts3.length; i++) dirs.add(parts3.slice(0, i).join("/"));
|
|
121399
121762
|
const bucket = filesByDir.get(dir) ?? [];
|
|
121400
|
-
bucket.push(
|
|
121763
|
+
bucket.push(import_node_path54.default.posix.basename(file2));
|
|
121401
121764
|
filesByDir.set(dir, bucket);
|
|
121402
121765
|
}
|
|
121403
121766
|
const render = (dirPath, depth) => {
|
|
121404
121767
|
const indent = " ".repeat(depth);
|
|
121405
|
-
let output2 = depth > 0 ? `${indent}${
|
|
121768
|
+
let output2 = depth > 0 ? `${indent}${import_node_path54.default.posix.basename(dirPath)}/
|
|
121406
121769
|
` : "";
|
|
121407
121770
|
const childIndent = " ".repeat(depth + 1);
|
|
121408
|
-
const children = [...dirs].filter((dir) => dir !== dirPath &&
|
|
121771
|
+
const children = [...dirs].filter((dir) => dir !== dirPath && import_node_path54.default.posix.dirname(dir) === dirPath).sort();
|
|
121409
121772
|
for (const child of children) output2 += render(child, depth + 1);
|
|
121410
121773
|
for (const file2 of (filesByDir.get(dirPath) ?? []).sort()) output2 += `${childIndent}${file2}
|
|
121411
121774
|
`;
|
|
@@ -121416,7 +121779,7 @@ ${render(".", 0)}`;
|
|
|
121416
121779
|
}
|
|
121417
121780
|
async function execute6(context, io, args) {
|
|
121418
121781
|
const search = resolvePath2(context.cwd, args.path ?? ".");
|
|
121419
|
-
const info = await (0,
|
|
121782
|
+
const info = await (0, import_promises48.stat)(search).catch(() => void 0);
|
|
121420
121783
|
if (!info) throw new ToolFailure(`Directory not found: ${search}`);
|
|
121421
121784
|
if (!info.isDirectory()) throw new ToolFailure(`Path is not a directory: ${search}`);
|
|
121422
121785
|
const files = await collectFiles(search, args.ignore ?? [], io.abortSignal);
|
|
@@ -121432,12 +121795,12 @@ function createListTool(cwd) {
|
|
|
121432
121795
|
execute: (args, api, context) => runDurable({ cwd, shells: void 0 }, api, context, (tool, io) => execute6(tool, io, args))
|
|
121433
121796
|
});
|
|
121434
121797
|
}
|
|
121435
|
-
var
|
|
121798
|
+
var import_promises48, import_node_path54, IGNORE_PATTERNS, LIMIT3, listTool;
|
|
121436
121799
|
var init_list = __esm({
|
|
121437
121800
|
"../alan-engine/src/tools/list.ts"() {
|
|
121438
121801
|
"use strict";
|
|
121439
|
-
|
|
121440
|
-
|
|
121802
|
+
import_promises48 = require("node:fs/promises");
|
|
121803
|
+
import_node_path54 = __toESM(require("node:path"), 1);
|
|
121441
121804
|
init_dist3();
|
|
121442
121805
|
init_durable();
|
|
121443
121806
|
init_glob_match();
|
|
@@ -121676,7 +122039,7 @@ async function sampleFiles(dir, signal) {
|
|
|
121676
122039
|
const files = [];
|
|
121677
122040
|
for await (const relative7 of walkFiles(dir, { hidden: true, exclude: [], signal })) {
|
|
121678
122041
|
if (relative7 === "SKILL.md") continue;
|
|
121679
|
-
files.push(
|
|
122042
|
+
files.push(import_node_path55.default.resolve(dir, relative7));
|
|
121680
122043
|
if (files.length >= MAX_LISTED_FILES) break;
|
|
121681
122044
|
}
|
|
121682
122045
|
return files;
|
|
@@ -121694,8 +122057,8 @@ async function execute7(skills, args, signal) {
|
|
|
121694
122057
|
throw new ToolFailure(`Skill "${args.name}" not found. Available skills: ${names2}`);
|
|
121695
122058
|
}
|
|
121696
122059
|
const dir = info.packageDirectory;
|
|
121697
|
-
const location =
|
|
121698
|
-
const markdown = await (0,
|
|
122060
|
+
const location = import_node_path55.default.join(dir, "SKILL.md");
|
|
122061
|
+
const markdown = await (0, import_promises49.readFile)(location, "utf8").catch((error62) => {
|
|
121699
122062
|
throw new ToolFailure(
|
|
121700
122063
|
`Skill "${info.name}" has no readable SKILL.md at ${location}: ${String(error62)}`
|
|
121701
122064
|
);
|
|
@@ -121728,12 +122091,12 @@ function createSkillTool(skills) {
|
|
|
121728
122091
|
execute: (args, _api, context) => guard(context, () => execute7(skills, args, context.abortSignal))
|
|
121729
122092
|
});
|
|
121730
122093
|
}
|
|
121731
|
-
var
|
|
122094
|
+
var import_promises49, import_node_path55, DESCRIPTION3, MAX_LISTED_FILES, MAX_SEARCH_RESULTS, parameters3;
|
|
121732
122095
|
var init_skill = __esm({
|
|
121733
122096
|
"../alan-engine/src/tools/skill.ts"() {
|
|
121734
122097
|
"use strict";
|
|
121735
|
-
|
|
121736
|
-
|
|
122098
|
+
import_promises49 = require("node:fs/promises");
|
|
122099
|
+
import_node_path55 = __toESM(require("node:path"), 1);
|
|
121737
122100
|
init_dist3();
|
|
121738
122101
|
init_build();
|
|
121739
122102
|
init_rank();
|
|
@@ -122169,14 +122532,14 @@ async function execute9(context, io, args) {
|
|
|
122169
122532
|
const filepath = resolvePath2(context.cwd, args.filePath);
|
|
122170
122533
|
const title = relativeTitle(context.cwd, filepath);
|
|
122171
122534
|
return withFileLock(filepath, async () => {
|
|
122172
|
-
const info = await (0,
|
|
122535
|
+
const info = await (0, import_promises50.stat)(filepath).catch(() => void 0);
|
|
122173
122536
|
if (info?.isDirectory()) throw new ToolFailure(`Path is a directory, not a file: ${filepath}`);
|
|
122174
122537
|
const exists5 = info !== void 0;
|
|
122175
122538
|
if (info !== void 0) await assertUnchangedSinceRead(context, filepath, info);
|
|
122176
|
-
const before = exists5 ? await (0,
|
|
122539
|
+
const before = exists5 ? await (0, import_promises50.readFile)(filepath, "utf8") : "";
|
|
122177
122540
|
io.abortSignal?.throwIfAborted();
|
|
122178
|
-
await (0,
|
|
122179
|
-
await (0,
|
|
122541
|
+
await (0, import_promises50.mkdir)(import_node_path56.default.dirname(filepath), { recursive: true });
|
|
122542
|
+
await (0, import_promises50.writeFile)(filepath, args.content, "utf8");
|
|
122180
122543
|
await recordFileStamp(context, filepath);
|
|
122181
122544
|
const stats = diffStats(before, args.content);
|
|
122182
122545
|
return textResult2(exists5 ? "Wrote file successfully." : "Created file successfully.", {
|
|
@@ -122195,12 +122558,12 @@ function createWriteTool(cwd) {
|
|
|
122195
122558
|
execute: (args, api, context) => runDurable({ cwd, shells: void 0 }, api, context, (tool, io) => execute9(tool, io, args))
|
|
122196
122559
|
});
|
|
122197
122560
|
}
|
|
122198
|
-
var
|
|
122561
|
+
var import_promises50, import_node_path56, writeTool;
|
|
122199
122562
|
var init_write = __esm({
|
|
122200
122563
|
"../alan-engine/src/tools/write.ts"() {
|
|
122201
122564
|
"use strict";
|
|
122202
|
-
|
|
122203
|
-
|
|
122565
|
+
import_promises50 = require("node:fs/promises");
|
|
122566
|
+
import_node_path56 = __toESM(require("node:path"), 1);
|
|
122204
122567
|
init_dist3();
|
|
122205
122568
|
init_diff();
|
|
122206
122569
|
init_durable();
|
|
@@ -122244,7 +122607,7 @@ function parentDirectories(file2) {
|
|
|
122244
122607
|
}
|
|
122245
122608
|
async function findWorkspaceFiles(workspace, options) {
|
|
122246
122609
|
const prefix2 = options.directory === void 0 ? "" : normalizeRelative(options.directory);
|
|
122247
|
-
const root =
|
|
122610
|
+
const root = import_node_path57.default.resolve(workspace, prefix2);
|
|
122248
122611
|
const files = await listFiles(root, options.signal);
|
|
122249
122612
|
const scanTruncated = files.length >= SCAN_LIMIT;
|
|
122250
122613
|
const withPrefix = (relative7) => prefix2 === "" ? relative7 : `${prefix2.replace(/\/$/u, "")}/${relative7}`;
|
|
@@ -122263,11 +122626,11 @@ async function findWorkspaceFiles(workspace, options) {
|
|
|
122263
122626
|
truncated: scanTruncated || matches.length > options.limit
|
|
122264
122627
|
};
|
|
122265
122628
|
}
|
|
122266
|
-
var
|
|
122629
|
+
var import_node_path57, SCAN_LIMIT;
|
|
122267
122630
|
var init_find_files = __esm({
|
|
122268
122631
|
"../alan-engine/src/tools/find-files.ts"() {
|
|
122269
122632
|
"use strict";
|
|
122270
|
-
|
|
122633
|
+
import_node_path57 = __toESM(require("node:path"), 1);
|
|
122271
122634
|
init_search2();
|
|
122272
122635
|
SCAN_LIMIT = 2e4;
|
|
122273
122636
|
}
|
|
@@ -122325,7 +122688,7 @@ function runUserShell(command, cwd, options = {}) {
|
|
|
122325
122688
|
const child = spawnShellTree(
|
|
122326
122689
|
shell,
|
|
122327
122690
|
process.env,
|
|
122328
|
-
(env) => (0,
|
|
122691
|
+
(env) => (0, import_node_child_process20.spawn)(shell, ["-c", command], {
|
|
122329
122692
|
cwd,
|
|
122330
122693
|
env,
|
|
122331
122694
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -122387,11 +122750,11 @@ function userShellContext(result) {
|
|
|
122387
122750
|
`(${status})`
|
|
122388
122751
|
].join("\n");
|
|
122389
122752
|
}
|
|
122390
|
-
var
|
|
122753
|
+
var import_node_child_process20;
|
|
122391
122754
|
var init_user_shell = __esm({
|
|
122392
122755
|
"../alan-engine/src/tools/user-shell.ts"() {
|
|
122393
122756
|
"use strict";
|
|
122394
|
-
|
|
122757
|
+
import_node_child_process20 = require("node:child_process");
|
|
122395
122758
|
init_bash();
|
|
122396
122759
|
init_process_tree2();
|
|
122397
122760
|
}
|
|
@@ -122755,6 +123118,9 @@ function unavailableHint(call, names2) {
|
|
|
122755
123118
|
const hint = suggestion === void 0 ? "" : ` Did you mean ${suggestion}?`;
|
|
122756
123119
|
return `.${hint} Valid tools: ${names2.join(", ")}`;
|
|
122757
123120
|
}
|
|
123121
|
+
function terminated(result, diagnostics) {
|
|
123122
|
+
return { ...result, diagnostics, control: { ...result.control, terminate: true } };
|
|
123123
|
+
}
|
|
122758
123124
|
function stopMessage(failures) {
|
|
122759
123125
|
return `Stopped: ${failures} tool calls in a row failed validation, so this turn ends here instead of retrying again. Tell the user what you were trying to do and what failed.`;
|
|
122760
123126
|
}
|
|
@@ -122775,6 +123141,10 @@ function createToolRepairExtension(options = {}) {
|
|
|
122775
123141
|
}
|
|
122776
123142
|
}),
|
|
122777
123143
|
hook(ToolTask, {
|
|
123144
|
+
beforeTool: (call, api) => {
|
|
123145
|
+
const stop2 = state2.block(api.conversationId, call);
|
|
123146
|
+
return stop2 === void 0 ? void 0 : { block: stop2 };
|
|
123147
|
+
},
|
|
122778
123148
|
afterTool: (call, result, api, context) => state2.settle(api.conversationId, call, result, context)
|
|
122779
123149
|
})
|
|
122780
123150
|
]
|
|
@@ -122806,7 +123176,8 @@ var init_tool_repair = __esm({
|
|
|
122806
123176
|
const entry2 = this.#conversations.get(id) ?? {
|
|
122807
123177
|
tools: [],
|
|
122808
123178
|
origin: UNKNOWN_ORIGIN,
|
|
122809
|
-
consecutiveFailures: 0
|
|
123179
|
+
consecutiveFailures: 0,
|
|
123180
|
+
stop: void 0
|
|
122810
123181
|
};
|
|
122811
123182
|
this.#conversations.delete(id);
|
|
122812
123183
|
this.#conversations.set(id, entry2);
|
|
@@ -122823,7 +123194,12 @@ var init_tool_repair = __esm({
|
|
|
122823
123194
|
this.#conversation(conversation).tools = tools;
|
|
122824
123195
|
}
|
|
122825
123196
|
startTurn(conversation) {
|
|
122826
|
-
this.#conversation(conversation)
|
|
123197
|
+
const entry2 = this.#conversation(conversation);
|
|
123198
|
+
entry2.consecutiveFailures = 0;
|
|
123199
|
+
entry2.stop = void 0;
|
|
123200
|
+
}
|
|
123201
|
+
block(conversation, call) {
|
|
123202
|
+
return call.parent === void 0 ? this.#conversation(conversation).stop : void 0;
|
|
122827
123203
|
}
|
|
122828
123204
|
tool(conversation, name) {
|
|
122829
123205
|
return this.#conversation(conversation).tools.find((entry2) => entry2.name === name);
|
|
@@ -122905,6 +123281,7 @@ var init_tool_repair = __esm({
|
|
|
122905
123281
|
const entry2 = this.#conversation(conversation);
|
|
122906
123282
|
const code = failureCode(result);
|
|
122907
123283
|
if (code === void 0) {
|
|
123284
|
+
if (entry2.stop !== void 0) return terminated(result, result.diagnostics ?? []);
|
|
122908
123285
|
entry2.consecutiveFailures = 0;
|
|
122909
123286
|
return void 0;
|
|
122910
123287
|
}
|
|
@@ -122917,21 +123294,14 @@ var init_tool_repair = __esm({
|
|
|
122917
123294
|
);
|
|
122918
123295
|
this.report(conversation, "unknown_tool", call.name, context);
|
|
122919
123296
|
}
|
|
123297
|
+
if (entry2.stop !== void 0) return terminated(result, diagnostics);
|
|
122920
123298
|
if (entry2.consecutiveFailures <= MAX_TOOL_REPAIR_RETRIES) {
|
|
122921
123299
|
return diagnostics === result.diagnostics ? void 0 : { ...result, diagnostics };
|
|
122922
123300
|
}
|
|
122923
123301
|
this.report(conversation, "retry_limit", call.name, context);
|
|
122924
|
-
|
|
122925
|
-
|
|
122926
|
-
|
|
122927
|
-
message: stopMessage(entry2.consecutiveFailures)
|
|
122928
|
-
};
|
|
122929
|
-
entry2.consecutiveFailures = 0;
|
|
122930
|
-
return {
|
|
122931
|
-
...result,
|
|
122932
|
-
diagnostics: [...diagnostics, stop2],
|
|
122933
|
-
control: { ...result.control, terminate: true }
|
|
122934
|
-
};
|
|
123302
|
+
entry2.stop = stopMessage(entry2.consecutiveFailures);
|
|
123303
|
+
const stop2 = { severity: "error", code: "repair_limit", message: entry2.stop };
|
|
123304
|
+
return terminated(result, [...diagnostics, stop2]);
|
|
122935
123305
|
}
|
|
122936
123306
|
};
|
|
122937
123307
|
}
|
|
@@ -124234,7 +124604,7 @@ async function openNodeSqliteDatabase(path21, options = {}) {
|
|
|
124234
124604
|
if (options.mode === "read-only")
|
|
124235
124605
|
return new NodeSqliteDatabase(new import_node_sqlite.DatabaseSync(path21, { timeout: timeout2, readOnly: true }), "read-only");
|
|
124236
124606
|
if (path21 !== ":memory:")
|
|
124237
|
-
await (0,
|
|
124607
|
+
await (0, import_promises51.mkdir)((0, import_node_path58.dirname)(path21), { recursive: true });
|
|
124238
124608
|
const database = new import_node_sqlite.DatabaseSync(path21, { timeout: timeout2 });
|
|
124239
124609
|
const adapter = new NodeSqliteDatabase(database);
|
|
124240
124610
|
try {
|
|
@@ -124250,12 +124620,12 @@ async function openNodeSqliteDatabase(path21, options = {}) {
|
|
|
124250
124620
|
throw error62;
|
|
124251
124621
|
}
|
|
124252
124622
|
}
|
|
124253
|
-
var
|
|
124623
|
+
var import_promises51, import_node_path58, import_node_sqlite, DEFAULT_WAL_AUTO_CHECKPOINT_PAGES, DEFAULT_BUSY_TIMEOUT_MS, ignore2, SerialOperationQueue, STATEMENT_CACHE_LIMIT, NodeSqliteExecutor, NodeSqliteTransaction, NodeSqliteDatabase;
|
|
124254
124624
|
var init_node2 = __esm({
|
|
124255
124625
|
"../../node_modules/@earendil-works/chord/dist/sqlite/node.js"() {
|
|
124256
124626
|
"use strict";
|
|
124257
|
-
|
|
124258
|
-
|
|
124627
|
+
import_promises51 = require("node:fs/promises");
|
|
124628
|
+
import_node_path58 = require("node:path");
|
|
124259
124629
|
import_node_sqlite = require("node:sqlite");
|
|
124260
124630
|
DEFAULT_WAL_AUTO_CHECKPOINT_PAGES = 1e3;
|
|
124261
124631
|
DEFAULT_BUSY_TIMEOUT_MS = 5e3;
|
|
@@ -124510,8 +124880,8 @@ var init_subagents3 = __esm({
|
|
|
124510
124880
|
|
|
124511
124881
|
// ../alan-engine/src/engine/session.ts
|
|
124512
124882
|
function sessionPaths(dir, sessionId) {
|
|
124513
|
-
const root = (0,
|
|
124514
|
-
return { root, database: (0,
|
|
124883
|
+
const root = (0, import_node_path59.join)(dir, sessionId);
|
|
124884
|
+
return { root, database: (0, import_node_path59.join)(root, "session.sqlite"), lock: (0, import_node_path59.join)(root, "session.lock") };
|
|
124515
124885
|
}
|
|
124516
124886
|
function deliver(listener, event) {
|
|
124517
124887
|
try {
|
|
@@ -124580,7 +124950,7 @@ async function openEngineSession(options) {
|
|
|
124580
124950
|
if (options.maxTurns !== void 0 && (!Number.isInteger(options.maxTurns) || options.maxTurns < 1))
|
|
124581
124951
|
throw new RangeError("maxTurns must be a positive integer");
|
|
124582
124952
|
const paths = sessionPaths(options.dir, options.sessionId);
|
|
124583
|
-
await (0,
|
|
124953
|
+
await (0, import_promises52.mkdir)(paths.root, { recursive: true });
|
|
124584
124954
|
const lock = await acquireSessionLock(paths.lock);
|
|
124585
124955
|
let mcp;
|
|
124586
124956
|
try {
|
|
@@ -124621,12 +124991,12 @@ async function openEngineSession(options) {
|
|
|
124621
124991
|
throw error62;
|
|
124622
124992
|
}
|
|
124623
124993
|
}
|
|
124624
|
-
var
|
|
124994
|
+
var import_promises52, import_node_path59, ctx, ENTRY_PAGE2, USER_SHELL_ENTRY_KIND, DurableEngineSession;
|
|
124625
124995
|
var init_session7 = __esm({
|
|
124626
124996
|
"../alan-engine/src/engine/session.ts"() {
|
|
124627
124997
|
"use strict";
|
|
124628
|
-
|
|
124629
|
-
|
|
124998
|
+
import_promises52 = require("node:fs/promises");
|
|
124999
|
+
import_node_path59 = require("node:path");
|
|
124630
125000
|
init_context();
|
|
124631
125001
|
init_dist3();
|
|
124632
125002
|
init_node();
|
|
@@ -125016,8 +125386,8 @@ function makeTargets(text4) {
|
|
|
125016
125386
|
}
|
|
125017
125387
|
async function commandsLine(probes, cwd, names2) {
|
|
125018
125388
|
const [manifest, makefile] = await Promise.all([
|
|
125019
|
-
names2.has("package.json") ? probes.readText(
|
|
125020
|
-
names2.has("Makefile") ? probes.readText(
|
|
125389
|
+
names2.has("package.json") ? probes.readText(import_node_path60.default.join(cwd, "package.json")) : void 0,
|
|
125390
|
+
names2.has("Makefile") ? probes.readText(import_node_path60.default.join(cwd, "Makefile")) : void 0
|
|
125021
125391
|
]);
|
|
125022
125392
|
const commands = [...packageScripts(manifest, names2), ...makeTargets(makefile)];
|
|
125023
125393
|
return commands.length === 0 ? void 0 : commands.map((command) => `\`${command}\``).join(", ");
|
|
@@ -125033,7 +125403,7 @@ function directoryLine(entries2) {
|
|
|
125033
125403
|
return more > 0 ? `${listed.join(", ")} (and ${more} more)` : listed.join(", ");
|
|
125034
125404
|
}
|
|
125035
125405
|
function shellLine(shell) {
|
|
125036
|
-
const login = shell === void 0 ? void 0 :
|
|
125406
|
+
const login = shell === void 0 ? void 0 : import_node_path60.default.basename(shell);
|
|
125037
125407
|
return login === void 0 || login === "bash" ? "bash" : `bash for the bash tool (login shell ${login})`;
|
|
125038
125408
|
}
|
|
125039
125409
|
function budgetLine(budget) {
|
|
@@ -125073,13 +125443,13 @@ async function runBounded(command, args) {
|
|
|
125073
125443
|
}
|
|
125074
125444
|
function nodeEnvironmentProbes(shell) {
|
|
125075
125445
|
return {
|
|
125076
|
-
platform:
|
|
125077
|
-
release:
|
|
125078
|
-
arch:
|
|
125446
|
+
platform: import_node_os9.default.platform(),
|
|
125447
|
+
release: import_node_os9.default.release(),
|
|
125448
|
+
arch: import_node_os9.default.arch(),
|
|
125079
125449
|
shell,
|
|
125080
125450
|
run: runBounded,
|
|
125081
|
-
readText: (file2) => (0,
|
|
125082
|
-
listDir: (dir) => (0,
|
|
125451
|
+
readText: (file2) => (0, import_promises53.readFile)(file2, "utf8").catch(() => void 0),
|
|
125452
|
+
listDir: (dir) => (0, import_promises53.readdir)(dir, { withFileTypes: true }).then(
|
|
125083
125453
|
(entries2) => entries2.map((entry2) => ({ name: entry2.name, directory: entry2.isDirectory() })),
|
|
125084
125454
|
() => void 0
|
|
125085
125455
|
)
|
|
@@ -125165,13 +125535,13 @@ function firstTurnEnvironment(options) {
|
|
|
125165
125535
|
recital
|
|
125166
125536
|
};
|
|
125167
125537
|
}
|
|
125168
|
-
var
|
|
125538
|
+
var import_promises53, import_node_os9, import_node_path60, PROBE_TIMEOUT_MS2, SAFE_GIT_CONFIG, MAX_DIRECTORY_ENTRIES, MAX_PACKAGE_JSON_CHARS, RUNTIMES, HIDDEN_ENTRIES, SCRIPT_NAMES, MAKE_TARGETS, LOCKFILES, RECITAL_EXTENSION, TAKE_DEADLINE_MS, MAX_CONVERSATIONS;
|
|
125169
125539
|
var init_alan_pi_environment = __esm({
|
|
125170
125540
|
"src/holder/drivers/alan-pi-environment.ts"() {
|
|
125171
125541
|
"use strict";
|
|
125172
|
-
|
|
125173
|
-
|
|
125174
|
-
|
|
125542
|
+
import_promises53 = require("node:fs/promises");
|
|
125543
|
+
import_node_os9 = __toESM(require("node:os"));
|
|
125544
|
+
import_node_path60 = __toESM(require("node:path"));
|
|
125175
125545
|
init_src2();
|
|
125176
125546
|
init_type_guards();
|
|
125177
125547
|
init_platform();
|
|
@@ -125989,11 +126359,11 @@ function field2(record3, key) {
|
|
|
125989
126359
|
function kindOf(name) {
|
|
125990
126360
|
return KINDS2[name] ?? toolKindFor(name);
|
|
125991
126361
|
}
|
|
125992
|
-
function displayPath(cwd, path21, paths = { isAbsolute:
|
|
126362
|
+
function displayPath(cwd, path21, paths = { isAbsolute: import_node_path61.isAbsolute, relative: import_node_path61.relative, sep: import_node_path61.sep }) {
|
|
125993
126363
|
if (!paths.isAbsolute(path21)) return path21;
|
|
125994
|
-
const
|
|
125995
|
-
if (
|
|
125996
|
-
return
|
|
126364
|
+
const inside = paths.relative(cwd, path21);
|
|
126365
|
+
if (inside === "" || inside.startsWith("..") || paths.isAbsolute(inside)) return path21;
|
|
126366
|
+
return inside.split(paths.sep).join("/");
|
|
125997
126367
|
}
|
|
125998
126368
|
function quoted(value2) {
|
|
125999
126369
|
return value2.length > 60 ? `"${value2.slice(0, 57)}\u2026"` : `"${value2}"`;
|
|
@@ -126030,7 +126400,7 @@ function toolTitle(name, args, context) {
|
|
|
126030
126400
|
function locationsOf(name, args, context) {
|
|
126031
126401
|
const path21 = field2(args, "filePath") || field2(args, "path");
|
|
126032
126402
|
if (path21 === "" || kindOf(name) === "execute" || kindOf(name) === "fetch") return void 0;
|
|
126033
|
-
const absolute = (0,
|
|
126403
|
+
const absolute = (0, import_node_path61.isAbsolute)(path21) ? path21 : (0, import_node_path61.resolve)(context.cwd, path21);
|
|
126034
126404
|
const offset = isRecord(args) ? args.offset : void 0;
|
|
126035
126405
|
return [typeof offset === "number" ? { path: absolute, line: offset } : { path: absolute }];
|
|
126036
126406
|
}
|
|
@@ -126115,11 +126485,11 @@ function toolEndUpdates(result, context) {
|
|
|
126115
126485
|
});
|
|
126116
126486
|
return [row, ...planUpdate(result)];
|
|
126117
126487
|
}
|
|
126118
|
-
var
|
|
126488
|
+
var import_node_path61, EXPLORE_RESULT, KINDS2, TITLES;
|
|
126119
126489
|
var init_alan_pi_tools = __esm({
|
|
126120
126490
|
"src/holder/drivers/alan-pi-tools.ts"() {
|
|
126121
126491
|
"use strict";
|
|
126122
|
-
|
|
126492
|
+
import_node_path61 = require("node:path");
|
|
126123
126493
|
init_acp2();
|
|
126124
126494
|
init_src2();
|
|
126125
126495
|
init_type_guards();
|
|
@@ -126467,8 +126837,9 @@ var init_alan_pi_session = __esm({
|
|
|
126467
126837
|
if (this.#options.bounded) return first;
|
|
126468
126838
|
let settled3 = first;
|
|
126469
126839
|
const sent = { output_limit: 0, narration: 0 };
|
|
126470
|
-
while (!turn.cancelRequested && turn.loops.stopMessage === void 0 && settled3.initial.status === "done") {
|
|
126840
|
+
while (!turn.cancelRequested && !turn.steerAskedToStop && turn.loops.stopMessage === void 0 && settled3.initial.status === "done") {
|
|
126471
126841
|
const last = (await this.#options.engine.transcript()).items.slice(seen).findLast((item) => item.role === "assistant");
|
|
126842
|
+
if (turn.cancelRequested || turn.steerAskedToStop) break;
|
|
126472
126843
|
const reason = stopReason(last);
|
|
126473
126844
|
if (reason === void 0 || sent[reason] >= STOP_CONTINUATIONS[reason].limit) break;
|
|
126474
126845
|
sent[reason] += 1;
|
|
@@ -126481,6 +126852,7 @@ var init_alan_pi_session = __esm({
|
|
|
126481
126852
|
const next = await this.#options.engine.submit(this.#notes.take(note), {
|
|
126482
126853
|
requestId: `${turn.id}:${id}-${attempt}`
|
|
126483
126854
|
});
|
|
126855
|
+
if (turn.cancelRequested) await this.#options.engine.abort();
|
|
126484
126856
|
const again = await this.#settle(turn, next);
|
|
126485
126857
|
settled3 = {
|
|
126486
126858
|
initial: again.initial,
|
|
@@ -126510,6 +126882,7 @@ var init_alan_pi_session = __esm({
|
|
|
126510
126882
|
const next = await this.#options.engine.submit(STEER_CONTINUE, {
|
|
126511
126883
|
requestId: `${input2.turnId}:steer-continue`
|
|
126512
126884
|
});
|
|
126885
|
+
if (turn.cancelRequested) await this.#options.engine.abort();
|
|
126513
126886
|
const again = await this.#settle(turn, next);
|
|
126514
126887
|
settled3 = {
|
|
126515
126888
|
initial: again.initial,
|
|
@@ -127972,15 +128345,25 @@ function engineMcpServers(options, planned) {
|
|
|
127972
128345
|
const alan = options.managedMcp === void 0 ? [] : [alanMcpServer(options.managedMcp, planned.conversationId)];
|
|
127973
128346
|
return [...alan, ...planned.externalMcp];
|
|
127974
128347
|
}
|
|
127975
|
-
function alanPiApprovals(readOnly, mode) {
|
|
128348
|
+
function alanPiApprovals(readOnly, mode, interactive = false) {
|
|
127976
128349
|
if (readOnly) return { mode: "deny-writes" };
|
|
127977
|
-
|
|
128350
|
+
if (mode === "ask") {
|
|
128351
|
+
return { mode: "ask", allowCommands: SAFE_COMMANDS, parkTimeoutMs: GUARD_PARK_TIMEOUT_MS };
|
|
128352
|
+
}
|
|
128353
|
+
return interactive ? { mode: "allow", guards: "ask", parkTimeoutMs: GUARD_PARK_TIMEOUT_MS } : { mode: "allow", guards: "block" };
|
|
127978
128354
|
}
|
|
127979
128355
|
function interactionApprovalMode(spec, fallback) {
|
|
127980
128356
|
const permissions = spec.interaction?.permissions;
|
|
127981
128357
|
if (permissions === void 0) return fallback;
|
|
127982
128358
|
return permissions === "ask" ? "ask" : "allow";
|
|
127983
128359
|
}
|
|
128360
|
+
function alanPiRunApprovals(readOnly, spec, fallback) {
|
|
128361
|
+
return alanPiApprovals(
|
|
128362
|
+
readOnly,
|
|
128363
|
+
interactionApprovalMode(spec, fallback),
|
|
128364
|
+
spec.interaction !== void 0
|
|
128365
|
+
);
|
|
128366
|
+
}
|
|
127984
128367
|
function alanPiThinkingLevel(spec) {
|
|
127985
128368
|
return thinkingLevelForEffort(
|
|
127986
128369
|
spec.selection === void 0 ? spec.selectedEffortLevel : spec.selection.effort
|
|
@@ -128076,13 +128459,21 @@ function alanPiTurnInputWith(environment) {
|
|
|
128076
128459
|
return alanPiTurnInput(spec, inputs, prefix2 || void 0);
|
|
128077
128460
|
};
|
|
128078
128461
|
}
|
|
128079
|
-
function alanApiServices(access6, credentials) {
|
|
128462
|
+
async function alanApiServices(access6, planned, managedMcp, credentials) {
|
|
128080
128463
|
const current = async () => credentials.current;
|
|
128464
|
+
const live = managedMcp === void 0 ? [] : await liveHarnessModels(
|
|
128465
|
+
{
|
|
128466
|
+
apiOrigin: access6.apiOrigin,
|
|
128467
|
+
conversationId: planned.conversationId,
|
|
128468
|
+
authorization: () => managedMcp.authorization(new AbortController().signal)
|
|
128469
|
+
},
|
|
128470
|
+
planned.model
|
|
128471
|
+
);
|
|
128081
128472
|
return {
|
|
128082
128473
|
webSearch: { apiUrl: access6.apiOrigin, credentials: current },
|
|
128083
128474
|
models: createAlanModels({
|
|
128084
128475
|
baseURL: alanHarnessBaseUrl({ apiUrl: access6.apiOrigin, env: {} }),
|
|
128085
|
-
catalog: seedAlanCatalog(),
|
|
128476
|
+
catalog: seedAlanCatalog(harnessModelInputModalities(live)),
|
|
128086
128477
|
credentials: current
|
|
128087
128478
|
})
|
|
128088
128479
|
};
|
|
@@ -128113,7 +128504,7 @@ function alanMcpServer(managedMcp, conversationId) {
|
|
|
128113
128504
|
}
|
|
128114
128505
|
async function exists3(path21) {
|
|
128115
128506
|
try {
|
|
128116
|
-
await (0,
|
|
128507
|
+
await (0, import_promises54.access)(path21);
|
|
128117
128508
|
return true;
|
|
128118
128509
|
} catch {
|
|
128119
128510
|
return false;
|
|
@@ -128164,7 +128555,7 @@ function createAlanPiHolderDriver(options) {
|
|
|
128164
128555
|
extensions: environment.extensions(planned.conversationId),
|
|
128165
128556
|
approvals: planned.approvals,
|
|
128166
128557
|
skills: sessionSkills,
|
|
128167
|
-
...alanApiServices(planned.access, credentials),
|
|
128558
|
+
...await alanApiServices(planned.access, planned, options.managedMcp, credentials),
|
|
128168
128559
|
mcpServers: engineMcpServers(options, planned),
|
|
128169
128560
|
onMcpError: (server, error62) => options.log.warn("alan_pi.mcp_unavailable", { server, error: String(error62) }),
|
|
128170
128561
|
onReport: (error62, info) => options.log.warn("alan_pi.engine_report", { error: String(error62), info })
|
|
@@ -128209,7 +128600,7 @@ function createAlanPiHolderDriver(options) {
|
|
|
128209
128600
|
cwd,
|
|
128210
128601
|
model: model2,
|
|
128211
128602
|
readOnly,
|
|
128212
|
-
approvals: approvals.mode
|
|
128603
|
+
approvals: `${approvals.mode}:${approvals.guards ?? "ask"}`,
|
|
128213
128604
|
origin: access6?.apiOrigin ?? ""
|
|
128214
128605
|
}),
|
|
128215
128606
|
skippedMcpEnvKeys: []
|
|
@@ -128239,10 +128630,7 @@ function createAlanPiHolderDriver(options) {
|
|
|
128239
128630
|
cwd,
|
|
128240
128631
|
readOnly
|
|
128241
128632
|
);
|
|
128242
|
-
const approvals =
|
|
128243
|
-
readOnly,
|
|
128244
|
-
interactionApprovalMode(spec, options.approvals ?? "allow")
|
|
128245
|
-
);
|
|
128633
|
+
const approvals = alanPiRunApprovals(readOnly, spec, options.approvals ?? "allow");
|
|
128246
128634
|
const externalMcp = externalMcpServerConfigs(spec);
|
|
128247
128635
|
skills.current = spec.promptContext?.availableSkills;
|
|
128248
128636
|
thinking.current = alanPiSessionThinking(spec, model2, options.defaultThinking);
|
|
@@ -128266,7 +128654,7 @@ function createAlanPiHolderDriver(options) {
|
|
|
128266
128654
|
model: model2,
|
|
128267
128655
|
systemPrompt,
|
|
128268
128656
|
readOnly,
|
|
128269
|
-
approvals: approvals.mode
|
|
128657
|
+
approvals: `${approvals.mode}:${approvals.guards ?? "ask"}`,
|
|
128270
128658
|
origin: access6?.apiOrigin ?? ""
|
|
128271
128659
|
}),
|
|
128272
128660
|
skippedMcpEnvKeys: []
|
|
@@ -128289,11 +128677,11 @@ function createAlanPiHolderDriver(options) {
|
|
|
128289
128677
|
}
|
|
128290
128678
|
};
|
|
128291
128679
|
}
|
|
128292
|
-
var
|
|
128680
|
+
var import_promises54, GUARD_PARK_TIMEOUT_MS, SAFE_COMMANDS, MODEL_DEFAULT_THINKING, NO_CREDENTIAL;
|
|
128293
128681
|
var init_alan_pi = __esm({
|
|
128294
128682
|
"src/holder/drivers/alan-pi.ts"() {
|
|
128295
128683
|
"use strict";
|
|
128296
|
-
|
|
128684
|
+
import_promises54 = require("node:fs/promises");
|
|
128297
128685
|
init_src();
|
|
128298
128686
|
init_classify2();
|
|
128299
128687
|
init_mcp2();
|
|
@@ -128310,6 +128698,7 @@ var init_alan_pi = __esm({
|
|
|
128310
128698
|
init_alan_pi_prompt();
|
|
128311
128699
|
init_alan_pi_session();
|
|
128312
128700
|
init_persistent();
|
|
128701
|
+
GUARD_PARK_TIMEOUT_MS = 30 * 6e4;
|
|
128313
128702
|
SAFE_COMMANDS = [
|
|
128314
128703
|
"git status",
|
|
128315
128704
|
"git diff",
|
|
@@ -128366,15 +128755,15 @@ function createAlanCodeHolderDriver(options) {
|
|
|
128366
128755
|
const engine = alanCodeEngineKind(options.cliEnvironment);
|
|
128367
128756
|
options.log.info("alan_code.engine_kind", { engine });
|
|
128368
128757
|
if (engine === "opencode") return createAlanCodeOpenCodeDriver(options);
|
|
128369
|
-
const home = options.cliEnvironment.HOME?.trim() || (0,
|
|
128758
|
+
const home = options.cliEnvironment.HOME?.trim() || (0, import_node_os10.homedir)();
|
|
128370
128759
|
const skillFolders = () => {
|
|
128371
128760
|
const synced = options.installedSkills?.()?.skillsDir;
|
|
128372
|
-
return [...synced === void 0 ? [] : [synced], (0,
|
|
128761
|
+
return [...synced === void 0 ? [] : [synced], (0, import_node_path62.join)(home, ".agents", "skills")];
|
|
128373
128762
|
};
|
|
128374
128763
|
return createAlanPiHolderDriver({
|
|
128375
128764
|
defaultCwd: options.defaultCwd,
|
|
128376
128765
|
cliEnvironment: options.cliEnvironment,
|
|
128377
|
-
storageDir: options.engineStateDir ?? (0,
|
|
128766
|
+
storageDir: options.engineStateDir ?? (0, import_node_path62.join)(home, ".alan", "alan-code", "pi"),
|
|
128378
128767
|
log: options.log,
|
|
128379
128768
|
fallback: options.fallback,
|
|
128380
128769
|
approvals: alanCodeApprovals(options.cliEnvironment),
|
|
@@ -128405,11 +128794,12 @@ function createAlanCodeOpenCodeDriver(options) {
|
|
|
128405
128794
|
});
|
|
128406
128795
|
const env = options.cliEnvironment;
|
|
128407
128796
|
const engine = resolveAlanCodeEngine({ env, platform, packaged: [] });
|
|
128408
|
-
const home = env.HOME?.trim() || (0,
|
|
128797
|
+
const home = env.HOME?.trim() || (0, import_node_os10.homedir)();
|
|
128409
128798
|
const engineRoot = alanCodeEngineRoot(home);
|
|
128410
128799
|
const globalConfigDirectory = openCodeGlobalConfigDirectory(env, home);
|
|
128411
|
-
const
|
|
128800
|
+
const plain2 = alanCodeOpenCodePlain(env);
|
|
128412
128801
|
const disabledTools = alanCodeDisabledTools(env);
|
|
128802
|
+
const openedModels = /* @__PURE__ */ new Map();
|
|
128413
128803
|
options.log.info("alan_code.engine", { command: engine.command, source: engine.source });
|
|
128414
128804
|
const profilePlan = (spec, managedMcp) => ({
|
|
128415
128805
|
access: {
|
|
@@ -128430,10 +128820,11 @@ function createAlanCodeOpenCodeDriver(options) {
|
|
|
128430
128820
|
existingConfig: opencode.config?.existing,
|
|
128431
128821
|
clock,
|
|
128432
128822
|
log: options.log,
|
|
128433
|
-
openCodePrompt:
|
|
128823
|
+
openCodePrompt: plain2,
|
|
128434
128824
|
openCodeTestedLine: OPENCODE_TESTED_LINE,
|
|
128435
128825
|
...options.loadModels === void 0 ? {} : { loadModels: options.loadModels }
|
|
128436
128826
|
});
|
|
128827
|
+
openedModels.set(planned.profile.access.conversationId, profile.model);
|
|
128437
128828
|
const openStartedAt = clock.monotonic();
|
|
128438
128829
|
const session = await sessions.open({
|
|
128439
128830
|
...opencode,
|
|
@@ -128446,7 +128837,7 @@ function createAlanCodeOpenCodeDriver(options) {
|
|
|
128446
128837
|
prompt: {
|
|
128447
128838
|
...opencode.prompt,
|
|
128448
128839
|
model: profile.model,
|
|
128449
|
-
system:
|
|
128840
|
+
system: plain2 ? void 0 : alanCodeSystemPrompt(opencode.prompt.system)
|
|
128450
128841
|
}
|
|
128451
128842
|
});
|
|
128452
128843
|
options.log.info("alan_code.cold_open", {
|
|
@@ -128476,7 +128867,7 @@ function createAlanCodeOpenCodeDriver(options) {
|
|
|
128476
128867
|
...alanCodeEngineEnv({ engineRoot, apiKey, conversationId: spec.conversationId })
|
|
128477
128868
|
},
|
|
128478
128869
|
providerEnv: inputs.providerEnv,
|
|
128479
|
-
...managedMcp === void 0 ||
|
|
128870
|
+
...managedMcp === void 0 || plain2 ? {} : { managedMcp },
|
|
128480
128871
|
...resumeId === void 0 ? {} : { resumeSessionId: resumeId },
|
|
128481
128872
|
...skills === null ? {} : { skillPaths: [skills.skillsDir] }
|
|
128482
128873
|
});
|
|
@@ -128487,13 +128878,25 @@ function createAlanCodeOpenCodeDriver(options) {
|
|
|
128487
128878
|
skippedMcpEnvKeys: planned.skippedMcpEnvKeys
|
|
128488
128879
|
};
|
|
128489
128880
|
},
|
|
128490
|
-
canResume: () =>
|
|
128881
|
+
canResume: (_planned, resumeId) => resumeId.startsWith(OPENCODE_SESSION_PREFIX),
|
|
128491
128882
|
open: open7,
|
|
128492
|
-
turnInput: async (spec, inputs, contextPrefix) =>
|
|
128493
|
-
|
|
128494
|
-
|
|
128495
|
-
|
|
128496
|
-
|
|
128883
|
+
turnInput: async (spec, inputs, contextPrefix) => {
|
|
128884
|
+
const { prompt, ...turn } = openCodeTurnInput(spec, {
|
|
128885
|
+
attachments: inputs.attachments,
|
|
128886
|
+
skills: inputs.skills,
|
|
128887
|
+
...contextPrefix === void 0 ? {} : { contextPrefix }
|
|
128888
|
+
});
|
|
128889
|
+
const model2 = openedModels.get(spec.conversationId);
|
|
128890
|
+
if (model2 === void 0) return turn;
|
|
128891
|
+
return {
|
|
128892
|
+
...turn,
|
|
128893
|
+
prompt: {
|
|
128894
|
+
...prompt,
|
|
128895
|
+
model: model2,
|
|
128896
|
+
system: plain2 ? void 0 : alanCodeSystemPrompt(prompt?.system)
|
|
128897
|
+
}
|
|
128898
|
+
};
|
|
128899
|
+
}
|
|
128497
128900
|
},
|
|
128498
128901
|
{
|
|
128499
128902
|
log: options.log,
|
|
@@ -128504,12 +128907,12 @@ function createAlanCodeOpenCodeDriver(options) {
|
|
|
128504
128907
|
}
|
|
128505
128908
|
);
|
|
128506
128909
|
}
|
|
128507
|
-
var
|
|
128910
|
+
var import_node_os10, import_node_path62, ALAN_CODE_APPROVALS_ENV, ALAN_CODE_DISABLED_TOOLS_ENV, ALAN_CODE_OPENCODE_PLAIN_ENV, OPENCODE_SESSION_PREFIX;
|
|
128508
128911
|
var init_alan_code3 = __esm({
|
|
128509
128912
|
"src/holder/drivers/alan-code.ts"() {
|
|
128510
128913
|
"use strict";
|
|
128511
|
-
|
|
128512
|
-
|
|
128914
|
+
import_node_os10 = require("node:os");
|
|
128915
|
+
import_node_path62 = require("node:path");
|
|
128513
128916
|
init_src();
|
|
128514
128917
|
init_alan_code();
|
|
128515
128918
|
init_opencode();
|
|
@@ -128522,6 +128925,7 @@ var init_alan_code3 = __esm({
|
|
|
128522
128925
|
ALAN_CODE_APPROVALS_ENV = "ALAN_CODE_APPROVALS";
|
|
128523
128926
|
ALAN_CODE_DISABLED_TOOLS_ENV = "ALAN_CODE_DISABLED_TOOLS";
|
|
128524
128927
|
ALAN_CODE_OPENCODE_PLAIN_ENV = "ALAN_CODE_OPENCODE_PLAIN";
|
|
128928
|
+
OPENCODE_SESSION_PREFIX = "ses";
|
|
128525
128929
|
}
|
|
128526
128930
|
});
|
|
128527
128931
|
|
|
@@ -128636,8 +129040,8 @@ function parseConfig(raw) {
|
|
|
128636
129040
|
}
|
|
128637
129041
|
}
|
|
128638
129042
|
async function writeCommandCodeProjectMcp(cwd, mcp) {
|
|
128639
|
-
const path21 = (0,
|
|
128640
|
-
const original = await (0,
|
|
129043
|
+
const path21 = (0, import_node_path63.join)(cwd, ".mcp.json");
|
|
129044
|
+
const original = await (0, import_promises55.readFile)(path21, "utf8").catch(() => null);
|
|
128641
129045
|
const config2 = parseConfig(original);
|
|
128642
129046
|
const next = {
|
|
128643
129047
|
...config2,
|
|
@@ -128654,20 +129058,20 @@ async function writeCommandCodeProjectMcp(cwd, mcp) {
|
|
|
128654
129058
|
}
|
|
128655
129059
|
}
|
|
128656
129060
|
};
|
|
128657
|
-
await (0,
|
|
128658
|
-
await (0,
|
|
129061
|
+
await (0, import_promises55.mkdir)(cwd, { recursive: true });
|
|
129062
|
+
await (0, import_promises55.writeFile)(path21, `${JSON.stringify(next, null, 2)}
|
|
128659
129063
|
`);
|
|
128660
129064
|
return async () => {
|
|
128661
|
-
if (original === null) await (0,
|
|
128662
|
-
else await (0,
|
|
129065
|
+
if (original === null) await (0, import_promises55.rm)(path21, { force: true });
|
|
129066
|
+
else await (0, import_promises55.writeFile)(path21, original);
|
|
128663
129067
|
};
|
|
128664
129068
|
}
|
|
128665
|
-
var
|
|
129069
|
+
var import_promises55, import_node_path63;
|
|
128666
129070
|
var init_project_mcp = __esm({
|
|
128667
129071
|
"../agent-core/src/providers/command-code/project-mcp.ts"() {
|
|
128668
129072
|
"use strict";
|
|
128669
|
-
|
|
128670
|
-
|
|
129073
|
+
import_promises55 = require("node:fs/promises");
|
|
129074
|
+
import_node_path63 = require("node:path");
|
|
128671
129075
|
init_agent2();
|
|
128672
129076
|
init_runtime_v2();
|
|
128673
129077
|
init_kernel2();
|
|
@@ -129657,7 +130061,7 @@ function createClaudeHolderDriver(options) {
|
|
|
129657
130061
|
canResume: (planned, resumeId) => claudeSessionLogExists({
|
|
129658
130062
|
sessionId: resumeId,
|
|
129659
130063
|
cwd: planned.spec.cwd,
|
|
129660
|
-
claudeHome: claudeHomeFor(planned.spec.env, options.homeDir ?? (0,
|
|
130064
|
+
claudeHome: claudeHomeFor(planned.spec.env, options.homeDir ?? (0, import_node_os11.homedir)())
|
|
129661
130065
|
}),
|
|
129662
130066
|
open: async (spec) => ({ session: await sessions.open(spec), resumeFailed: false }),
|
|
129663
130067
|
turnInput: (spec, inputs, contextPrefix) => claudeTurnInput(spec, {
|
|
@@ -129675,11 +130079,11 @@ function createClaudeHolderDriver(options) {
|
|
|
129675
130079
|
}
|
|
129676
130080
|
);
|
|
129677
130081
|
}
|
|
129678
|
-
var
|
|
130082
|
+
var import_node_os11;
|
|
129679
130083
|
var init_claude2 = __esm({
|
|
129680
130084
|
"src/holder/drivers/claude.ts"() {
|
|
129681
130085
|
"use strict";
|
|
129682
|
-
|
|
130086
|
+
import_node_os11 = require("node:os");
|
|
129683
130087
|
init_src();
|
|
129684
130088
|
init_claude();
|
|
129685
130089
|
init_kernel();
|
|
@@ -130883,7 +131287,7 @@ function createProviderDrivers(providerOptions) {
|
|
|
130883
131287
|
}
|
|
130884
131288
|
|
|
130885
131289
|
// src/holder/engine-records.ts
|
|
130886
|
-
var
|
|
131290
|
+
var import_node_path64 = require("node:path");
|
|
130887
131291
|
init_process();
|
|
130888
131292
|
init_zod();
|
|
130889
131293
|
init_kernel();
|
|
@@ -130903,7 +131307,7 @@ var engineRecordsSchema = external_exports.strictObject({
|
|
|
130903
131307
|
engines: external_exports.array(engineRecordSchema)
|
|
130904
131308
|
});
|
|
130905
131309
|
function engineRecordsPath(sessionDir) {
|
|
130906
|
-
return (0,
|
|
131310
|
+
return (0, import_node_path64.join)(sessionDir, ENGINES_FILE);
|
|
130907
131311
|
}
|
|
130908
131312
|
function recordSpawnedEngines(path21, clock, log, sessionId) {
|
|
130909
131313
|
const live = /* @__PURE__ */ new Map();
|
|
@@ -130923,7 +131327,7 @@ function recordSpawnedEngines(path21, clock, log, sessionId) {
|
|
|
130923
131327
|
};
|
|
130924
131328
|
writes = writes.then(async () => {
|
|
130925
131329
|
await writeJsonFileAtomic(path21, value2);
|
|
130926
|
-
await createMetadataDurability().sync((0,
|
|
131330
|
+
await createMetadataDurability().sync((0, import_node_path64.dirname)(path21));
|
|
130927
131331
|
});
|
|
130928
131332
|
return writes;
|
|
130929
131333
|
};
|
|
@@ -131076,18 +131480,18 @@ function createConversationMcpAuthorization(options) {
|
|
|
131076
131480
|
}
|
|
131077
131481
|
|
|
131078
131482
|
// src/holder/mcp-helper-access.ts
|
|
131079
|
-
var
|
|
131483
|
+
var import_promises56 = require("node:fs/promises");
|
|
131080
131484
|
init_kernel();
|
|
131081
131485
|
function createHelperMcpAccess(options) {
|
|
131082
131486
|
return {
|
|
131083
131487
|
[Symbol.asyncDispose]: async () => {
|
|
131084
|
-
await (0,
|
|
131488
|
+
await (0, import_promises56.rm)(options.credentialPath, { force: true });
|
|
131085
131489
|
},
|
|
131086
131490
|
url: options.managedMcp.url,
|
|
131087
131491
|
authorization: async (signal) => {
|
|
131088
131492
|
const authorization = await options.managedMcp.authorization(signal);
|
|
131089
131493
|
if (authorization === void 0 || signal.aborted) {
|
|
131090
|
-
await (0,
|
|
131494
|
+
await (0, import_promises56.rm)(options.credentialPath, { force: true });
|
|
131091
131495
|
return void 0;
|
|
131092
131496
|
}
|
|
131093
131497
|
const credential = {
|
|
@@ -131103,8 +131507,8 @@ function createHelperMcpAccess(options) {
|
|
|
131103
131507
|
|
|
131104
131508
|
// src/holder/native-turn-bindings.ts
|
|
131105
131509
|
var import_node_crypto37 = require("node:crypto");
|
|
131106
|
-
var
|
|
131107
|
-
var
|
|
131510
|
+
var import_promises58 = require("node:fs/promises");
|
|
131511
|
+
var import_node_path66 = require("node:path");
|
|
131108
131512
|
init_runtime_v2();
|
|
131109
131513
|
init_zod();
|
|
131110
131514
|
init_kernel();
|
|
@@ -131112,8 +131516,8 @@ init_platform();
|
|
|
131112
131516
|
init_alan_pi_identity();
|
|
131113
131517
|
|
|
131114
131518
|
// src/holder/prepared-session-state.ts
|
|
131115
|
-
var
|
|
131116
|
-
var
|
|
131519
|
+
var import_promises57 = require("node:fs/promises");
|
|
131520
|
+
var import_node_path65 = require("node:path");
|
|
131117
131521
|
init_runtime_v2();
|
|
131118
131522
|
init_zod();
|
|
131119
131523
|
init_kernel();
|
|
@@ -131125,7 +131529,7 @@ var identitySchema = external_exports.strictObject({
|
|
|
131125
131529
|
providerSessionId: external_exports.string().min(1).max(512)
|
|
131126
131530
|
});
|
|
131127
131531
|
async function readPreparedIdentityRecord(directory) {
|
|
131128
|
-
const saved = await readJsonFile((0,
|
|
131532
|
+
const saved = await readJsonFile((0, import_node_path65.join)(directory, "engine-session.json"), identitySchema);
|
|
131129
131533
|
if (saved.kind === "missing") return void 0;
|
|
131130
131534
|
if (saved.kind !== "ok") throw new LocalSessionActionError("history_unavailable");
|
|
131131
131535
|
return saved.value;
|
|
@@ -131134,7 +131538,7 @@ function samePreparationBinding(a, b) {
|
|
|
131134
131538
|
return Object.keys(a).every((key) => Reflect.get(a, key) === Reflect.get(b, key));
|
|
131135
131539
|
}
|
|
131136
131540
|
async function readPreparedIdentity(directory, binding) {
|
|
131137
|
-
const saved = await readJsonFile((0,
|
|
131541
|
+
const saved = await readJsonFile((0, import_node_path65.join)(directory, "engine-session.json"), identitySchema);
|
|
131138
131542
|
if (saved.kind === "missing") return void 0;
|
|
131139
131543
|
if (saved.kind !== "ok") throw new LocalSessionActionError("history_unavailable");
|
|
131140
131544
|
if (!samePreparationBinding(saved.value.binding, binding))
|
|
@@ -131150,9 +131554,9 @@ async function writePreparedIdentity(directory, binding, providerSessionId) {
|
|
|
131150
131554
|
binding,
|
|
131151
131555
|
providerSessionId
|
|
131152
131556
|
});
|
|
131153
|
-
await (0,
|
|
131154
|
-
await (0,
|
|
131155
|
-
await writeJsonFileAtomic((0,
|
|
131557
|
+
await (0, import_promises57.mkdir)(directory, { recursive: true, mode: 448 });
|
|
131558
|
+
await (0, import_promises57.chmod)(directory, 448);
|
|
131559
|
+
await writeJsonFileAtomic((0, import_node_path65.join)(directory, "engine-session.json"), value2);
|
|
131156
131560
|
await createMetadataDurability().sync(directory);
|
|
131157
131561
|
}
|
|
131158
131562
|
|
|
@@ -131388,19 +131792,19 @@ function reserveFloor(current, identity2) {
|
|
|
131388
131792
|
async function openNativeTurnBindings(options) {
|
|
131389
131793
|
if (nativeEngineOwnership() !== "durable-posix") throw unavailable2();
|
|
131390
131794
|
const { directory, machineId, conversationId } = options;
|
|
131391
|
-
const runDirectory2 = (0,
|
|
131392
|
-
const orderPath = (0,
|
|
131393
|
-
await (0,
|
|
131394
|
-
await (0,
|
|
131395
|
-
await (0,
|
|
131795
|
+
const runDirectory2 = (0, import_node_path66.join)(directory, "native-turn-bindings");
|
|
131796
|
+
const orderPath = (0, import_node_path66.join)(directory, "native-message-order.json");
|
|
131797
|
+
await (0, import_promises58.mkdir)(runDirectory2, { recursive: true, mode: 448 });
|
|
131798
|
+
await (0, import_promises58.chmod)(directory, 448);
|
|
131799
|
+
await (0, import_promises58.chmod)(runDirectory2, 448);
|
|
131396
131800
|
await createMetadataDurability().sync(directory);
|
|
131397
131801
|
const stored = await readJsonFile(orderPath, projectionSchema);
|
|
131398
131802
|
if (stored.kind === "invalid") throw unavailable2();
|
|
131399
131803
|
let projection = stored.kind === "ok" ? stored.value : void 0;
|
|
131400
131804
|
const unresolved = /* @__PURE__ */ new Set();
|
|
131401
|
-
const names2 = await (0,
|
|
131805
|
+
const names2 = await (0, import_promises58.readdir)(runDirectory2);
|
|
131402
131806
|
for (const name of names2.filter((entry2) => entry2.endsWith(".json"))) {
|
|
131403
|
-
const item = await readJsonFile((0,
|
|
131807
|
+
const item = await readJsonFile((0, import_node_path66.join)(runDirectory2, name), bindingSchema);
|
|
131404
131808
|
if (item.kind !== "ok" || item.value.machineId !== machineId || item.value.conversationId !== conversationId || name !== `${item.value.runId}.json`)
|
|
131405
131809
|
throw unavailable2();
|
|
131406
131810
|
if (!projection) throw unavailable2();
|
|
@@ -131468,7 +131872,7 @@ async function openNativeTurnBindings(options) {
|
|
|
131468
131872
|
workspace ||= options.defaultWorkspace ?? "";
|
|
131469
131873
|
if (spec.conversationId !== conversationId || !workspace) throw unavailable2();
|
|
131470
131874
|
const allowSupplied = canonicalPair(spec);
|
|
131471
|
-
const path21 = (0,
|
|
131875
|
+
const path21 = (0, import_node_path66.join)(runDirectory2, `${spec.runId}.json`);
|
|
131472
131876
|
const specDigest = digest3(spec);
|
|
131473
131877
|
let record3;
|
|
131474
131878
|
const save = async () => {
|
|
@@ -131543,25 +131947,25 @@ async function openNativeTurnBindings(options) {
|
|
|
131543
131947
|
}
|
|
131544
131948
|
|
|
131545
131949
|
// src/holder/requested-checkout.ts
|
|
131546
|
-
var
|
|
131547
|
-
var
|
|
131950
|
+
var import_promises60 = require("node:fs/promises");
|
|
131951
|
+
var import_node_path68 = require("node:path");
|
|
131548
131952
|
init_capabilities3();
|
|
131549
131953
|
|
|
131550
131954
|
// src/holder/claim-once.ts
|
|
131551
131955
|
var import_node_crypto38 = require("node:crypto");
|
|
131552
|
-
var
|
|
131553
|
-
var
|
|
131956
|
+
var import_promises59 = require("node:fs/promises");
|
|
131957
|
+
var import_node_path67 = require("node:path");
|
|
131554
131958
|
async function claimOnce(dir, name) {
|
|
131555
131959
|
try {
|
|
131556
|
-
await (0,
|
|
131557
|
-
await (await (0,
|
|
131960
|
+
await (0, import_promises59.mkdir)(dir, { recursive: true, mode: 448 });
|
|
131961
|
+
await (await (0, import_promises59.open)((0, import_node_path67.join)(dir, name), "wx")).close();
|
|
131558
131962
|
return true;
|
|
131559
131963
|
} catch {
|
|
131560
131964
|
return false;
|
|
131561
131965
|
}
|
|
131562
131966
|
}
|
|
131563
131967
|
function claimFirstLease(freshnessDir, path21) {
|
|
131564
|
-
return claimOnce((0,
|
|
131968
|
+
return claimOnce((0, import_node_path67.join)(freshnessDir, "leased"), (0, import_node_crypto38.createHash)("sha256").update(path21).digest("hex"));
|
|
131565
131969
|
}
|
|
131566
131970
|
|
|
131567
131971
|
// src/holder/requested-checkout.ts
|
|
@@ -131585,8 +131989,8 @@ function notSwitched(checkout, current, reason) {
|
|
|
131585
131989
|
);
|
|
131586
131990
|
}
|
|
131587
131991
|
async function clone2(checkout, deps, signal) {
|
|
131588
|
-
const parent = (0,
|
|
131589
|
-
await (0,
|
|
131992
|
+
const parent = (0, import_node_path68.dirname)(checkout.path);
|
|
131993
|
+
await (0, import_promises60.mkdir)(parent, { recursive: true });
|
|
131590
131994
|
await assertValidBranch(deps.git, parent, checkout.branch, signal);
|
|
131591
131995
|
const output2 = await deps.git.run(
|
|
131592
131996
|
{
|
|
@@ -131752,8 +132156,8 @@ async function applyRequestedCheckout(checkout, operationId, deps, signal) {
|
|
|
131752
132156
|
}
|
|
131753
132157
|
|
|
131754
132158
|
// src/holder/run-inputs.ts
|
|
131755
|
-
var
|
|
131756
|
-
var
|
|
132159
|
+
var import_promises61 = require("node:fs/promises");
|
|
132160
|
+
var import_node_path69 = require("node:path");
|
|
131757
132161
|
init_src();
|
|
131758
132162
|
var NO_RUN_INPUTS = {
|
|
131759
132163
|
attachments: [],
|
|
@@ -131767,17 +132171,17 @@ function safeFilename(filename) {
|
|
|
131767
132171
|
return safe || "attachment";
|
|
131768
132172
|
}
|
|
131769
132173
|
function persistentAttachmentDir(workspaceRoot2) {
|
|
131770
|
-
return (0,
|
|
132174
|
+
return (0, import_node_path69.join)(workspaceRoot2, ".alan", "attachments");
|
|
131771
132175
|
}
|
|
131772
132176
|
function attachmentPath(spec, attachment, index, runDir) {
|
|
131773
132177
|
const workspaceRoot2 = spec.approvedWorkspacePaths?.[0];
|
|
131774
132178
|
if (attachment.persist && workspaceRoot2) {
|
|
131775
|
-
return (0,
|
|
132179
|
+
return (0, import_node_path69.join)(
|
|
131776
132180
|
persistentAttachmentDir(workspaceRoot2),
|
|
131777
132181
|
`${attachment.id.slice(0, 8)}-${safeFilename(attachment.filename)}`
|
|
131778
132182
|
);
|
|
131779
132183
|
}
|
|
131780
|
-
return (0,
|
|
132184
|
+
return (0, import_node_path69.join)(runDir, `${index}-${safeFilename(attachment.filename)}`);
|
|
131781
132185
|
}
|
|
131782
132186
|
function runMediaUploader(source, runId) {
|
|
131783
132187
|
const upload = source.uploadMedia?.bind(source);
|
|
@@ -131789,8 +132193,8 @@ function runMediaUploader(source, runId) {
|
|
|
131789
132193
|
async function downloadRunAttachment(spec, attachment, index, dir, { source, signal }) {
|
|
131790
132194
|
const bytes2 = await source.downloadAttachment(spec.runId, attachment.id, signal);
|
|
131791
132195
|
const path21 = attachmentPath(spec, attachment, index, dir);
|
|
131792
|
-
await (0,
|
|
131793
|
-
await (0,
|
|
132196
|
+
await (0, import_promises61.mkdir)((0, import_node_path69.dirname)(path21), { recursive: true, mode: 448 });
|
|
132197
|
+
await (0, import_promises61.writeFile)(path21, bytes2, { mode: 384 });
|
|
131794
132198
|
const imageMimeType = attachment.kind === "image" ? detectImageMimeType(Buffer.from(bytes2.buffer, bytes2.byteOffset, bytes2.byteLength)) : null;
|
|
131795
132199
|
return {
|
|
131796
132200
|
id: attachment.id,
|
|
@@ -131811,9 +132215,9 @@ async function settleAll(pending) {
|
|
|
131811
132215
|
return Promise.all(pending);
|
|
131812
132216
|
}
|
|
131813
132217
|
async function prepareRunInputs(spec, options) {
|
|
131814
|
-
const dir = (0,
|
|
132218
|
+
const dir = (0, import_node_path69.join)(options.tmpDir, "runs", spec.runId);
|
|
131815
132219
|
const cleanup = async () => {
|
|
131816
|
-
await (0,
|
|
132220
|
+
await (0, import_promises61.rm)(dir, { recursive: true, force: true });
|
|
131817
132221
|
};
|
|
131818
132222
|
try {
|
|
131819
132223
|
const [credential, attachments] = await settleAll([
|
|
@@ -131845,7 +132249,7 @@ async function prepareRunInputs(spec, options) {
|
|
|
131845
132249
|
// src/holder/serve.ts
|
|
131846
132250
|
var import_node_crypto41 = require("node:crypto");
|
|
131847
132251
|
var import_node_net = require("node:net");
|
|
131848
|
-
var
|
|
132252
|
+
var import_node_path78 = require("node:path");
|
|
131849
132253
|
init_runtime_v2();
|
|
131850
132254
|
init_kernel();
|
|
131851
132255
|
init_platform();
|
|
@@ -131861,16 +132265,16 @@ function replyToAbort({ driver, queuedStarts, holder, background }, request3, cl
|
|
|
131861
132265
|
|
|
131862
132266
|
// src/holder/admission.ts
|
|
131863
132267
|
var import_node_fs28 = require("node:fs");
|
|
131864
|
-
var
|
|
131865
|
-
var
|
|
131866
|
-
var
|
|
132268
|
+
var import_promises64 = require("node:fs/promises");
|
|
132269
|
+
var import_node_os13 = require("node:os");
|
|
132270
|
+
var import_node_path74 = require("node:path");
|
|
131867
132271
|
init_constants();
|
|
131868
132272
|
|
|
131869
132273
|
// ../shared/src/node/local-workspace.ts
|
|
131870
|
-
var
|
|
131871
|
-
var
|
|
131872
|
-
function resolveAlanDefaultWorkspacePath(homeDirectory = (0,
|
|
131873
|
-
return (0,
|
|
132274
|
+
var import_node_os12 = require("node:os");
|
|
132275
|
+
var import_node_path70 = require("node:path");
|
|
132276
|
+
function resolveAlanDefaultWorkspacePath(homeDirectory = (0, import_node_os12.homedir)()) {
|
|
132277
|
+
return (0, import_node_path70.join)(homeDirectory, ".alan", "workspace");
|
|
131874
132278
|
}
|
|
131875
132279
|
|
|
131876
132280
|
// src/holder/admission.ts
|
|
@@ -131878,12 +132282,12 @@ init_capabilities3();
|
|
|
131878
132282
|
init_kernel();
|
|
131879
132283
|
|
|
131880
132284
|
// src/holder/agent-context.ts
|
|
131881
|
-
var
|
|
131882
|
-
var
|
|
132285
|
+
var import_promises62 = require("node:fs/promises");
|
|
132286
|
+
var import_node_path71 = require("node:path");
|
|
131883
132287
|
init_prompt();
|
|
131884
132288
|
init_kernel();
|
|
131885
132289
|
async function readText3(path21) {
|
|
131886
|
-
return (0,
|
|
132290
|
+
return (0, import_promises62.readFile)(path21, "utf8").then(
|
|
131887
132291
|
(text4) => text4.trim(),
|
|
131888
132292
|
() => null
|
|
131889
132293
|
);
|
|
@@ -131898,10 +132302,10 @@ async function startCommandState(statusPath) {
|
|
|
131898
132302
|
return code === 0 ? { state: "exited_ok" } : { state: "failed", exitCode: code };
|
|
131899
132303
|
}
|
|
131900
132304
|
function createAgentContext(deps) {
|
|
131901
|
-
const statusPath = (0,
|
|
131902
|
-
const logPath = (0,
|
|
132305
|
+
const statusPath = (0, import_node_path71.join)(deps.homeDir, ".alan", "start-commands.status");
|
|
132306
|
+
const logPath = (0, import_node_path71.join)(deps.homeDir, ".alan", "start-commands.log");
|
|
131903
132307
|
return async (spec, problems) => {
|
|
131904
|
-
const file2 = (0,
|
|
132308
|
+
const file2 = (0, import_node_path71.join)(deps.dir, `${spec.conversationId}.json`);
|
|
131905
132309
|
const saved = await readJsonFile(file2, agentContextSnapshotSchema);
|
|
131906
132310
|
const known = saved.kind === "ok" ? saved.value : void 0;
|
|
131907
132311
|
const hasEnvironment = (spec.agentContext ?? known)?.environment !== void 0;
|
|
@@ -131925,7 +132329,7 @@ function createAgentContext(deps) {
|
|
|
131925
132329
|
}
|
|
131926
132330
|
|
|
131927
132331
|
// src/holder/checkout-refresh.ts
|
|
131928
|
-
var
|
|
132332
|
+
var import_node_path72 = require("node:path");
|
|
131929
132333
|
init_capabilities3();
|
|
131930
132334
|
function short(sha2) {
|
|
131931
132335
|
return sha2.slice(0, 12);
|
|
@@ -132015,7 +132419,7 @@ async function applyRequestedCheckouts(spec, deps, signal) {
|
|
|
132015
132419
|
ms: Date.now() - startedAt
|
|
132016
132420
|
});
|
|
132017
132421
|
if (outcome2.kind === "on_branch") continue;
|
|
132018
|
-
settled3.add((0,
|
|
132422
|
+
settled3.add((0, import_node_path72.resolve)(checkout.path));
|
|
132019
132423
|
if (outcome2.kind === "noted") {
|
|
132020
132424
|
problems.push({ path: checkout.path, problem: outcome2.problem, action: outcome2.action });
|
|
132021
132425
|
}
|
|
@@ -132025,7 +132429,7 @@ async function applyRequestedCheckouts(spec, deps, signal) {
|
|
|
132025
132429
|
async function refreshSnapshotCheckouts(spec, targets, settled3, deps, signal) {
|
|
132026
132430
|
const problems = [];
|
|
132027
132431
|
for (const target of targets) {
|
|
132028
|
-
if (settled3.has((0,
|
|
132432
|
+
if (settled3.has((0, import_node_path72.resolve)(target))) continue;
|
|
132029
132433
|
const freshness = await readCheckoutFreshness(deps.dir, target);
|
|
132030
132434
|
if (freshness === null) continue;
|
|
132031
132435
|
const startedAt = Date.now();
|
|
@@ -132046,7 +132450,7 @@ async function refreshSnapshotCheckouts(spec, targets, settled3, deps, signal) {
|
|
|
132046
132450
|
function createCheckoutRefresh(deps) {
|
|
132047
132451
|
return async (spec, signal) => {
|
|
132048
132452
|
if (spec.providerSessionId !== void 0) return [];
|
|
132049
|
-
if (!await claimOnce((0,
|
|
132453
|
+
if (!await claimOnce((0, import_node_path72.join)(deps.dir, "conversations"), spec.conversationId)) return [];
|
|
132050
132454
|
const requested = await applyRequestedCheckouts(spec, deps, signal);
|
|
132051
132455
|
const targets = await checkoutsOf(spec);
|
|
132052
132456
|
return [
|
|
@@ -132057,8 +132461,8 @@ function createCheckoutRefresh(deps) {
|
|
|
132057
132461
|
}
|
|
132058
132462
|
|
|
132059
132463
|
// src/holder/git-state.ts
|
|
132060
|
-
var
|
|
132061
|
-
var
|
|
132464
|
+
var import_promises63 = require("node:fs/promises");
|
|
132465
|
+
var import_node_path73 = require("node:path");
|
|
132062
132466
|
init_runtime_v2();
|
|
132063
132467
|
var SHA_PATTERN = /^[0-9a-f]{40,64}$/;
|
|
132064
132468
|
var REF_NAME_MAX_LENGTH = 256;
|
|
@@ -132132,7 +132536,7 @@ async function readRepository(git, repoRoot, signal) {
|
|
|
132132
132536
|
}
|
|
132133
132537
|
async function isCheckout2(path21) {
|
|
132134
132538
|
try {
|
|
132135
|
-
await (0,
|
|
132539
|
+
await (0, import_promises63.stat)((0, import_node_path73.join)(path21, ".git"));
|
|
132136
132540
|
return true;
|
|
132137
132541
|
} catch {
|
|
132138
132542
|
return false;
|
|
@@ -132140,8 +132544,8 @@ async function isCheckout2(path21) {
|
|
|
132140
132544
|
}
|
|
132141
132545
|
async function childCheckouts(path21) {
|
|
132142
132546
|
try {
|
|
132143
|
-
const entries2 = await (0,
|
|
132144
|
-
const children = entries2.filter((entry2) => entry2.isDirectory() && !entry2.name.startsWith(".")).map((entry2) => (0,
|
|
132547
|
+
const entries2 = await (0, import_promises63.readdir)(path21, { withFileTypes: true });
|
|
132548
|
+
const children = entries2.filter((entry2) => entry2.isDirectory() && !entry2.name.startsWith(".")).map((entry2) => (0, import_node_path73.join)(path21, entry2.name));
|
|
132145
132549
|
const checkouts = await Promise.all(
|
|
132146
132550
|
children.map(async (child) => await isCheckout2(child) ? child : null)
|
|
132147
132551
|
);
|
|
@@ -132163,7 +132567,7 @@ async function repositoryRoots(git, spec, signal) {
|
|
|
132163
132567
|
const root = await read3(git, folder, ["rev-parse", "--show-toplevel"], signal).catch(
|
|
132164
132568
|
() => null
|
|
132165
132569
|
);
|
|
132166
|
-
if (root !== null) roots.add((0,
|
|
132570
|
+
if (root !== null) roots.add((0, import_node_path73.resolve)(root));
|
|
132167
132571
|
else for (const child of await childCheckouts(folder)) roots.add(child);
|
|
132168
132572
|
if (roots.size >= RUN_GIT_STATE_MAX_REPOSITORIES) break;
|
|
132169
132573
|
}
|
|
@@ -132210,7 +132614,7 @@ function volumeRoot(path21) {
|
|
|
132210
132614
|
}
|
|
132211
132615
|
async function exists4(path21) {
|
|
132212
132616
|
try {
|
|
132213
|
-
await (0,
|
|
132617
|
+
await (0, import_promises64.stat)(path21);
|
|
132214
132618
|
return true;
|
|
132215
132619
|
} catch {
|
|
132216
132620
|
return false;
|
|
@@ -132218,10 +132622,10 @@ async function exists4(path21) {
|
|
|
132218
132622
|
}
|
|
132219
132623
|
async function inspectReadiness(path21) {
|
|
132220
132624
|
try {
|
|
132221
|
-
if (!(await (0,
|
|
132625
|
+
if (!(await (0, import_promises64.stat)(path21)).isDirectory()) {
|
|
132222
132626
|
return { ready: false, missing: true, message: MESSAGES.missing };
|
|
132223
132627
|
}
|
|
132224
|
-
await (0,
|
|
132628
|
+
await (0, import_promises64.access)(path21, import_node_fs28.constants.R_OK | import_node_fs28.constants.W_OK | import_node_fs28.constants.X_OK);
|
|
132225
132629
|
return { ready: true };
|
|
132226
132630
|
} catch (error62) {
|
|
132227
132631
|
const code = errnoCode(error62) ?? "";
|
|
@@ -132265,10 +132669,10 @@ async function checkProvider(spec, context) {
|
|
|
132265
132669
|
}
|
|
132266
132670
|
async function admitDefaultWorkspace(spec, context, skills) {
|
|
132267
132671
|
const { env } = context;
|
|
132268
|
-
const path21 = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0,
|
|
132672
|
+
const path21 = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os13.homedir)());
|
|
132269
132673
|
try {
|
|
132270
|
-
await (0,
|
|
132271
|
-
await (0,
|
|
132674
|
+
await (0, import_promises64.mkdir)(path21, { recursive: true, mode: 448 });
|
|
132675
|
+
await (0, import_promises64.access)(path21, import_node_fs28.constants.R_OK | import_node_fs28.constants.W_OK | import_node_fs28.constants.X_OK);
|
|
132272
132676
|
return { kind: "admitted", spec: { ...spec, projectPath: path21 }, skills };
|
|
132273
132677
|
} catch (error62) {
|
|
132274
132678
|
const code = errnoCode(error62);
|
|
@@ -132374,11 +132778,11 @@ function createHolderWorkspace(machine, clock, log) {
|
|
|
132374
132778
|
platform,
|
|
132375
132779
|
skills: skillsLayout(
|
|
132376
132780
|
machine.stateDir,
|
|
132377
|
-
machine.env.HOME || machine.env.USERPROFILE || (0,
|
|
132781
|
+
machine.env.HOME || machine.env.USERPROFILE || (0, import_node_os13.homedir)()
|
|
132378
132782
|
),
|
|
132379
132783
|
approvedRoots: async () => {
|
|
132380
132784
|
const approved = await openApprovedPaths({
|
|
132381
|
-
file: (0,
|
|
132785
|
+
file: (0, import_node_path74.join)(machine.stateDir, "workspaces.json"),
|
|
132382
132786
|
log,
|
|
132383
132787
|
platform
|
|
132384
132788
|
});
|
|
@@ -132395,13 +132799,13 @@ function createHolderWorkspace(machine, clock, log) {
|
|
|
132395
132799
|
localTimeoutMs: CHECKOUT_LOCAL_TIMEOUT_MS,
|
|
132396
132800
|
networkTimeoutMs: CHECKOUT_NETWORK_TIMEOUT_MS
|
|
132397
132801
|
}),
|
|
132398
|
-
locks: openRepositoryLocks({ dir: (0,
|
|
132802
|
+
locks: openRepositoryLocks({ dir: (0, import_node_path74.join)(machine.stateDir, "locks"), clock, platform }),
|
|
132399
132803
|
log,
|
|
132400
|
-
dir: (0,
|
|
132804
|
+
dir: (0, import_node_path74.join)(machine.stateDir, "checkout-freshness")
|
|
132401
132805
|
}),
|
|
132402
132806
|
prepareAgentContext: createAgentContext({
|
|
132403
|
-
dir: (0,
|
|
132404
|
-
homeDir: machine.env.HOME || (0,
|
|
132807
|
+
dir: (0, import_node_path74.join)(machine.stateDir, "agent-context"),
|
|
132808
|
+
homeDir: machine.env.HOME || (0, import_node_os13.homedir)()
|
|
132405
132809
|
})
|
|
132406
132810
|
} : {}
|
|
132407
132811
|
};
|
|
@@ -132411,8 +132815,8 @@ function createHolderWorkspace(machine, clock, log) {
|
|
|
132411
132815
|
init_acp2();
|
|
132412
132816
|
|
|
132413
132817
|
// src/run-log/directory.ts
|
|
132414
|
-
var
|
|
132415
|
-
var
|
|
132818
|
+
var import_promises65 = require("node:fs/promises");
|
|
132819
|
+
var import_node_path75 = require("node:path");
|
|
132416
132820
|
init_runtime_v2();
|
|
132417
132821
|
init_zod();
|
|
132418
132822
|
init_kernel();
|
|
@@ -132436,17 +132840,17 @@ var runMetaSchema = external_exports.object({
|
|
|
132436
132840
|
}).optional()
|
|
132437
132841
|
});
|
|
132438
132842
|
function runDirectory(runsDir, runId) {
|
|
132439
|
-
const dir = (0,
|
|
132843
|
+
const dir = (0, import_node_path75.join)(runsDir, runId);
|
|
132440
132844
|
return {
|
|
132441
132845
|
dir,
|
|
132442
|
-
log: (0,
|
|
132443
|
-
upload: (0,
|
|
132444
|
-
meta: (0,
|
|
132846
|
+
log: (0, import_node_path75.join)(dir, "log.jsonl"),
|
|
132847
|
+
upload: (0, import_node_path75.join)(dir, "upload.json"),
|
|
132848
|
+
meta: (0, import_node_path75.join)(dir, "run.json")
|
|
132445
132849
|
};
|
|
132446
132850
|
}
|
|
132447
132851
|
async function isRunClaimed(runsDir, runId) {
|
|
132448
132852
|
try {
|
|
132449
|
-
return (await (0,
|
|
132853
|
+
return (await (0, import_promises65.stat)(runDirectory(runsDir, runId).log)).size > 0;
|
|
132450
132854
|
} catch (error62) {
|
|
132451
132855
|
if (errnoCode(error62) === "ENOENT") return false;
|
|
132452
132856
|
throw error62;
|
|
@@ -132454,8 +132858,8 @@ async function isRunClaimed(runsDir, runId) {
|
|
|
132454
132858
|
}
|
|
132455
132859
|
|
|
132456
132860
|
// src/run-log/conversation-index.ts
|
|
132457
|
-
var
|
|
132458
|
-
var
|
|
132861
|
+
var import_promises66 = require("node:fs/promises");
|
|
132862
|
+
var import_node_path76 = require("node:path");
|
|
132459
132863
|
init_runtime_v2();
|
|
132460
132864
|
init_zod();
|
|
132461
132865
|
init_kernel();
|
|
@@ -132472,13 +132876,13 @@ var coverageSchema2 = external_exports.object({
|
|
|
132472
132876
|
nextExpectedOrdinal: external_exports.number().int().positive()
|
|
132473
132877
|
});
|
|
132474
132878
|
function conversationsDirectory(runsDir) {
|
|
132475
|
-
return (0,
|
|
132879
|
+
return (0, import_node_path76.join)((0, import_node_path76.dirname)(runsDir), "conversations");
|
|
132476
132880
|
}
|
|
132477
132881
|
function indexDirectory(runsDir, conversationId) {
|
|
132478
|
-
return (0,
|
|
132882
|
+
return (0, import_node_path76.join)(conversationsDirectory(runsDir), conversationId, "turn-index");
|
|
132479
132883
|
}
|
|
132480
132884
|
function shardPath(runsDir, conversationId, ordinal) {
|
|
132481
|
-
return (0,
|
|
132885
|
+
return (0, import_node_path76.join)(
|
|
132482
132886
|
indexDirectory(runsDir, conversationId),
|
|
132483
132887
|
`${Math.floor(ordinal / ORDINALS_PER_SHARD)}.jsonl`
|
|
132484
132888
|
);
|
|
@@ -132487,10 +132891,10 @@ async function indexConversationRun(runsDir, conversationId, ordinal, assistantO
|
|
|
132487
132891
|
const nextOrdinal = assistantOrdinal + 1;
|
|
132488
132892
|
if (nextOrdinal <= ordinal) throw new Error("Assistant order must follow the prompt");
|
|
132489
132893
|
const path21 = shardPath(runsDir, conversationId, ordinal);
|
|
132490
|
-
await (0,
|
|
132491
|
-
await (0,
|
|
132894
|
+
await (0, import_promises66.mkdir)((0, import_node_path76.dirname)(path21), { recursive: true, mode: 448 });
|
|
132895
|
+
await (0, import_promises66.appendFile)(path21, `${JSON.stringify({ ordinal, nextOrdinal, runId })}
|
|
132492
132896
|
`, { mode: 384 });
|
|
132493
|
-
const coveragePath = (0,
|
|
132897
|
+
const coveragePath = (0, import_node_path76.join)((0, import_node_path76.dirname)((0, import_node_path76.dirname)(path21)), "coverage.json");
|
|
132494
132898
|
const coverage = await readJsonFile(coveragePath, coverageSchema2);
|
|
132495
132899
|
const current = coverage.kind === "ok" ? coverage.value : null;
|
|
132496
132900
|
const next = nextCoverage(current, ordinal, nextOrdinal);
|
|
@@ -132550,7 +132954,7 @@ var decoder2 = new TextDecoder();
|
|
|
132550
132954
|
|
|
132551
132955
|
// src/run-log/writer.ts
|
|
132552
132956
|
var import_node_fs29 = require("node:fs");
|
|
132553
|
-
var
|
|
132957
|
+
var import_node_path77 = require("node:path");
|
|
132554
132958
|
init_runtime_v2();
|
|
132555
132959
|
init_kernel();
|
|
132556
132960
|
|
|
@@ -132648,7 +133052,7 @@ function writeAt(fd, bytes2, position) {
|
|
|
132648
133052
|
}
|
|
132649
133053
|
}
|
|
132650
133054
|
function openRunLog(path21, clock) {
|
|
132651
|
-
(0, import_node_fs29.mkdirSync)((0,
|
|
133055
|
+
(0, import_node_fs29.mkdirSync)((0, import_node_path77.dirname)(path21), { recursive: true, mode: 448 });
|
|
132652
133056
|
const fd = (0, import_node_fs29.openSync)(path21, import_node_fs29.constants.O_RDWR | import_node_fs29.constants.O_CREAT, 384);
|
|
132653
133057
|
const fileSize = (0, import_node_fs29.fstatSync)(fd).size;
|
|
132654
133058
|
const tail2 = readTail(fd, fileSize);
|
|
@@ -133664,7 +134068,7 @@ function replyToStopTask({ driver, log }, request3, client) {
|
|
|
133664
134068
|
}
|
|
133665
134069
|
|
|
133666
134070
|
// src/holder/session-facts.ts
|
|
133667
|
-
var
|
|
134071
|
+
var import_promises67 = require("node:fs/promises");
|
|
133668
134072
|
init_capabilities3();
|
|
133669
134073
|
init_platform();
|
|
133670
134074
|
var CLI_RSS_CACHE_MS = 1e4;
|
|
@@ -133693,8 +134097,8 @@ function createSessionFacts(options) {
|
|
|
133693
134097
|
const path21 = await resolveCommandOnPath(command, env, platform);
|
|
133694
134098
|
if (path21 === null) return null;
|
|
133695
134099
|
try {
|
|
133696
|
-
const real = await (0,
|
|
133697
|
-
const info = await (0,
|
|
134100
|
+
const real = await (0, import_promises67.realpath)(path21);
|
|
134101
|
+
const info = await (0, import_promises67.stat)(real);
|
|
133698
134102
|
return { command, key: `${real}:${info.ino}:${info.size}:${info.mtimeMs}` };
|
|
133699
134103
|
} catch {
|
|
133700
134104
|
return null;
|
|
@@ -133790,7 +134194,7 @@ function createSessionFacts(options) {
|
|
|
133790
134194
|
|
|
133791
134195
|
// src/holder/session-preparation.ts
|
|
133792
134196
|
var import_node_crypto40 = require("node:crypto");
|
|
133793
|
-
var
|
|
134197
|
+
var import_promises68 = require("node:fs/promises");
|
|
133794
134198
|
init_runtime_v2();
|
|
133795
134199
|
init_kernel();
|
|
133796
134200
|
init_platform();
|
|
@@ -133843,7 +134247,7 @@ function createHolderPreparation(options) {
|
|
|
133843
134247
|
signal.throwIfAborted();
|
|
133844
134248
|
if (!samePreparationBinding(fresh.binding, reference))
|
|
133845
134249
|
throw new LocalSessionActionError("forbidden");
|
|
133846
|
-
if (await (0,
|
|
134250
|
+
if (await (0, import_promises68.realpath)(reference.workspace) !== reference.workspace)
|
|
133847
134251
|
throw new LocalSessionActionError("invalid_path");
|
|
133848
134252
|
return fresh;
|
|
133849
134253
|
};
|
|
@@ -134040,7 +134444,7 @@ function holderEngines(deps) {
|
|
|
134040
134444
|
if (deps.engineRecording) return deps.engineRecording;
|
|
134041
134445
|
if (deps.engineOwnership !== "durable-posix") return void 0;
|
|
134042
134446
|
return recordSpawnedEngines(
|
|
134043
|
-
engineRecordsPath((0,
|
|
134447
|
+
engineRecordsPath((0, import_node_path78.dirname)(deps.launch.statusPath)),
|
|
134044
134448
|
deps.clock,
|
|
134045
134449
|
deps.log,
|
|
134046
134450
|
deps.launch.conversationId
|
|
@@ -134080,7 +134484,7 @@ async function runHolder({
|
|
|
134080
134484
|
clients: /* @__PURE__ */ new Set()
|
|
134081
134485
|
};
|
|
134082
134486
|
const activity = __using(_stack, startActivityFile({
|
|
134083
|
-
path: sessionActivityPath((0,
|
|
134487
|
+
path: sessionActivityPath((0, import_node_path78.dirname)(launch.statusPath)),
|
|
134084
134488
|
read: () => ({
|
|
134085
134489
|
runId: holder.runId,
|
|
134086
134490
|
...driver.activity?.() ?? IDLE_DRIVER_ACTIVITY
|
|
@@ -134122,7 +134526,7 @@ async function runHolder({
|
|
|
134122
134526
|
enginesClosed = true;
|
|
134123
134527
|
};
|
|
134124
134528
|
const preparation = createHolderPreparation({
|
|
134125
|
-
directory: (0,
|
|
134529
|
+
directory: (0, import_node_path78.dirname)(launch.statusPath),
|
|
134126
134530
|
conversationId: launch.conversationId,
|
|
134127
134531
|
machineId: launch.machineId,
|
|
134128
134532
|
driver: observed,
|
|
@@ -134391,7 +134795,7 @@ async function runHolder({
|
|
|
134391
134795
|
// package.json
|
|
134392
134796
|
var package_default = {
|
|
134393
134797
|
name: "@alan-ai-hq/agent-manager",
|
|
134394
|
-
version: "0.1.
|
|
134798
|
+
version: "0.1.197",
|
|
134395
134799
|
private: true,
|
|
134396
134800
|
type: "module",
|
|
134397
134801
|
description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
|
|
@@ -134477,14 +134881,14 @@ var package_default = {
|
|
|
134477
134881
|
};
|
|
134478
134882
|
|
|
134479
134883
|
// src/cli/config.ts
|
|
134480
|
-
var
|
|
134481
|
-
var
|
|
134884
|
+
var import_node_os14 = require("node:os");
|
|
134885
|
+
var import_node_path81 = require("node:path");
|
|
134482
134886
|
init_runtime_v2();
|
|
134483
134887
|
init_zod();
|
|
134484
134888
|
|
|
134485
134889
|
// src/client/browser-agent-discovery.ts
|
|
134486
134890
|
var import_node_crypto42 = require("node:crypto");
|
|
134487
|
-
var
|
|
134891
|
+
var import_node_path79 = require("node:path");
|
|
134488
134892
|
init_agent2();
|
|
134489
134893
|
init_zod();
|
|
134490
134894
|
var BROWSER_AGENT_DISCOVERY_FILE = "browser-agent.json";
|
|
@@ -134494,7 +134898,7 @@ var browserAgentDiscoverySchema = external_exports.object({
|
|
|
134494
134898
|
secret: external_exports.string().min(32)
|
|
134495
134899
|
});
|
|
134496
134900
|
function browserAgentDiscoveryPath(stateDir) {
|
|
134497
|
-
return (0,
|
|
134901
|
+
return (0, import_node_path79.join)(stateDir, BROWSER_AGENT_DISCOVERY_FILE);
|
|
134498
134902
|
}
|
|
134499
134903
|
function deriveBrowserScopeToken(secret, scopeId) {
|
|
134500
134904
|
return (0, import_node_crypto42.createHmac)("sha256", secret).update(scopeId).digest("hex");
|
|
@@ -134507,19 +134911,19 @@ function browserScopeIdForRun(run3) {
|
|
|
134507
134911
|
}
|
|
134508
134912
|
|
|
134509
134913
|
// src/client/locate.ts
|
|
134510
|
-
var
|
|
134914
|
+
var import_node_path80 = require("node:path");
|
|
134511
134915
|
var RUNTIME_PROFILES = ["production", "staging", "development", "local"];
|
|
134512
134916
|
function defaultStateDir({ profile, platform, home, env }) {
|
|
134513
134917
|
if (platform === "win32") {
|
|
134514
|
-
return (0,
|
|
134918
|
+
return (0, import_node_path80.join)(env.LOCALAPPDATA ?? (0, import_node_path80.join)(home, "AppData", "Local"), "Alan", profile);
|
|
134515
134919
|
}
|
|
134516
|
-
return (0,
|
|
134920
|
+
return (0, import_node_path80.join)(env.XDG_STATE_HOME ?? (0, import_node_path80.join)(home, ".local", "state"), "alan", profile);
|
|
134517
134921
|
}
|
|
134518
134922
|
function defaultInstallDir({ platform, home, env }) {
|
|
134519
134923
|
if (platform === "win32") {
|
|
134520
|
-
return (0,
|
|
134924
|
+
return (0, import_node_path80.join)(env.LOCALAPPDATA ?? (0, import_node_path80.join)(home, "AppData", "Local"), "Alan", "runtime");
|
|
134521
134925
|
}
|
|
134522
|
-
return (0,
|
|
134926
|
+
return (0, import_node_path80.join)(env.XDG_DATA_HOME ?? (0, import_node_path80.join)(home, ".local", "share"), "alan", "runtime");
|
|
134523
134927
|
}
|
|
134524
134928
|
|
|
134525
134929
|
// src/cli/config.ts
|
|
@@ -134630,9 +135034,9 @@ function memoryPressureSource(raw) {
|
|
|
134630
135034
|
);
|
|
134631
135035
|
}
|
|
134632
135036
|
function codexSkillsDir(config2) {
|
|
134633
|
-
return config2.gitGatewayUrl === null ? null : (0,
|
|
135037
|
+
return config2.gitGatewayUrl === null ? null : (0, import_node_path81.join)(config2.codexHome, "skills");
|
|
134634
135038
|
}
|
|
134635
|
-
function sessionSuspendConfig(idleMs, cliIdleMs, piIdleMs, checkEveryMs, pressure, maxIdleSessions, totalMemoryBytes = (0,
|
|
135039
|
+
function sessionSuspendConfig(idleMs, cliIdleMs, piIdleMs, checkEveryMs, pressure, maxIdleSessions, totalMemoryBytes = (0, import_node_os14.totalmem)()) {
|
|
134636
135040
|
const general = idleMs ?? DEFAULT_SUSPEND_POLICY.idleMs;
|
|
134637
135041
|
return {
|
|
134638
135042
|
idleMs: general,
|
|
@@ -134689,7 +135093,7 @@ function loadRuntimeConfig(env = process.env) {
|
|
|
134689
135093
|
GH_CONFIG_DIR,
|
|
134690
135094
|
CODEX_HOME
|
|
134691
135095
|
} = parsed.data;
|
|
134692
|
-
const home = (0,
|
|
135096
|
+
const home = (0, import_node_os14.homedir)();
|
|
134693
135097
|
const nativeIdentityCandidate = candidateEnabled(parsed.data);
|
|
134694
135098
|
return {
|
|
134695
135099
|
nativeIdentityCandidate,
|
|
@@ -134698,10 +135102,10 @@ function loadRuntimeConfig(env = process.env) {
|
|
|
134698
135102
|
stateDir: ALAN_RUNTIME_STATE_DIR ?? defaultStateDir({
|
|
134699
135103
|
profile: ALAN_RUNTIME_PROFILE,
|
|
134700
135104
|
platform: process.platform,
|
|
134701
|
-
home: (0,
|
|
135105
|
+
home: (0, import_node_os14.homedir)(),
|
|
134702
135106
|
env
|
|
134703
135107
|
}),
|
|
134704
|
-
installDir: ALAN_RUNTIME_INSTALL_DIR ?? defaultInstallDir({ platform: process.platform, home: (0,
|
|
135108
|
+
installDir: ALAN_RUNTIME_INSTALL_DIR ?? defaultInstallDir({ platform: process.platform, home: (0, import_node_os14.homedir)(), env }),
|
|
134705
135109
|
logLevel: ALAN_RUNTIME_LOG_LEVEL,
|
|
134706
135110
|
sessionTimings: SESSION_TIMINGS,
|
|
134707
135111
|
sessionSuspend: sessionSuspendConfig(
|
|
@@ -134724,7 +135128,7 @@ function loadRuntimeConfig(env = process.env) {
|
|
|
134724
135128
|
providerProbes: ALAN_RUNTIME_PROVIDER_PROBES === "on",
|
|
134725
135129
|
providerToolchain: ALAN_RUNTIME_PROVIDER_NODE !== void 0 && ALAN_RUNTIME_PROVIDER_NPM_CLI !== void 0 ? { node: ALAN_RUNTIME_PROVIDER_NODE, npmCli: ALAN_RUNTIME_PROVIDER_NPM_CLI } : null,
|
|
134726
135130
|
home,
|
|
134727
|
-
configHome: XDG_CONFIG_HOME ?? (0,
|
|
135131
|
+
configHome: XDG_CONFIG_HOME ?? (0, import_node_path81.join)(home, ".config"),
|
|
134728
135132
|
codexHome: resolveCodexHome(CODEX_HOME, home),
|
|
134729
135133
|
...githubProxyConfig({ ALAN_RUNTIME_GITHUB_PROXY, XDG_CONFIG_HOME, GH_CONFIG_DIR }, home),
|
|
134730
135134
|
gitGatewayUrl: ALAN_RUNTIME_GIT_GATEWAY_URL ?? null,
|
|
@@ -134736,7 +135140,7 @@ function loadRuntimeConfig(env = process.env) {
|
|
|
134736
135140
|
};
|
|
134737
135141
|
}
|
|
134738
135142
|
function resolveCodexHome(configuredHome, home) {
|
|
134739
|
-
return configuredHome ?? (0,
|
|
135143
|
+
return configuredHome ?? (0, import_node_path81.join)(home, ".codex");
|
|
134740
135144
|
}
|
|
134741
135145
|
var GATEWAY_HOSTNAME = /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$/;
|
|
134742
135146
|
function parseGatewayHosts(raw) {
|
|
@@ -134744,10 +135148,10 @@ function parseGatewayHosts(raw) {
|
|
|
134744
135148
|
return [...new Set(hosts)];
|
|
134745
135149
|
}
|
|
134746
135150
|
function githubProxyConfig(env, home) {
|
|
134747
|
-
const configHome = env.XDG_CONFIG_HOME ?? (0,
|
|
135151
|
+
const configHome = env.XDG_CONFIG_HOME ?? (0, import_node_path81.join)(home, ".config");
|
|
134748
135152
|
return {
|
|
134749
135153
|
githubProxy: env.ALAN_RUNTIME_GITHUB_PROXY === "on",
|
|
134750
|
-
ghConfigDir: env.GH_CONFIG_DIR ?? (0,
|
|
135154
|
+
ghConfigDir: env.GH_CONFIG_DIR ?? (0, import_node_path81.join)(configHome, "gh")
|
|
134751
135155
|
};
|
|
134752
135156
|
}
|
|
134753
135157
|
function serviceEnvironment(env, profile) {
|
|
@@ -134852,7 +135256,7 @@ async function loadStoredAccess(paths, access6 = { exec: systemExec }) {
|
|
|
134852
135256
|
}
|
|
134853
135257
|
|
|
134854
135258
|
// src/cli/commands/hold.ts
|
|
134855
|
-
var
|
|
135259
|
+
var import_node_path83 = require("node:path");
|
|
134856
135260
|
init_agent2();
|
|
134857
135261
|
init_runtime_v2();
|
|
134858
135262
|
init_capabilities3();
|
|
@@ -134860,24 +135264,46 @@ init_kernel();
|
|
|
134860
135264
|
init_platform();
|
|
134861
135265
|
|
|
134862
135266
|
// src/cli/browser-mcp.ts
|
|
134863
|
-
var
|
|
135267
|
+
var import_promises69 = require("node:fs/promises");
|
|
135268
|
+
init_src2();
|
|
135269
|
+
init_capabilities3();
|
|
134864
135270
|
var BROWSER_WORKSPACE_ROOT_HEADER = "X-Alan-Workspace-Root";
|
|
135271
|
+
var BROWSER_ACCEPTS_IMAGES_HEADER = "X-Alan-Accepts-Images";
|
|
135272
|
+
async function defaultHarnessCatalog(spec, managedMcp) {
|
|
135273
|
+
if (managedMcp === void 0) return [];
|
|
135274
|
+
return liveHarnessModels(
|
|
135275
|
+
{
|
|
135276
|
+
apiOrigin: new URL(managedMcp.url).origin,
|
|
135277
|
+
conversationId: spec.conversationId,
|
|
135278
|
+
authorization: () => managedMcp.authorization(new AbortController().signal)
|
|
135279
|
+
},
|
|
135280
|
+
spec.model
|
|
135281
|
+
);
|
|
135282
|
+
}
|
|
135283
|
+
function acceptsImages(model2, live) {
|
|
135284
|
+
if (model2 === void 0) return void 0;
|
|
135285
|
+
const liveModalities = harnessModelInputModalities(live).get(model2);
|
|
135286
|
+
if (liveModalities !== void 0) return liveModalities.includes("image");
|
|
135287
|
+
if (seedAlanCatalog().every((entry2) => entry2.id !== model2)) return void 0;
|
|
135288
|
+
return false;
|
|
135289
|
+
}
|
|
134865
135290
|
async function readDiscovery(stateDir) {
|
|
134866
135291
|
try {
|
|
134867
135292
|
const parsed = browserAgentDiscoverySchema.safeParse(
|
|
134868
|
-
JSON.parse(await (0,
|
|
135293
|
+
JSON.parse(await (0, import_promises69.readFile)(browserAgentDiscoveryPath(stateDir), "utf8"))
|
|
134869
135294
|
);
|
|
134870
135295
|
return parsed.success ? parsed.data : null;
|
|
134871
135296
|
} catch {
|
|
134872
135297
|
return null;
|
|
134873
135298
|
}
|
|
134874
135299
|
}
|
|
134875
|
-
async function withBrowserMcp(spec, stateDir) {
|
|
135300
|
+
async function withBrowserMcp(spec, stateDir, managedMcp, loadCatalog = defaultHarnessCatalog) {
|
|
134876
135301
|
if (stateDir === void 0 || spec.externalMcpServers?.[BROWSER_AGENT_MCP_SERVER_NAME])
|
|
134877
135302
|
return spec;
|
|
134878
135303
|
const discovery = await readDiscovery(stateDir);
|
|
134879
135304
|
if (discovery === null) return spec;
|
|
134880
135305
|
const scopeId = browserScopeIdForRun(spec);
|
|
135306
|
+
const images = acceptsImages(spec.model, await loadCatalog(spec, managedMcp));
|
|
134881
135307
|
return {
|
|
134882
135308
|
...spec,
|
|
134883
135309
|
externalMcpServers: {
|
|
@@ -134887,16 +135313,17 @@ async function withBrowserMcp(spec, stateDir) {
|
|
|
134887
135313
|
url: browserScopeUrl(discovery, scopeId, spec.conversationId),
|
|
134888
135314
|
headers: {
|
|
134889
135315
|
Authorization: `Bearer ${deriveBrowserScopeToken(discovery.secret, scopeId)}`,
|
|
135316
|
+
...images === void 0 ? {} : { [BROWSER_ACCEPTS_IMAGES_HEADER]: images ? "1" : "0" },
|
|
134890
135317
|
...spec.projectPath === void 0 ? {} : { [BROWSER_WORKSPACE_ROOT_HEADER]: encodeURIComponent(spec.projectPath) }
|
|
134891
135318
|
}
|
|
134892
135319
|
}
|
|
134893
135320
|
}
|
|
134894
135321
|
};
|
|
134895
135322
|
}
|
|
134896
|
-
function withBrowserMcpDriver(driver, stateDir) {
|
|
135323
|
+
function withBrowserMcpDriver(driver, stateDir, managedMcp) {
|
|
134897
135324
|
return {
|
|
134898
135325
|
...driver,
|
|
134899
|
-
runTurn: async (spec, sink, signal, inputs) => driver.runTurn(await withBrowserMcp(spec, stateDir), sink, signal, inputs)
|
|
135326
|
+
runTurn: async (spec, sink, signal, inputs) => driver.runTurn(await withBrowserMcp(spec, stateDir, managedMcp), sink, signal, inputs)
|
|
134900
135327
|
};
|
|
134901
135328
|
}
|
|
134902
135329
|
|
|
@@ -134912,13 +135339,13 @@ function configUserAgent(config2) {
|
|
|
134912
135339
|
}
|
|
134913
135340
|
|
|
134914
135341
|
// src/cli/commands/cli-flag-probes.ts
|
|
134915
|
-
var
|
|
135342
|
+
var import_node_path82 = require("node:path");
|
|
134916
135343
|
init_process();
|
|
134917
135344
|
init_claude();
|
|
134918
135345
|
var CLI_FLAG_PROBES_FILE = "cli-flag-probes.json";
|
|
134919
135346
|
function openCliFlagProbe(stateDir) {
|
|
134920
135347
|
return createFlagProbe({
|
|
134921
|
-
store: createFileFlagProbeStore((0,
|
|
135348
|
+
store: createFileFlagProbeStore((0, import_node_path82.join)(stateDir, CLI_FLAG_PROBES_FILE))
|
|
134922
135349
|
});
|
|
134923
135350
|
}
|
|
134924
135351
|
|
|
@@ -134983,7 +135410,7 @@ async function runHold(argv) {
|
|
|
134983
135410
|
const config2 = loadRuntimeConfig();
|
|
134984
135411
|
const paths = runtimePaths(config2.stateDir);
|
|
134985
135412
|
const log = __using(_stack, openFileLog(
|
|
134986
|
-
(0,
|
|
135413
|
+
(0, import_node_path83.join)(paths.logs, `holder-${launch.value.conversationId}.jsonl`),
|
|
134987
135414
|
config2.logLevel,
|
|
134988
135415
|
systemClock
|
|
134989
135416
|
));
|
|
@@ -134993,7 +135420,7 @@ async function runHold(argv) {
|
|
|
134993
135420
|
process.platform
|
|
134994
135421
|
);
|
|
134995
135422
|
const commitAttribution = await installCommitAttribution({
|
|
134996
|
-
dir: (0,
|
|
135423
|
+
dir: (0, import_node_path83.join)(paths.stateDir, "git-attribution"),
|
|
134997
135424
|
env: cliEnvironment,
|
|
134998
135425
|
platform: process.platform
|
|
134999
135426
|
}).catch((error62) => {
|
|
@@ -135003,7 +135430,7 @@ async function runHold(argv) {
|
|
|
135003
135430
|
const agentEnvironment = commitAttribution?.env ?? cliEnvironment;
|
|
135004
135431
|
const transport = __using(_stack, createHttpTransport({ userAgent: configUserAgent(config2) }));
|
|
135005
135432
|
const access6 = await machineAccess(paths, log, launch.value.conversationId, transport);
|
|
135006
|
-
const credentialPath = (0,
|
|
135433
|
+
const credentialPath = (0, import_node_path83.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
|
|
135007
135434
|
const managedMcp = __using(_stack, access6.managedMcp === void 0 ? void 0 : createHelperMcpAccess({
|
|
135008
135435
|
managedMcp: access6.managedMcp,
|
|
135009
135436
|
conversationId: launch.value.conversationId,
|
|
@@ -135018,7 +135445,7 @@ async function runHold(argv) {
|
|
|
135018
135445
|
const flags = openCliFlagProbe(paths.stateDir);
|
|
135019
135446
|
const engineOwnership = nativeEngineOwnership();
|
|
135020
135447
|
const nativeIdentity = config2.nativeIdentityCandidate ? await openNativeTurnBindings({
|
|
135021
|
-
directory: (0,
|
|
135448
|
+
directory: (0, import_node_path83.dirname)(launchPath),
|
|
135022
135449
|
defaultWorkspace: process.cwd(),
|
|
135023
135450
|
machineId: launch.value.machineId,
|
|
135024
135451
|
conversationId: launch.value.conversationId
|
|
@@ -135026,7 +135453,7 @@ async function runHold(argv) {
|
|
|
135026
135453
|
if (engineOwnership === "unsupported")
|
|
135027
135454
|
throw new RuntimeFault("platform_unsupported", "Native engine ownership is unavailable");
|
|
135028
135455
|
const engineRecording = engineOwnership === "durable-posix" ? recordSpawnedEngines(
|
|
135029
|
-
engineRecordsPath((0,
|
|
135456
|
+
engineRecordsPath((0, import_node_path83.dirname)(launchPath)),
|
|
135030
135457
|
systemClock,
|
|
135031
135458
|
log,
|
|
135032
135459
|
launch.value.conversationId
|
|
@@ -135047,10 +135474,11 @@ async function runHold(argv) {
|
|
|
135047
135474
|
mcpProxy,
|
|
135048
135475
|
codexCredentials: access6.codexCredentials,
|
|
135049
135476
|
installedSkills: () => installedSkillFolders(skillsLayout(paths.stateDir)),
|
|
135050
|
-
engineStateDir: (0,
|
|
135477
|
+
engineStateDir: (0, import_node_path83.join)(paths.stateDir, "alan-code"),
|
|
135051
135478
|
flagProbe: flags
|
|
135052
135479
|
}),
|
|
135053
|
-
paths.stateDir
|
|
135480
|
+
paths.stateDir,
|
|
135481
|
+
managedMcp
|
|
135054
135482
|
),
|
|
135055
135483
|
clock: systemClock,
|
|
135056
135484
|
log,
|