@alan-ai-hq/agent-manager-linux-arm64 0.1.146 → 0.1.148
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 +1743 -888
- package/alan-holder.cjs +1428 -641
- package/package.json +1 -1
package/alan-holder.cjs
CHANGED
|
@@ -12529,7 +12529,7 @@ function compileValidator(schema, parser) {
|
|
|
12529
12529
|
function compile(schema, options) {
|
|
12530
12530
|
try {
|
|
12531
12531
|
const parser = compileFn(schema);
|
|
12532
|
-
const
|
|
12532
|
+
const clone3 = clone(schema);
|
|
12533
12533
|
const liveRun = schema._zod.run;
|
|
12534
12534
|
const originalRun = liveRun.__originalRun ?? liveRun;
|
|
12535
12535
|
const wrapped = (payload, ctx) => {
|
|
@@ -12549,12 +12549,12 @@ function compile(schema, options) {
|
|
|
12549
12549
|
return originalRun(payload, ctx);
|
|
12550
12550
|
};
|
|
12551
12551
|
wrapped.__originalRun = originalRun;
|
|
12552
|
-
|
|
12553
|
-
|
|
12554
|
-
|
|
12552
|
+
clone3._zod.bag.fallbackRun = originalRun;
|
|
12553
|
+
clone3._zod.bag.validator = compileValidator(schema, parser);
|
|
12554
|
+
clone3._zod.run = wrapped;
|
|
12555
12555
|
if (!liveRun.__originalRun)
|
|
12556
|
-
installCompiledUserMethods(
|
|
12557
|
-
return
|
|
12556
|
+
installCompiledUserMethods(clone3, schema, parser);
|
|
12557
|
+
return clone3;
|
|
12558
12558
|
} catch (err) {
|
|
12559
12559
|
if (options?.strict)
|
|
12560
12560
|
throw err;
|
|
@@ -19060,21 +19060,21 @@ function visit(schema, fnOrHandlers) {
|
|
|
19060
19060
|
case "object": {
|
|
19061
19061
|
const oldShape = def.shape;
|
|
19062
19062
|
const keys = Object.keys(oldShape);
|
|
19063
|
-
let
|
|
19063
|
+
let changed2 = false;
|
|
19064
19064
|
const newShape = {};
|
|
19065
19065
|
for (const k of keys) {
|
|
19066
19066
|
const mapped = run(oldShape[k]);
|
|
19067
19067
|
if (mapped !== oldShape[k])
|
|
19068
|
-
|
|
19068
|
+
changed2 = true;
|
|
19069
19069
|
newShape[k] = mapped;
|
|
19070
19070
|
}
|
|
19071
19071
|
let newCatchall = def.catchall;
|
|
19072
19072
|
if (def.catchall) {
|
|
19073
19073
|
newCatchall = run(def.catchall);
|
|
19074
19074
|
if (newCatchall !== def.catchall)
|
|
19075
|
-
|
|
19075
|
+
changed2 = true;
|
|
19076
19076
|
}
|
|
19077
|
-
return
|
|
19077
|
+
return changed2 ? clone(s, { ...def, shape: newShape, catchall: newCatchall }) : s;
|
|
19078
19078
|
}
|
|
19079
19079
|
case "array": {
|
|
19080
19080
|
const mapped = run(def.element);
|
|
@@ -19082,21 +19082,21 @@ function visit(schema, fnOrHandlers) {
|
|
|
19082
19082
|
}
|
|
19083
19083
|
case "tuple": {
|
|
19084
19084
|
const oldItems = def.items;
|
|
19085
|
-
let
|
|
19085
|
+
let changed2 = false;
|
|
19086
19086
|
const newItems = [];
|
|
19087
19087
|
for (const item of oldItems) {
|
|
19088
19088
|
const mapped = run(item);
|
|
19089
19089
|
if (mapped !== item)
|
|
19090
|
-
|
|
19090
|
+
changed2 = true;
|
|
19091
19091
|
newItems.push(mapped);
|
|
19092
19092
|
}
|
|
19093
19093
|
let newRest = def.rest;
|
|
19094
19094
|
if (def.rest) {
|
|
19095
19095
|
newRest = run(def.rest);
|
|
19096
19096
|
if (newRest !== def.rest)
|
|
19097
|
-
|
|
19097
|
+
changed2 = true;
|
|
19098
19098
|
}
|
|
19099
|
-
return
|
|
19099
|
+
return changed2 ? clone(s, { ...def, items: newItems, rest: newRest }) : s;
|
|
19100
19100
|
}
|
|
19101
19101
|
case "record":
|
|
19102
19102
|
case "map": {
|
|
@@ -19110,15 +19110,15 @@ function visit(schema, fnOrHandlers) {
|
|
|
19110
19110
|
}
|
|
19111
19111
|
case "union": {
|
|
19112
19112
|
const oldOptions = def.options;
|
|
19113
|
-
let
|
|
19113
|
+
let changed2 = false;
|
|
19114
19114
|
const newOptions = [];
|
|
19115
19115
|
for (const opt of oldOptions) {
|
|
19116
19116
|
const mapped = run(opt);
|
|
19117
19117
|
if (mapped !== opt)
|
|
19118
|
-
|
|
19118
|
+
changed2 = true;
|
|
19119
19119
|
newOptions.push(mapped);
|
|
19120
19120
|
}
|
|
19121
|
-
return
|
|
19121
|
+
return changed2 ? clone(s, { ...def, options: newOptions }) : s;
|
|
19122
19122
|
}
|
|
19123
19123
|
case "intersection": {
|
|
19124
19124
|
const newLeft = run(def.left);
|
|
@@ -19568,6 +19568,259 @@ var init_zod = __esm({
|
|
|
19568
19568
|
}
|
|
19569
19569
|
});
|
|
19570
19570
|
|
|
19571
|
+
// ../shared/dist/runtime-v2/workspace.js
|
|
19572
|
+
var UNSAFE_LINE, CONTROL_CHARACTERS, machinePathSchema, gitShaSchema, gitBranchSchema, gitRemoteNameSchema, gitRemoteUrlSchema, statusFingerprintSchema, singleLineSchema, operationIdSchema, repoTargetShape, trustedRepoTargetShape, workspaceStatusRequestSchema, gitStatusRequestSchema, gitCheckpointRequestSchema, gitPushRequestSchema, gitPrepareCheckoutRequestSchema, gitVerifyHeadRequestSchema, workspaceQueryRequestSchema, WORKSPACE_QUERY_METHODS, workspaceQueryMethodSchema, workspaceStatusValueSchema, gitStatusValueSchema, gitCheckpointValueSchema, gitPushValueSchema, gitPrepareCheckoutValueSchema, gitVerifyHeadValueSchema, WORKSPACE_QUERY_ERROR_CODES, workspaceQueryErrorCodeSchema, publishedGitReceiptSchema, workspaceQueryErrorSchema, resultEnvelopeSchema;
|
|
19573
|
+
var init_workspace = __esm({
|
|
19574
|
+
"../shared/dist/runtime-v2/workspace.js"() {
|
|
19575
|
+
"use strict";
|
|
19576
|
+
init_zod();
|
|
19577
|
+
UNSAFE_LINE = /[\0\r\n]/;
|
|
19578
|
+
CONTROL_CHARACTERS = /[\x00-\x1f\x7f]/;
|
|
19579
|
+
machinePathSchema = external_exports.string().min(1).max(4096).refine((value) => !UNSAFE_LINE.test(value), "path contains unsafe characters");
|
|
19580
|
+
gitShaSchema = external_exports.string().regex(/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/, "not a Git SHA");
|
|
19581
|
+
gitBranchSchema = external_exports.string().min(1).max(255).refine((value) => !value.startsWith("-") && !value.startsWith("+") && !value.includes("..") && !value.includes("@{") && !value.endsWith(".lock") && !/[\s~^:?*[\\]/.test(value) && !CONTROL_CHARACTERS.test(value), "not a safe Git branch name");
|
|
19582
|
+
gitRemoteNameSchema = external_exports.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/, "not a safe Git remote name");
|
|
19583
|
+
gitRemoteUrlSchema = external_exports.string().min(1).max(2048).refine((value) => !UNSAFE_LINE.test(value), "remote URL contains unsafe characters");
|
|
19584
|
+
statusFingerprintSchema = external_exports.string().regex(/^[0-9a-f]{64}$/, "not a status fingerprint");
|
|
19585
|
+
singleLineSchema = (max) => external_exports.string().min(1).max(max).refine((value) => !CONTROL_CHARACTERS.test(value), "contains control characters");
|
|
19586
|
+
operationIdSchema = external_exports.guid();
|
|
19587
|
+
repoTargetShape = {
|
|
19588
|
+
path: machinePathSchema,
|
|
19589
|
+
expectedRepoRoot: machinePathSchema.optional(),
|
|
19590
|
+
projectPath: machinePathSchema.optional()
|
|
19591
|
+
};
|
|
19592
|
+
trustedRepoTargetShape = {
|
|
19593
|
+
path: machinePathSchema,
|
|
19594
|
+
expectedRepoRoot: machinePathSchema,
|
|
19595
|
+
projectPath: machinePathSchema
|
|
19596
|
+
};
|
|
19597
|
+
workspaceStatusRequestSchema = external_exports.object({
|
|
19598
|
+
method: external_exports.literal("workspace.status"),
|
|
19599
|
+
path: machinePathSchema
|
|
19600
|
+
});
|
|
19601
|
+
gitStatusRequestSchema = external_exports.object({
|
|
19602
|
+
method: external_exports.literal("git.status"),
|
|
19603
|
+
...repoTargetShape,
|
|
19604
|
+
remote: gitRemoteNameSchema.default("origin"),
|
|
19605
|
+
expectedRemoteUrl: gitRemoteUrlSchema.optional()
|
|
19606
|
+
});
|
|
19607
|
+
gitCheckpointRequestSchema = external_exports.object({
|
|
19608
|
+
method: external_exports.literal("git.checkpoint"),
|
|
19609
|
+
operationId: operationIdSchema,
|
|
19610
|
+
...trustedRepoTargetShape,
|
|
19611
|
+
switchId: singleLineSchema(200),
|
|
19612
|
+
repoKey: singleLineSchema(256),
|
|
19613
|
+
expectedHeadSha: gitShaSchema,
|
|
19614
|
+
expectedBranch: gitBranchSchema,
|
|
19615
|
+
expectedStatusFingerprint: statusFingerprintSchema,
|
|
19616
|
+
expectedProposedTreeSha: gitShaSchema,
|
|
19617
|
+
/** Goes to `git commit-tree` over stdin; newlines carry trailers, NUL is unrepresentable. */
|
|
19618
|
+
commitMessage: external_exports.string().min(1).max(64 * 1024).refine((value) => !value.includes("\0") && value.trim().length > 0, "invalid commit message"),
|
|
19619
|
+
authorName: singleLineSchema(256),
|
|
19620
|
+
authorEmail: singleLineSchema(320).refine((value) => !/[<>]/.test(value), "invalid email")
|
|
19621
|
+
});
|
|
19622
|
+
gitPushRequestSchema = external_exports.object({
|
|
19623
|
+
method: external_exports.literal("git.push"),
|
|
19624
|
+
operationId: operationIdSchema,
|
|
19625
|
+
...trustedRepoTargetShape,
|
|
19626
|
+
remote: gitRemoteNameSchema.default("origin"),
|
|
19627
|
+
expectedRemoteUrl: gitRemoteUrlSchema,
|
|
19628
|
+
expectedHeadSha: gitShaSchema,
|
|
19629
|
+
expectedBranch: gitBranchSchema
|
|
19630
|
+
});
|
|
19631
|
+
gitPrepareCheckoutRequestSchema = external_exports.object({
|
|
19632
|
+
method: external_exports.literal("git.prepare_checkout"),
|
|
19633
|
+
operationId: operationIdSchema,
|
|
19634
|
+
...trustedRepoTargetShape,
|
|
19635
|
+
remote: gitRemoteNameSchema.default("origin"),
|
|
19636
|
+
expectedRemoteUrl: gitRemoteUrlSchema,
|
|
19637
|
+
branch: gitBranchSchema,
|
|
19638
|
+
targetSha: gitShaSchema
|
|
19639
|
+
});
|
|
19640
|
+
gitVerifyHeadRequestSchema = external_exports.object({
|
|
19641
|
+
method: external_exports.literal("git.verify_head"),
|
|
19642
|
+
...trustedRepoTargetShape,
|
|
19643
|
+
expectedSha: gitShaSchema
|
|
19644
|
+
});
|
|
19645
|
+
workspaceQueryRequestSchema = external_exports.discriminatedUnion("method", [
|
|
19646
|
+
workspaceStatusRequestSchema,
|
|
19647
|
+
gitStatusRequestSchema,
|
|
19648
|
+
gitCheckpointRequestSchema,
|
|
19649
|
+
gitPushRequestSchema,
|
|
19650
|
+
gitPrepareCheckoutRequestSchema,
|
|
19651
|
+
gitVerifyHeadRequestSchema
|
|
19652
|
+
]);
|
|
19653
|
+
WORKSPACE_QUERY_METHODS = [
|
|
19654
|
+
"workspace.status",
|
|
19655
|
+
"git.status",
|
|
19656
|
+
"git.checkpoint",
|
|
19657
|
+
"git.push",
|
|
19658
|
+
"git.prepare_checkout",
|
|
19659
|
+
"git.verify_head"
|
|
19660
|
+
];
|
|
19661
|
+
workspaceQueryMethodSchema = external_exports.enum(WORKSPACE_QUERY_METHODS);
|
|
19662
|
+
workspaceStatusValueSchema = external_exports.object({
|
|
19663
|
+
repoRoot: machinePathSchema,
|
|
19664
|
+
/** null: detached HEAD. */
|
|
19665
|
+
branch: external_exports.string().nullable(),
|
|
19666
|
+
/** null: unborn branch. */
|
|
19667
|
+
headSha: gitShaSchema.nullable(),
|
|
19668
|
+
dirty: external_exports.boolean(),
|
|
19669
|
+
filesChanged: external_exports.number().int().nonnegative(),
|
|
19670
|
+
ahead: external_exports.number().int().nonnegative().nullable(),
|
|
19671
|
+
behind: external_exports.number().int().nonnegative().nullable(),
|
|
19672
|
+
hasUpstream: external_exports.boolean()
|
|
19673
|
+
});
|
|
19674
|
+
gitStatusValueSchema = workspaceStatusValueSchema.extend({
|
|
19675
|
+
remoteUrl: gitRemoteUrlSchema.nullable(),
|
|
19676
|
+
upstream: external_exports.string().nullable(),
|
|
19677
|
+
statusFingerprint: statusFingerprintSchema,
|
|
19678
|
+
proposedTreeSha: gitShaSchema
|
|
19679
|
+
});
|
|
19680
|
+
gitCheckpointValueSchema = external_exports.object({
|
|
19681
|
+
repoRoot: machinePathSchema,
|
|
19682
|
+
sha: gitShaSchema,
|
|
19683
|
+
replayed: external_exports.boolean()
|
|
19684
|
+
});
|
|
19685
|
+
gitPushValueSchema = external_exports.object({
|
|
19686
|
+
repoRoot: machinePathSchema,
|
|
19687
|
+
pushedSha: gitShaSchema,
|
|
19688
|
+
branch: gitBranchSchema,
|
|
19689
|
+
remote: gitRemoteNameSchema,
|
|
19690
|
+
/** The remote already had the SHA before this push. */
|
|
19691
|
+
replayed: external_exports.boolean()
|
|
19692
|
+
});
|
|
19693
|
+
gitPrepareCheckoutValueSchema = external_exports.object({
|
|
19694
|
+
repoRoot: machinePathSchema,
|
|
19695
|
+
branch: gitBranchSchema,
|
|
19696
|
+
headSha: gitShaSchema,
|
|
19697
|
+
replayed: external_exports.boolean()
|
|
19698
|
+
});
|
|
19699
|
+
gitVerifyHeadValueSchema = external_exports.object({
|
|
19700
|
+
repoRoot: machinePathSchema,
|
|
19701
|
+
headSha: gitShaSchema,
|
|
19702
|
+
verified: external_exports.literal(true)
|
|
19703
|
+
});
|
|
19704
|
+
WORKSPACE_QUERY_ERROR_CODES = [
|
|
19705
|
+
"path_not_approved",
|
|
19706
|
+
"workspace_busy",
|
|
19707
|
+
"workspace_repository_mismatch",
|
|
19708
|
+
"operation_in_progress",
|
|
19709
|
+
"git_not_installed",
|
|
19710
|
+
"runtime_operation_failed",
|
|
19711
|
+
"invalid_git_request",
|
|
19712
|
+
"repository_not_found",
|
|
19713
|
+
"repository_path_changed",
|
|
19714
|
+
"repository_path_not_authorized",
|
|
19715
|
+
"path_canonicalization_failed",
|
|
19716
|
+
"git_status_unreadable",
|
|
19717
|
+
"git_operation_failed",
|
|
19718
|
+
"git_network_timeout",
|
|
19719
|
+
"git_output_limit_exceeded",
|
|
19720
|
+
"git_remote_unavailable",
|
|
19721
|
+
"git_fetch_failed",
|
|
19722
|
+
"git_push_failed",
|
|
19723
|
+
"remote_url_credentials_rejected",
|
|
19724
|
+
"remote_url_mismatch",
|
|
19725
|
+
"source_changed_since_approval",
|
|
19726
|
+
"source_dirty_after_checkpoint",
|
|
19727
|
+
"source_head_unreadable",
|
|
19728
|
+
"checkpoint_empty",
|
|
19729
|
+
"checkpoint_tree_unavailable",
|
|
19730
|
+
"checkpoint_commit_failed",
|
|
19731
|
+
"checkpoint_lock_unavailable",
|
|
19732
|
+
"checkpoint_index_sync_failed",
|
|
19733
|
+
"push_verification_failed",
|
|
19734
|
+
"target_checkout_dirty",
|
|
19735
|
+
"target_checkout_failed",
|
|
19736
|
+
"target_branch_in_use",
|
|
19737
|
+
"target_branch_diverged",
|
|
19738
|
+
"target_fast_forward_failed",
|
|
19739
|
+
"target_verification_failed",
|
|
19740
|
+
"target_sha_mismatch",
|
|
19741
|
+
"target_sha_unavailable",
|
|
19742
|
+
"target_head_unreadable",
|
|
19743
|
+
"verify_head_mismatch"
|
|
19744
|
+
];
|
|
19745
|
+
workspaceQueryErrorCodeSchema = external_exports.enum(WORKSPACE_QUERY_ERROR_CODES);
|
|
19746
|
+
publishedGitReceiptSchema = external_exports.object({
|
|
19747
|
+
pushedSha: gitShaSchema,
|
|
19748
|
+
branch: gitBranchSchema,
|
|
19749
|
+
remote: gitRemoteNameSchema,
|
|
19750
|
+
replayed: external_exports.boolean()
|
|
19751
|
+
});
|
|
19752
|
+
workspaceQueryErrorSchema = external_exports.object({
|
|
19753
|
+
code: workspaceQueryErrorCodeSchema,
|
|
19754
|
+
message: external_exports.string().max(4096),
|
|
19755
|
+
/** Only with source_changed_since_approval after a push: what already reached the remote. */
|
|
19756
|
+
published: publishedGitReceiptSchema.optional()
|
|
19757
|
+
});
|
|
19758
|
+
resultEnvelopeSchema = external_exports.discriminatedUnion("ok", [
|
|
19759
|
+
external_exports.object({ ok: external_exports.literal(true), value: external_exports.unknown() }),
|
|
19760
|
+
external_exports.object({ ok: external_exports.literal(false), error: workspaceQueryErrorSchema })
|
|
19761
|
+
]);
|
|
19762
|
+
}
|
|
19763
|
+
});
|
|
19764
|
+
|
|
19765
|
+
// ../shared/dist/runtime-v2/agent-context.js
|
|
19766
|
+
var AGENT_CONTEXT_VERSION, agentSessionKindSchema, agentTurnTriggerSchema, agentBranchSourceSchema, agentContextRepositorySchema, agentContextBuildSchema, agentContextEnvironmentSchema, agentContextPullRequestSchema, agentContextSchema;
|
|
19767
|
+
var init_agent_context = __esm({
|
|
19768
|
+
"../shared/dist/runtime-v2/agent-context.js"() {
|
|
19769
|
+
"use strict";
|
|
19770
|
+
init_zod();
|
|
19771
|
+
init_workspace();
|
|
19772
|
+
AGENT_CONTEXT_VERSION = 1;
|
|
19773
|
+
agentSessionKindSchema = external_exports.enum(["chat", "task", "workflow", "pr_review"]);
|
|
19774
|
+
agentTurnTriggerSchema = external_exports.enum(["user", "image_build"]);
|
|
19775
|
+
agentBranchSourceSchema = external_exports.enum([
|
|
19776
|
+
"handoff",
|
|
19777
|
+
"pull_request",
|
|
19778
|
+
"task",
|
|
19779
|
+
"chat_selection",
|
|
19780
|
+
"environment_default"
|
|
19781
|
+
]);
|
|
19782
|
+
agentContextRepositorySchema = external_exports.object({
|
|
19783
|
+
name: external_exports.string().min(1).max(200),
|
|
19784
|
+
url: gitRemoteUrlSchema,
|
|
19785
|
+
path: machinePathSchema,
|
|
19786
|
+
branch: gitBranchSchema,
|
|
19787
|
+
branchSource: agentBranchSourceSchema,
|
|
19788
|
+
base: gitBranchSchema
|
|
19789
|
+
});
|
|
19790
|
+
agentContextBuildSchema = external_exports.object({
|
|
19791
|
+
id: external_exports.guid(),
|
|
19792
|
+
status: external_exports.enum(["queued", "running", "succeeded", "failed", "cancelled", "superseded"]),
|
|
19793
|
+
trigger: external_exports.enum(["agent", "base_bumped", "preview", "manual", "push"])
|
|
19794
|
+
});
|
|
19795
|
+
agentContextEnvironmentSchema = external_exports.object({
|
|
19796
|
+
id: external_exports.guid(),
|
|
19797
|
+
name: external_exports.string().min(1).max(200),
|
|
19798
|
+
installCommand: external_exports.string().max(8192).nullable(),
|
|
19799
|
+
startCommand: external_exports.string().max(8192).nullable(),
|
|
19800
|
+
imageBuildId: external_exports.guid().nullable(),
|
|
19801
|
+
/** The newest build when it is not the one sessions boot from. */
|
|
19802
|
+
pendingBuild: agentContextBuildSchema.optional(),
|
|
19803
|
+
/** Saved variable names; values never leave the API. */
|
|
19804
|
+
variables: external_exports.array(external_exports.string().min(1).max(200)).max(200)
|
|
19805
|
+
});
|
|
19806
|
+
agentContextPullRequestSchema = external_exports.object({
|
|
19807
|
+
number: external_exports.number().int().positive(),
|
|
19808
|
+
url: external_exports.string().url().max(2048),
|
|
19809
|
+
head: gitBranchSchema,
|
|
19810
|
+
base: gitBranchSchema
|
|
19811
|
+
});
|
|
19812
|
+
agentContextSchema = external_exports.object({
|
|
19813
|
+
kind: agentSessionKindSchema,
|
|
19814
|
+
trigger: agentTurnTriggerSchema,
|
|
19815
|
+
organizationId: external_exports.guid(),
|
|
19816
|
+
taskWorkingBranch: gitBranchSchema.optional(),
|
|
19817
|
+
pullRequest: agentContextPullRequestSchema.optional(),
|
|
19818
|
+
repositories: external_exports.array(agentContextRepositorySchema).max(64),
|
|
19819
|
+
environment: agentContextEnvironmentSchema.optional()
|
|
19820
|
+
});
|
|
19821
|
+
}
|
|
19822
|
+
});
|
|
19823
|
+
|
|
19571
19824
|
// ../shared/dist/skills/domain.js
|
|
19572
19825
|
var SKILLS_PROTOCOL_VERSION, SKILL_PACKAGE_LIMITS;
|
|
19573
19826
|
var init_domain = __esm({
|
|
@@ -20114,207 +20367,14 @@ var init_run_context = __esm({
|
|
|
20114
20367
|
}
|
|
20115
20368
|
});
|
|
20116
20369
|
|
|
20117
|
-
// ../shared/dist/runtime-v2/workspace.js
|
|
20118
|
-
var UNSAFE_LINE, CONTROL_CHARACTERS, machinePathSchema, gitShaSchema, gitBranchSchema, gitRemoteNameSchema, gitRemoteUrlSchema, statusFingerprintSchema, singleLineSchema, operationIdSchema, repoTargetShape, trustedRepoTargetShape, workspaceStatusRequestSchema, gitStatusRequestSchema, gitCheckpointRequestSchema, gitPushRequestSchema, gitPrepareCheckoutRequestSchema, gitVerifyHeadRequestSchema, workspaceQueryRequestSchema, WORKSPACE_QUERY_METHODS, workspaceQueryMethodSchema, workspaceStatusValueSchema, gitStatusValueSchema, gitCheckpointValueSchema, gitPushValueSchema, gitPrepareCheckoutValueSchema, gitVerifyHeadValueSchema, WORKSPACE_QUERY_ERROR_CODES, workspaceQueryErrorCodeSchema, publishedGitReceiptSchema, workspaceQueryErrorSchema, resultEnvelopeSchema;
|
|
20119
|
-
var init_workspace = __esm({
|
|
20120
|
-
"../shared/dist/runtime-v2/workspace.js"() {
|
|
20121
|
-
"use strict";
|
|
20122
|
-
init_zod();
|
|
20123
|
-
UNSAFE_LINE = /[\0\r\n]/;
|
|
20124
|
-
CONTROL_CHARACTERS = /[\x00-\x1f\x7f]/;
|
|
20125
|
-
machinePathSchema = external_exports.string().min(1).max(4096).refine((value) => !UNSAFE_LINE.test(value), "path contains unsafe characters");
|
|
20126
|
-
gitShaSchema = external_exports.string().regex(/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/, "not a Git SHA");
|
|
20127
|
-
gitBranchSchema = external_exports.string().min(1).max(255).refine((value) => !value.startsWith("-") && !value.startsWith("+") && !value.includes("..") && !value.includes("@{") && !value.endsWith(".lock") && !/[\s~^:?*[\\]/.test(value) && !CONTROL_CHARACTERS.test(value), "not a safe Git branch name");
|
|
20128
|
-
gitRemoteNameSchema = external_exports.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/, "not a safe Git remote name");
|
|
20129
|
-
gitRemoteUrlSchema = external_exports.string().min(1).max(2048).refine((value) => !UNSAFE_LINE.test(value), "remote URL contains unsafe characters");
|
|
20130
|
-
statusFingerprintSchema = external_exports.string().regex(/^[0-9a-f]{64}$/, "not a status fingerprint");
|
|
20131
|
-
singleLineSchema = (max) => external_exports.string().min(1).max(max).refine((value) => !CONTROL_CHARACTERS.test(value), "contains control characters");
|
|
20132
|
-
operationIdSchema = external_exports.guid();
|
|
20133
|
-
repoTargetShape = {
|
|
20134
|
-
path: machinePathSchema,
|
|
20135
|
-
expectedRepoRoot: machinePathSchema.optional(),
|
|
20136
|
-
projectPath: machinePathSchema.optional()
|
|
20137
|
-
};
|
|
20138
|
-
trustedRepoTargetShape = {
|
|
20139
|
-
path: machinePathSchema,
|
|
20140
|
-
expectedRepoRoot: machinePathSchema,
|
|
20141
|
-
projectPath: machinePathSchema
|
|
20142
|
-
};
|
|
20143
|
-
workspaceStatusRequestSchema = external_exports.object({
|
|
20144
|
-
method: external_exports.literal("workspace.status"),
|
|
20145
|
-
path: machinePathSchema
|
|
20146
|
-
});
|
|
20147
|
-
gitStatusRequestSchema = external_exports.object({
|
|
20148
|
-
method: external_exports.literal("git.status"),
|
|
20149
|
-
...repoTargetShape,
|
|
20150
|
-
remote: gitRemoteNameSchema.default("origin"),
|
|
20151
|
-
expectedRemoteUrl: gitRemoteUrlSchema.optional()
|
|
20152
|
-
});
|
|
20153
|
-
gitCheckpointRequestSchema = external_exports.object({
|
|
20154
|
-
method: external_exports.literal("git.checkpoint"),
|
|
20155
|
-
operationId: operationIdSchema,
|
|
20156
|
-
...trustedRepoTargetShape,
|
|
20157
|
-
switchId: singleLineSchema(200),
|
|
20158
|
-
repoKey: singleLineSchema(256),
|
|
20159
|
-
expectedHeadSha: gitShaSchema,
|
|
20160
|
-
expectedBranch: gitBranchSchema,
|
|
20161
|
-
expectedStatusFingerprint: statusFingerprintSchema,
|
|
20162
|
-
expectedProposedTreeSha: gitShaSchema,
|
|
20163
|
-
/** Goes to `git commit-tree` over stdin; newlines carry trailers, NUL is unrepresentable. */
|
|
20164
|
-
commitMessage: external_exports.string().min(1).max(64 * 1024).refine((value) => !value.includes("\0") && value.trim().length > 0, "invalid commit message"),
|
|
20165
|
-
authorName: singleLineSchema(256),
|
|
20166
|
-
authorEmail: singleLineSchema(320).refine((value) => !/[<>]/.test(value), "invalid email")
|
|
20167
|
-
});
|
|
20168
|
-
gitPushRequestSchema = external_exports.object({
|
|
20169
|
-
method: external_exports.literal("git.push"),
|
|
20170
|
-
operationId: operationIdSchema,
|
|
20171
|
-
...trustedRepoTargetShape,
|
|
20172
|
-
remote: gitRemoteNameSchema.default("origin"),
|
|
20173
|
-
expectedRemoteUrl: gitRemoteUrlSchema,
|
|
20174
|
-
expectedHeadSha: gitShaSchema,
|
|
20175
|
-
expectedBranch: gitBranchSchema
|
|
20176
|
-
});
|
|
20177
|
-
gitPrepareCheckoutRequestSchema = external_exports.object({
|
|
20178
|
-
method: external_exports.literal("git.prepare_checkout"),
|
|
20179
|
-
operationId: operationIdSchema,
|
|
20180
|
-
...trustedRepoTargetShape,
|
|
20181
|
-
remote: gitRemoteNameSchema.default("origin"),
|
|
20182
|
-
expectedRemoteUrl: gitRemoteUrlSchema,
|
|
20183
|
-
branch: gitBranchSchema,
|
|
20184
|
-
targetSha: gitShaSchema
|
|
20185
|
-
});
|
|
20186
|
-
gitVerifyHeadRequestSchema = external_exports.object({
|
|
20187
|
-
method: external_exports.literal("git.verify_head"),
|
|
20188
|
-
...trustedRepoTargetShape,
|
|
20189
|
-
expectedSha: gitShaSchema
|
|
20190
|
-
});
|
|
20191
|
-
workspaceQueryRequestSchema = external_exports.discriminatedUnion("method", [
|
|
20192
|
-
workspaceStatusRequestSchema,
|
|
20193
|
-
gitStatusRequestSchema,
|
|
20194
|
-
gitCheckpointRequestSchema,
|
|
20195
|
-
gitPushRequestSchema,
|
|
20196
|
-
gitPrepareCheckoutRequestSchema,
|
|
20197
|
-
gitVerifyHeadRequestSchema
|
|
20198
|
-
]);
|
|
20199
|
-
WORKSPACE_QUERY_METHODS = [
|
|
20200
|
-
"workspace.status",
|
|
20201
|
-
"git.status",
|
|
20202
|
-
"git.checkpoint",
|
|
20203
|
-
"git.push",
|
|
20204
|
-
"git.prepare_checkout",
|
|
20205
|
-
"git.verify_head"
|
|
20206
|
-
];
|
|
20207
|
-
workspaceQueryMethodSchema = external_exports.enum(WORKSPACE_QUERY_METHODS);
|
|
20208
|
-
workspaceStatusValueSchema = external_exports.object({
|
|
20209
|
-
repoRoot: machinePathSchema,
|
|
20210
|
-
/** null: detached HEAD. */
|
|
20211
|
-
branch: external_exports.string().nullable(),
|
|
20212
|
-
/** null: unborn branch. */
|
|
20213
|
-
headSha: gitShaSchema.nullable(),
|
|
20214
|
-
dirty: external_exports.boolean(),
|
|
20215
|
-
filesChanged: external_exports.number().int().nonnegative(),
|
|
20216
|
-
ahead: external_exports.number().int().nonnegative().nullable(),
|
|
20217
|
-
behind: external_exports.number().int().nonnegative().nullable(),
|
|
20218
|
-
hasUpstream: external_exports.boolean()
|
|
20219
|
-
});
|
|
20220
|
-
gitStatusValueSchema = workspaceStatusValueSchema.extend({
|
|
20221
|
-
remoteUrl: gitRemoteUrlSchema.nullable(),
|
|
20222
|
-
upstream: external_exports.string().nullable(),
|
|
20223
|
-
statusFingerprint: statusFingerprintSchema,
|
|
20224
|
-
proposedTreeSha: gitShaSchema
|
|
20225
|
-
});
|
|
20226
|
-
gitCheckpointValueSchema = external_exports.object({
|
|
20227
|
-
repoRoot: machinePathSchema,
|
|
20228
|
-
sha: gitShaSchema,
|
|
20229
|
-
replayed: external_exports.boolean()
|
|
20230
|
-
});
|
|
20231
|
-
gitPushValueSchema = external_exports.object({
|
|
20232
|
-
repoRoot: machinePathSchema,
|
|
20233
|
-
pushedSha: gitShaSchema,
|
|
20234
|
-
branch: gitBranchSchema,
|
|
20235
|
-
remote: gitRemoteNameSchema,
|
|
20236
|
-
/** The remote already had the SHA before this push. */
|
|
20237
|
-
replayed: external_exports.boolean()
|
|
20238
|
-
});
|
|
20239
|
-
gitPrepareCheckoutValueSchema = external_exports.object({
|
|
20240
|
-
repoRoot: machinePathSchema,
|
|
20241
|
-
branch: gitBranchSchema,
|
|
20242
|
-
headSha: gitShaSchema,
|
|
20243
|
-
replayed: external_exports.boolean()
|
|
20244
|
-
});
|
|
20245
|
-
gitVerifyHeadValueSchema = external_exports.object({
|
|
20246
|
-
repoRoot: machinePathSchema,
|
|
20247
|
-
headSha: gitShaSchema,
|
|
20248
|
-
verified: external_exports.literal(true)
|
|
20249
|
-
});
|
|
20250
|
-
WORKSPACE_QUERY_ERROR_CODES = [
|
|
20251
|
-
"path_not_approved",
|
|
20252
|
-
"workspace_busy",
|
|
20253
|
-
"workspace_repository_mismatch",
|
|
20254
|
-
"operation_in_progress",
|
|
20255
|
-
"git_not_installed",
|
|
20256
|
-
"runtime_operation_failed",
|
|
20257
|
-
"invalid_git_request",
|
|
20258
|
-
"repository_not_found",
|
|
20259
|
-
"repository_path_changed",
|
|
20260
|
-
"repository_path_not_authorized",
|
|
20261
|
-
"path_canonicalization_failed",
|
|
20262
|
-
"git_status_unreadable",
|
|
20263
|
-
"git_operation_failed",
|
|
20264
|
-
"git_network_timeout",
|
|
20265
|
-
"git_output_limit_exceeded",
|
|
20266
|
-
"git_remote_unavailable",
|
|
20267
|
-
"git_fetch_failed",
|
|
20268
|
-
"git_push_failed",
|
|
20269
|
-
"remote_url_credentials_rejected",
|
|
20270
|
-
"remote_url_mismatch",
|
|
20271
|
-
"source_changed_since_approval",
|
|
20272
|
-
"source_dirty_after_checkpoint",
|
|
20273
|
-
"source_head_unreadable",
|
|
20274
|
-
"checkpoint_empty",
|
|
20275
|
-
"checkpoint_tree_unavailable",
|
|
20276
|
-
"checkpoint_commit_failed",
|
|
20277
|
-
"checkpoint_lock_unavailable",
|
|
20278
|
-
"checkpoint_index_sync_failed",
|
|
20279
|
-
"push_verification_failed",
|
|
20280
|
-
"target_checkout_dirty",
|
|
20281
|
-
"target_checkout_failed",
|
|
20282
|
-
"target_branch_in_use",
|
|
20283
|
-
"target_branch_diverged",
|
|
20284
|
-
"target_fast_forward_failed",
|
|
20285
|
-
"target_verification_failed",
|
|
20286
|
-
"target_sha_mismatch",
|
|
20287
|
-
"target_sha_unavailable",
|
|
20288
|
-
"target_head_unreadable",
|
|
20289
|
-
"verify_head_mismatch"
|
|
20290
|
-
];
|
|
20291
|
-
workspaceQueryErrorCodeSchema = external_exports.enum(WORKSPACE_QUERY_ERROR_CODES);
|
|
20292
|
-
publishedGitReceiptSchema = external_exports.object({
|
|
20293
|
-
pushedSha: gitShaSchema,
|
|
20294
|
-
branch: gitBranchSchema,
|
|
20295
|
-
remote: gitRemoteNameSchema,
|
|
20296
|
-
replayed: external_exports.boolean()
|
|
20297
|
-
});
|
|
20298
|
-
workspaceQueryErrorSchema = external_exports.object({
|
|
20299
|
-
code: workspaceQueryErrorCodeSchema,
|
|
20300
|
-
message: external_exports.string().max(4096),
|
|
20301
|
-
/** Only with source_changed_since_approval after a push: what already reached the remote. */
|
|
20302
|
-
published: publishedGitReceiptSchema.optional()
|
|
20303
|
-
});
|
|
20304
|
-
resultEnvelopeSchema = external_exports.discriminatedUnion("ok", [
|
|
20305
|
-
external_exports.object({ ok: external_exports.literal(true), value: external_exports.unknown() }),
|
|
20306
|
-
external_exports.object({ ok: external_exports.literal(false), error: workspaceQueryErrorSchema })
|
|
20307
|
-
]);
|
|
20308
|
-
}
|
|
20309
|
-
});
|
|
20310
|
-
|
|
20311
20370
|
// ../shared/dist/runtime-v2/desired-state.js
|
|
20312
|
-
var repoLocalPathSchema, runSpecSchema, desiredRunSchema, desiredStateSchema;
|
|
20371
|
+
var repoLocalPathSchema, requestedCheckoutSchema, runSpecSchema, desiredRunSchema, desiredStateSchema;
|
|
20313
20372
|
var init_desired_state = __esm({
|
|
20314
20373
|
"../shared/dist/runtime-v2/desired-state.js"() {
|
|
20315
20374
|
"use strict";
|
|
20316
20375
|
init_zod();
|
|
20317
20376
|
init_contracts();
|
|
20377
|
+
init_agent_context();
|
|
20318
20378
|
init_ids();
|
|
20319
20379
|
init_run_context();
|
|
20320
20380
|
init_workspace();
|
|
@@ -20324,6 +20384,11 @@ var init_desired_state = __esm({
|
|
|
20324
20384
|
localPath: external_exports.string().min(1),
|
|
20325
20385
|
branch: external_exports.string().min(1).optional()
|
|
20326
20386
|
});
|
|
20387
|
+
requestedCheckoutSchema = external_exports.object({
|
|
20388
|
+
path: machinePathSchema,
|
|
20389
|
+
repoUrl: gitRemoteUrlSchema,
|
|
20390
|
+
branch: gitBranchSchema
|
|
20391
|
+
});
|
|
20327
20392
|
runSpecSchema = external_exports.object({
|
|
20328
20393
|
runId: runIdSchema,
|
|
20329
20394
|
conversationId: conversationIdSchema,
|
|
@@ -20342,6 +20407,9 @@ var init_desired_state = __esm({
|
|
|
20342
20407
|
workspacePathPinned: external_exports.boolean().optional(),
|
|
20343
20408
|
approvedWorkspacePaths: external_exports.array(external_exports.string().min(1)).optional(),
|
|
20344
20409
|
repoLocalPaths: external_exports.array(repoLocalPathSchema).optional(),
|
|
20410
|
+
/** Applied once, at the conversation's first turn on a cloud sandbox; never moves local work. */
|
|
20411
|
+
requestedCheckouts: external_exports.array(requestedCheckoutSchema).max(64).optional(),
|
|
20412
|
+
agentContext: agentContextSchema.optional(),
|
|
20345
20413
|
workflowId: external_exports.guid().optional(),
|
|
20346
20414
|
workflowExecutionId: external_exports.guid().optional(),
|
|
20347
20415
|
agentId: external_exports.string().min(1).optional(),
|
|
@@ -20933,13 +21001,20 @@ var init_problem = __esm({
|
|
|
20933
21001
|
});
|
|
20934
21002
|
|
|
20935
21003
|
// ../shared/dist/cli-usage.js
|
|
20936
|
-
var usagePercentSchema, usageTimestampSchema, cliUsageWindowPatchSchema, cliUsageWindowSchema, cliUsageBucketSchema, cliUsageSnapshotSchema;
|
|
21004
|
+
var usagePercentSchema, usageTimestampSchema, usageAmountSchema, usageObservationShape, cliUsageWindowPatchSchema, cliUsageWindowSchema, cliUsageSpendPatchSchema, cliUsageSpendSchema, cliUsageCreditsPatchSchema, cliUsageCreditsSchema, cliUsageBucketSchema, cliUsageSnapshotSchema;
|
|
20937
21005
|
var init_cli_usage = __esm({
|
|
20938
21006
|
"../shared/dist/cli-usage.js"() {
|
|
20939
21007
|
"use strict";
|
|
20940
21008
|
init_zod();
|
|
20941
21009
|
usagePercentSchema = external_exports.number().min(0).max(100);
|
|
20942
21010
|
usageTimestampSchema = external_exports.iso.datetime();
|
|
21011
|
+
usageAmountSchema = external_exports.string().min(1);
|
|
21012
|
+
usageObservationShape = {
|
|
21013
|
+
observedAt: usageTimestampSchema,
|
|
21014
|
+
receivedAt: usageTimestampSchema,
|
|
21015
|
+
sourceId: external_exports.string().min(1),
|
|
21016
|
+
sequence: external_exports.number().int().nonnegative()
|
|
21017
|
+
};
|
|
20943
21018
|
cliUsageWindowPatchSchema = external_exports.object({
|
|
20944
21019
|
usedPercent: usagePercentSchema.nullable().optional(),
|
|
20945
21020
|
windowMinutes: external_exports.number().positive().nullable().optional(),
|
|
@@ -20949,14 +21024,41 @@ var init_cli_usage = __esm({
|
|
|
20949
21024
|
usedPercent: usagePercentSchema.optional(),
|
|
20950
21025
|
windowMinutes: external_exports.number().positive().optional(),
|
|
20951
21026
|
resetsAt: usageTimestampSchema.optional(),
|
|
20952
|
-
|
|
20953
|
-
|
|
20954
|
-
|
|
20955
|
-
|
|
21027
|
+
...usageObservationShape
|
|
21028
|
+
});
|
|
21029
|
+
cliUsageSpendPatchSchema = external_exports.object({
|
|
21030
|
+
reached: external_exports.boolean(),
|
|
21031
|
+
limit: usageAmountSchema.nullable().optional(),
|
|
21032
|
+
used: usageAmountSchema.nullable().optional(),
|
|
21033
|
+
remaining: usageAmountSchema.nullable().optional(),
|
|
21034
|
+
usedPercent: usagePercentSchema.nullable().optional(),
|
|
21035
|
+
resetsAt: usageTimestampSchema.nullable().optional()
|
|
21036
|
+
});
|
|
21037
|
+
cliUsageSpendSchema = external_exports.object({
|
|
21038
|
+
reached: external_exports.boolean(),
|
|
21039
|
+
limit: usageAmountSchema.optional(),
|
|
21040
|
+
used: usageAmountSchema.optional(),
|
|
21041
|
+
remaining: usageAmountSchema.optional(),
|
|
21042
|
+
usedPercent: usagePercentSchema.optional(),
|
|
21043
|
+
resetsAt: usageTimestampSchema.optional(),
|
|
21044
|
+
...usageObservationShape
|
|
21045
|
+
});
|
|
21046
|
+
cliUsageCreditsPatchSchema = external_exports.object({
|
|
21047
|
+
hasCredits: external_exports.boolean(),
|
|
21048
|
+
unlimited: external_exports.boolean(),
|
|
21049
|
+
balance: usageAmountSchema.nullable().optional()
|
|
21050
|
+
});
|
|
21051
|
+
cliUsageCreditsSchema = external_exports.object({
|
|
21052
|
+
hasCredits: external_exports.boolean(),
|
|
21053
|
+
unlimited: external_exports.boolean(),
|
|
21054
|
+
balance: usageAmountSchema.optional(),
|
|
21055
|
+
...usageObservationShape
|
|
20956
21056
|
});
|
|
20957
21057
|
cliUsageBucketSchema = external_exports.object({
|
|
20958
21058
|
primary: cliUsageWindowSchema.optional(),
|
|
20959
21059
|
secondary: cliUsageWindowSchema.optional(),
|
|
21060
|
+
spend: cliUsageSpendSchema.optional(),
|
|
21061
|
+
credits: cliUsageCreditsSchema.optional(),
|
|
20960
21062
|
planType: external_exports.string().min(1).nullable().optional()
|
|
20961
21063
|
});
|
|
20962
21064
|
cliUsageSnapshotSchema = external_exports.object({
|
|
@@ -20992,6 +21094,8 @@ var init_run_log = __esm({
|
|
|
20992
21094
|
limitId: external_exports.string().min(1),
|
|
20993
21095
|
primary: cliUsageWindowPatchSchema.nullable().optional(),
|
|
20994
21096
|
secondary: cliUsageWindowPatchSchema.nullable().optional(),
|
|
21097
|
+
spend: cliUsageSpendPatchSchema.nullable().optional(),
|
|
21098
|
+
credits: cliUsageCreditsPatchSchema.nullable().optional(),
|
|
20995
21099
|
planType: external_exports.string().min(1).nullable().optional(),
|
|
20996
21100
|
observedAt: external_exports.iso.datetime(),
|
|
20997
21101
|
sourceId: external_exports.string().min(1),
|
|
@@ -21319,6 +21423,7 @@ var init_skills = __esm({
|
|
|
21319
21423
|
var init_runtime_v2 = __esm({
|
|
21320
21424
|
"../shared/dist/runtime-v2/index.js"() {
|
|
21321
21425
|
"use strict";
|
|
21426
|
+
init_agent_context();
|
|
21322
21427
|
init_capabilities();
|
|
21323
21428
|
init_desired_state();
|
|
21324
21429
|
init_git_capability();
|
|
@@ -22225,11 +22330,11 @@ function createListeners() {
|
|
|
22225
22330
|
}
|
|
22226
22331
|
};
|
|
22227
22332
|
}
|
|
22228
|
-
var
|
|
22333
|
+
var import_promises5, CoreFault, NANOS_PER_MILLI, systemClock2, silentLog;
|
|
22229
22334
|
var init_chunk_YXWJW7I5 = __esm({
|
|
22230
22335
|
"../agent-core/dist/chunk-YXWJW7I5.js"() {
|
|
22231
22336
|
"use strict";
|
|
22232
|
-
|
|
22337
|
+
import_promises5 = require("timers/promises");
|
|
22233
22338
|
CoreFault = class extends Error {
|
|
22234
22339
|
code;
|
|
22235
22340
|
constructor(code, message, options) {
|
|
@@ -22243,7 +22348,7 @@ var init_chunk_YXWJW7I5 = __esm({
|
|
|
22243
22348
|
now: () => Date.now(),
|
|
22244
22349
|
monotonic: () => Number(process.hrtime.bigint() / NANOS_PER_MILLI),
|
|
22245
22350
|
sleep: async (ms, signal) => {
|
|
22246
|
-
await (0,
|
|
22351
|
+
await (0, import_promises5.setTimeout)(ms, void 0, signal ? { signal } : void 0);
|
|
22247
22352
|
}
|
|
22248
22353
|
};
|
|
22249
22354
|
silentLog = {
|
|
@@ -22450,7 +22555,7 @@ function plan(command, args, options) {
|
|
|
22450
22555
|
function captureOutput(command, args, options) {
|
|
22451
22556
|
const launch = plan(command, args, options);
|
|
22452
22557
|
if (launch === void 0) return Promise.resolve(NEVER_STARTED);
|
|
22453
|
-
return new Promise((
|
|
22558
|
+
return new Promise((resolve9) => {
|
|
22454
22559
|
(0, import_child_process.execFile)(
|
|
22455
22560
|
launch.file,
|
|
22456
22561
|
[...launch.args],
|
|
@@ -22464,7 +22569,7 @@ function captureOutput(command, args, options) {
|
|
|
22464
22569
|
},
|
|
22465
22570
|
(error61, stdout, stderr) => {
|
|
22466
22571
|
const code = error61 && typeof error61.code === "number" ? error61.code : error61 ? void 0 : 0;
|
|
22467
|
-
|
|
22572
|
+
resolve9({ stdout, stderr, exitCode: code });
|
|
22468
22573
|
}
|
|
22469
22574
|
);
|
|
22470
22575
|
});
|
|
@@ -22506,18 +22611,18 @@ function decode3(bytes, start, end) {
|
|
|
22506
22611
|
}
|
|
22507
22612
|
async function linuxStartTicks(pid) {
|
|
22508
22613
|
try {
|
|
22509
|
-
const
|
|
22510
|
-
const fields =
|
|
22614
|
+
const stat16 = await (0, import_promises6.readFile)(`/proc/${pid}/stat`, "utf8");
|
|
22615
|
+
const fields = stat16.slice(stat16.lastIndexOf(")") + 2).split(" ");
|
|
22511
22616
|
return fields[19];
|
|
22512
22617
|
} catch {
|
|
22513
22618
|
return void 0;
|
|
22514
22619
|
}
|
|
22515
22620
|
}
|
|
22516
22621
|
function psStartTime(pid) {
|
|
22517
|
-
return new Promise((
|
|
22622
|
+
return new Promise((resolve9) => {
|
|
22518
22623
|
(0, import_child_process2.execFile)("ps", ["-o", "lstart=", "-p", String(pid)], { timeout: 2e3 }, (error61, stdout) => {
|
|
22519
22624
|
const text2 = stdout.trim();
|
|
22520
|
-
|
|
22625
|
+
resolve9(error61 || !text2 ? void 0 : text2);
|
|
22521
22626
|
});
|
|
22522
22627
|
});
|
|
22523
22628
|
}
|
|
@@ -22546,12 +22651,12 @@ function parseProcessList(text2) {
|
|
|
22546
22651
|
}
|
|
22547
22652
|
function listProcesses(platform = process.platform) {
|
|
22548
22653
|
if (platform === "win32") return Promise.resolve([]);
|
|
22549
|
-
return new Promise((
|
|
22654
|
+
return new Promise((resolve9) => {
|
|
22550
22655
|
(0, import_child_process3.execFile)(
|
|
22551
22656
|
"ps",
|
|
22552
22657
|
["-A", "-o", "pid=,ppid=,pgid=,lstart="],
|
|
22553
22658
|
{ timeout: 5e3, maxBuffer: 8 * 1024 * 1024 },
|
|
22554
|
-
(error61, stdout) =>
|
|
22659
|
+
(error61, stdout) => resolve9(error61 ? [] : parseProcessList(stdout))
|
|
22555
22660
|
);
|
|
22556
22661
|
});
|
|
22557
22662
|
}
|
|
@@ -22591,11 +22696,11 @@ async function taskkill(pid, options) {
|
|
|
22591
22696
|
stdio: "ignore",
|
|
22592
22697
|
windowsHide: true
|
|
22593
22698
|
});
|
|
22594
|
-
const exited = new Promise((
|
|
22595
|
-
killer.once("error", (error210) =>
|
|
22699
|
+
const exited = new Promise((resolve9) => {
|
|
22700
|
+
killer.once("error", (error210) => resolve9(error210));
|
|
22596
22701
|
killer.once(
|
|
22597
22702
|
"exit",
|
|
22598
|
-
(code, signal) =>
|
|
22703
|
+
(code, signal) => resolve9(code === 0 ? void 0 : new Error(`taskkill failed: exit ${code}, signal ${signal}`))
|
|
22599
22704
|
);
|
|
22600
22705
|
});
|
|
22601
22706
|
const timedOut = clock.sleep(options.timeoutMs ?? DEFAULT_TASKKILL_TIMEOUT_MS, timeout.signal).then(() => new Error("taskkill timed out")).catch(() => void 0);
|
|
@@ -22799,7 +22904,7 @@ async function waitForWindowsJob(child, command) {
|
|
|
22799
22904
|
const deadline = systemClock2.monotonic() + START_TIMEOUT_MS;
|
|
22800
22905
|
try {
|
|
22801
22906
|
while (systemClock2.monotonic() < deadline) {
|
|
22802
|
-
const providerPid = await (0,
|
|
22907
|
+
const providerPid = await (0, import_promises7.readFile)(status.path, "utf8").catch(() => void 0);
|
|
22803
22908
|
if (providerPid !== void 0) {
|
|
22804
22909
|
requireStartedProvider(providerPid, command);
|
|
22805
22910
|
return;
|
|
@@ -22822,7 +22927,7 @@ async function waitForWindowsJob(child, command) {
|
|
|
22822
22927
|
throw new CoreFault("spawn_failed", `Could not start ${command} (Windows helper timed out)`);
|
|
22823
22928
|
} finally {
|
|
22824
22929
|
statuses.delete(child);
|
|
22825
|
-
await (0,
|
|
22930
|
+
await (0, import_promises7.rm)(status.directory, { recursive: true, force: true });
|
|
22826
22931
|
}
|
|
22827
22932
|
}
|
|
22828
22933
|
function onCliSpawned(listener) {
|
|
@@ -22851,10 +22956,10 @@ function spawnCli(options) {
|
|
|
22851
22956
|
function waitForSpawn(child, command) {
|
|
22852
22957
|
if (isWindowsJob(child)) return waitForWindowsJob(child, command);
|
|
22853
22958
|
if (child.pid !== void 0) return Promise.resolve();
|
|
22854
|
-
return new Promise((
|
|
22959
|
+
return new Promise((resolve9, reject) => {
|
|
22855
22960
|
const onSpawn = () => {
|
|
22856
22961
|
child.off("error", onError);
|
|
22857
|
-
|
|
22962
|
+
resolve9();
|
|
22858
22963
|
};
|
|
22859
22964
|
const onError = (error61) => {
|
|
22860
22965
|
child.off("spawn", onSpawn);
|
|
@@ -22867,7 +22972,7 @@ function waitForSpawn(child, command) {
|
|
|
22867
22972
|
child.once("error", onError);
|
|
22868
22973
|
});
|
|
22869
22974
|
}
|
|
22870
|
-
var import_child_process, import_fs, import_path, import_child_process2,
|
|
22975
|
+
var import_child_process, import_fs, import_path, import_child_process2, import_promises6, import_child_process3, import_child_process4, import_child_process5, import_child_process6, import_crypto, import_fs2, import_promises7, import_os, import_path2, SHIM_MAX_BYTES, CMD_MAX_COMMAND_LINE, MAX_COMMAND_LINE, DEFAULT_PATHEXT, LAUNCHABLE_EXTENSIONS, nodeWindowsFiles, NODE_SHIM_ENTRY, NATIVE_SHIM_LINES, NATIVE_SHIM_ENTRY, CMD_META, NEVER_STARTED, HIDDEN_FLAG_PROBE_VALUE, NEWLINE, CARRIAGE_RETURN, EMPTY, MAX_LINE_BYTES, LineSplitter, PS_LINE, POLL_MS, DEFAULT_GRACE_MS, DEFAULT_KILL_WAIT_MS, DEFAULT_TASKKILL_TIMEOUT_MS, statuses, START_TIMEOUT_MS, spawnListeners;
|
|
22871
22976
|
var init_chunk_M6YHY2EZ = __esm({
|
|
22872
22977
|
"../agent-core/dist/chunk-M6YHY2EZ.js"() {
|
|
22873
22978
|
"use strict";
|
|
@@ -22876,14 +22981,14 @@ var init_chunk_M6YHY2EZ = __esm({
|
|
|
22876
22981
|
import_fs = require("fs");
|
|
22877
22982
|
import_path = require("path");
|
|
22878
22983
|
import_child_process2 = require("child_process");
|
|
22879
|
-
|
|
22984
|
+
import_promises6 = require("fs/promises");
|
|
22880
22985
|
import_child_process3 = require("child_process");
|
|
22881
22986
|
import_child_process4 = require("child_process");
|
|
22882
22987
|
import_child_process5 = require("child_process");
|
|
22883
22988
|
import_child_process6 = require("child_process");
|
|
22884
22989
|
import_crypto = require("crypto");
|
|
22885
22990
|
import_fs2 = require("fs");
|
|
22886
|
-
|
|
22991
|
+
import_promises7 = require("fs/promises");
|
|
22887
22992
|
import_os = require("os");
|
|
22888
22993
|
import_path2 = require("path");
|
|
22889
22994
|
SHIM_MAX_BYTES = 64 * 1024;
|
|
@@ -24765,8 +24870,8 @@ function readMediaFiles(candidates2, cwd, mimeByExt, maxBytes) {
|
|
|
24765
24870
|
seen.add(path);
|
|
24766
24871
|
const mimeType = mimeByExt[(0, import_path3.extname)(path).toLowerCase()];
|
|
24767
24872
|
if (!mimeType) continue;
|
|
24768
|
-
const
|
|
24769
|
-
if (!
|
|
24873
|
+
const stat16 = (0, import_fs4.statSync)(path);
|
|
24874
|
+
if (!stat16.isFile() || stat16.size <= 0 || stat16.size > maxBytes) continue;
|
|
24770
24875
|
files.push({ path, mimeType, buffer: (0, import_fs4.readFileSync)(path) });
|
|
24771
24876
|
}
|
|
24772
24877
|
return files;
|
|
@@ -24841,8 +24946,8 @@ function createJsonRpcPeer(writer, handlers) {
|
|
|
24841
24946
|
},
|
|
24842
24947
|
request: (method, params = {}) => {
|
|
24843
24948
|
const id = counter.next++;
|
|
24844
|
-
return new Promise((
|
|
24845
|
-
pending.set(id, { method, resolve:
|
|
24949
|
+
return new Promise((resolve9, reject) => {
|
|
24950
|
+
pending.set(id, { method, resolve: resolve9, reject });
|
|
24846
24951
|
writer.write({ id, method, params }).catch((error61) => {
|
|
24847
24952
|
pending.delete(id);
|
|
24848
24953
|
reject(error61 instanceof Error ? error61 : new Error(String(error61)));
|
|
@@ -24955,7 +25060,7 @@ function createNdjsonWriter(stream) {
|
|
|
24955
25060
|
get writable() {
|
|
24956
25061
|
return stream.writable && !stream.destroyed && failure5.error === void 0;
|
|
24957
25062
|
},
|
|
24958
|
-
write: (value) => new Promise((
|
|
25063
|
+
write: (value) => new Promise((resolve9, reject) => {
|
|
24959
25064
|
if (failure5.error) {
|
|
24960
25065
|
reject(failure5.error);
|
|
24961
25066
|
return;
|
|
@@ -24967,7 +25072,7 @@ function createNdjsonWriter(stream) {
|
|
|
24967
25072
|
stream.write(`${JSON.stringify(value)}
|
|
24968
25073
|
`, (error61) => {
|
|
24969
25074
|
if (error61) reject(error61);
|
|
24970
|
-
else
|
|
25075
|
+
else resolve9();
|
|
24971
25076
|
});
|
|
24972
25077
|
}),
|
|
24973
25078
|
end: () => {
|
|
@@ -24983,11 +25088,11 @@ function hostProcess(child, tree, options, handlers) {
|
|
|
24983
25088
|
const stderr = new LineSplitter((line) => handlers.onStderrLine(line));
|
|
24984
25089
|
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
24985
25090
|
child.stderr.once("end", () => stderr.flush());
|
|
24986
|
-
const processExit = new Promise((
|
|
24987
|
-
child.once("exit", (code, signal) =>
|
|
25091
|
+
const processExit = new Promise((resolve9) => {
|
|
25092
|
+
child.once("exit", (code, signal) => resolve9({ code, signal }));
|
|
24988
25093
|
});
|
|
24989
|
-
const outputEnded = new Promise((
|
|
24990
|
-
child.stdout.once("close", () =>
|
|
25094
|
+
const outputEnded = new Promise((resolve9) => {
|
|
25095
|
+
child.stdout.once("close", () => resolve9());
|
|
24991
25096
|
});
|
|
24992
25097
|
const watch = async () => {
|
|
24993
25098
|
const { clock, stdoutDrainMs, log, name } = options;
|
|
@@ -25277,13 +25382,13 @@ var init_chunk_4G77APXN = __esm({
|
|
|
25277
25382
|
const turnId = input2.turnId;
|
|
25278
25383
|
let finish = () => {
|
|
25279
25384
|
};
|
|
25280
|
-
const done = new Promise((
|
|
25385
|
+
const done = new Promise((resolve9) => {
|
|
25281
25386
|
finish = (outcome2) => {
|
|
25282
25387
|
if (this.#current?.id !== turnId) return;
|
|
25283
25388
|
this.#current = void 0;
|
|
25284
25389
|
if (this.#state === "busy") this.#state = "idle";
|
|
25285
25390
|
this.#emit({ type: "turn_ended", turnId, outcome: outcome2 });
|
|
25286
|
-
|
|
25391
|
+
resolve9({ turnId, outcome: outcome2, providerSessionId: this.#sessionId });
|
|
25287
25392
|
};
|
|
25288
25393
|
});
|
|
25289
25394
|
const pending = {
|
|
@@ -25479,20 +25584,20 @@ function canonicalizeManagedMcpToolName(toolName) {
|
|
|
25479
25584
|
return flattened ? `mcp__${MANAGED_MCP_SERVER_NAME}__${flattened[1]}` : toolName;
|
|
25480
25585
|
}
|
|
25481
25586
|
async function writeSecretFile(name, contents) {
|
|
25482
|
-
const dir = await (0,
|
|
25587
|
+
const dir = await (0, import_promises14.mkdtemp)((0, import_path4.join)((0, import_os2.tmpdir)(), "alan-mcp-"));
|
|
25483
25588
|
const path = (0, import_path4.join)(dir, name);
|
|
25484
25589
|
const remove = async () => {
|
|
25485
|
-
await (0,
|
|
25590
|
+
await (0, import_promises14.rm)(dir, { recursive: true, force: true });
|
|
25486
25591
|
};
|
|
25487
25592
|
try {
|
|
25488
|
-
await (0,
|
|
25593
|
+
await (0, import_promises14.writeFile)(path, contents, { mode: 384, flag: "wx" });
|
|
25489
25594
|
} catch (error61) {
|
|
25490
25595
|
await remove();
|
|
25491
25596
|
throw error61;
|
|
25492
25597
|
}
|
|
25493
25598
|
return { path, remove, [Symbol.asyncDispose]: remove };
|
|
25494
25599
|
}
|
|
25495
|
-
var import_crypto4, import_crypto5,
|
|
25600
|
+
var import_crypto4, import_crypto5, import_promises14, import_os2, import_path4, MANAGED_MCP_SERVER_NAME, RUN_SCOPED_SERVER, NAMESPACED_RUN_TOOL, FLATTENED_RUN_TOOL;
|
|
25496
25601
|
var init_chunk_J2KTV5FP = __esm({
|
|
25497
25602
|
"../agent-core/dist/chunk-J2KTV5FP.js"() {
|
|
25498
25603
|
"use strict";
|
|
@@ -25501,7 +25606,7 @@ var init_chunk_J2KTV5FP = __esm({
|
|
|
25501
25606
|
import_crypto5 = require("crypto");
|
|
25502
25607
|
init_agent2();
|
|
25503
25608
|
init_runtime_v2();
|
|
25504
|
-
|
|
25609
|
+
import_promises14 = require("fs/promises");
|
|
25505
25610
|
import_os2 = require("os");
|
|
25506
25611
|
import_path4 = require("path");
|
|
25507
25612
|
MANAGED_MCP_SERVER_NAME = "alan";
|
|
@@ -25511,7 +25616,259 @@ var init_chunk_J2KTV5FP = __esm({
|
|
|
25511
25616
|
}
|
|
25512
25617
|
});
|
|
25513
25618
|
|
|
25514
|
-
// ../agent-core/dist/chunk-
|
|
25619
|
+
// ../agent-core/dist/chunk-GI3ZGXTY.js
|
|
25620
|
+
function repositories(input2, context) {
|
|
25621
|
+
const problems = new Map(input2.problems.map((problem) => [problem.path, problem]));
|
|
25622
|
+
const listed = context?.repositories ?? [];
|
|
25623
|
+
const known = new Set(listed.map((repository) => repository.path));
|
|
25624
|
+
const unlisted = input2.problems.filter((problem) => !known.has(problem.path));
|
|
25625
|
+
return [
|
|
25626
|
+
...listed.map((repository) => {
|
|
25627
|
+
const problem = problems.get(repository.path);
|
|
25628
|
+
return {
|
|
25629
|
+
path: repository.path,
|
|
25630
|
+
name: repository.name,
|
|
25631
|
+
url: repository.url,
|
|
25632
|
+
branch: repository.branch,
|
|
25633
|
+
branchSource: repository.branchSource,
|
|
25634
|
+
base: repository.base,
|
|
25635
|
+
checkout: problem ? "needs_attention" : "ok",
|
|
25636
|
+
...problem ? { problem: problem.problem, action: problem.action } : {}
|
|
25637
|
+
};
|
|
25638
|
+
}),
|
|
25639
|
+
...unlisted.map(
|
|
25640
|
+
(problem) => ({
|
|
25641
|
+
path: problem.path,
|
|
25642
|
+
checkout: "needs_attention",
|
|
25643
|
+
problem: problem.problem,
|
|
25644
|
+
action: problem.action
|
|
25645
|
+
})
|
|
25646
|
+
)
|
|
25647
|
+
];
|
|
25648
|
+
}
|
|
25649
|
+
function branchInstruction(repository) {
|
|
25650
|
+
const { path, branch, branchSource } = repository;
|
|
25651
|
+
if (!branch || !branchSource) return void 0;
|
|
25652
|
+
const reason = BRANCH_REASONS[branchSource];
|
|
25653
|
+
if (branchSource === "task") {
|
|
25654
|
+
return `Commit work in ${path} on ${branch}, ${reason}; create it from ${repository.base ?? "the default branch"} if it does not exist.`;
|
|
25655
|
+
}
|
|
25656
|
+
return `Work in ${path} on ${branch}, ${reason}.`;
|
|
25657
|
+
}
|
|
25658
|
+
function repositoryInstructions(repository) {
|
|
25659
|
+
const problem = repository.problem && repository.action ? `${repository.path} ${repository.problem}. ${repository.action} before relying on its files.` : void 0;
|
|
25660
|
+
const branch = problem && repository.branchSource !== "environment_default" ? void 0 : branchInstruction(repository);
|
|
25661
|
+
return [branch, problem].filter((line) => line !== void 0);
|
|
25662
|
+
}
|
|
25663
|
+
function environmentInstructions(environment, cwd) {
|
|
25664
|
+
const lines = [];
|
|
25665
|
+
const start = environment.start;
|
|
25666
|
+
if (start?.state === "failed") {
|
|
25667
|
+
lines.push(
|
|
25668
|
+
`The start command exited with code ${start.exitCode}. Read ${start.log}, fix the cause, then run the start command from ${cwd} before testing the app.`
|
|
25669
|
+
);
|
|
25670
|
+
} else if (start?.state === "pending") {
|
|
25671
|
+
lines.push(`The start command is still starting; check ${start.log} before testing the app.`);
|
|
25672
|
+
}
|
|
25673
|
+
const build = environment.pendingBuild;
|
|
25674
|
+
if (build?.status === "queued" || build?.status === "running") {
|
|
25675
|
+
lines.push(
|
|
25676
|
+
`Image build ${build.id} is ${build.status}; its result arrives as a message, so do not poll for it.`
|
|
25677
|
+
);
|
|
25678
|
+
} else if (build?.status === "failed") {
|
|
25679
|
+
lines.push(
|
|
25680
|
+
`The latest image build (${build.id}) failed; sessions still boot from the previous image.`
|
|
25681
|
+
);
|
|
25682
|
+
}
|
|
25683
|
+
if (environment.variables.length > 0) {
|
|
25684
|
+
lines.push("Saved variables are set in this sandbox; never print or commit their values.");
|
|
25685
|
+
}
|
|
25686
|
+
return lines;
|
|
25687
|
+
}
|
|
25688
|
+
function instructionsFor(snapshot2) {
|
|
25689
|
+
const cwd = snapshot2.workspace.cwd ?? snapshot2.workspace.root ?? "the workspace";
|
|
25690
|
+
return [
|
|
25691
|
+
...snapshot2.session.trigger === "image_build" ? ["Alan sent this turn, not the user: it reports an image build result."] : [],
|
|
25692
|
+
...snapshot2.environment ? environmentInstructions(snapshot2.environment, cwd) : []
|
|
25693
|
+
];
|
|
25694
|
+
}
|
|
25695
|
+
function startingInstructions(snapshot2) {
|
|
25696
|
+
const cwd = snapshot2.workspace.cwd ?? snapshot2.workspace.root;
|
|
25697
|
+
return [
|
|
25698
|
+
...cwd ? [`Work from ${cwd}.`] : [],
|
|
25699
|
+
...snapshot2.workspace.repositories.flatMap(repositoryInstructions)
|
|
25700
|
+
];
|
|
25701
|
+
}
|
|
25702
|
+
function sessionKind(input2, context) {
|
|
25703
|
+
if (context) return context.kind;
|
|
25704
|
+
if (input2.spec.workflowExecutionId) return "workflow";
|
|
25705
|
+
return input2.spec.taskId ? "task" : "chat";
|
|
25706
|
+
}
|
|
25707
|
+
function environmentOf(input2, context) {
|
|
25708
|
+
const environment = context?.environment;
|
|
25709
|
+
if (!environment) return void 0;
|
|
25710
|
+
const start = environment.startCommand === null ? { state: "not_configured" } : input2.start;
|
|
25711
|
+
return {
|
|
25712
|
+
id: environment.id,
|
|
25713
|
+
name: environment.name,
|
|
25714
|
+
installCommand: environment.installCommand,
|
|
25715
|
+
startCommand: environment.startCommand,
|
|
25716
|
+
imageBuildId: environment.imageBuildId,
|
|
25717
|
+
...environment.pendingBuild ? { pendingBuild: environment.pendingBuild } : {},
|
|
25718
|
+
variables: environment.variables,
|
|
25719
|
+
...start ? { start: start.state === "not_configured" ? start : { ...start, log: input2.startLogPath } } : {}
|
|
25720
|
+
};
|
|
25721
|
+
}
|
|
25722
|
+
function knownContext(snapshot2) {
|
|
25723
|
+
const organizationId = snapshot2?.session.organizationId;
|
|
25724
|
+
if (!snapshot2 || !organizationId) return void 0;
|
|
25725
|
+
const environment = snapshot2.environment;
|
|
25726
|
+
return {
|
|
25727
|
+
kind: snapshot2.session.kind,
|
|
25728
|
+
trigger: "user",
|
|
25729
|
+
organizationId,
|
|
25730
|
+
...snapshot2.task ? { taskWorkingBranch: snapshot2.task.workingBranch } : {},
|
|
25731
|
+
...snapshot2.pullRequest ? { pullRequest: snapshot2.pullRequest } : {},
|
|
25732
|
+
repositories: snapshot2.workspace.repositories.flatMap(
|
|
25733
|
+
({ path, name, url: url2, branch, branchSource, base }) => name && url2 && branch && branchSource && base ? [{ path, name, url: url2, branch, branchSource, base }] : []
|
|
25734
|
+
),
|
|
25735
|
+
...environment ? {
|
|
25736
|
+
environment: {
|
|
25737
|
+
id: environment.id,
|
|
25738
|
+
name: environment.name,
|
|
25739
|
+
installCommand: environment.installCommand,
|
|
25740
|
+
startCommand: environment.startCommand,
|
|
25741
|
+
imageBuildId: environment.imageBuildId,
|
|
25742
|
+
...environment.pendingBuild ? { pendingBuild: environment.pendingBuild } : {},
|
|
25743
|
+
variables: environment.variables
|
|
25744
|
+
}
|
|
25745
|
+
} : {}
|
|
25746
|
+
};
|
|
25747
|
+
}
|
|
25748
|
+
function agentContextSnapshot(input2) {
|
|
25749
|
+
const context = input2.spec.agentContext ?? knownContext(input2.known);
|
|
25750
|
+
if (!context && input2.problems.length === 0) return null;
|
|
25751
|
+
const environment = environmentOf(input2, context);
|
|
25752
|
+
const base = {
|
|
25753
|
+
session: {
|
|
25754
|
+
kind: sessionKind(input2, context),
|
|
25755
|
+
trigger: context?.trigger ?? "user",
|
|
25756
|
+
conversationId: input2.spec.conversationId,
|
|
25757
|
+
runId: input2.spec.runId,
|
|
25758
|
+
...input2.spec.teamId ? { teamId: input2.spec.teamId } : {},
|
|
25759
|
+
...input2.spec.taskId ? { taskId: input2.spec.taskId } : {},
|
|
25760
|
+
...input2.spec.workflowExecutionId ? { workflowExecutionId: input2.spec.workflowExecutionId } : {},
|
|
25761
|
+
...context ? { organizationId: context.organizationId } : {}
|
|
25762
|
+
},
|
|
25763
|
+
...context?.taskWorkingBranch ? { task: { workingBranch: context.taskWorkingBranch } } : {},
|
|
25764
|
+
...context?.pullRequest ? { pullRequest: context.pullRequest } : {},
|
|
25765
|
+
workspace: {
|
|
25766
|
+
...input2.workspaceRoot ? { root: input2.workspaceRoot } : {},
|
|
25767
|
+
...input2.spec.projectPath ? { cwd: input2.spec.projectPath } : {},
|
|
25768
|
+
repositories: repositories(input2, context)
|
|
25769
|
+
},
|
|
25770
|
+
...environment ? { environment } : {}
|
|
25771
|
+
};
|
|
25772
|
+
return { ...base, instructions: instructionsFor(base) };
|
|
25773
|
+
}
|
|
25774
|
+
function isScalar(value) {
|
|
25775
|
+
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
25776
|
+
}
|
|
25777
|
+
function scalar(value) {
|
|
25778
|
+
if (typeof value !== "string") return String(value);
|
|
25779
|
+
return PLAIN_SCALAR.test(value) ? value : JSON.stringify(value);
|
|
25780
|
+
}
|
|
25781
|
+
function snakeCase(key) {
|
|
25782
|
+
return key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
25783
|
+
}
|
|
25784
|
+
function yamlLines(record2, indent) {
|
|
25785
|
+
return Object.entries(record2).flatMap(([key, value]) => {
|
|
25786
|
+
const name = `${indent}${snakeCase(key)}:`;
|
|
25787
|
+
if (isScalar(value)) return [`${name} ${scalar(value)}`];
|
|
25788
|
+
if (Array.isArray(value)) {
|
|
25789
|
+
if (value.length === 0) return [];
|
|
25790
|
+
return [
|
|
25791
|
+
name,
|
|
25792
|
+
...value.flatMap((item) => {
|
|
25793
|
+
if (isScalar(item)) return [`${indent} - ${scalar(item)}`];
|
|
25794
|
+
if (typeof item !== "object" || item === null) return [];
|
|
25795
|
+
const [first = "", ...rest] = yamlLines(item, `${indent} `);
|
|
25796
|
+
return [`${indent} - ${first.trimStart()}`, ...rest];
|
|
25797
|
+
})
|
|
25798
|
+
];
|
|
25799
|
+
}
|
|
25800
|
+
if (typeof value === "object" && value !== null)
|
|
25801
|
+
return [name, ...yamlLines(value, `${indent} `)];
|
|
25802
|
+
return [];
|
|
25803
|
+
});
|
|
25804
|
+
}
|
|
25805
|
+
function block(tag, body) {
|
|
25806
|
+
return [`<${tag} version="${AGENT_CONTEXT_VERSION}">`, ...yamlLines(body, ""), `</${tag}>`].join(
|
|
25807
|
+
"\n"
|
|
25808
|
+
);
|
|
25809
|
+
}
|
|
25810
|
+
function stableRepository(repository) {
|
|
25811
|
+
const { checkout: _checkout, problem: _problem, action: _action, ...rest } = repository;
|
|
25812
|
+
return rest;
|
|
25813
|
+
}
|
|
25814
|
+
function commandPreview(command) {
|
|
25815
|
+
if (command === null || command.length <= COMMAND_PREVIEW_CHARS) return command;
|
|
25816
|
+
const lines = command.split("\n").length;
|
|
25817
|
+
return `${command.slice(0, COMMAND_PREVIEW_CHARS)}\u2026 (${lines} lines; get_cloud_machine has the full command)`;
|
|
25818
|
+
}
|
|
25819
|
+
function withCommandPreviews(environment) {
|
|
25820
|
+
return {
|
|
25821
|
+
...environment,
|
|
25822
|
+
...environment.installCommand !== void 0 ? { installCommand: commandPreview(environment.installCommand) } : {},
|
|
25823
|
+
...environment.startCommand !== void 0 ? { startCommand: commandPreview(environment.startCommand) } : {}
|
|
25824
|
+
};
|
|
25825
|
+
}
|
|
25826
|
+
function changed(a, b) {
|
|
25827
|
+
return JSON.stringify(a) !== JSON.stringify(b);
|
|
25828
|
+
}
|
|
25829
|
+
function environmentUpdate(previous, next) {
|
|
25830
|
+
if (!next) return void 0;
|
|
25831
|
+
const { start: previousStart, ...previousFacts } = previous ?? {};
|
|
25832
|
+
const { start, ...facts } = next;
|
|
25833
|
+
if (changed(previousFacts, facts)) return next;
|
|
25834
|
+
return start?.state === "failed" && changed(previousStart, start) ? { start } : void 0;
|
|
25835
|
+
}
|
|
25836
|
+
function updateBody(previous, next) {
|
|
25837
|
+
const known = new Set(previous.instructions);
|
|
25838
|
+
const instructions = next.instructions.filter((line) => !known.has(line));
|
|
25839
|
+
const before = new Map(
|
|
25840
|
+
previous.workspace.repositories.map((repository) => [
|
|
25841
|
+
repository.path,
|
|
25842
|
+
stableRepository(repository)
|
|
25843
|
+
])
|
|
25844
|
+
);
|
|
25845
|
+
const repositories2 = next.workspace.repositories.map(stableRepository).filter(
|
|
25846
|
+
(repository) => repository.path !== void 0 && changed(before.get(repository.path), repository)
|
|
25847
|
+
);
|
|
25848
|
+
const environment = environmentUpdate(previous.environment, next.environment);
|
|
25849
|
+
const facts = {
|
|
25850
|
+
...changed(previous.task, next.task) && next.task ? { task: next.task } : {},
|
|
25851
|
+
...changed(previous.pullRequest, next.pullRequest) && next.pullRequest ? { pullRequest: next.pullRequest } : {},
|
|
25852
|
+
...repositories2.length > 0 ? { workspace: { repositories: repositories2 } } : {},
|
|
25853
|
+
...environment ? { environment: withCommandPreviews(environment) } : {},
|
|
25854
|
+
...instructions.length > 0 ? { instructions } : {}
|
|
25855
|
+
};
|
|
25856
|
+
if (Object.keys(facts).length === 0) return void 0;
|
|
25857
|
+
return next.session.trigger === "user" ? facts : { session: { trigger: next.session.trigger }, ...facts };
|
|
25858
|
+
}
|
|
25859
|
+
function renderAgentContext(snapshot2, previous) {
|
|
25860
|
+
const full = block("alan_agent_context", {
|
|
25861
|
+
...snapshot2,
|
|
25862
|
+
...snapshot2.environment ? { environment: withCommandPreviews(snapshot2.environment) } : {},
|
|
25863
|
+
instructions: [...startingInstructions(snapshot2), ...snapshot2.instructions]
|
|
25864
|
+
});
|
|
25865
|
+
const update = previous ? updateBody(previous, snapshot2) : void 0;
|
|
25866
|
+
return {
|
|
25867
|
+
snapshot: snapshot2,
|
|
25868
|
+
full,
|
|
25869
|
+
...update ? { update: block("alan_agent_context_update", update) } : {}
|
|
25870
|
+
};
|
|
25871
|
+
}
|
|
25515
25872
|
function truncate(value, limit) {
|
|
25516
25873
|
const normalized2 = Array.from(value, (character) => {
|
|
25517
25874
|
const code = character.charCodeAt(0);
|
|
@@ -25770,11 +26127,12 @@ function cloudExecutionSection(spec) {
|
|
|
25770
26127
|
if (spec.sandboxId) lines.push(`Sandbox ID: ${spec.sandboxId}.`);
|
|
25771
26128
|
if (spec.cloudEnvironmentId) lines.push(`Cloud environment ID: ${spec.cloudEnvironmentId}.`);
|
|
25772
26129
|
lines.push(
|
|
25773
|
-
"Run setup, development and validation in this sandbox. The execution location is separate from the deployment of the application you are testing; verify that application's origin before acting."
|
|
26130
|
+
"Run setup, development and validation in this sandbox. The execution location is separate from the deployment of the application you are testing; verify that application's origin before acting.",
|
|
26131
|
+
"A turn can begin with an <alan_agent_context> block, or an <alan_agent_context_update> with only what changed since. Alan writes these, not the user: they state this session's repositories, branches, environment and start command state, and their instructions apply."
|
|
25774
26132
|
);
|
|
25775
26133
|
if (!isReadOnlyMode(spec.mode) && !isReadOnlyAgent(spec.agentId)) {
|
|
25776
26134
|
lines.push(
|
|
25777
|
-
"Own the authorized work end to end: inspect context, make reasonable assumptions, implement, test, review and create or update the pull request for code changes when the repository workflow calls for one. Do not stop at a plan or ask for routine implementation choices or permission already granted. For application changes,
|
|
26135
|
+
"Own the authorized work end to end: inspect context, make reasonable assumptions, implement, test, review and create or update the pull request for code changes when the repository workflow calls for one. Do not stop at a plan or ask for routine implementation choices or permission already granted. For application changes, follow the session context for where to work and whether the start command is running, start the app if needed, and verify it is reachable before testing. For user-facing flows, use alan-test-feature when installed to test the running app, capture a video, and create a test report. Ask only for a missing secret, an essential decision you cannot derive, or an action requiring explicit approval. Respect the user's scope, repository rules and tool authorization; report blocked capabilities and validation gaps while continuing independent work."
|
|
25778
26136
|
);
|
|
25779
26137
|
}
|
|
25780
26138
|
const skills = spec.promptContext?.availableSkills ?? [];
|
|
@@ -25871,11 +26229,71 @@ function buildTurnText(input2) {
|
|
|
25871
26229
|
${body}` : body;
|
|
25872
26230
|
return spec.mode === "plan" ? planModePrefix(prefixed) : prefixed;
|
|
25873
26231
|
}
|
|
25874
|
-
var MAX_PARSED_ATTACHMENTS, MAX_PARSED_ATTACHMENT_CHARS, MAX_METADATA_CHARS, UNAVAILABLE, READ_ONLY_MODES, AGENT_MODES;
|
|
25875
|
-
var
|
|
25876
|
-
"../agent-core/dist/chunk-
|
|
26232
|
+
var startCommandStateSchema, repositorySnapshotSchema, environmentSnapshotSchema, agentContextSnapshotSchema, BRANCH_REASONS, PLAIN_SCALAR, COMMAND_PREVIEW_CHARS, MAX_PARSED_ATTACHMENTS, MAX_PARSED_ATTACHMENT_CHARS, MAX_METADATA_CHARS, UNAVAILABLE, READ_ONLY_MODES, AGENT_MODES;
|
|
26233
|
+
var init_chunk_GI3ZGXTY = __esm({
|
|
26234
|
+
"../agent-core/dist/chunk-GI3ZGXTY.js"() {
|
|
25877
26235
|
"use strict";
|
|
26236
|
+
init_runtime_v2();
|
|
26237
|
+
init_zod();
|
|
25878
26238
|
init_agent2();
|
|
26239
|
+
startCommandStateSchema = external_exports.discriminatedUnion("state", [
|
|
26240
|
+
external_exports.object({ state: external_exports.literal("not_configured") }),
|
|
26241
|
+
external_exports.object({ state: external_exports.literal("pending") }),
|
|
26242
|
+
external_exports.object({ state: external_exports.literal("running") }),
|
|
26243
|
+
external_exports.object({ state: external_exports.literal("exited_ok") }),
|
|
26244
|
+
external_exports.object({ state: external_exports.literal("failed"), exitCode: external_exports.number().int() })
|
|
26245
|
+
]);
|
|
26246
|
+
repositorySnapshotSchema = external_exports.object({
|
|
26247
|
+
path: external_exports.string(),
|
|
26248
|
+
name: external_exports.string().optional(),
|
|
26249
|
+
url: external_exports.string().optional(),
|
|
26250
|
+
branch: external_exports.string().optional(),
|
|
26251
|
+
branchSource: agentBranchSourceSchema.optional(),
|
|
26252
|
+
base: external_exports.string().optional(),
|
|
26253
|
+
checkout: external_exports.enum(["ok", "needs_attention"]),
|
|
26254
|
+
problem: external_exports.string().optional(),
|
|
26255
|
+
action: external_exports.string().optional()
|
|
26256
|
+
});
|
|
26257
|
+
environmentSnapshotSchema = external_exports.object({
|
|
26258
|
+
id: external_exports.string(),
|
|
26259
|
+
name: external_exports.string(),
|
|
26260
|
+
installCommand: external_exports.string().nullable(),
|
|
26261
|
+
startCommand: external_exports.string().nullable(),
|
|
26262
|
+
imageBuildId: external_exports.string().nullable(),
|
|
26263
|
+
pendingBuild: agentContextBuildSchema.optional(),
|
|
26264
|
+
variables: external_exports.array(external_exports.string()),
|
|
26265
|
+
start: external_exports.intersection(startCommandStateSchema, external_exports.object({ log: external_exports.string().optional() })).optional()
|
|
26266
|
+
});
|
|
26267
|
+
agentContextSnapshotSchema = external_exports.object({
|
|
26268
|
+
session: external_exports.object({
|
|
26269
|
+
kind: agentSessionKindSchema,
|
|
26270
|
+
trigger: agentTurnTriggerSchema,
|
|
26271
|
+
conversationId: external_exports.string(),
|
|
26272
|
+
runId: external_exports.string(),
|
|
26273
|
+
teamId: external_exports.string().optional(),
|
|
26274
|
+
taskId: external_exports.string().optional(),
|
|
26275
|
+
workflowExecutionId: external_exports.string().optional(),
|
|
26276
|
+
organizationId: external_exports.string().optional()
|
|
26277
|
+
}),
|
|
26278
|
+
task: external_exports.object({ workingBranch: external_exports.string() }).optional(),
|
|
26279
|
+
pullRequest: agentContextPullRequestSchema.optional(),
|
|
26280
|
+
workspace: external_exports.object({
|
|
26281
|
+
root: external_exports.string().optional(),
|
|
26282
|
+
cwd: external_exports.string().optional(),
|
|
26283
|
+
repositories: external_exports.array(repositorySnapshotSchema)
|
|
26284
|
+
}),
|
|
26285
|
+
environment: environmentSnapshotSchema.optional(),
|
|
26286
|
+
instructions: external_exports.array(external_exports.string())
|
|
26287
|
+
});
|
|
26288
|
+
BRANCH_REASONS = {
|
|
26289
|
+
handoff: "the branch handed off from the user's computer",
|
|
26290
|
+
pull_request: "this pull request's branch",
|
|
26291
|
+
task: "this task's branch",
|
|
26292
|
+
chat_selection: "the branch the user selected for this chat",
|
|
26293
|
+
environment_default: "the environment's default branch"
|
|
26294
|
+
};
|
|
26295
|
+
PLAIN_SCALAR = /^[A-Za-z0-9_./@~+-][A-Za-z0-9_./@~+:-]*$/;
|
|
26296
|
+
COMMAND_PREVIEW_CHARS = 200;
|
|
25879
26297
|
MAX_PARSED_ATTACHMENTS = 3;
|
|
25880
26298
|
MAX_PARSED_ATTACHMENT_CHARS = 12e3;
|
|
25881
26299
|
MAX_METADATA_CHARS = 240;
|
|
@@ -26313,16 +26731,16 @@ function parseClaudeEvent(event, state) {
|
|
|
26313
26731
|
}
|
|
26314
26732
|
function thoughtsOf(event, content, messageId, state) {
|
|
26315
26733
|
const texts = content.flatMap((raw) => {
|
|
26316
|
-
const
|
|
26317
|
-
if (!
|
|
26318
|
-
return [asString(
|
|
26734
|
+
const block2 = asRecord(raw);
|
|
26735
|
+
if (!block2 || asString(block2.type) !== "thinking") return [];
|
|
26736
|
+
return [asString(block2.thinking) || asString(block2.text)];
|
|
26319
26737
|
});
|
|
26320
26738
|
if (texts.length === 0) return [];
|
|
26321
26739
|
const frameId = asString(event.uuid) || synthId(state, "claude-thought-frame");
|
|
26322
26740
|
return thoughtBlocksFor(state, messageId).complete(frameId, texts);
|
|
26323
26741
|
}
|
|
26324
|
-
function textUpdates(frame,
|
|
26325
|
-
const text2 = asString(
|
|
26742
|
+
function textUpdates(frame, block2) {
|
|
26743
|
+
const text2 = asString(block2.text);
|
|
26326
26744
|
if (!text2 || frame.alreadyStreamed) return [];
|
|
26327
26745
|
const content = textBlock(frame.previousBlockWasText ? `
|
|
26328
26746
|
${text2}` : text2);
|
|
@@ -26343,12 +26761,12 @@ function thoughtUpdates(frame) {
|
|
|
26343
26761
|
}
|
|
26344
26762
|
];
|
|
26345
26763
|
}
|
|
26346
|
-
function blockUpdates(frame,
|
|
26347
|
-
const blockType = asString(
|
|
26348
|
-
if (blockType === "text") return textUpdates(frame,
|
|
26764
|
+
function blockUpdates(frame, block2) {
|
|
26765
|
+
const blockType = asString(block2.type);
|
|
26766
|
+
if (blockType === "text") return textUpdates(frame, block2);
|
|
26349
26767
|
frame.previousBlockWasText = false;
|
|
26350
26768
|
if (blockType === "thinking") return thoughtUpdates(frame);
|
|
26351
|
-
if (blockType === "tool_use") return parseToolUse(
|
|
26769
|
+
if (blockType === "tool_use") return parseToolUse(block2, frame.meta);
|
|
26352
26770
|
return [];
|
|
26353
26771
|
}
|
|
26354
26772
|
function parseAssistant(event, state) {
|
|
@@ -26366,8 +26784,8 @@ function parseAssistant(event, state) {
|
|
|
26366
26784
|
previousBlockWasText: false
|
|
26367
26785
|
};
|
|
26368
26786
|
return content.flatMap((raw) => {
|
|
26369
|
-
const
|
|
26370
|
-
return
|
|
26787
|
+
const block2 = asRecord(raw);
|
|
26788
|
+
return block2 ? blockUpdates(frame, block2) : [];
|
|
26371
26789
|
});
|
|
26372
26790
|
}
|
|
26373
26791
|
function toolUseMeta(name, input2, meta3) {
|
|
@@ -26380,11 +26798,11 @@ function toolUseMeta(name, input2, meta3) {
|
|
|
26380
26798
|
...!isAsk && normalizeToolName2(name) === "exitplanmode" ? { [EXIT_PLAN_MODE_INPUT_META]: input2 } : {}
|
|
26381
26799
|
};
|
|
26382
26800
|
}
|
|
26383
|
-
function parseToolUse(
|
|
26384
|
-
const toolCallId = asString(
|
|
26801
|
+
function parseToolUse(block2, meta3) {
|
|
26802
|
+
const toolCallId = asString(block2.id);
|
|
26385
26803
|
if (!toolCallId) return [];
|
|
26386
|
-
const name = canonicalizeManagedMcpToolName(asString(
|
|
26387
|
-
const input2 =
|
|
26804
|
+
const name = canonicalizeManagedMcpToolName(asString(block2.name));
|
|
26805
|
+
const input2 = block2.input;
|
|
26388
26806
|
const inputRecord = asRecord(input2) ?? {};
|
|
26389
26807
|
const pendingFileChange = claudeToolInputDiffContent(name, input2);
|
|
26390
26808
|
const updates = [
|
|
@@ -26426,21 +26844,21 @@ function parseUser(event) {
|
|
|
26426
26844
|
if (!message) return [];
|
|
26427
26845
|
const meta3 = nesting(event);
|
|
26428
26846
|
return asArray(message.content).flatMap((raw) => {
|
|
26429
|
-
const
|
|
26430
|
-
if (!
|
|
26431
|
-
const toolCallId = asString(
|
|
26847
|
+
const block2 = asRecord(raw);
|
|
26848
|
+
if (!block2 || asString(block2.type) !== "tool_result") return [];
|
|
26849
|
+
const toolCallId = asString(block2.tool_use_id);
|
|
26432
26850
|
if (!toolCallId) return [];
|
|
26433
|
-
const text2 = flattenToolResult(
|
|
26851
|
+
const text2 = flattenToolResult(block2.content);
|
|
26434
26852
|
const content = outputContent(text2);
|
|
26435
26853
|
const diffs = claudeFileChangeContents(event.tool_use_result);
|
|
26436
26854
|
return [
|
|
26437
26855
|
{
|
|
26438
26856
|
sessionUpdate: "tool_call_update",
|
|
26439
26857
|
toolCallId,
|
|
26440
|
-
status:
|
|
26858
|
+
status: block2.is_error === true ? "failed" : "completed",
|
|
26441
26859
|
...content || diffs.length ? { content: [...diffs, ...content ?? []] } : {},
|
|
26442
26860
|
rawOutput: text2,
|
|
26443
|
-
_meta: { ...meta3._meta, [PROVIDER_PAYLOAD_META]: event.tool_use_result ??
|
|
26861
|
+
_meta: { ...meta3._meta, [PROVIDER_PAYLOAD_META]: event.tool_use_result ?? block2 }
|
|
26444
26862
|
}
|
|
26445
26863
|
];
|
|
26446
26864
|
});
|
|
@@ -26944,12 +27362,12 @@ async function claudeTurnInput(run, context) {
|
|
|
26944
27362
|
const encoded = await Promise.all(
|
|
26945
27363
|
images.map(async (image) => ({
|
|
26946
27364
|
mimeType: image.mimeType,
|
|
26947
|
-
data: (await (0,
|
|
27365
|
+
data: (await (0, import_promises15.readFile)(image.path)).toString("base64")
|
|
26948
27366
|
}))
|
|
26949
27367
|
);
|
|
26950
27368
|
return { turnId: run.runId, text: text2, ...encoded.length ? { images: encoded } : {} };
|
|
26951
27369
|
}
|
|
26952
|
-
var import_crypto6, import_fs5, import_path5, import_crypto7,
|
|
27370
|
+
var import_crypto6, import_fs5, import_path5, import_crypto7, import_promises15, EDIT_TOOLS, ThoughtBlocks, UNDERSTOOD_SYSTEM_SUBTYPES, RATE_LIMIT_WARN_AT, CLAUDE_GRAMMAR_NAME, SUBAGENT_TOOL_NAMES, PLAN_ENTRY_STATUSES, controlResponseSchema, STOPPED_STATUSES, TaskRecords, TERMINAL_BACKGROUND_STATUSES, NON_TERMINAL_BACKGROUND_STATUSES, ASYNC_LAUNCH_ACK, BackgroundTasks, FAILED_STATUSES, STOPPED_BY_USER_TEXT, ClaudeTurn, STDERR_TAIL_LINES2, MAX_EARLY_LINES, UNSUPPORTED_STOP, OUTPUT_CLOSED_REASON, ClaudeSession, DEFAULTS, READ_ONLY_DISALLOWED_TOOLS, DEFAULT_MCP_TIMEOUT_MS;
|
|
26953
27371
|
var init_claude = __esm({
|
|
26954
27372
|
"../agent-core/dist/providers/claude.js"() {
|
|
26955
27373
|
"use strict";
|
|
@@ -26959,7 +27377,7 @@ var init_claude = __esm({
|
|
|
26959
27377
|
init_chunk_HBIPWAUI();
|
|
26960
27378
|
init_chunk_J2KTV5FP();
|
|
26961
27379
|
init_chunk_M6YHY2EZ();
|
|
26962
|
-
|
|
27380
|
+
init_chunk_GI3ZGXTY();
|
|
26963
27381
|
init_chunk_YXWJW7I5();
|
|
26964
27382
|
init_effort();
|
|
26965
27383
|
import_crypto6 = require("crypto");
|
|
@@ -26972,7 +27390,7 @@ var init_claude = __esm({
|
|
|
26972
27390
|
import_fs5 = require("fs");
|
|
26973
27391
|
import_path5 = require("path");
|
|
26974
27392
|
import_crypto7 = require("crypto");
|
|
26975
|
-
|
|
27393
|
+
import_promises15 = require("fs/promises");
|
|
26976
27394
|
init_agent2();
|
|
26977
27395
|
EDIT_TOOLS = /* @__PURE__ */ new Set([
|
|
26978
27396
|
"Edit",
|
|
@@ -27482,11 +27900,11 @@ var init_claude = __esm({
|
|
|
27482
27900
|
}
|
|
27483
27901
|
this.#iterations += 1;
|
|
27484
27902
|
for (const raw of asArray(asRecord(event.message)?.content)) {
|
|
27485
|
-
const
|
|
27486
|
-
if (!
|
|
27487
|
-
const id = asString(
|
|
27903
|
+
const block2 = asRecord(raw);
|
|
27904
|
+
if (!block2 || asString(block2.type) !== "tool_use") continue;
|
|
27905
|
+
const id = asString(block2.id);
|
|
27488
27906
|
if (!id) continue;
|
|
27489
|
-
const name = canonicalizeManagedMcpToolName(asString(
|
|
27907
|
+
const name = canonicalizeManagedMcpToolName(asString(block2.name));
|
|
27490
27908
|
if (isInteractiveToolName(name) || INTERACTIVE_TOOL_NAMES.has(normalizeToolName2(name))) {
|
|
27491
27909
|
this.#suppressedResults.add(id);
|
|
27492
27910
|
}
|
|
@@ -27682,8 +28100,8 @@ var init_claude = __esm({
|
|
|
27682
28100
|
}
|
|
27683
28101
|
async #awaitTaskStop(requestId, taskId) {
|
|
27684
28102
|
const timer = new AbortController();
|
|
27685
|
-
const answered = new Promise((
|
|
27686
|
-
this.#taskStops.set(requestId,
|
|
28103
|
+
const answered = new Promise((resolve9) => {
|
|
28104
|
+
this.#taskStops.set(requestId, resolve9);
|
|
27687
28105
|
});
|
|
27688
28106
|
const timeoutMs = this.#options.stopTaskTimeoutMs;
|
|
27689
28107
|
const timedOut = this.#options.clock.sleep(timeoutMs, timer.signal).then(
|
|
@@ -27756,17 +28174,17 @@ var init_claude = __esm({
|
|
|
27756
28174
|
};
|
|
27757
28175
|
let markStarted = () => {
|
|
27758
28176
|
};
|
|
27759
|
-
const whenStarted = new Promise((
|
|
27760
|
-
markStarted =
|
|
28177
|
+
const whenStarted = new Promise((resolve9) => {
|
|
28178
|
+
markStarted = resolve9;
|
|
27761
28179
|
});
|
|
27762
|
-
const done = new Promise((
|
|
28180
|
+
const done = new Promise((resolve9) => {
|
|
27763
28181
|
finish = (outcome2) => {
|
|
27764
28182
|
if (this.#current?.id !== id) return;
|
|
27765
28183
|
this.#current = void 0;
|
|
27766
28184
|
this.#lastTurn = turn;
|
|
27767
28185
|
if (this.#state === "busy") this.#state = "idle";
|
|
27768
28186
|
this.#emit({ type: "turn_ended", turnId: id, outcome: outcome2 });
|
|
27769
|
-
|
|
28187
|
+
resolve9({ turnId: id, outcome: outcome2, providerSessionId: this.#providerSessionId });
|
|
27770
28188
|
};
|
|
27771
28189
|
});
|
|
27772
28190
|
const active = {
|
|
@@ -27884,8 +28302,8 @@ var init_claude = __esm({
|
|
|
27884
28302
|
void removeLaunchFiles(this.#launchFiles).catch((error61) => {
|
|
27885
28303
|
this.#options.log.warn("claude.launch_files_cleanup_failed", { error: error61 });
|
|
27886
28304
|
});
|
|
27887
|
-
for (const
|
|
27888
|
-
|
|
28305
|
+
for (const resolve9 of this.#taskStops.values()) {
|
|
28306
|
+
resolve9({ ok: false, reason: "runtime_unavailable", message: "Claude Code exited." });
|
|
27889
28307
|
}
|
|
27890
28308
|
const active = this.#current;
|
|
27891
28309
|
if (active) {
|
|
@@ -28281,6 +28699,44 @@ function windowPatch(value) {
|
|
|
28281
28699
|
}
|
|
28282
28700
|
return patch;
|
|
28283
28701
|
}
|
|
28702
|
+
function amount(value) {
|
|
28703
|
+
const text2 = asString(value).trim();
|
|
28704
|
+
return text2.length > 0 ? text2 : void 0;
|
|
28705
|
+
}
|
|
28706
|
+
function spendPatch(limit, reached) {
|
|
28707
|
+
const record2 = asRecord(limit);
|
|
28708
|
+
const reachedFlag = reached === true;
|
|
28709
|
+
if (!record2)
|
|
28710
|
+
return limit === null && !reachedFlag ? null : reachedFlag ? { reached: true } : void 0;
|
|
28711
|
+
const patch = { reached: reachedFlag };
|
|
28712
|
+
const limitAmount = amount(record2.limit);
|
|
28713
|
+
const usedAmount = amount(record2.used);
|
|
28714
|
+
if (limitAmount) patch.limit = limitAmount;
|
|
28715
|
+
if (usedAmount) patch.used = usedAmount;
|
|
28716
|
+
const remainingPercent = asFiniteNumber(record2.remainingPercent);
|
|
28717
|
+
if (remainingPercent !== void 0) {
|
|
28718
|
+
patch.usedPercent = Math.min(100, Math.max(0, 100 - remainingPercent));
|
|
28719
|
+
}
|
|
28720
|
+
const seconds = asFiniteNumber(record2.resetsAt);
|
|
28721
|
+
if (seconds !== void 0 && seconds >= 0) {
|
|
28722
|
+
const reset = new Date(seconds * 1e3);
|
|
28723
|
+
if (Number.isFinite(reset.getTime())) patch.resetsAt = reset.toISOString();
|
|
28724
|
+
}
|
|
28725
|
+
return patch;
|
|
28726
|
+
}
|
|
28727
|
+
function creditsPatch(value) {
|
|
28728
|
+
if (value === null) return null;
|
|
28729
|
+
const record2 = asRecord(value);
|
|
28730
|
+
if (!record2 || typeof record2.hasCredits !== "boolean" || typeof record2.unlimited !== "boolean") {
|
|
28731
|
+
return void 0;
|
|
28732
|
+
}
|
|
28733
|
+
const balance = amount(record2.balance);
|
|
28734
|
+
return {
|
|
28735
|
+
hasCredits: record2.hasCredits,
|
|
28736
|
+
unlimited: record2.unlimited,
|
|
28737
|
+
...balance ? { balance } : {}
|
|
28738
|
+
};
|
|
28739
|
+
}
|
|
28284
28740
|
function isApprovalRequest(method) {
|
|
28285
28741
|
return COMMAND_OR_FILE.has(method) || LEGACY.has(method);
|
|
28286
28742
|
}
|
|
@@ -29136,7 +29592,7 @@ var init_codex = __esm({
|
|
|
29136
29592
|
init_chunk_HBIPWAUI();
|
|
29137
29593
|
init_chunk_J2KTV5FP();
|
|
29138
29594
|
init_chunk_M6YHY2EZ();
|
|
29139
|
-
|
|
29595
|
+
init_chunk_GI3ZGXTY();
|
|
29140
29596
|
init_chunk_YXWJW7I5();
|
|
29141
29597
|
import_fs6 = require("fs");
|
|
29142
29598
|
import_path6 = require("path");
|
|
@@ -29357,12 +29813,16 @@ var init_codex = __esm({
|
|
|
29357
29813
|
if (!snapshot2) return [];
|
|
29358
29814
|
const primary = windowPatch(snapshot2.primary);
|
|
29359
29815
|
const secondary = windowPatch(snapshot2.secondary);
|
|
29816
|
+
const spend = spendPatch(snapshot2.individualLimit, snapshot2.spendControlReached);
|
|
29817
|
+
const credits = creditsPatch(snapshot2.credits);
|
|
29360
29818
|
const planType = snapshot2.planType === null ? null : asString(snapshot2.planType) || void 0;
|
|
29361
29819
|
const parsed = runCodexRateLimitsUpdateSchema.safeParse({
|
|
29362
29820
|
sessionUpdate: "_alan/codex.rate_limits",
|
|
29363
29821
|
limitId: bucketId ?? (asString(snapshot2.limitId) || "codex"),
|
|
29364
29822
|
...primary === void 0 ? {} : { primary },
|
|
29365
29823
|
...secondary === void 0 ? {} : { secondary },
|
|
29824
|
+
...spend === void 0 ? {} : { spend },
|
|
29825
|
+
...credits === void 0 ? {} : { credits },
|
|
29366
29826
|
...planType === void 0 ? {} : { planType },
|
|
29367
29827
|
observedAt: new Date(this.#clock.now()).toISOString(),
|
|
29368
29828
|
sourceId: this.#sourceId,
|
|
@@ -29801,10 +30261,10 @@ var init_codex = __esm({
|
|
|
29801
30261
|
};
|
|
29802
30262
|
let identify = () => {
|
|
29803
30263
|
};
|
|
29804
|
-
const identified = new Promise((
|
|
29805
|
-
identify =
|
|
30264
|
+
const identified = new Promise((resolve9) => {
|
|
30265
|
+
identify = resolve9;
|
|
29806
30266
|
});
|
|
29807
|
-
const done = new Promise((
|
|
30267
|
+
const done = new Promise((resolve9) => {
|
|
29808
30268
|
finish = (outcome2) => {
|
|
29809
30269
|
if (this.#current?.id !== id) return;
|
|
29810
30270
|
this.#current = void 0;
|
|
@@ -29812,7 +30272,7 @@ var init_codex = __esm({
|
|
|
29812
30272
|
if (this.#state === "busy") this.#state = "idle";
|
|
29813
30273
|
this.#host.scanDescendants(true);
|
|
29814
30274
|
this.#emit({ type: "turn_ended", turnId: id, outcome: outcome2 });
|
|
29815
|
-
|
|
30275
|
+
resolve9({ turnId: id, outcome: outcome2, providerSessionId: this.#threadId });
|
|
29816
30276
|
};
|
|
29817
30277
|
});
|
|
29818
30278
|
const active = {
|
|
@@ -30302,7 +30762,7 @@ function alanCodeConfigContent(existing, input2) {
|
|
|
30302
30762
|
});
|
|
30303
30763
|
}
|
|
30304
30764
|
function readBody2(response) {
|
|
30305
|
-
return new Promise((
|
|
30765
|
+
return new Promise((resolve9, reject) => {
|
|
30306
30766
|
const chunks = [];
|
|
30307
30767
|
let size = 0;
|
|
30308
30768
|
response.on("data", (chunk) => {
|
|
@@ -30310,7 +30770,7 @@ function readBody2(response) {
|
|
|
30310
30770
|
if (size > MAX_CATALOG_BYTES) response.destroy(new Error("catalog too large"));
|
|
30311
30771
|
else chunks.push(chunk);
|
|
30312
30772
|
});
|
|
30313
|
-
response.on("end", () =>
|
|
30773
|
+
response.on("end", () => resolve9(Buffer.concat(chunks).toString("utf8")));
|
|
30314
30774
|
response.on("error", reject);
|
|
30315
30775
|
});
|
|
30316
30776
|
}
|
|
@@ -30326,13 +30786,13 @@ function parseResponseBody(text2, status) {
|
|
|
30326
30786
|
}
|
|
30327
30787
|
function getJson(url2, headers, timeout, signal) {
|
|
30328
30788
|
const request2 = url2.protocol === "https:" ? import_https.request : import_http3.request;
|
|
30329
|
-
return new Promise((
|
|
30789
|
+
return new Promise((resolve9, reject) => {
|
|
30330
30790
|
const outgoing = request2(url2, { method: "GET", headers, timeout, signal }, (response) => {
|
|
30331
30791
|
const status = response.statusCode ?? 0;
|
|
30332
30792
|
readBody2(response).then((text2) => {
|
|
30333
30793
|
const body = parseResponseBody(text2, status);
|
|
30334
30794
|
if (status < 200 || status >= 300) reject(new CatalogResponseError(status, body));
|
|
30335
|
-
else
|
|
30795
|
+
else resolve9(body);
|
|
30336
30796
|
}).catch(reject);
|
|
30337
30797
|
});
|
|
30338
30798
|
outgoing.on("timeout", () => outgoing.destroy(new Error("catalog timed out")));
|
|
@@ -30549,15 +31009,15 @@ async function writePlugin(directory, apiOrigin) {
|
|
|
30549
31009
|
const origin = (0, import_crypto12.createHash)("sha256").update(apiOrigin).digest("hex").slice(0, 12);
|
|
30550
31010
|
const target = (0, import_path8.join)(directory, `engine-plugin-v${ALAN_CODE_ENGINE_PLUGIN_VERSION}-${origin}.mjs`);
|
|
30551
31011
|
const temporary = `${target}.${(0, import_crypto12.randomUUID)()}.tmp`;
|
|
30552
|
-
await (0,
|
|
30553
|
-
await (0,
|
|
30554
|
-
await (0,
|
|
31012
|
+
await (0, import_promises16.mkdir)(directory, { recursive: true, mode: 448 });
|
|
31013
|
+
await (0, import_promises16.writeFile)(temporary, alanCodeEnginePluginSource(apiOrigin), { mode: 384 });
|
|
31014
|
+
await (0, import_promises16.rename)(temporary, target);
|
|
30555
31015
|
return (0, import_url.pathToFileURL)(target).href;
|
|
30556
31016
|
}
|
|
30557
31017
|
async function prepareAlanCodeProfile(input2) {
|
|
30558
31018
|
const directories = Object.values(alanCodeEngineDirectories(input2.engineRoot));
|
|
30559
31019
|
await Promise.all(
|
|
30560
|
-
directories.map((directory) => (0,
|
|
31020
|
+
directories.map((directory) => (0, import_promises16.mkdir)(directory, { recursive: true, mode: 448 }))
|
|
30561
31021
|
);
|
|
30562
31022
|
const [pluginUrl, models] = await Promise.all([
|
|
30563
31023
|
writePlugin((0, import_path8.join)(input2.engineRoot, "plugin"), input2.access.apiOrigin),
|
|
@@ -30580,7 +31040,7 @@ function alanCodeSystemPrompt(alanSystemPrompt) {
|
|
|
30580
31040
|
|
|
30581
31041
|
${instructions}` : ALAN_CODE_TOOL_NAMING_PROMPT;
|
|
30582
31042
|
}
|
|
30583
|
-
var import_http3, import_https, import_fs7, import_path7, import_crypto12,
|
|
31043
|
+
var import_http3, import_https, import_fs7, import_path7, import_crypto12, import_promises16, import_path8, import_url, ALAN_CODE_BASELINE_PROMPT, ALAN_CODE_ENGINE_PROVIDER_ID, DEFAULT_CONTEXT_WINDOW, DEFAULT_MAX_OUTPUT_TOKENS, ALAN_CODE_API_KEY_ENV, ALAN_CODE_CONVERSATION_ID_ENV, ALAN_CODE_PROXY_PATH, ALAN_CODE_WEBSEARCH_PATH, ALAN_CODE_CATALOG_PATH, CATALOG_TIMEOUT_MS, MAX_CATALOG_BYTES, ACTIVATION_WAIT_MS, ACTIVATION_POLL_MS, CatalogResponseError, ALAN_CODE_ENGINE_PATH_ENV, ALAN_CODE_ENGINE_COMMAND, ALAN_CODE_ENGINE_NAME, WINDOWS_RUNNABLE_EXTENSION, ALAN_CODE_ENGINE_PLUGIN_VERSION, ALAN_CODE_TOOL_NAMING_PROMPT;
|
|
30584
31044
|
var init_alan_code = __esm({
|
|
30585
31045
|
"../agent-core/dist/providers/alan-code.js"() {
|
|
30586
31046
|
"use strict";
|
|
@@ -30594,7 +31054,7 @@ var init_alan_code = __esm({
|
|
|
30594
31054
|
import_path7 = require("path");
|
|
30595
31055
|
init_runtime_v2();
|
|
30596
31056
|
import_crypto12 = require("crypto");
|
|
30597
|
-
|
|
31057
|
+
import_promises16 = require("fs/promises");
|
|
30598
31058
|
import_path8 = require("path");
|
|
30599
31059
|
import_url = require("url");
|
|
30600
31060
|
ALAN_CODE_BASELINE_PROMPT = "You are alan-code, an interactive CLI coding agent that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.\n\nDo not invent URLs. Use verified URLs or ones supplied by the user or project.\n\nIf the user asks for help or wants to give feedback, inform them of the following:\n- `--harness-help` / harness help: learn how to run alan-code\n- For product feedback or bugs, report through the Alan / Supatest issue channels used by this repository\n\nWhen the user directly asks about alan-code capabilities (for example \"can alan-code\u2026\", \"does the harness have\u2026\") or asks in second person about your abilities, answer from the tools and instructions available in this session. If a docs/fetch tool is available and project docs URLs are known, use them; otherwise inspect local README / AGENTS.md rather than inventing product claims.\n\n# Personality\n\nYour default personality and tone is concise, direct, and friendly. You communicate efficiently, always keeping the user clearly informed about ongoing actions without unnecessary detail. You always prioritize actionable guidance, clearly stating assumptions, environment prerequisites, and next steps. Unless explicitly asked, you avoid excessively verbose explanations about your work.\n\n# Tone and style\n\nYou should be concise, direct, and to the point. When you run a non-trivial bash command, you should explain what the command does and why you are running it, so the user understands what you are doing (especially important for commands that change their system).\nRemember that your output will be displayed on a command line interface. Your responses can use GitHub-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.\nOutput text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like Bash or code comments as means to communicate with the user during the session.\nIf you cannot or will not help the user with something, do not lecture about why. Offer helpful alternatives if possible; otherwise keep the response to 1-2 sentences.\nOnly use emojis if the user explicitly requests it. Avoid emojis in all communication unless asked.\nIMPORTANT: Minimize output tokens while staying helpful, correct, and accurate. Only address the specific query or task. Avoid tangential information unless it is critical to completing the request. If you can answer in 1-3 sentences or a short paragraph, do that.\nAnswer the user's question directly. One-word answers are best when they suffice. Avoid text before/after your response such as \"The answer is <answer>.\", \"Here is the content of the file\u2026\", \"Based on the information provided\u2026\", or \"Here is what I will do next\u2026\". Examples of appropriate verbosity:\n<example>\nuser: what is 2+2?\nassistant: 4\n</example>\n\n<example>\nuser: is 11 a prime number?\nassistant: Yes\n</example>\n\n<example>\nuser: what command should I run to list files in the current directory?\nassistant: ls\n</example>\n\n<example>\nuser: what command should I run to watch files in the current directory?\nassistant: [use tools to inspect the project, then answer]\nnpm run dev\n</example>\n\n<example>\nuser: what files are in the directory src/?\nassistant: [lists files and sees foo.c, bar.c, baz.c]\nuser: which file contains the implementation of foo?\nassistant: src/foo.c\n</example>\n\n<example>\nuser: write tests for new feature\nassistant: [searches for similar tests, reads relevant files concurrently, edits/writes tests]\n</example>\n\n# Responsiveness\n\n## Preamble messages\n\nBefore making tool calls, send a brief preamble to the user explaining what you're about to do. When sending preamble messages, follow these principles and examples:\n\n- **Logically group related actions**: if you're about to run several related commands, describe them together in one preamble rather than sending a separate note for each.\n- **Keep it concise**: be no more than 1-2 sentences, focused on immediate, tangible next steps. (8\u201312 words for quick updates).\n- **Build on prior context**: if this is not your first tool call, use the preamble message to connect the dots with what's been done so far and create a sense of momentum and clarity for the user to understand your next actions.\n- **Keep your tone light, friendly and curious**: add small touches of personality in preambles feel collaborative and engaging.\n- **Exception**: Avoid adding a preamble for every trivial read (e.g., `cat` a single file) unless it's part of a larger grouped action.\n\nExamples:\n\n- \"I've explored the repo; now checking the API route definitions.\"\n- \"Next, I'll patch the config and update the related tests.\"\n- \"I'm about to scaffold the CLI commands and helper functions.\"\n- \"Ok cool, so I've wrapped my head around the repo. Now digging into the API routes.\"\n- \"Config's looking tidy. Next up is patching helpers to keep things in sync.\"\n- \"Finished poking at the DB gateway. I will now chase down error handling.\"\n- \"Alright, build pipeline order is interesting. Checking how it reports failures.\"\n- \"Spotted a clever caching util; now hunting where it gets used.\"\n\n# Planning\n\nIf a planning tool is available, use it when it helps track complex work. Keep the plan brief and update it as work progresses.\n\nNote that plans are not for padding out simple work with filler steps or stating the obvious. The content of your plan should not involve doing anything that you aren't capable of doing (i.e. don't try to test things that you can't test). Do not use plans for simple or single-step queries that you can just do or answer immediately.\n\nWhen a planning tool displays the plan, summarize only what changed or what comes next.\n\nKeep any active plan aligned with the work completed and remaining.\n\nUse a plan when:\n\n- The task is non-trivial and will require multiple actions over a long time horizon.\n- There are logical phases or dependencies where sequencing matters.\n- The work has ambiguity that benefits from outlining high-level goals.\n- You want intermediate checkpoints for feedback and validation.\n- When the user asked you to do more than one thing in a single prompt\n- The user has asked you to use the plan tool (aka \"TODOs\")\n- You generate additional steps while working, and plan to do them before yielding to the user\n\n## Examples\n\n**High-quality plans**\n\nExample 1:\n\n1. Add CLI entry with file args\n2. Parse Markdown via CommonMark library\n3. Apply semantic HTML template\n4. Handle code blocks, images, links\n5. Add error handling for invalid files\n\nExample 2:\n\n1. Define CSS variables for colors\n2. Add toggle with localStorage state\n3. Refactor components to use variables\n4. Verify all views for readability\n5. Add smooth theme-change transition\n\nExample 3:\n\n1. Set up Node.js + WebSocket server\n2. Add join/leave broadcast events\n3. Implement messaging with timestamps\n4. Add usernames + mention highlighting\n5. Persist messages in lightweight DB\n6. Add typing indicators + unread count\n\n**Low-quality plans**\n\nExample 1:\n\n1. Create CLI tool\n2. Add Markdown parser\n3. Convert to HTML\n\nExample 2:\n\n1. Add dark mode toggle\n2. Save preference\n3. Make styles look good\n\nExample 3:\n\n1. Create single-file HTML game\n2. Run quick sanity check\n3. Summarize usage instructions\n\nIf you need to write a plan, only write high quality plans, not low quality ones.\n\n## Plan mode and clarification (harness specifics)\n\n- When the session is in plan mode, inspect without making changes and produce a concrete plan. Outside plan mode, proceed with authorized work and ask for approval only when the action requires it.\n- Prefer the durable plan file path over relying on chat memory after compaction.\n- When requirements are ambiguous, ask a targeted question using an available user-input tool instead of guessing.\n- An execution checklist is not a substitute for a durable plan when the task requires one.\n\n# Task execution\n\nYou are a coding agent. Please keep going until the query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved. Autonomously resolve the query to the best of your ability, using the tools available to you, before coming back to the user. Do NOT guess or make up an answer.\n\nYou MUST adhere to the following criteria when solving queries:\n\n- Working on the repo(s) in the current environment is allowed, even if they are proprietary.\n- Analyzing code for vulnerabilities is allowed.\n- Showing user code and tool call details is allowed.\n- Use the editing tools available in the current host to modify files. Do not assume a particular tool name.\n\nIf completing the user's task requires writing or modifying files, your code and final answer should follow these coding guidelines, though user instructions (i.e. AGENTS.md) may override these guidelines:\n\n- Fix the problem at the root cause rather than applying surface-level patches, when possible.\n- Avoid unneeded complexity in your solution.\n- Do not attempt to fix unrelated bugs or broken tests. It is not your responsibility to fix them. (You may mention them to the user in your final message though.)\n- Update documentation as necessary.\n- Keep changes consistent with the style of the existing codebase. Changes should be minimal and focused on the task.\n- Use `git log` and `git blame` to search the history of the codebase if additional context is required.\n- NEVER add copyright or license headers unless specifically requested.\n- Do not waste tokens by re-reading files after editing them. The tool call will fail if it didn't work. The same goes for making folders, deleting folders, etc.\n- Do not `git commit` your changes or create new git branches unless explicitly requested.\n- Add comments when they explain a non-obvious invariant or reason for a decision.\n- Do not use one-letter variable names unless explicitly requested.\n- NEVER output inline citations like \"\u3010F:README.md\u2020L5-L14\u3011\" in your outputs. The CLI is not able to render these so they will just be broken in the UI. Instead, if you output valid filepaths, users will be able to click on them to open the files in their editor.\n\n# Validating your work\n\nIf the codebase has tests or the ability to build or run, consider using them to verify that your work is complete.\n\nWhen testing, your philosophy should be to start as specific as possible to the code you changed so that you can catch issues efficiently, then make your way to broader tests as you build confidence. If there's no test for the code you changed, and if the adjacent patterns in the codebases show that there's a logical place for you to add a test, you may do so. However, do not add tests to codebases with no tests.\n\nSimilarly, once you're confident in correctness, you can suggest or use formatting commands to ensure that your code is well formatted. If there are issues you can iterate up to 3 times to get formatting right, but if you still can't manage it's better to save the user time and present them a correct solution where you call out the formatting in your final message. If the codebase does not have a formatter configured, do not add one.\n\nFor all of testing, running, building, and formatting, do not attempt to fix unrelated bugs. It is not your responsibility to fix them. (You may mention them to the user in your final message though.)\n\nBe mindful of whether to run validation commands proactively. In the absence of behavioral guidance:\n\n- When running in a non-interactive mode where edits are auto-approved (print/headless, or the `allow edits` permission mode), proactively run tests, lint and do whatever you need to ensure you've completed the task.\n- In plan mode, stay read-only. Otherwise, run focused checks after changes when the host permits them.\n- When working on test-related tasks, such as adding tests, fixing tests, or reproducing a bug to verify behavior, you may proactively run tests regardless of permission mode. Use your judgement to decide whether this is a test-related task.\n\n# Ambition vs. precision\n\nFor tasks that have no prior context (i.e. the user is starting something brand new), you should feel free to be ambitious and demonstrate creativity with your implementation.\n\nIf you're operating in an existing codebase, you should make sure you do exactly what the user asks with surgical precision. Treat the surrounding codebase with respect, and don't overstep (i.e. changing filenames or variables unnecessarily). You should balance being sufficiently ambitious and proactive when completing tasks of this nature.\n\nYou should use judicious initiative to decide on the right level of detail and complexity to deliver based on the user's needs. This means showing good judgment that you're capable of doing the right extras without gold-plating. This might be demonstrated by high-value, creative touches when scope of the task is vague; while being surgical and targeted when scope is tightly specified.\n\n# Sharing progress updates\n\nFor especially longer tasks that you work on (i.e. requiring many tool calls, or a plan with multiple steps), you should provide progress updates back to the user at reasonable intervals. These updates should be structured as a concise sentence or two (no more than 8-10 words long) recapping progress so far in plain language: this update demonstrates your understanding of what needs to be done, progress so far (i.e. files explores, subtasks complete), and where you're going next.\n\nBefore doing large chunks of work that may incur latency as experienced by the user (i.e. writing a new file), you should send a concise message to the user with an update indicating what you're about to do to ensure they know what you're spending time on. Don't start editing or writing large files before informing the user what you are doing and why.\n\nThe messages you send before tool calls should describe what is immediately about to be done next in very concise language. If there was previous work done, this preamble message should also include a note about the work done so far to bring the user along.\n\n# Presenting your work and final message\n\nYour final message should read naturally, like an update from a concise teammate. For casual conversation, brainstorming tasks, or quick questions from the user, respond in a friendly, conversational tone. You should ask questions, suggest ideas, and adapt to the user's style. If you've finished a large amount of work, when describing what you've done to the user, you should follow the final answer formatting guidelines to communicate substantive changes. You don't need to add structured formatting for one-word answers, greetings, or purely conversational exchanges.\n\nYou can skip heavy formatting for single, simple actions or confirmations. In these cases, respond in plain sentences with any relevant next step or quick option. Reserve multi-section structured responses for results that need grouping or explanation.\n\nThe user is working on the same computer as you, and has access to your work. As such there's no need to show the full contents of large files you have already written unless the user explicitly asks for them. Similarly, if you've created or modified files, there's no need to tell users to \"save the file\" or \"copy the code into a file\"\u2014just reference the file path.\n\nComplete authorized next steps, including relevant tests. Ask before a consequential action that needs approval, and briefly report anything you could not verify.\n\nBrevity is very important as a default. You should be very concise (i.e. no more than 10 lines), but can relax this requirement for tasks where additional detail and comprehensiveness is important for the user's understanding.\n\n## Final answer structure and style guidelines\n\nYou are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.\n\n**Section Headers**\n\n- Use only when they improve clarity \u2014 they are not mandatory for every answer.\n- Choose descriptive names that fit the content\n- Keep headers short (1\u20133 words) and in `**Title Case**`. Always start headers with `**` and end with `**`\n- Use the blank lines required by the renderer for headings and lists.\n- Section headers should only be used where they genuinely improve scanability; avoid fragmenting the answer.\n\n**Bullets**\n\n- Use `-` followed by a space for every bullet.\n- Merge related points when possible; avoid a bullet for every trivial detail.\n- Keep bullets to one line unless breaking for clarity is unavoidable.\n- Group into short lists (4\u20136 bullets) ordered by importance.\n- Use consistent keyword phrasing and formatting across sections.\n\n**Monospace**\n\n- Wrap all commands, file paths, env vars, and code identifiers in backticks (`` `...` ``).\n- Apply to inline examples and to bullet keywords if the keyword itself is a literal file/command.\n- Never mix monospace and bold markers; choose one based on whether it's a keyword (`**`) or inline code/path (`` ` ``).\n\n**File References**\n\nWhen referencing files in your response, make sure to include the relevant start line and always follow the below rules:\n\n- Use inline code to make file paths clickable.\n- Each reference should have a stand alone path. Even if it's the same file.\n- Accepted: absolute, workspace\u2011relative, a/ or b/ diff prefixes, or bare filename/suffix.\n- Line/column (1\u2011based, optional): :line[:column] or #Lline[Ccolumn] (column defaults to 1).\n- Do not use URIs like file://, vscode://, or https://.\n- Do not provide range of lines\n- Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\\repo\\project\\main.rs:12:5\n\n**Structure**\n\n- Place related bullets together; don't mix unrelated concepts in the same section.\n- Order sections from general \u2192 specific \u2192 supporting info.\n- For subsections (e.g., \"Binaries\" under \"Rust Workspace\"), introduce with a bolded keyword bullet, then list items under it.\n- Match structure to complexity:\n - Multi-part or detailed results \u2192 use clear headers and grouped bullets.\n - Simple results \u2192 minimal headers, possibly just a short list or paragraph.\n\n**Tone**\n\n- Keep the voice collaborative and natural, like a coding partner handing off work.\n- Be concise and factual \u2014 no filler or conversational commentary and avoid unnecessary repetition\n- Use present tense and active voice (e.g., \"Runs tests\" not \"This will run tests\").\n- Keep descriptions self-contained; don't refer to \"above\" or \"below\".\n- Use parallel structure in lists for consistency.\n\n**Don't**\n\n- Don't use literal words \"bold\" or \"monospace\" in the content.\n- Don't nest bullets or create deep hierarchies.\n- Don't output ANSI escape codes directly \u2014 the CLI renderer applies them.\n- Don't cram unrelated keywords into a single bullet; split for clarity.\n- Don't let keyword lists run long \u2014 wrap or reformat for scanability.\n\nGenerally, ensure your final answers adapt their shape and depth to the request. For example, answers to code explanations should have a precise, structured explanation with code references that answer the question directly. For tasks with a simple implementation, lead with the outcome and supplement only with what's needed for clarity. Larger changes can be presented as a logical walkthrough of your approach, grouping related steps, explaining rationale where it adds value, and highlighting next actions to accelerate the user. Your answers should provide the right level of detail while being easily scannable.\n\nFor casual greetings, acknowledgements, or other one-off conversational messages that are not delivering substantive information or structured results, respond naturally without section headers or bullet formatting.\n\n# Professional objectivity\n\nPrioritize technical accuracy and truthfulness over validating the user's beliefs. Focus on facts and problem-solving. Be direct and objective without unnecessary praise or emotional validation. Disagree when needed. When uncertain, investigate before confirming the user's assumptions.\n\n# Proactiveness\n\nProactively complete work that follows from the user's request. Avoid unrelated actions that would surprise the user. Strike a balance between:\n\n1. Doing the right thing when asked, including follow-up actions\n2. Not surprising the user with unrequested actions\n For example, if the user asks how to approach something, answer first; do not immediately jump into edits.\n\n# Following conventions\n\nWhen changing files, first understand the file's conventions. Mimic code style, use existing libraries and utilities, and follow existing patterns.\n\n- NEVER assume a library is available, even if it is well known. Whenever you write code that uses a library or framework, first check that this codebase already uses it (neighboring files, package.json, cargo.toml, go.mod, etc.).\n- When creating a new component, first look at existing components for framework choice, naming, typing, and other conventions.\n- When editing code, first look at surrounding context (especially imports) to understand chosen frameworks/libraries, then make the change idiomatically.\n- Always follow security best practices. Never introduce code that exposes or logs secrets and keys. Never commit secrets or keys to the repository.\n\n# Doing tasks\n\nThe user will primarily request software engineering tasks: bugs, features, refactors, explanations, and more. Recommended steps:\n\n- Use available search/read tools extensively to understand the codebase and the query (in parallel when independent).\n- Implement the solution with the tools available to you.\n- Prefer editing existing files. Create documentation when the task or project instructions require it.\n- Verify when possible with tests. NEVER assume a specific test framework or script \u2014 check README / AGENTS.md or search the repo.\n- Run lint and typecheck commands (for example npm run lint, npm run typecheck, ruff, pnpm lint) if they were provided to you \u2014 see Validating your work for when to run them proactively vs. when to hold off. If you cannot find the correct command, ask the user, and if they supply it, proactively suggest writing it to AGENTS.md so you know next time.\n\n- Tool results and user messages may include <system-reminder> tags. Those tags contain useful reminders. They are NOT part of the user's provided input or the tool result.\n\n# Tool usage policy\n\n- Prefer specialized file tools over shell for reading, editing, writing, listing, and searching when those tools are available. Use the `grep`, `glob`, and `list` tools instead of bash for search and listing \u2014 they are ripgrep-backed and return structured, length-capped results. Use shell for real system commands (git, package managers, builds, tests, process control).\n- When doing broad codebase exploration, use the available search tools and delegate only when the task benefits from independent work.\n- You can call multiple tools in one response. When multiple independent pieces of information are needed, batch tool calls for performance. When making multiple bash tool calls, send a single message with multiple tool calls so they can run in parallel (for example git status and git diff together).\n- Match edit old-text exactly, including whitespace.\n- If a tool call is denied by policy, adapt: use an allowed approach or ask the user. Do not retry the same blocked call in a loop.\n\n## Shell commands\n\nWhen using the shell, you must adhere to the following guidelines:\n\n- When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much faster than alternatives like `grep` and `find`. (If the `rg` command is not found, then use alternatives.) Reach for the shell only when the `grep`/`glob` tools cannot express the query \u2014 for example counting matches, or piping results into another command.\n- Search narrow first: use `rg -l` or `rg -c` to find which files match, then read only those files. Do not dump full match bodies across a repo into context.\n- Never pipe a large file into your context. Do not `cat` a big file; use the `read` tool with an offset/limit, or `sed -n 'START,ENDp'` for a specific range.\n- Do not use python scripts to attempt to output larger chunks of a file.\n\nIMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames and directory structure.\n\n# AGENTS.md spec\n\n- Repos often contain AGENTS.md files. These files can appear anywhere within the repository.\n- These files are a way for humans to give you (the agent) instructions or tips for working within the container.\n- Some examples might be: coding conventions, info about how code is organized, or instructions for how to run or test code.\n- Instructions in AGENTS.md files:\n - The scope of an AGENTS.md file is the entire directory tree rooted at the folder that contains it.\n - For every file you touch in the final change, you must obey instructions in any AGENTS.md file whose scope includes that file.\n - Instructions about code style, structure, naming, etc. apply only to code within the AGENTS.md file's scope, unless the file states otherwise.\n - More-deeply-nested AGENTS.md files take precedence in the case of conflicting instructions.\n - Direct system/developer/user instructions (as part of a prompt) take precedence over AGENTS.md instructions.\n- The contents of the AGENTS.md file at the root of the repo and the project directory are loaded into your context automatically and don't need to be re-read. AGENTS.md files in subdirectories are NOT loaded automatically: when working in a subdirectory, or a directory outside the CWD, check for any AGENTS.md files that may be applicable.\n\n# Permissions and safety\n\n- Never commit secrets or keys.\n- Never create a git commit unless the user explicitly asks.\n- Do not run destructive commands (mass delete, force-push, hard reset) unless the user clearly requested them.\n";
|
|
@@ -30647,7 +31107,7 @@ var require_identity = __commonJS({
|
|
|
30647
31107
|
var isDocument = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === DOC;
|
|
30648
31108
|
var isMap = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === MAP;
|
|
30649
31109
|
var isPair = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === PAIR;
|
|
30650
|
-
var
|
|
31110
|
+
var isScalar2 = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === SCALAR;
|
|
30651
31111
|
var isSeq = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === SEQ;
|
|
30652
31112
|
function isCollection(node2) {
|
|
30653
31113
|
if (node2 && typeof node2 === "object")
|
|
@@ -30669,7 +31129,7 @@ var require_identity = __commonJS({
|
|
|
30669
31129
|
}
|
|
30670
31130
|
return false;
|
|
30671
31131
|
}
|
|
30672
|
-
var hasAnchor = (node2) => (
|
|
31132
|
+
var hasAnchor = (node2) => (isScalar2(node2) || isCollection(node2)) && !!node2.anchor;
|
|
30673
31133
|
exports2.ALIAS = ALIAS;
|
|
30674
31134
|
exports2.DOC = DOC;
|
|
30675
31135
|
exports2.MAP = MAP;
|
|
@@ -30684,7 +31144,7 @@ var require_identity = __commonJS({
|
|
|
30684
31144
|
exports2.isMap = isMap;
|
|
30685
31145
|
exports2.isNode = isNode;
|
|
30686
31146
|
exports2.isPair = isPair;
|
|
30687
|
-
exports2.isScalar =
|
|
31147
|
+
exports2.isScalar = isScalar2;
|
|
30688
31148
|
exports2.isSeq = isSeq;
|
|
30689
31149
|
}
|
|
30690
31150
|
});
|
|
@@ -35040,13 +35500,13 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
35040
35500
|
"../../node_modules/yaml/dist/compose/resolve-block-scalar.js"(exports2) {
|
|
35041
35501
|
"use strict";
|
|
35042
35502
|
var Scalar = require_Scalar();
|
|
35043
|
-
function resolveBlockScalar(ctx,
|
|
35044
|
-
const start =
|
|
35045
|
-
const header = parseBlockScalarHeader(
|
|
35503
|
+
function resolveBlockScalar(ctx, scalar2, onError) {
|
|
35504
|
+
const start = scalar2.offset;
|
|
35505
|
+
const header = parseBlockScalarHeader(scalar2, ctx.options.strict, onError);
|
|
35046
35506
|
if (!header)
|
|
35047
35507
|
return { value: "", type: null, comment: "", range: [start, start, start] };
|
|
35048
35508
|
const type = header.mode === ">" ? Scalar.Scalar.BLOCK_FOLDED : Scalar.Scalar.BLOCK_LITERAL;
|
|
35049
|
-
const lines =
|
|
35509
|
+
const lines = scalar2.source ? splitLines(scalar2.source) : [];
|
|
35050
35510
|
let chompStart = lines.length;
|
|
35051
35511
|
for (let i = lines.length - 1; i >= 0; --i) {
|
|
35052
35512
|
const content = lines[i][1];
|
|
@@ -35058,12 +35518,12 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
35058
35518
|
if (chompStart === 0) {
|
|
35059
35519
|
const value2 = header.chomp === "+" && lines.length > 0 ? "\n".repeat(Math.max(1, lines.length - 1)) : "";
|
|
35060
35520
|
let end2 = start + header.length;
|
|
35061
|
-
if (
|
|
35062
|
-
end2 +=
|
|
35521
|
+
if (scalar2.source)
|
|
35522
|
+
end2 += scalar2.source.length;
|
|
35063
35523
|
return { value: value2, type, comment: header.comment, range: [start, end2, end2] };
|
|
35064
35524
|
}
|
|
35065
|
-
let trimIndent =
|
|
35066
|
-
let offset =
|
|
35525
|
+
let trimIndent = scalar2.indent + header.indent;
|
|
35526
|
+
let offset = scalar2.offset + header.length;
|
|
35067
35527
|
let contentStart = 0;
|
|
35068
35528
|
for (let i = 0; i < chompStart; ++i) {
|
|
35069
35529
|
const [indent, content] = lines[i];
|
|
@@ -35141,7 +35601,7 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
35141
35601
|
default:
|
|
35142
35602
|
value += "\n";
|
|
35143
35603
|
}
|
|
35144
|
-
const end = start + header.length +
|
|
35604
|
+
const end = start + header.length + scalar2.source.length;
|
|
35145
35605
|
return { value, type, comment: header.comment, range: [start, end, end] };
|
|
35146
35606
|
}
|
|
35147
35607
|
function parseBlockScalarHeader({ offset, props }, strict, onError) {
|
|
@@ -35224,8 +35684,8 @@ var require_resolve_flow_scalar = __commonJS({
|
|
|
35224
35684
|
"use strict";
|
|
35225
35685
|
var Scalar = require_Scalar();
|
|
35226
35686
|
var resolveEnd = require_resolve_end();
|
|
35227
|
-
function resolveFlowScalar(
|
|
35228
|
-
const { offset, type, source, end } =
|
|
35687
|
+
function resolveFlowScalar(scalar2, strict, onError) {
|
|
35688
|
+
const { offset, type, source, end } = scalar2;
|
|
35229
35689
|
let _type;
|
|
35230
35690
|
let value;
|
|
35231
35691
|
const _onError = (rel, code, msg) => onError(offset + rel, code, msg);
|
|
@@ -35244,7 +35704,7 @@ var require_resolve_flow_scalar = __commonJS({
|
|
|
35244
35704
|
break;
|
|
35245
35705
|
/* istanbul ignore next should not happen */
|
|
35246
35706
|
default:
|
|
35247
|
-
onError(
|
|
35707
|
+
onError(scalar2, "UNEXPECTED_TOKEN", `Expected a flow scalar value, but found: ${type}`);
|
|
35248
35708
|
return {
|
|
35249
35709
|
value: "",
|
|
35250
35710
|
type: null,
|
|
@@ -35458,26 +35918,26 @@ var require_compose_scalar = __commonJS({
|
|
|
35458
35918
|
tag = findScalarTagByTest(ctx, value, token, onError);
|
|
35459
35919
|
else
|
|
35460
35920
|
tag = ctx.schema[identity.SCALAR];
|
|
35461
|
-
let
|
|
35921
|
+
let scalar2;
|
|
35462
35922
|
try {
|
|
35463
35923
|
const res = tag.resolve(value, (msg) => onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg), ctx.options);
|
|
35464
|
-
|
|
35924
|
+
scalar2 = identity.isScalar(res) ? res : new Scalar.Scalar(res);
|
|
35465
35925
|
} catch (error61) {
|
|
35466
35926
|
const msg = error61 instanceof Error ? error61.message : String(error61);
|
|
35467
35927
|
onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg);
|
|
35468
|
-
|
|
35928
|
+
scalar2 = new Scalar.Scalar(value);
|
|
35469
35929
|
}
|
|
35470
|
-
|
|
35471
|
-
|
|
35930
|
+
scalar2.range = range;
|
|
35931
|
+
scalar2.source = value;
|
|
35472
35932
|
if (type)
|
|
35473
|
-
|
|
35933
|
+
scalar2.type = type;
|
|
35474
35934
|
if (tagName)
|
|
35475
|
-
|
|
35935
|
+
scalar2.tag = tagName;
|
|
35476
35936
|
if (tag.format)
|
|
35477
|
-
|
|
35937
|
+
scalar2.format = tag.format;
|
|
35478
35938
|
if (comment)
|
|
35479
|
-
|
|
35480
|
-
return
|
|
35939
|
+
scalar2.comment = comment;
|
|
35940
|
+
return scalar2;
|
|
35481
35941
|
}
|
|
35482
35942
|
function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
35483
35943
|
if (tagName === "!")
|
|
@@ -36226,7 +36686,7 @@ var require_cst = __commonJS({
|
|
|
36226
36686
|
var FLOW_END = "";
|
|
36227
36687
|
var SCALAR = "";
|
|
36228
36688
|
var isCollection = (token) => !!token && "items" in token;
|
|
36229
|
-
var
|
|
36689
|
+
var isScalar2 = (token) => !!token && (token.type === "scalar" || token.type === "single-quoted-scalar" || token.type === "double-quoted-scalar" || token.type === "block-scalar");
|
|
36230
36690
|
function prettyToken(token) {
|
|
36231
36691
|
switch (token) {
|
|
36232
36692
|
case BOM:
|
|
@@ -36310,7 +36770,7 @@ var require_cst = __commonJS({
|
|
|
36310
36770
|
exports2.FLOW_END = FLOW_END;
|
|
36311
36771
|
exports2.SCALAR = SCALAR;
|
|
36312
36772
|
exports2.isCollection = isCollection;
|
|
36313
|
-
exports2.isScalar =
|
|
36773
|
+
exports2.isScalar = isScalar2;
|
|
36314
36774
|
exports2.prettyToken = prettyToken;
|
|
36315
36775
|
exports2.tokenType = tokenType;
|
|
36316
36776
|
}
|
|
@@ -37305,37 +37765,37 @@ var require_parser = __commonJS({
|
|
|
37305
37765
|
};
|
|
37306
37766
|
}
|
|
37307
37767
|
}
|
|
37308
|
-
*scalar(
|
|
37768
|
+
*scalar(scalar2) {
|
|
37309
37769
|
if (this.type === "map-value-ind") {
|
|
37310
37770
|
const prev = getPrevProps(this.peek(2));
|
|
37311
37771
|
const start = getFirstKeyStartProps(prev);
|
|
37312
37772
|
let sep4;
|
|
37313
|
-
if (
|
|
37314
|
-
sep4 =
|
|
37773
|
+
if (scalar2.end) {
|
|
37774
|
+
sep4 = scalar2.end;
|
|
37315
37775
|
sep4.push(this.sourceToken);
|
|
37316
|
-
delete
|
|
37776
|
+
delete scalar2.end;
|
|
37317
37777
|
} else
|
|
37318
37778
|
sep4 = [this.sourceToken];
|
|
37319
37779
|
const map2 = {
|
|
37320
37780
|
type: "block-map",
|
|
37321
|
-
offset:
|
|
37322
|
-
indent:
|
|
37323
|
-
items: [{ start, key:
|
|
37781
|
+
offset: scalar2.offset,
|
|
37782
|
+
indent: scalar2.indent,
|
|
37783
|
+
items: [{ start, key: scalar2, sep: sep4 }]
|
|
37324
37784
|
};
|
|
37325
37785
|
this.onKeyLine = true;
|
|
37326
37786
|
this.stack[this.stack.length - 1] = map2;
|
|
37327
37787
|
} else
|
|
37328
|
-
yield* this.lineEnd(
|
|
37788
|
+
yield* this.lineEnd(scalar2);
|
|
37329
37789
|
}
|
|
37330
|
-
*blockScalar(
|
|
37790
|
+
*blockScalar(scalar2) {
|
|
37331
37791
|
switch (this.type) {
|
|
37332
37792
|
case "space":
|
|
37333
37793
|
case "comment":
|
|
37334
37794
|
case "newline":
|
|
37335
|
-
|
|
37795
|
+
scalar2.props.push(this.sourceToken);
|
|
37336
37796
|
return;
|
|
37337
37797
|
case "scalar":
|
|
37338
|
-
|
|
37798
|
+
scalar2.source = this.source;
|
|
37339
37799
|
this.atNewLine = true;
|
|
37340
37800
|
this.indent = 0;
|
|
37341
37801
|
if (this.onNewLine) {
|
|
@@ -38058,7 +38518,7 @@ function within(root, path) {
|
|
|
38058
38518
|
}
|
|
38059
38519
|
async function resolveReal(path) {
|
|
38060
38520
|
try {
|
|
38061
|
-
return await (0,
|
|
38521
|
+
return await (0, import_promises24.realpath)(path);
|
|
38062
38522
|
} catch {
|
|
38063
38523
|
const parent = (0, import_path9.dirname)(path);
|
|
38064
38524
|
if (parent === path) return path;
|
|
@@ -38087,14 +38547,14 @@ function createWorkspaceFs(roots, writable) {
|
|
|
38087
38547
|
return {
|
|
38088
38548
|
read: async (params) => {
|
|
38089
38549
|
const path = await confined(params);
|
|
38090
|
-
const bytes = await (0,
|
|
38550
|
+
const bytes = await (0, import_promises24.readFile)(path);
|
|
38091
38551
|
if (bytes.byteLength > MAX_READ_BYTES) throw new FsDenied(`${path} is too large to read`);
|
|
38092
38552
|
return { content: sliceLines(bytes.toString("utf8"), params) };
|
|
38093
38553
|
},
|
|
38094
38554
|
write: async (params) => {
|
|
38095
38555
|
if (!writable) throw new FsDenied("This session is read-only");
|
|
38096
38556
|
const path = await confined(params);
|
|
38097
|
-
await (0,
|
|
38557
|
+
await (0, import_promises24.writeFile)(path, asString(params.content));
|
|
38098
38558
|
return {};
|
|
38099
38559
|
}
|
|
38100
38560
|
};
|
|
@@ -38191,8 +38651,8 @@ function refusal(error61, displayName) {
|
|
|
38191
38651
|
return failure2("failed", String(error61));
|
|
38192
38652
|
}
|
|
38193
38653
|
function toolResultText(update) {
|
|
38194
|
-
const texts = (update.content ?? []).flatMap((
|
|
38195
|
-
const text2 = asString(asRecord(asRecord(
|
|
38654
|
+
const texts = (update.content ?? []).flatMap((block2) => {
|
|
38655
|
+
const text2 = asString(asRecord(asRecord(block2)?.content)?.text);
|
|
38196
38656
|
return text2 ? [text2] : [];
|
|
38197
38657
|
});
|
|
38198
38658
|
if (typeof update.rawOutput === "string" && update.rawOutput) texts.push(update.rawOutput);
|
|
@@ -38288,11 +38748,11 @@ function isStopReason(value) {
|
|
|
38288
38748
|
function v2ToolContent(content) {
|
|
38289
38749
|
if (!Array.isArray(content)) return void 0;
|
|
38290
38750
|
return content.map((item) => {
|
|
38291
|
-
const
|
|
38292
|
-
if (!
|
|
38293
|
-
const path = asString(
|
|
38294
|
-
const oldText = typeof
|
|
38295
|
-
const newText = typeof
|
|
38751
|
+
const block2 = asRecord(item);
|
|
38752
|
+
if (!block2 || asString(block2.type) !== "diff" || asRecord(block2.diff)) return item;
|
|
38753
|
+
const path = asString(block2.path);
|
|
38754
|
+
const oldText = typeof block2.oldText === "string" ? block2.oldText : null;
|
|
38755
|
+
const newText = typeof block2.newText === "string" ? block2.newText : null;
|
|
38296
38756
|
const operation = oldText === null ? "add" : newText === null ? "delete" : "modify";
|
|
38297
38757
|
return {
|
|
38298
38758
|
type: "diff",
|
|
@@ -38697,7 +39157,7 @@ async function acpTurnInput(run, context) {
|
|
|
38697
39157
|
const encoded = await Promise.all(
|
|
38698
39158
|
images.map(async (image) => ({
|
|
38699
39159
|
mimeType: image.mimeType,
|
|
38700
|
-
data: (await (0,
|
|
39160
|
+
data: (await (0, import_promises25.readFile)(image.path)).toString("base64")
|
|
38701
39161
|
}))
|
|
38702
39162
|
);
|
|
38703
39163
|
return {
|
|
@@ -38706,7 +39166,7 @@ async function acpTurnInput(run, context) {
|
|
|
38706
39166
|
...encoded.length ? { images: encoded, imagePaths: images.map((image) => image.path) } : {}
|
|
38707
39167
|
};
|
|
38708
39168
|
}
|
|
38709
|
-
var
|
|
39169
|
+
var import_promises24, import_path9, import_crypto13, import_promises25, CURSOR_ASK_QUESTION, copilotAcpProfile, cursorAcpProfile, MODEL_REJECTED, MAX_READ_BYTES, FsDenied, ENV_REFERENCE, AcpBackgroundTasks, CURSOR_CREATE_PLAN, STATUSES, READ_KINDS, ALLOW_KINDS, REJECT_KINDS, CANCELLED_PERMISSION, STOP_REASONS, CHUNKS, ECHOES, AcpTurn, STDERR_TAIL_LINES4, MAX_BETWEEN_UPDATES2, AcpSession, DEFAULTS3, CLIENT_INFO2, TASK_BACKGROUNDED, TASK_COMPLETED, SESSION_NOTIFICATION, KILLED_STATUSES, SUCCESS_STATUSES, SUBAGENT_ID, grokTaskDialect, grokAcpProfile, kimiAcpProfile, ACP_PROFILES, ACP_MODES;
|
|
38710
39170
|
var init_acp3 = __esm({
|
|
38711
39171
|
"../agent-core/dist/providers/acp.js"() {
|
|
38712
39172
|
"use strict";
|
|
@@ -38715,14 +39175,14 @@ var init_acp3 = __esm({
|
|
|
38715
39175
|
init_chunk_HBIPWAUI();
|
|
38716
39176
|
init_chunk_J2KTV5FP();
|
|
38717
39177
|
init_chunk_M6YHY2EZ();
|
|
38718
|
-
|
|
39178
|
+
init_chunk_GI3ZGXTY();
|
|
38719
39179
|
init_chunk_YXWJW7I5();
|
|
38720
|
-
|
|
39180
|
+
import_promises24 = require("fs/promises");
|
|
38721
39181
|
import_path9 = require("path");
|
|
38722
39182
|
init_effort();
|
|
38723
39183
|
init_acp();
|
|
38724
39184
|
import_crypto13 = require("crypto");
|
|
38725
|
-
|
|
39185
|
+
import_promises25 = require("fs/promises");
|
|
38726
39186
|
init_agent2();
|
|
38727
39187
|
CURSOR_ASK_QUESTION = "cursor/ask_question";
|
|
38728
39188
|
copilotAcpProfile = {
|
|
@@ -39238,7 +39698,7 @@ var init_acp3 = __esm({
|
|
|
39238
39698
|
const turn = new AcpTurn(`acp-${this.#turns}-${id}`, this.#profile);
|
|
39239
39699
|
let finish = () => {
|
|
39240
39700
|
};
|
|
39241
|
-
const done = new Promise((
|
|
39701
|
+
const done = new Promise((resolve9) => {
|
|
39242
39702
|
finish = (outcome2) => {
|
|
39243
39703
|
if (this.#current?.id !== id) return;
|
|
39244
39704
|
this.#current = void 0;
|
|
@@ -39246,7 +39706,7 @@ var init_acp3 = __esm({
|
|
|
39246
39706
|
if (this.#state === "busy") this.#state = "idle";
|
|
39247
39707
|
this.#host.scanDescendants(true);
|
|
39248
39708
|
this.#emit({ type: "turn_ended", turnId: id, outcome: outcome2 });
|
|
39249
|
-
|
|
39709
|
+
resolve9({ turnId: id, outcome: outcome2, providerSessionId: this.#sessionId });
|
|
39250
39710
|
};
|
|
39251
39711
|
});
|
|
39252
39712
|
const active = { id, turn, done, finish, cancelRequested: false };
|
|
@@ -39542,6 +40002,9 @@ var init_driver = __esm({
|
|
|
39542
40002
|
});
|
|
39543
40003
|
|
|
39544
40004
|
// src/holder/drivers/persistent.ts
|
|
40005
|
+
function sessionContextFor(opened, inputs) {
|
|
40006
|
+
return opened.fresh ? inputs.agentContext?.full : inputs.agentContext?.update;
|
|
40007
|
+
}
|
|
39545
40008
|
function errorMessage(error61) {
|
|
39546
40009
|
return error61 instanceof Error ? error61.message : String(error61);
|
|
39547
40010
|
}
|
|
@@ -39597,14 +40060,14 @@ function createPersistentDriver(provider4, options) {
|
|
|
39597
40060
|
const resumeNotice = (spec, session, sink) => {
|
|
39598
40061
|
if (spec.resumeFallbackContext) {
|
|
39599
40062
|
log.info("holder.session_resume_fallback", { harness: provider4.harness, runId: spec.runId });
|
|
39600
|
-
return { session, contextPrefix: spec.resumeFallbackContext };
|
|
40063
|
+
return { session, fresh: true, contextPrefix: spec.resumeFallbackContext };
|
|
39601
40064
|
}
|
|
39602
40065
|
sink.onEvent({
|
|
39603
40066
|
seq: 0,
|
|
39604
40067
|
at: clock.now(),
|
|
39605
40068
|
update: noticeUpdate("warning", "session_resume_failed", RESUME_UNAVAILABLE)
|
|
39606
40069
|
});
|
|
39607
|
-
return { session };
|
|
40070
|
+
return { session, fresh: true };
|
|
39608
40071
|
};
|
|
39609
40072
|
const managedMcpAccess = async (signal) => {
|
|
39610
40073
|
const managed = options.managedMcp;
|
|
@@ -39615,7 +40078,7 @@ function createPersistentDriver(provider4, options) {
|
|
|
39615
40078
|
const ensureSession = async (spec, inputs, sink, managedMcp) => {
|
|
39616
40079
|
const wanted = provider4.plan(spec, inputs, void 0, managedMcp);
|
|
39617
40080
|
const reused = await reuseLive(spec, wanted.key);
|
|
39618
|
-
if (reused) return { session: reused };
|
|
40081
|
+
if (reused) return { session: reused, fresh: false };
|
|
39619
40082
|
const requested = live.providerSessionId ?? spec.providerSessionId;
|
|
39620
40083
|
const resumeId = requested !== void 0 && requested !== live.rejectedSessionId && provider4.canResume(wanted, requested) ? requested : void 0;
|
|
39621
40084
|
const planned = provider4.plan(spec, inputs, resumeId, managedMcp);
|
|
@@ -39634,7 +40097,7 @@ function createPersistentDriver(provider4, options) {
|
|
|
39634
40097
|
requested
|
|
39635
40098
|
});
|
|
39636
40099
|
const resumed = resumeId !== void 0 && !opened.resumeFailed;
|
|
39637
|
-
if (requested === void 0 || resumed) return { session: opened.session };
|
|
40100
|
+
if (requested === void 0 || resumed) return { session: opened.session, fresh: !resumed };
|
|
39638
40101
|
return resumeNotice(spec, opened.session, sink);
|
|
39639
40102
|
};
|
|
39640
40103
|
const runOnSession = async (opened, spec, sink, signal, inputs) => {
|
|
@@ -39686,7 +40149,7 @@ function createPersistentDriver(provider4, options) {
|
|
|
39686
40149
|
};
|
|
39687
40150
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
39688
40151
|
try {
|
|
39689
|
-
const contextPrefix = [inputs
|
|
40152
|
+
const contextPrefix = [sessionContextFor(opened, inputs), opened.contextPrefix].filter((part) => part !== void 0).join("\n\n");
|
|
39690
40153
|
const input2 = await provider4.turnInput(spec, inputs, contextPrefix || void 0);
|
|
39691
40154
|
if (signal.aborted) return { outcome: "aborted" };
|
|
39692
40155
|
const result = await session.sendTurn(input2);
|
|
@@ -39867,8 +40330,8 @@ var init_acp4 = __esm({
|
|
|
39867
40330
|
});
|
|
39868
40331
|
|
|
39869
40332
|
// ../agent-core/dist/providers/opencode.js
|
|
39870
|
-
function parseSseBlock(
|
|
39871
|
-
const data =
|
|
40333
|
+
function parseSseBlock(block2) {
|
|
40334
|
+
const data = block2.split("\n").map((line) => line.endsWith("\r") ? line.slice(0, -1) : line).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).replace(/^ /, "")).join("\n");
|
|
39872
40335
|
if (!data) return void 0;
|
|
39873
40336
|
let parsed;
|
|
39874
40337
|
try {
|
|
@@ -40247,7 +40710,7 @@ async function sameDirectory(left, right) {
|
|
|
40247
40710
|
}
|
|
40248
40711
|
async function canonicalDirectory(directory) {
|
|
40249
40712
|
try {
|
|
40250
|
-
return await (0,
|
|
40713
|
+
return await (0, import_promises26.realpath)(directory);
|
|
40251
40714
|
} catch {
|
|
40252
40715
|
return (0, import_path10.resolve)(directory);
|
|
40253
40716
|
}
|
|
@@ -40443,7 +40906,7 @@ function openCodeTurnInput(run, context) {
|
|
|
40443
40906
|
...images.length ? { imagePaths: images.map((image) => image.path) } : {}
|
|
40444
40907
|
};
|
|
40445
40908
|
}
|
|
40446
|
-
var import_http4, import_crypto14,
|
|
40909
|
+
var import_http4, import_crypto14, import_promises26, import_path10, import_path11, import_url2, import_crypto15, IDLE_SOCKET_MS2, OpenCodeHttpError, OpenCodeClient, OPENCODE_CONFIG_ENV, OPENCODE_ENGINE, TEXT_PARTS, STEP_PARTS, STOPPED_BY_USER, OpenCodeSubagents, NAMED_KINDS, OPENCODE_ABORTED_ERROR, PROVIDER_EVENT_META, TASK_TOOL_NAME, TASK_RESULT_TAG, TASK_ERROR_TAG, PERMISSION_DENIED, FILE_OPERATIONS, PartReader, NOTHING, NON_INTERACTIVE_PERMISSIONS, CONTENT_FILTER_FINISHES, OUTPUT_PARTS, OpenCodeTurn, LISTENING, OUTPUT_TAIL_LINES, IMAGE_TYPES, OpenCodeSession, OPENCODE_MIN_VERSION, OPENCODE_REQUIREMENT, OPENCODE_TESTED_LINE, OPENCODE_SUPPORTED_MAJOR, DEFAULTS4, STORE_LOCKED, NON_INTERACTIVE_RULES, TITLE_LENGTH, MAX_VARIANT_LENGTH;
|
|
40447
40910
|
var init_opencode = __esm({
|
|
40448
40911
|
"../agent-core/dist/providers/opencode.js"() {
|
|
40449
40912
|
"use strict";
|
|
@@ -40452,12 +40915,12 @@ var init_opencode = __esm({
|
|
|
40452
40915
|
init_chunk_HBIPWAUI();
|
|
40453
40916
|
init_chunk_J2KTV5FP();
|
|
40454
40917
|
init_chunk_M6YHY2EZ();
|
|
40455
|
-
|
|
40918
|
+
init_chunk_GI3ZGXTY();
|
|
40456
40919
|
init_chunk_YXWJW7I5();
|
|
40457
40920
|
import_http4 = require("http");
|
|
40458
40921
|
init_runtime_v2();
|
|
40459
40922
|
import_crypto14 = require("crypto");
|
|
40460
|
-
|
|
40923
|
+
import_promises26 = require("fs/promises");
|
|
40461
40924
|
import_path10 = require("path");
|
|
40462
40925
|
init_agent2();
|
|
40463
40926
|
import_path11 = require("path");
|
|
@@ -41922,8 +42385,8 @@ function createDroidPeer(writer, handlers) {
|
|
|
41922
42385
|
},
|
|
41923
42386
|
request: (method, params = {}) => {
|
|
41924
42387
|
const id = `alan-${counter.next++}`;
|
|
41925
|
-
return new Promise((
|
|
41926
|
-
pending.set(id, { method, resolve:
|
|
42388
|
+
return new Promise((resolve9, reject) => {
|
|
42389
|
+
pending.set(id, { method, resolve: resolve9, reject });
|
|
41927
42390
|
writer.write(envelope("request", { id, method, params })).catch((error61) => {
|
|
41928
42391
|
pending.delete(id);
|
|
41929
42392
|
reject(error61 instanceof Error ? error61 : new Error(String(error61)));
|
|
@@ -42008,7 +42471,7 @@ function droidToolCall(toolUse) {
|
|
|
42008
42471
|
function droidResultText(result) {
|
|
42009
42472
|
const blocks = asArray(result.content);
|
|
42010
42473
|
if (blocks.length) {
|
|
42011
|
-
return blocks.map((
|
|
42474
|
+
return blocks.map((block2) => asString(asRecord(block2)?.text)).filter(Boolean).join("\n");
|
|
42012
42475
|
}
|
|
42013
42476
|
const value = result.value;
|
|
42014
42477
|
if (typeof value === "string") return value;
|
|
@@ -42258,12 +42721,12 @@ async function droidTurnInput(run, context) {
|
|
|
42258
42721
|
const encoded = await Promise.all(
|
|
42259
42722
|
images.map(async (image) => ({
|
|
42260
42723
|
mimeType: image.mimeType,
|
|
42261
|
-
data: (await (0,
|
|
42724
|
+
data: (await (0, import_promises27.readFile)(image.path)).toString("base64")
|
|
42262
42725
|
}))
|
|
42263
42726
|
);
|
|
42264
42727
|
return { turnId: run.runId, text: text2, ...encoded.length ? { images: encoded } : {} };
|
|
42265
42728
|
}
|
|
42266
|
-
var import_crypto16,
|
|
42729
|
+
var import_crypto16, import_promises27, FACTORY_API_VERSION, FACTORY_PROTOCOL_VERSION, SUBAGENT_TOOLS, TASK_OUTPUT_TOOLS, TASK_STOP_TOOLS, SILENT2, DroidTurn, STDERR_TAIL_LINES5, UNSUPPORTED_REQUEST2, DroidSession, DEFAULTS5, DROID_REQUIREMENT, DROID_JSONRPC_ARGS;
|
|
42267
42730
|
var init_droid = __esm({
|
|
42268
42731
|
"../agent-core/dist/providers/droid.js"() {
|
|
42269
42732
|
"use strict";
|
|
@@ -42272,11 +42735,11 @@ var init_droid = __esm({
|
|
|
42272
42735
|
init_chunk_HBIPWAUI();
|
|
42273
42736
|
init_chunk_J2KTV5FP();
|
|
42274
42737
|
init_chunk_M6YHY2EZ();
|
|
42275
|
-
|
|
42738
|
+
init_chunk_GI3ZGXTY();
|
|
42276
42739
|
init_chunk_YXWJW7I5();
|
|
42277
42740
|
init_runtime_v2();
|
|
42278
42741
|
import_crypto16 = require("crypto");
|
|
42279
|
-
|
|
42742
|
+
import_promises27 = require("fs/promises");
|
|
42280
42743
|
init_agent2();
|
|
42281
42744
|
FACTORY_API_VERSION = "1.0.0";
|
|
42282
42745
|
FACTORY_PROTOCOL_VERSION = "1.187.0";
|
|
@@ -42548,14 +43011,14 @@ var init_droid = __esm({
|
|
|
42548
43011
|
const turn = new DroidTurn(sessionId, this.#memory);
|
|
42549
43012
|
let finish = () => {
|
|
42550
43013
|
};
|
|
42551
|
-
const done = new Promise((
|
|
43014
|
+
const done = new Promise((resolve9) => {
|
|
42552
43015
|
finish = (outcome2) => {
|
|
42553
43016
|
if (this.#current?.id !== id) return;
|
|
42554
43017
|
this.#current = void 0;
|
|
42555
43018
|
if (this.#state === "busy") this.#state = "idle";
|
|
42556
43019
|
this.#host.scanDescendants(true);
|
|
42557
43020
|
this.#emit({ type: "turn_ended", turnId: id, outcome: outcome2 });
|
|
42558
|
-
|
|
43021
|
+
resolve9({ turnId: id, outcome: outcome2, providerSessionId: this.#sessionId });
|
|
42559
43022
|
};
|
|
42560
43023
|
});
|
|
42561
43024
|
const active = { id, turn, done, finish, cancelRequested: false };
|
|
@@ -42751,7 +43214,7 @@ function settingsPath(env) {
|
|
|
42751
43214
|
async function readSettings(path) {
|
|
42752
43215
|
let raw;
|
|
42753
43216
|
try {
|
|
42754
|
-
raw = (await (0,
|
|
43217
|
+
raw = (await (0, import_promises28.readFile)(path, "utf8")).trim();
|
|
42755
43218
|
} catch {
|
|
42756
43219
|
return {};
|
|
42757
43220
|
}
|
|
@@ -42769,8 +43232,8 @@ async function selectAntigravityApiKeyMode(env) {
|
|
|
42769
43232
|
const settings2 = await readSettings(path);
|
|
42770
43233
|
if (settings2 === "malformed") return "malformed";
|
|
42771
43234
|
if (settings2.modelProvider === "gemini") return "already_selected";
|
|
42772
|
-
await (0,
|
|
42773
|
-
await (0,
|
|
43235
|
+
await (0, import_promises28.mkdir)((0, import_path12.dirname)(path), { recursive: true });
|
|
43236
|
+
await (0, import_promises28.writeFile)(path, JSON.stringify({ ...settings2, modelProvider: "gemini" }), { mode: 384 });
|
|
42774
43237
|
return "selected";
|
|
42775
43238
|
}
|
|
42776
43239
|
function readAntigravityCapabilities(version2, help) {
|
|
@@ -43369,7 +43832,7 @@ function antigravityTurnInput(run, context) {
|
|
|
43369
43832
|
});
|
|
43370
43833
|
return { turnId: run.runId, text: appendImagePathReferences(text2, images) };
|
|
43371
43834
|
}
|
|
43372
|
-
var
|
|
43835
|
+
var import_promises28, import_path12, import_fs8, import_path13, import_path14, import_url3, import_crypto17, NO_ANTIGRAVITY_CAPABILITIES, INSTRUCTIONS_FILE, MAX_INSTRUCTION_CHARS, SHORTENED_NOTE, DIFF_BLOCK_START, DIFF_BLOCK_END, HUNK_HEADER, TRANSCRIPT_FILE, FULL_TRANSCRIPT_FILE, LOG_DIRS, TOOL_RESULT_TYPES, BrainTranscript, AntigravityTranscripts, ANTIGRAVITY_GRAMMAR_NAME, AntigravityGrammar, ignored, HANDLERS, SUCCESSFUL_STATUSES, SESSION_START_TYPES, RESULT_TYPES, SUBAGENT_START_TYPES, RESUME_FORKED, EXITED_WITHOUT_RESULT, AntigravityTurn, DEFAULTS6, AntigravitySession, WINDOWS_LINE_MARGIN;
|
|
43373
43836
|
var init_antigravity = __esm({
|
|
43374
43837
|
"../agent-core/dist/providers/antigravity.js"() {
|
|
43375
43838
|
"use strict";
|
|
@@ -43378,9 +43841,9 @@ var init_antigravity = __esm({
|
|
|
43378
43841
|
init_chunk_XC5676SG();
|
|
43379
43842
|
init_chunk_HBIPWAUI();
|
|
43380
43843
|
init_chunk_M6YHY2EZ();
|
|
43381
|
-
|
|
43844
|
+
init_chunk_GI3ZGXTY();
|
|
43382
43845
|
init_chunk_YXWJW7I5();
|
|
43383
|
-
|
|
43846
|
+
import_promises28 = require("fs/promises");
|
|
43384
43847
|
import_path12 = require("path");
|
|
43385
43848
|
init_type_guards();
|
|
43386
43849
|
import_fs8 = require("fs");
|
|
@@ -43880,7 +44343,7 @@ function parseConfig(raw) {
|
|
|
43880
44343
|
}
|
|
43881
44344
|
async function writeCommandCodeProjectMcp(cwd, mcp) {
|
|
43882
44345
|
const path = (0, import_path15.join)(cwd, ".mcp.json");
|
|
43883
|
-
const original = await (0,
|
|
44346
|
+
const original = await (0, import_promises29.readFile)(path, "utf8").catch(() => null);
|
|
43884
44347
|
const config2 = parseConfig(original);
|
|
43885
44348
|
const next = {
|
|
43886
44349
|
...config2,
|
|
@@ -43897,12 +44360,12 @@ async function writeCommandCodeProjectMcp(cwd, mcp) {
|
|
|
43897
44360
|
}
|
|
43898
44361
|
}
|
|
43899
44362
|
};
|
|
43900
|
-
await (0,
|
|
43901
|
-
await (0,
|
|
44363
|
+
await (0, import_promises29.mkdir)(cwd, { recursive: true });
|
|
44364
|
+
await (0, import_promises29.writeFile)(path, `${JSON.stringify(next, null, 2)}
|
|
43902
44365
|
`);
|
|
43903
44366
|
return async () => {
|
|
43904
|
-
if (original === null) await (0,
|
|
43905
|
-
else await (0,
|
|
44367
|
+
if (original === null) await (0, import_promises29.rm)(path, { force: true });
|
|
44368
|
+
else await (0, import_promises29.writeFile)(path, original);
|
|
43906
44369
|
};
|
|
43907
44370
|
}
|
|
43908
44371
|
function commandCodeString(value) {
|
|
@@ -44074,7 +44537,7 @@ function commandCodeTurnInput(run, context) {
|
|
|
44074
44537
|
});
|
|
44075
44538
|
return { turnId: run.runId, text: appendImagePathReferences(text2, images) };
|
|
44076
44539
|
}
|
|
44077
|
-
var
|
|
44540
|
+
var import_promises29, import_path15, import_crypto18, COMMAND_CODE_GRAMMAR_NAME, SILENT3, CommandCodeGrammar, SHELL_TOOL, STOP_TOOLS, REPORTED_STATUS, SHELL_STATUS, SWEEP_INTERVAL_MS, CommandCodeBackgroundTasks, EXITED_WITHOUT_RESULT2, CommandCodeTurn, COMMAND_CODE_MAX_TURNS, DEFAULTS7, CommandCodeSession;
|
|
44078
44541
|
var init_command_code = __esm({
|
|
44079
44542
|
"../agent-core/dist/providers/command-code.js"() {
|
|
44080
44543
|
"use strict";
|
|
@@ -44083,9 +44546,9 @@ var init_command_code = __esm({
|
|
|
44083
44546
|
init_chunk_HBIPWAUI();
|
|
44084
44547
|
init_chunk_J2KTV5FP();
|
|
44085
44548
|
init_chunk_M6YHY2EZ();
|
|
44086
|
-
|
|
44549
|
+
init_chunk_GI3ZGXTY();
|
|
44087
44550
|
init_chunk_YXWJW7I5();
|
|
44088
|
-
|
|
44551
|
+
import_promises29 = require("fs/promises");
|
|
44089
44552
|
import_path15 = require("path");
|
|
44090
44553
|
init_agent2();
|
|
44091
44554
|
init_runtime_v2();
|
|
@@ -44947,7 +45410,7 @@ function transportFailure(request2, error61) {
|
|
|
44947
45410
|
});
|
|
44948
45411
|
}
|
|
44949
45412
|
function readBody(incoming, url2, maxBytes) {
|
|
44950
|
-
return new Promise((
|
|
45413
|
+
return new Promise((resolve9, reject) => {
|
|
44951
45414
|
const declared = Number(incoming.headers["content-length"] ?? "0");
|
|
44952
45415
|
if (maxBytes !== void 0 && declared > maxBytes) {
|
|
44953
45416
|
incoming.destroy();
|
|
@@ -44966,7 +45429,7 @@ function readBody(incoming, url2, maxBytes) {
|
|
|
44966
45429
|
chunks.push(chunk);
|
|
44967
45430
|
});
|
|
44968
45431
|
incoming.on("error", reject);
|
|
44969
|
-
incoming.on("end", () =>
|
|
45432
|
+
incoming.on("end", () => resolve9(Buffer.concat(chunks)));
|
|
44970
45433
|
});
|
|
44971
45434
|
}
|
|
44972
45435
|
function isConnectionReset(error61) {
|
|
@@ -44974,7 +45437,7 @@ function isConnectionReset(error61) {
|
|
|
44974
45437
|
}
|
|
44975
45438
|
function exchange(request2, agents, attempt = 0) {
|
|
44976
45439
|
const { signal, url: url2 } = request2;
|
|
44977
|
-
return new Promise((
|
|
45440
|
+
return new Promise((resolve9, reject) => {
|
|
44978
45441
|
if (signal.aborted) {
|
|
44979
45442
|
reject(signal.reason);
|
|
44980
45443
|
return;
|
|
@@ -45001,7 +45464,7 @@ function exchange(request2, agents, attempt = 0) {
|
|
|
45001
45464
|
const stale = outgoing.reusedSocket && !responded && isConnectionReset(error61);
|
|
45002
45465
|
if (stale && attempt < STALE_SOCKET_RETRIES && !signal.aborted) {
|
|
45003
45466
|
settle();
|
|
45004
|
-
|
|
45467
|
+
resolve9(exchange(request2, agents, attempt + 1));
|
|
45005
45468
|
return;
|
|
45006
45469
|
}
|
|
45007
45470
|
fail(error61);
|
|
@@ -45014,7 +45477,7 @@ function exchange(request2, agents, attempt = 0) {
|
|
|
45014
45477
|
readBody(incoming, url2, isRedirect(status) ? void 0 : request2.maxBodyBytes).then(
|
|
45015
45478
|
(body) => {
|
|
45016
45479
|
settle();
|
|
45017
|
-
|
|
45480
|
+
resolve9({ status, headers: incoming.headers, body });
|
|
45018
45481
|
},
|
|
45019
45482
|
fail
|
|
45020
45483
|
);
|
|
@@ -45184,6 +45647,19 @@ var GitFault = class extends Error {
|
|
|
45184
45647
|
}
|
|
45185
45648
|
};
|
|
45186
45649
|
|
|
45650
|
+
// src/capabilities/git/repository.ts
|
|
45651
|
+
var import_promises4 = require("fs/promises");
|
|
45652
|
+
var import_node_path3 = require("path");
|
|
45653
|
+
async function assertValidBranch(git, repoRoot, branch, signal) {
|
|
45654
|
+
const output2 = await git.run(
|
|
45655
|
+
{ cwd: repoRoot, args: ["check-ref-format", "--branch", branch], readOnly: true },
|
|
45656
|
+
signal
|
|
45657
|
+
);
|
|
45658
|
+
if (branch.startsWith("-") || output2.exitCode !== 0) {
|
|
45659
|
+
throw new GitFault("invalid_git_request", "branch is not a valid Git ref");
|
|
45660
|
+
}
|
|
45661
|
+
}
|
|
45662
|
+
|
|
45187
45663
|
// src/capabilities/git/run-git.ts
|
|
45188
45664
|
var import_node_child_process = require("child_process");
|
|
45189
45665
|
|
|
@@ -45320,7 +45796,7 @@ function createGitRunner(options) {
|
|
|
45320
45796
|
}
|
|
45321
45797
|
await killProcessTree(child.pid, { signal: "SIGKILL", child, platform });
|
|
45322
45798
|
};
|
|
45323
|
-
return new Promise((
|
|
45799
|
+
return new Promise((resolve9, reject) => {
|
|
45324
45800
|
let ending = null;
|
|
45325
45801
|
const stop = (next) => {
|
|
45326
45802
|
if (ending !== null) return;
|
|
@@ -45345,7 +45821,7 @@ function createGitRunner(options) {
|
|
|
45345
45821
|
signal.removeEventListener("abort", onAbort);
|
|
45346
45822
|
const final = ending ?? last;
|
|
45347
45823
|
if (final.kind === "exited") {
|
|
45348
|
-
|
|
45824
|
+
resolve9({ exitCode: final.exitCode, stdout: stdout.text(), stderr: stderr.text() });
|
|
45349
45825
|
} else {
|
|
45350
45826
|
reject(faultFor(final, command));
|
|
45351
45827
|
}
|
|
@@ -45369,8 +45845,8 @@ function createGitRunner(options) {
|
|
|
45369
45845
|
|
|
45370
45846
|
// src/capabilities/git/checkout-freshness.ts
|
|
45371
45847
|
var import_node_crypto3 = require("crypto");
|
|
45372
|
-
var
|
|
45373
|
-
var
|
|
45848
|
+
var import_promises8 = require("fs/promises");
|
|
45849
|
+
var import_node_path4 = require("path");
|
|
45374
45850
|
init_zod();
|
|
45375
45851
|
var REMOTE = "origin";
|
|
45376
45852
|
var snapshotSchema = external_exports.object({
|
|
@@ -45400,7 +45876,7 @@ var freshnessSchema = external_exports.discriminatedUnion("state", [
|
|
|
45400
45876
|
})
|
|
45401
45877
|
]);
|
|
45402
45878
|
function freshnessFile(dir, path) {
|
|
45403
|
-
return (0,
|
|
45879
|
+
return (0, import_node_path4.join)(dir, `${(0, import_node_crypto3.createHash)("sha256").update(path).digest("hex").slice(0, 32)}.json`);
|
|
45404
45880
|
}
|
|
45405
45881
|
function parseStatus(stdout) {
|
|
45406
45882
|
const lines = stdout.split("\n").filter((line) => line.length > 0);
|
|
@@ -45432,32 +45908,35 @@ async function readCheckoutStatus(git, cwd, signal) {
|
|
|
45432
45908
|
return output2.exitCode === 0 ? parseStatus(output2.stdout) : null;
|
|
45433
45909
|
}
|
|
45434
45910
|
async function isCheckout(path) {
|
|
45435
|
-
return (0,
|
|
45911
|
+
return (0, import_promises8.stat)((0, import_node_path4.join)(path, ".git")).then(
|
|
45436
45912
|
() => true,
|
|
45437
45913
|
() => false
|
|
45438
45914
|
);
|
|
45439
45915
|
}
|
|
45440
45916
|
async function checkoutsUnder(root) {
|
|
45441
45917
|
if (await isCheckout(root)) return [root];
|
|
45442
|
-
const entries = await (0,
|
|
45918
|
+
const entries = await (0, import_promises8.readdir)(root, { withFileTypes: true }).catch(() => []);
|
|
45443
45919
|
const found = await Promise.all(
|
|
45444
45920
|
entries.filter((entry) => entry.isDirectory()).map(
|
|
45445
|
-
async (entry) => await isCheckout((0,
|
|
45921
|
+
async (entry) => await isCheckout((0, import_node_path4.join)(root, entry.name)) ? (0, import_node_path4.join)(root, entry.name) : null
|
|
45446
45922
|
)
|
|
45447
45923
|
);
|
|
45448
45924
|
return found.filter((path) => path !== null);
|
|
45449
45925
|
}
|
|
45926
|
+
async function recordCheckoutKept(dir, path, reason) {
|
|
45927
|
+
await writeJsonFileAtomic(freshnessFile(dir, path), { state: "kept", path, reason });
|
|
45928
|
+
}
|
|
45450
45929
|
async function readCheckoutFreshness(dir, path) {
|
|
45451
|
-
for (let current = path; ; current = (0,
|
|
45930
|
+
for (let current = path; ; current = (0, import_node_path4.dirname)(current)) {
|
|
45452
45931
|
const read = await readJsonFile(freshnessFile(dir, current), freshnessSchema);
|
|
45453
45932
|
if (read.kind === "ok") return read.value;
|
|
45454
|
-
if ((0,
|
|
45933
|
+
if ((0, import_node_path4.dirname)(current) === current) return null;
|
|
45455
45934
|
}
|
|
45456
45935
|
}
|
|
45457
45936
|
|
|
45458
45937
|
// src/platform/credential-store/credential-store.ts
|
|
45459
45938
|
var import_node_crypto4 = require("crypto");
|
|
45460
|
-
var
|
|
45939
|
+
var import_promises9 = require("fs/promises");
|
|
45461
45940
|
|
|
45462
45941
|
// src/platform/credential-store/parse.ts
|
|
45463
45942
|
function parseStoredJson(text2, schema) {
|
|
@@ -45473,16 +45952,16 @@ function parseStoredJson(text2, schema) {
|
|
|
45473
45952
|
|
|
45474
45953
|
// src/platform/windows-helper.ts
|
|
45475
45954
|
var import_node_fs3 = require("fs");
|
|
45476
|
-
var
|
|
45955
|
+
var import_node_path5 = require("path");
|
|
45477
45956
|
var import_node_url = require("url");
|
|
45478
45957
|
var import_meta = {};
|
|
45479
45958
|
function windowsHelperPath(entry = process.argv[1]) {
|
|
45480
|
-
const packaged = entry === void 0 ? null : (0,
|
|
45959
|
+
const packaged = entry === void 0 ? null : (0, import_node_path5.join)((0, import_node_path5.dirname)((0, import_node_path5.resolve)(entry)), "alan-winhelper.exe");
|
|
45481
45960
|
if (entry !== void 0) {
|
|
45482
45961
|
if (packaged !== null && (0, import_node_fs3.existsSync)(packaged)) return packaged;
|
|
45483
45962
|
}
|
|
45484
45963
|
try {
|
|
45485
|
-
const local = (0,
|
|
45964
|
+
const local = (0, import_node_path5.resolve)((0, import_node_path5.dirname)((0, import_node_url.fileURLToPath)(import_meta.url)), "../../dist/alan-winhelper.exe");
|
|
45486
45965
|
return (0, import_node_fs3.existsSync)(local) ? local : packaged;
|
|
45487
45966
|
} catch {
|
|
45488
45967
|
return packaged;
|
|
@@ -45550,7 +46029,7 @@ function createFileCredentialStore(path) {
|
|
|
45550
46029
|
kind: "file",
|
|
45551
46030
|
read: (schema) => readJsonFile(path, schema),
|
|
45552
46031
|
write: (value) => writeJsonFileAtomic(path, value),
|
|
45553
|
-
clear: () => (0,
|
|
46032
|
+
clear: () => (0, import_promises9.rm)(path, { force: true })
|
|
45554
46033
|
};
|
|
45555
46034
|
}
|
|
45556
46035
|
var KEYCHAIN_SERVICE = "ai.tryalan.runtime";
|
|
@@ -45645,14 +46124,14 @@ function defaultCredentialStoreKind(platform) {
|
|
|
45645
46124
|
var import_node_child_process3 = require("child_process");
|
|
45646
46125
|
var import_node_crypto5 = require("crypto");
|
|
45647
46126
|
var import_node_fs4 = require("fs");
|
|
45648
|
-
var
|
|
45649
|
-
var
|
|
46127
|
+
var import_promises11 = require("fs/promises");
|
|
46128
|
+
var import_node_path6 = require("path");
|
|
45650
46129
|
var import_node_util2 = require("util");
|
|
45651
46130
|
init_zod();
|
|
45652
46131
|
|
|
45653
46132
|
// src/platform/process-identity.ts
|
|
45654
46133
|
var import_node_child_process2 = require("child_process");
|
|
45655
|
-
var
|
|
46134
|
+
var import_promises10 = require("fs/promises");
|
|
45656
46135
|
var import_node_util = require("util");
|
|
45657
46136
|
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
45658
46137
|
function isProcessAlive(pid) {
|
|
@@ -45664,13 +46143,13 @@ function isProcessAlive(pid) {
|
|
|
45664
46143
|
}
|
|
45665
46144
|
}
|
|
45666
46145
|
async function linuxStartTime(pid) {
|
|
45667
|
-
const
|
|
45668
|
-
if (
|
|
45669
|
-
const fields =
|
|
46146
|
+
const stat16 = await (0, import_promises10.readFile)(`/proc/${pid}/stat`, "utf8").catch(() => null);
|
|
46147
|
+
if (stat16 === null) return null;
|
|
46148
|
+
const fields = stat16.slice(stat16.lastIndexOf(")") + 2).split(" ");
|
|
45670
46149
|
return fields[19] ?? null;
|
|
45671
46150
|
}
|
|
45672
46151
|
async function linuxCommand(pid) {
|
|
45673
|
-
const raw = await (0,
|
|
46152
|
+
const raw = await (0, import_promises10.readFile)(`/proc/${pid}/cmdline`, "utf8").catch(() => null);
|
|
45674
46153
|
return raw === null ? null : normalizeCommand(raw.replaceAll("\0", " "));
|
|
45675
46154
|
}
|
|
45676
46155
|
async function darwinCommand(pid) {
|
|
@@ -45764,11 +46243,11 @@ async function mayBeSameProcess(expected, probe = systemProcessProbe) {
|
|
|
45764
46243
|
var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process3.execFile);
|
|
45765
46244
|
var packageJsonSchema = external_exports.object({ version: external_exports.string().min(1) });
|
|
45766
46245
|
function markVersionInUse(bundlePath) {
|
|
45767
|
-
const versionDir = (0,
|
|
45768
|
-
if ((0,
|
|
46246
|
+
const versionDir = (0, import_node_path6.dirname)(bundlePath);
|
|
46247
|
+
if ((0, import_node_path6.basename)((0, import_node_path6.dirname)(versionDir)) !== "versions") return { [Symbol.dispose]: () => {
|
|
45769
46248
|
} };
|
|
45770
|
-
const marker = (0,
|
|
45771
|
-
(0, import_node_fs4.mkdirSync)((0,
|
|
46249
|
+
const marker = (0, import_node_path6.join)(versionDir, ".running", String(process.pid));
|
|
46250
|
+
(0, import_node_fs4.mkdirSync)((0, import_node_path6.dirname)(marker), { recursive: true, mode: 448 });
|
|
45772
46251
|
(0, import_node_fs4.writeFileSync)(marker, "");
|
|
45773
46252
|
const remove = () => (0, import_node_fs4.rmSync)(marker, { force: true });
|
|
45774
46253
|
process.once("exit", remove);
|
|
@@ -45784,36 +46263,36 @@ function markVersionInUse(bundlePath) {
|
|
|
45784
46263
|
var import_node_crypto6 = require("crypto");
|
|
45785
46264
|
var import_node_fs5 = require("fs");
|
|
45786
46265
|
var import_node_os = require("os");
|
|
45787
|
-
var
|
|
46266
|
+
var import_node_path7 = require("path");
|
|
45788
46267
|
function removeStaleEndpoint(endpoint) {
|
|
45789
46268
|
if (!endpoint.startsWith("\\\\.\\pipe\\")) (0, import_node_fs5.rmSync)(endpoint, { force: true });
|
|
45790
46269
|
}
|
|
45791
46270
|
|
|
45792
46271
|
// src/platform/paths.ts
|
|
45793
|
-
var
|
|
46272
|
+
var import_node_path8 = require("path");
|
|
45794
46273
|
function runtimePaths(stateDir) {
|
|
45795
46274
|
return {
|
|
45796
46275
|
stateDir,
|
|
45797
|
-
lock: (0,
|
|
45798
|
-
machine: (0,
|
|
45799
|
-
credential: (0,
|
|
45800
|
-
runs: (0,
|
|
45801
|
-
sessions: (0,
|
|
45802
|
-
sockets: (0,
|
|
45803
|
-
logs: (0,
|
|
45804
|
-
tmp: (0,
|
|
46276
|
+
lock: (0, import_node_path8.join)(stateDir, "runtime.lock"),
|
|
46277
|
+
machine: (0, import_node_path8.join)(stateDir, "machine.json"),
|
|
46278
|
+
credential: (0, import_node_path8.join)(stateDir, "credential.json"),
|
|
46279
|
+
runs: (0, import_node_path8.join)(stateDir, "runs"),
|
|
46280
|
+
sessions: (0, import_node_path8.join)(stateDir, "sessions"),
|
|
46281
|
+
sockets: (0, import_node_path8.join)(stateDir, "s"),
|
|
46282
|
+
logs: (0, import_node_path8.join)(stateDir, "logs"),
|
|
46283
|
+
tmp: (0, import_node_path8.join)(stateDir, "tmp")
|
|
45805
46284
|
};
|
|
45806
46285
|
}
|
|
45807
46286
|
|
|
45808
46287
|
// src/platform/process-memory.ts
|
|
45809
46288
|
var import_node_child_process4 = require("child_process");
|
|
45810
|
-
var
|
|
46289
|
+
var import_promises12 = require("fs/promises");
|
|
45811
46290
|
var import_node_util3 = require("util");
|
|
45812
46291
|
var execFileAsync3 = (0, import_node_util3.promisify)(import_node_child_process4.execFile);
|
|
45813
46292
|
var PROBE_TIMEOUT_MS = 2e3;
|
|
45814
46293
|
async function readProcessRss(pid) {
|
|
45815
46294
|
if (process.platform === "linux") {
|
|
45816
|
-
const status = await (0,
|
|
46295
|
+
const status = await (0, import_promises12.readFile)(`/proc/${pid}/status`, "utf8").catch(() => null);
|
|
45817
46296
|
const kilobytes = status === null ? void 0 : /^VmRSS:\s+(\d+)\s+kB$/m.exec(status)?.[1];
|
|
45818
46297
|
return kilobytes === void 0 ? null : Number(kilobytes) * 1024;
|
|
45819
46298
|
}
|
|
@@ -45830,7 +46309,7 @@ async function readProcessRss(pid) {
|
|
|
45830
46309
|
}
|
|
45831
46310
|
|
|
45832
46311
|
// src/platform/runtime-host.ts
|
|
45833
|
-
var
|
|
46312
|
+
var import_promises13 = require("fs/promises");
|
|
45834
46313
|
var RUNTIME_HOST_KINDS = ["app", "standalone"];
|
|
45835
46314
|
|
|
45836
46315
|
// src/platform/service/exec.ts
|
|
@@ -45845,7 +46324,7 @@ function statusOf(error61) {
|
|
|
45845
46324
|
}
|
|
45846
46325
|
return 1;
|
|
45847
46326
|
}
|
|
45848
|
-
var systemExec = (request2) => new Promise((
|
|
46327
|
+
var systemExec = (request2) => new Promise((resolve9) => {
|
|
45849
46328
|
const child = (0, import_node_child_process5.execFile)(
|
|
45850
46329
|
request2.command,
|
|
45851
46330
|
[...request2.args],
|
|
@@ -45856,7 +46335,7 @@ var systemExec = (request2) => new Promise((resolve7) => {
|
|
|
45856
46335
|
windowsHide: true
|
|
45857
46336
|
},
|
|
45858
46337
|
(error61, stdout, stderr) => {
|
|
45859
|
-
|
|
46338
|
+
resolve9({ status: statusOf(error61), stdout, stderr });
|
|
45860
46339
|
}
|
|
45861
46340
|
);
|
|
45862
46341
|
child.stdin?.on("error", () => {
|
|
@@ -45869,8 +46348,8 @@ init_alan_code();
|
|
|
45869
46348
|
|
|
45870
46349
|
// src/capabilities/providers/commands.ts
|
|
45871
46350
|
var import_node_fs6 = require("fs");
|
|
45872
|
-
var
|
|
45873
|
-
var
|
|
46351
|
+
var import_promises17 = require("fs/promises");
|
|
46352
|
+
var import_node_path9 = require("path");
|
|
45874
46353
|
var PROVIDER_COMMANDS = [
|
|
45875
46354
|
// The engine, not a CLI of its own: `resolveProviderExecutable` finds the bundled one first.
|
|
45876
46355
|
{ backendKind: "alan_code", command: "opencode", name: "Alan Code" },
|
|
@@ -45905,8 +46384,8 @@ function pathDelimiter(platform) {
|
|
|
45905
46384
|
}
|
|
45906
46385
|
async function isRunnable(path, platform) {
|
|
45907
46386
|
try {
|
|
45908
|
-
if (!(await (0,
|
|
45909
|
-
if (platform !== "win32") await (0,
|
|
46387
|
+
if (!(await (0, import_promises17.stat)(path)).isFile()) return false;
|
|
46388
|
+
if (platform !== "win32") await (0, import_promises17.access)(path, import_node_fs6.constants.X_OK);
|
|
45910
46389
|
return true;
|
|
45911
46390
|
} catch {
|
|
45912
46391
|
return false;
|
|
@@ -45923,12 +46402,12 @@ async function resolveCommandOnPath(command, env, platform) {
|
|
|
45923
46402
|
const directories = envValue(env, "PATH").split(pathDelimiter(platform)).map(
|
|
45924
46403
|
(directory) => platform === "win32" ? directory.trim().replace(/^"(.*)"$/, "$1") : directory
|
|
45925
46404
|
).filter(
|
|
45926
|
-
(directory) => platform === "win32" ?
|
|
46405
|
+
(directory) => platform === "win32" ? import_node_path9.win32.isAbsolute(directory) : directory.length > 0
|
|
45927
46406
|
);
|
|
45928
46407
|
const extensions = platform === "win32" ? windowsExtensions(command, env) : [""];
|
|
45929
46408
|
for (const directory of directories) {
|
|
45930
46409
|
for (const extension of extensions) {
|
|
45931
|
-
const candidate = (0,
|
|
46410
|
+
const candidate = (0, import_node_path9.join)(directory, `${command}${extension}`);
|
|
45932
46411
|
if (await isRunnable(candidate, platform)) return candidate;
|
|
45933
46412
|
}
|
|
45934
46413
|
}
|
|
@@ -45963,14 +46442,14 @@ function resolveProviderExecutable(provider4, env, platform) {
|
|
|
45963
46442
|
|
|
45964
46443
|
// src/capabilities/providers/managed.ts
|
|
45965
46444
|
var import_node_crypto7 = require("crypto");
|
|
45966
|
-
var
|
|
45967
|
-
var
|
|
46445
|
+
var import_promises18 = require("fs/promises");
|
|
46446
|
+
var import_node_path10 = require("path");
|
|
45968
46447
|
init_zod();
|
|
45969
46448
|
var VERSION = /^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
45970
46449
|
var selectedSchema = external_exports.record(external_exports.string(), external_exports.string());
|
|
45971
46450
|
async function readManagedProviderVersion(file2, backendKind) {
|
|
45972
46451
|
try {
|
|
45973
|
-
const selected = selectedSchema.parse(JSON.parse(await (0,
|
|
46452
|
+
const selected = selectedSchema.parse(JSON.parse(await (0, import_promises18.readFile)(file2, "utf8")));
|
|
45974
46453
|
const version2 = selected[backendKind];
|
|
45975
46454
|
return version2 !== void 0 && VERSION.test(version2) ? version2 : null;
|
|
45976
46455
|
} catch {
|
|
@@ -45981,8 +46460,8 @@ async function readManagedProviderVersion(file2, backendKind) {
|
|
|
45981
46460
|
// ../shared/dist/node/skill-package.js
|
|
45982
46461
|
var import_node_buffer = require("buffer");
|
|
45983
46462
|
var import_node_crypto8 = require("crypto");
|
|
45984
|
-
var
|
|
45985
|
-
var
|
|
46463
|
+
var import_promises19 = require("fs/promises");
|
|
46464
|
+
var import_node_path11 = require("path");
|
|
45986
46465
|
var import_yaml = __toESM(require_dist(), 1);
|
|
45987
46466
|
init_contracts();
|
|
45988
46467
|
init_domain();
|
|
@@ -46053,7 +46532,7 @@ async function inspectSkillPackage(packageRoot, options = {}) {
|
|
|
46053
46532
|
}
|
|
46054
46533
|
const inspectedFiles = await Promise.all(files.map(readPackageFile));
|
|
46055
46534
|
inspectedFiles.sort(comparePackageFiles);
|
|
46056
|
-
const parsedMetadata = parseSkillMetadata(inspectedFiles.find((file2) => file2.manifest.path === "SKILL.md")?.bytes, options.expectedName === void 0 ? (0,
|
|
46535
|
+
const parsedMetadata = parseSkillMetadata(inspectedFiles.find((file2) => file2.manifest.path === "SKILL.md")?.bytes, options.expectedName === void 0 ? (0, import_node_path11.basename)(root) : options.expectedName);
|
|
46057
46536
|
const manifestFiles = inspectedFiles.map((file2) => file2.manifest);
|
|
46058
46537
|
const diagnostics = [
|
|
46059
46538
|
...parsedMetadata.conformance,
|
|
@@ -46071,11 +46550,11 @@ async function inspectSkillPackage(packageRoot, options = {}) {
|
|
|
46071
46550
|
};
|
|
46072
46551
|
}
|
|
46073
46552
|
async function requirePackageRoot(packageRoot) {
|
|
46074
|
-
const root = await (0,
|
|
46553
|
+
const root = await (0, import_promises19.realpath)((0, import_node_path11.resolve)(packageRoot)).catch(() => null);
|
|
46075
46554
|
if (!root) {
|
|
46076
46555
|
throw new SkillPackageError("INVALID_PACKAGE_ROOT", "Skill package directory does not exist");
|
|
46077
46556
|
}
|
|
46078
|
-
const rootStat = await (0,
|
|
46557
|
+
const rootStat = await (0, import_promises19.lstat)(root);
|
|
46079
46558
|
if (!rootStat.isDirectory()) {
|
|
46080
46559
|
throw new SkillPackageError("INVALID_PACKAGE_ROOT", "Skill package root must be a directory");
|
|
46081
46560
|
}
|
|
@@ -46095,13 +46574,13 @@ async function walkPackage(root, ignoredPaths) {
|
|
|
46095
46574
|
}
|
|
46096
46575
|
return files;
|
|
46097
46576
|
async function walkDirectory(directory) {
|
|
46098
|
-
const entries = await (0,
|
|
46577
|
+
const entries = await (0, import_promises19.readdir)(directory, { withFileTypes: true });
|
|
46099
46578
|
for (const entry of entries) {
|
|
46100
|
-
const absolutePath = (0,
|
|
46579
|
+
const absolutePath = (0, import_node_path11.resolve)(directory, entry.name);
|
|
46101
46580
|
const normalizedPath = normalizeRelativePath(root, absolutePath);
|
|
46102
46581
|
if (isIgnored(normalizedPath, entry.name, entry.isDirectory(), ignored2))
|
|
46103
46582
|
continue;
|
|
46104
|
-
const entryStat = await (0,
|
|
46583
|
+
const entryStat = await (0, import_promises19.lstat)(absolutePath);
|
|
46105
46584
|
if (entryStat.isSymbolicLink()) {
|
|
46106
46585
|
throw new SkillPackageError("SYMLINK_BLOCKED", `Nested symbolic links are not allowed in Skill packages: ${normalizedPath}`, normalizedPath);
|
|
46107
46586
|
}
|
|
@@ -46164,12 +46643,12 @@ function globToRegExp(pattern) {
|
|
|
46164
46643
|
return new RegExp(`${source}(?:/.*)?$`);
|
|
46165
46644
|
}
|
|
46166
46645
|
function normalizeRelativePath(root, absolutePath) {
|
|
46167
|
-
const nativeRelativePath = (0,
|
|
46168
|
-
if (!nativeRelativePath || nativeRelativePath.startsWith(`..${
|
|
46646
|
+
const nativeRelativePath = (0, import_node_path11.relative)(root, absolutePath);
|
|
46647
|
+
if (!nativeRelativePath || nativeRelativePath.startsWith(`..${import_node_path11.sep}`) || nativeRelativePath === "..") {
|
|
46169
46648
|
throw new SkillPackageError("INVALID_PATH", "Skill package path escapes its root");
|
|
46170
46649
|
}
|
|
46171
|
-
const normalized2 = nativeRelativePath.split(
|
|
46172
|
-
if (normalized2.includes("\0") || normalized2.includes("\uFFFD") ||
|
|
46650
|
+
const normalized2 = nativeRelativePath.split(import_node_path11.sep).join("/").normalize("NFC");
|
|
46651
|
+
if (normalized2.includes("\0") || normalized2.includes("\uFFFD") || import_node_path11.posix.isAbsolute(normalized2)) {
|
|
46173
46652
|
throw new SkillPackageError("INVALID_PATH", `Invalid Skill package path: ${normalized2}`);
|
|
46174
46653
|
}
|
|
46175
46654
|
return normalized2;
|
|
@@ -46204,13 +46683,13 @@ function requireSafeFile(path, size, normalizedPaths) {
|
|
|
46204
46683
|
}
|
|
46205
46684
|
}
|
|
46206
46685
|
function isSecretPath(path) {
|
|
46207
|
-
const name =
|
|
46686
|
+
const name = import_node_path11.posix.basename(path).toLowerCase();
|
|
46208
46687
|
if (SECRET_BASENAMES.has(name) || name.startsWith(".env."))
|
|
46209
46688
|
return true;
|
|
46210
46689
|
return name.endsWith(".private-key.pem") || name.endsWith(".private-key.key");
|
|
46211
46690
|
}
|
|
46212
46691
|
async function readPackageFile(file2) {
|
|
46213
|
-
const bytes = await (0,
|
|
46692
|
+
const bytes = await (0, import_promises19.readFile)(file2.absolutePath);
|
|
46214
46693
|
return {
|
|
46215
46694
|
bytes,
|
|
46216
46695
|
manifest: {
|
|
@@ -46232,12 +46711,12 @@ function classifyFileKind(path) {
|
|
|
46232
46711
|
return "reference";
|
|
46233
46712
|
if (path.startsWith("assets/"))
|
|
46234
46713
|
return "asset";
|
|
46235
|
-
if (/^(?:licen[cs]e|copying|notice)(?:\.|$)/i.test(
|
|
46714
|
+
if (/^(?:licen[cs]e|copying|notice)(?:\.|$)/i.test(import_node_path11.posix.basename(path)))
|
|
46236
46715
|
return "license";
|
|
46237
46716
|
return "other";
|
|
46238
46717
|
}
|
|
46239
46718
|
function classifyPreview(path, bytes) {
|
|
46240
|
-
const extension =
|
|
46719
|
+
const extension = import_node_path11.posix.extname(path).toLowerCase();
|
|
46241
46720
|
if (IMAGE_EXTENSIONS2.has(extension))
|
|
46242
46721
|
return "image";
|
|
46243
46722
|
if (bytes.includes(0))
|
|
@@ -46341,7 +46820,7 @@ function normalizePackageReference(value) {
|
|
|
46341
46820
|
const withoutSuffix = trimmed4.split(/[?#]/, 1)[0];
|
|
46342
46821
|
if (!withoutSuffix)
|
|
46343
46822
|
return null;
|
|
46344
|
-
const normalized2 =
|
|
46823
|
+
const normalized2 = import_node_path11.posix.normalize(withoutSuffix).replace(/^\.\//, "").normalize("NFC");
|
|
46345
46824
|
if (normalized2 === ".." || normalized2.startsWith("../"))
|
|
46346
46825
|
return null;
|
|
46347
46826
|
return normalized2;
|
|
@@ -46380,8 +46859,8 @@ function uint642(value) {
|
|
|
46380
46859
|
}
|
|
46381
46860
|
|
|
46382
46861
|
// src/capabilities/skills/store.ts
|
|
46383
|
-
var
|
|
46384
|
-
var
|
|
46862
|
+
var import_promises20 = require("fs/promises");
|
|
46863
|
+
var import_node_path12 = require("path");
|
|
46385
46864
|
|
|
46386
46865
|
// ../shared/dist/node/alan-skill-identity.js
|
|
46387
46866
|
var import_node_crypto9 = require("crypto");
|
|
@@ -46404,21 +46883,21 @@ function alanSkillVersionId(slug, contentHash) {
|
|
|
46404
46883
|
init_runtime_v2();
|
|
46405
46884
|
init_zod();
|
|
46406
46885
|
function skillsLayout(stateDir, home) {
|
|
46407
|
-
const root = (0,
|
|
46886
|
+
const root = (0, import_node_path12.join)(stateDir, "skills");
|
|
46408
46887
|
return {
|
|
46409
46888
|
root,
|
|
46410
|
-
installedFile: (0,
|
|
46411
|
-
retiredFile: (0,
|
|
46412
|
-
localFile: (0,
|
|
46413
|
-
versionsDir: (0,
|
|
46414
|
-
tmpDir: (0,
|
|
46415
|
-
pluginDir: (0,
|
|
46416
|
-
pluginSkillsDir: (0,
|
|
46417
|
-
nativeDir: home === void 0 || home === "" ? null : (0,
|
|
46889
|
+
installedFile: (0, import_node_path12.join)(root, "installed.json"),
|
|
46890
|
+
retiredFile: (0, import_node_path12.join)(root, "retired.json"),
|
|
46891
|
+
localFile: (0, import_node_path12.join)(root, "local.json"),
|
|
46892
|
+
versionsDir: (0, import_node_path12.join)(root, "versions"),
|
|
46893
|
+
tmpDir: (0, import_node_path12.join)(root, "tmp"),
|
|
46894
|
+
pluginDir: (0, import_node_path12.join)(root, "alan-plugin"),
|
|
46895
|
+
pluginSkillsDir: (0, import_node_path12.join)(root, "alan-plugin", "skills"),
|
|
46896
|
+
nativeDir: home === void 0 || home === "" ? null : (0, import_node_path12.join)(home, ".agents", "skills")
|
|
46418
46897
|
};
|
|
46419
46898
|
}
|
|
46420
46899
|
function packageDirectory(layout, versionId) {
|
|
46421
|
-
return (0,
|
|
46900
|
+
return (0, import_node_path12.join)(layout.versionsDir, versionId);
|
|
46422
46901
|
}
|
|
46423
46902
|
var installedFileSchema = external_exports.object({ skills: external_exports.array(desiredMachineSkillSchema) });
|
|
46424
46903
|
async function readInstalledSkills(layout) {
|
|
@@ -46445,7 +46924,7 @@ async function readLocalSkills(layout) {
|
|
|
46445
46924
|
async function isLocalSkillCurrent(entry, contentHash, ignoredPaths) {
|
|
46446
46925
|
if (entry.contentHash !== contentHash) return false;
|
|
46447
46926
|
try {
|
|
46448
|
-
if (await (0,
|
|
46927
|
+
if (await (0, import_promises20.realpath)(entry.path) !== entry.path) return false;
|
|
46449
46928
|
const inspected = await inspectSkillPackage(entry.path, { expectedName: null, ignoredPaths });
|
|
46450
46929
|
return inspected.contentHash === contentHash;
|
|
46451
46930
|
} catch {
|
|
@@ -46460,7 +46939,7 @@ async function resolveLocalSkill(local, invocation) {
|
|
|
46460
46939
|
}
|
|
46461
46940
|
async function hasSkillFile(directory) {
|
|
46462
46941
|
try {
|
|
46463
|
-
return (await (0,
|
|
46942
|
+
return (await (0, import_promises20.stat)((0, import_node_path12.join)(directory, "SKILL.md"))).isFile();
|
|
46464
46943
|
} catch {
|
|
46465
46944
|
return false;
|
|
46466
46945
|
}
|
|
@@ -46478,7 +46957,7 @@ async function isIntact(layout, skill) {
|
|
|
46478
46957
|
async function resolveNativeBuiltIn(layout, invocation, baked) {
|
|
46479
46958
|
const slug = invocation.displayName;
|
|
46480
46959
|
if (layout.nativeDir === null || invocation.skillId !== alanSkillId(slug)) return null;
|
|
46481
|
-
const directory = (0,
|
|
46960
|
+
const directory = (0, import_node_path12.join)(layout.nativeDir, slug);
|
|
46482
46961
|
try {
|
|
46483
46962
|
const inspected = await inspectSkillPackage(directory, { expectedName: slug });
|
|
46484
46963
|
if (baked === "exact" && alanSkillVersionId(slug, inspected.contentHash) !== invocation.versionId)
|
|
@@ -46524,10 +47003,10 @@ async function availableSkillIndex(layout) {
|
|
|
46524
47003
|
});
|
|
46525
47004
|
}
|
|
46526
47005
|
if (layout.nativeDir !== null) {
|
|
46527
|
-
const entries = await (0,
|
|
47006
|
+
const entries = await (0, import_promises20.readdir)(layout.nativeDir, { withFileTypes: true }).catch(() => []);
|
|
46528
47007
|
for (const entry of entries) {
|
|
46529
47008
|
if (entry.isDirectory() || entry.isSymbolicLink())
|
|
46530
|
-
candidates2.push({ directory: (0,
|
|
47009
|
+
candidates2.push({ directory: (0, import_node_path12.join)(layout.nativeDir, entry.name) });
|
|
46531
47010
|
}
|
|
46532
47011
|
}
|
|
46533
47012
|
const bounded = candidates2.slice(0, 2e3);
|
|
@@ -46557,8 +47036,8 @@ async function inspectIndexedSkill(directory, contentHash) {
|
|
|
46557
47036
|
// src/capabilities/skills/native-index.ts
|
|
46558
47037
|
var import_node_crypto10 = require("crypto");
|
|
46559
47038
|
var import_node_fs7 = require("fs");
|
|
46560
|
-
var
|
|
46561
|
-
var
|
|
47039
|
+
var import_promises21 = require("fs/promises");
|
|
47040
|
+
var import_node_path13 = require("path");
|
|
46562
47041
|
var ALAN_SKILLS_PLUGIN_NAME = "alan";
|
|
46563
47042
|
var PLUGIN_MANIFEST = `${JSON.stringify(
|
|
46564
47043
|
{
|
|
@@ -46570,18 +47049,18 @@ var PLUGIN_MANIFEST = `${JSON.stringify(
|
|
|
46570
47049
|
)}
|
|
46571
47050
|
`;
|
|
46572
47051
|
function installedSkillFolders(layout) {
|
|
46573
|
-
return (0, import_node_fs7.existsSync)((0,
|
|
47052
|
+
return (0, import_node_fs7.existsSync)((0, import_node_path13.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
|
|
46574
47053
|
}
|
|
46575
47054
|
|
|
46576
47055
|
// src/capabilities/workspace/index.ts
|
|
46577
|
-
var
|
|
47056
|
+
var import_node_path16 = require("path");
|
|
46578
47057
|
|
|
46579
47058
|
// src/capabilities/workspace/approved-paths.ts
|
|
46580
|
-
var
|
|
47059
|
+
var import_promises22 = require("fs/promises");
|
|
46581
47060
|
init_zod();
|
|
46582
47061
|
|
|
46583
47062
|
// src/capabilities/workspace/paths.ts
|
|
46584
|
-
var
|
|
47063
|
+
var import_node_path14 = require("path");
|
|
46585
47064
|
function stripWin32Namespace(path) {
|
|
46586
47065
|
if (/^\\\\\?\\UNC\\/i.test(path)) return `\\\\${path.slice(8)}`;
|
|
46587
47066
|
if (path.startsWith("\\\\?\\")) return path.slice(4);
|
|
@@ -46589,15 +47068,15 @@ function stripWin32Namespace(path) {
|
|
|
46589
47068
|
}
|
|
46590
47069
|
function comparablePath(path, platform) {
|
|
46591
47070
|
if (platform === "win32") {
|
|
46592
|
-
const normalized3 =
|
|
47071
|
+
const normalized3 = import_node_path14.win32.normalize(stripWin32Namespace(path).replaceAll("/", "\\"));
|
|
46593
47072
|
const trimmed4 = normalized3.length > 3 || !/^[a-z]:\\$/i.test(normalized3) ? normalized3.replace(/\\+$/, "") : normalized3;
|
|
46594
47073
|
return trimmed4.toLowerCase();
|
|
46595
47074
|
}
|
|
46596
|
-
const normalized2 =
|
|
47075
|
+
const normalized2 = import_node_path14.posix.normalize(path);
|
|
46597
47076
|
return normalized2.length > 1 ? normalized2.replace(/\/+$/, "") : normalized2;
|
|
46598
47077
|
}
|
|
46599
47078
|
function isAbsoluteFor(path, platform) {
|
|
46600
|
-
return platform === "win32" ?
|
|
47079
|
+
return platform === "win32" ? import_node_path14.win32.isAbsolute(path) : import_node_path14.posix.isAbsolute(path);
|
|
46601
47080
|
}
|
|
46602
47081
|
function isWithin(root, candidate, platform) {
|
|
46603
47082
|
const separator = platform === "win32" ? "\\" : "/";
|
|
@@ -46615,7 +47094,7 @@ var storeSchema = external_exports.object({
|
|
|
46615
47094
|
});
|
|
46616
47095
|
async function realpathOrNull(path) {
|
|
46617
47096
|
try {
|
|
46618
|
-
return await (0,
|
|
47097
|
+
return await (0, import_promises22.realpath)(path);
|
|
46619
47098
|
} catch (error61) {
|
|
46620
47099
|
const code = errnoCode(error61);
|
|
46621
47100
|
if (code === "ENOENT" || code === "ENOTDIR" || code === "EACCES" || code === "EPERM") {
|
|
@@ -46675,8 +47154,8 @@ async function openApprovedPaths(options) {
|
|
|
46675
47154
|
|
|
46676
47155
|
// src/capabilities/workspace/locks.ts
|
|
46677
47156
|
var import_node_crypto11 = require("crypto");
|
|
46678
|
-
var
|
|
46679
|
-
var
|
|
47157
|
+
var import_promises23 = require("fs/promises");
|
|
47158
|
+
var import_node_path15 = require("path");
|
|
46680
47159
|
init_zod();
|
|
46681
47160
|
var LOCK_FORMAT = 1;
|
|
46682
47161
|
var EXCLUSIVE_FILE = "exclusive.json";
|
|
@@ -46696,7 +47175,7 @@ function repositoryLockKey(commonDir, platform) {
|
|
|
46696
47175
|
async function readOwner(path) {
|
|
46697
47176
|
let text2;
|
|
46698
47177
|
try {
|
|
46699
|
-
text2 = await (0,
|
|
47178
|
+
text2 = await (0, import_promises23.readFile)(path, "utf8");
|
|
46700
47179
|
} catch (error61) {
|
|
46701
47180
|
if (errnoCode(error61) === "ENOENT") return { kind: "missing" };
|
|
46702
47181
|
return { kind: "unreadable" };
|
|
@@ -46717,7 +47196,7 @@ async function removeIfSame(path, expected) {
|
|
|
46717
47196
|
if (current.kind !== "owner" || current.owner.since !== expected.since) return;
|
|
46718
47197
|
if (current.owner.pid !== expected.pid || current.owner.holder !== expected.holder) return;
|
|
46719
47198
|
}
|
|
46720
|
-
await (0,
|
|
47199
|
+
await (0, import_promises23.unlink)(path).catch((error61) => {
|
|
46721
47200
|
if (errnoCode(error61) !== "ENOENT") throw error61;
|
|
46722
47201
|
});
|
|
46723
47202
|
}
|
|
@@ -46742,7 +47221,7 @@ function openRepositoryLocks(options) {
|
|
|
46742
47221
|
await removeIfSame(path, read.owner);
|
|
46743
47222
|
return null;
|
|
46744
47223
|
}
|
|
46745
|
-
const age = await (0,
|
|
47224
|
+
const age = await (0, import_promises23.stat)(path).then(
|
|
46746
47225
|
(info) => clock.now() - info.mtimeMs,
|
|
46747
47226
|
() => 0
|
|
46748
47227
|
);
|
|
@@ -46756,13 +47235,13 @@ function openRepositoryLocks(options) {
|
|
|
46756
47235
|
});
|
|
46757
47236
|
const folder = async (commonDir) => {
|
|
46758
47237
|
const key = repositoryLockKey(commonDir, platform);
|
|
46759
|
-
const dir = (0,
|
|
46760
|
-
await (0,
|
|
47238
|
+
const dir = (0, import_node_path15.join)(options.dir, key);
|
|
47239
|
+
await (0, import_promises23.mkdir)(dir, { recursive: true, mode: 448 });
|
|
46761
47240
|
return { key, dir };
|
|
46762
47241
|
};
|
|
46763
47242
|
const createExclusive = async (path, owner) => {
|
|
46764
47243
|
try {
|
|
46765
|
-
const handle = await (0,
|
|
47244
|
+
const handle = await (0, import_promises23.open)(path, "wx", 384);
|
|
46766
47245
|
try {
|
|
46767
47246
|
await handle.writeFile(JSON.stringify(owner));
|
|
46768
47247
|
} finally {
|
|
@@ -46775,10 +47254,10 @@ function openRepositoryLocks(options) {
|
|
|
46775
47254
|
}
|
|
46776
47255
|
};
|
|
46777
47256
|
const liveRun = async (dir) => {
|
|
46778
|
-
const entries = await (0,
|
|
47257
|
+
const entries = await (0, import_promises23.readdir)(dir);
|
|
46779
47258
|
for (const entry of entries) {
|
|
46780
47259
|
if (!entry.startsWith(RUN_FILE_PREFIX)) continue;
|
|
46781
|
-
const holder = await heldBy((0,
|
|
47260
|
+
const holder = await heldBy((0, import_node_path15.join)(dir, entry));
|
|
46782
47261
|
if (holder !== null) return holder;
|
|
46783
47262
|
}
|
|
46784
47263
|
return null;
|
|
@@ -46786,7 +47265,7 @@ function openRepositoryLocks(options) {
|
|
|
46786
47265
|
return {
|
|
46787
47266
|
tryExclusive: async (commonDir, operationId) => {
|
|
46788
47267
|
const { key, dir } = await folder(commonDir);
|
|
46789
|
-
const path = (0,
|
|
47268
|
+
const path = (0, import_node_path15.join)(dir, EXCLUSIVE_FILE);
|
|
46790
47269
|
const owner = await self(operationId);
|
|
46791
47270
|
if (!await createExclusive(path, owner)) {
|
|
46792
47271
|
const holder = await heldBy(path);
|
|
@@ -46805,10 +47284,10 @@ function openRepositoryLocks(options) {
|
|
|
46805
47284
|
tryShared: async (commonDir, runId) => {
|
|
46806
47285
|
const { key, dir } = await folder(commonDir);
|
|
46807
47286
|
const file2 = `${RUN_FILE_PREFIX}${(0, import_node_crypto11.createHash)("sha256").update(runId).digest("hex").slice(0, 32)}.json`;
|
|
46808
|
-
const path = (0,
|
|
47287
|
+
const path = (0, import_node_path15.join)(dir, file2);
|
|
46809
47288
|
const owner = await self(runId);
|
|
46810
47289
|
await writeJsonFileAtomic(path, owner);
|
|
46811
|
-
const operation = await heldBy((0,
|
|
47290
|
+
const operation = await heldBy((0, import_node_path15.join)(dir, EXCLUSIVE_FILE));
|
|
46812
47291
|
if (operation !== null) {
|
|
46813
47292
|
await removeIfSame(path, owner);
|
|
46814
47293
|
return { kind: "busy", holder: operation };
|
|
@@ -46820,30 +47299,30 @@ function openRepositoryLocks(options) {
|
|
|
46820
47299
|
|
|
46821
47300
|
// src/cli/config.ts
|
|
46822
47301
|
var import_node_os7 = require("os");
|
|
46823
|
-
var
|
|
47302
|
+
var import_node_path33 = require("path");
|
|
46824
47303
|
init_zod();
|
|
46825
47304
|
|
|
46826
47305
|
// src/client/locate.ts
|
|
46827
|
-
var
|
|
47306
|
+
var import_node_path17 = require("path");
|
|
46828
47307
|
var RUNTIME_PROFILES = ["production", "staging", "development", "local"];
|
|
46829
47308
|
function defaultStateDir({ profile, platform, home, env }) {
|
|
46830
47309
|
if (platform === "win32") {
|
|
46831
|
-
return (0,
|
|
47310
|
+
return (0, import_node_path17.join)(env.LOCALAPPDATA ?? (0, import_node_path17.join)(home, "AppData", "Local"), "Alan", profile);
|
|
46832
47311
|
}
|
|
46833
|
-
return (0,
|
|
47312
|
+
return (0, import_node_path17.join)(env.XDG_STATE_HOME ?? (0, import_node_path17.join)(home, ".local", "state"), "alan", profile);
|
|
46834
47313
|
}
|
|
46835
47314
|
function defaultInstallDir({ platform, home, env }) {
|
|
46836
47315
|
if (platform === "win32") {
|
|
46837
|
-
return (0,
|
|
47316
|
+
return (0, import_node_path17.join)(env.LOCALAPPDATA ?? (0, import_node_path17.join)(home, "AppData", "Local"), "Alan", "runtime");
|
|
46838
47317
|
}
|
|
46839
|
-
return (0,
|
|
47318
|
+
return (0, import_node_path17.join)(env.XDG_DATA_HOME ?? (0, import_node_path17.join)(home, ".local", "share"), "alan", "runtime");
|
|
46840
47319
|
}
|
|
46841
47320
|
|
|
46842
47321
|
// src/sessions/index.ts
|
|
46843
47322
|
var import_node_crypto16 = require("crypto");
|
|
46844
|
-
var
|
|
47323
|
+
var import_promises41 = require("fs/promises");
|
|
46845
47324
|
var import_node_os6 = require("os");
|
|
46846
|
-
var
|
|
47325
|
+
var import_node_path32 = require("path");
|
|
46847
47326
|
|
|
46848
47327
|
// src/holder/control-client.ts
|
|
46849
47328
|
var import_node_crypto12 = require("crypto");
|
|
@@ -47010,7 +47489,7 @@ function createProviderDrivers(options) {
|
|
|
47010
47489
|
}
|
|
47011
47490
|
|
|
47012
47491
|
// src/holder/engine-records.ts
|
|
47013
|
-
var
|
|
47492
|
+
var import_node_path18 = require("path");
|
|
47014
47493
|
init_zod();
|
|
47015
47494
|
var ENGINES_FILE = "engines.json";
|
|
47016
47495
|
var engineRecordSchema = external_exports.object({
|
|
@@ -47020,7 +47499,7 @@ var engineRecordSchema = external_exports.object({
|
|
|
47020
47499
|
});
|
|
47021
47500
|
var engineRecordsSchema = external_exports.object({ engines: external_exports.array(engineRecordSchema) });
|
|
47022
47501
|
function engineRecordsPath(sessionDir) {
|
|
47023
|
-
return (0,
|
|
47502
|
+
return (0, import_node_path18.join)(sessionDir, ENGINES_FILE);
|
|
47024
47503
|
}
|
|
47025
47504
|
function recordSpawnedEngines(path, clock, log) {
|
|
47026
47505
|
const live = /* @__PURE__ */ new Map();
|
|
@@ -47075,17 +47554,17 @@ function createConversationMcpAuthorization(options) {
|
|
|
47075
47554
|
}
|
|
47076
47555
|
|
|
47077
47556
|
// src/holder/mcp-helper-access.ts
|
|
47078
|
-
var
|
|
47557
|
+
var import_promises30 = require("fs/promises");
|
|
47079
47558
|
function createHelperMcpAccess(options) {
|
|
47080
47559
|
return {
|
|
47081
47560
|
[Symbol.asyncDispose]: async () => {
|
|
47082
|
-
await (0,
|
|
47561
|
+
await (0, import_promises30.rm)(options.credentialPath, { force: true });
|
|
47083
47562
|
},
|
|
47084
47563
|
url: options.managedMcp.url,
|
|
47085
47564
|
authorization: async (signal) => {
|
|
47086
47565
|
const authorization = await options.managedMcp.authorization(signal);
|
|
47087
47566
|
if (authorization === void 0 || signal.aborted) {
|
|
47088
|
-
await (0,
|
|
47567
|
+
await (0, import_promises30.rm)(options.credentialPath, { force: true });
|
|
47089
47568
|
return void 0;
|
|
47090
47569
|
}
|
|
47091
47570
|
const credential = {
|
|
@@ -47100,8 +47579,8 @@ function createHelperMcpAccess(options) {
|
|
|
47100
47579
|
}
|
|
47101
47580
|
|
|
47102
47581
|
// src/holder/run-inputs.ts
|
|
47103
|
-
var
|
|
47104
|
-
var
|
|
47582
|
+
var import_promises31 = require("fs/promises");
|
|
47583
|
+
var import_node_path19 = require("path");
|
|
47105
47584
|
init_dist();
|
|
47106
47585
|
var NO_RUN_INPUTS = {
|
|
47107
47586
|
attachments: [],
|
|
@@ -47115,18 +47594,18 @@ function safeFilename(filename) {
|
|
|
47115
47594
|
return safe || "attachment";
|
|
47116
47595
|
}
|
|
47117
47596
|
async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
|
|
47118
|
-
const dir = (0,
|
|
47597
|
+
const dir = (0, import_node_path19.join)(tmpDir, "runs", spec.runId);
|
|
47119
47598
|
const cleanup = async () => {
|
|
47120
|
-
await (0,
|
|
47599
|
+
await (0, import_promises31.rm)(dir, { recursive: true, force: true });
|
|
47121
47600
|
};
|
|
47122
47601
|
try {
|
|
47123
47602
|
const credential = await source.fetchProviderCredential(spec.runId, signal);
|
|
47124
47603
|
const attachments = [];
|
|
47125
|
-
if (spec.attachments?.length) await (0,
|
|
47604
|
+
if (spec.attachments?.length) await (0, import_promises31.mkdir)(dir, { recursive: true, mode: 448 });
|
|
47126
47605
|
for (const [index, attachment] of (spec.attachments ?? []).entries()) {
|
|
47127
47606
|
const bytes = await source.downloadAttachment(spec.runId, attachment.id, signal);
|
|
47128
|
-
const path = (0,
|
|
47129
|
-
await (0,
|
|
47607
|
+
const path = (0, import_node_path19.join)(dir, `${index}-${safeFilename(attachment.filename)}`);
|
|
47608
|
+
await (0, import_promises31.writeFile)(path, bytes, { mode: 384 });
|
|
47130
47609
|
const imageMimeType = attachment.kind === "image" ? detectImageMimeType(Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)) : null;
|
|
47131
47610
|
attachments.push({
|
|
47132
47611
|
id: attachment.id,
|
|
@@ -47157,27 +47636,27 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
|
|
|
47157
47636
|
var import_node_crypto15 = require("crypto");
|
|
47158
47637
|
var import_node_fs11 = require("fs");
|
|
47159
47638
|
var import_node_net2 = require("net");
|
|
47160
|
-
var
|
|
47639
|
+
var import_node_path31 = require("path");
|
|
47161
47640
|
init_runtime_v2();
|
|
47162
47641
|
|
|
47163
47642
|
// src/holder/admission.ts
|
|
47164
47643
|
var import_node_fs9 = require("fs");
|
|
47165
|
-
var
|
|
47644
|
+
var import_promises37 = require("fs/promises");
|
|
47166
47645
|
var import_node_os5 = require("os");
|
|
47167
|
-
var
|
|
47646
|
+
var import_node_path27 = require("path");
|
|
47168
47647
|
init_constants();
|
|
47169
47648
|
|
|
47170
47649
|
// ../shared/dist/node/local-workspace.js
|
|
47171
47650
|
var import_node_fs8 = require("fs");
|
|
47172
47651
|
var import_node_os4 = require("os");
|
|
47173
|
-
var
|
|
47652
|
+
var import_node_path20 = require("path");
|
|
47174
47653
|
function resolveAlanDefaultWorkspacePath(homeDirectory = (0, import_node_os4.homedir)()) {
|
|
47175
|
-
return (0,
|
|
47654
|
+
return (0, import_node_path20.join)(homeDirectory, ".alan", "workspace");
|
|
47176
47655
|
}
|
|
47177
47656
|
|
|
47178
47657
|
// src/holder/admission-relocation.ts
|
|
47179
|
-
var
|
|
47180
|
-
var
|
|
47658
|
+
var import_promises32 = require("fs/promises");
|
|
47659
|
+
var import_node_path21 = require("path");
|
|
47181
47660
|
var MAX_RELOCATION_CANDIDATES = 200;
|
|
47182
47661
|
var RELOCATION_BUDGET_MS = 2e4;
|
|
47183
47662
|
function repositoryIdentity(url2) {
|
|
@@ -47212,8 +47691,8 @@ async function originIdentity(git, path, signal) {
|
|
|
47212
47691
|
}
|
|
47213
47692
|
async function childDirectories(parent, limit) {
|
|
47214
47693
|
try {
|
|
47215
|
-
const entries = await (0,
|
|
47216
|
-
return entries.filter((entry) => entry.isDirectory()).slice(0, limit).map((entry) => (0,
|
|
47694
|
+
const entries = await (0, import_promises32.readdir)(parent, { withFileTypes: true });
|
|
47695
|
+
return entries.filter((entry) => entry.isDirectory()).slice(0, limit).map((entry) => (0, import_node_path21.join)(parent, entry.name));
|
|
47217
47696
|
} catch {
|
|
47218
47697
|
return [];
|
|
47219
47698
|
}
|
|
@@ -47221,7 +47700,7 @@ async function childDirectories(parent, limit) {
|
|
|
47221
47700
|
async function candidateFolders(search) {
|
|
47222
47701
|
const roots = /* @__PURE__ */ new Map();
|
|
47223
47702
|
for (const path of [search.missingPath, ...search.approvedWorkspacePaths]) {
|
|
47224
|
-
const parent = (0,
|
|
47703
|
+
const parent = (0, import_node_path21.dirname)((0, import_node_path21.resolve)(path));
|
|
47225
47704
|
roots.set(comparablePath(parent, search.platform), parent);
|
|
47226
47705
|
}
|
|
47227
47706
|
const candidates2 = /* @__PURE__ */ new Map();
|
|
@@ -47247,28 +47726,262 @@ async function discoverRelocatedWorkspace(search) {
|
|
|
47247
47726
|
return matches[0] ?? null;
|
|
47248
47727
|
}
|
|
47249
47728
|
|
|
47250
|
-
// src/holder/
|
|
47251
|
-
var
|
|
47252
|
-
var
|
|
47253
|
-
|
|
47254
|
-
|
|
47255
|
-
|
|
47729
|
+
// src/holder/agent-context.ts
|
|
47730
|
+
var import_promises33 = require("fs/promises");
|
|
47731
|
+
var import_node_path22 = require("path");
|
|
47732
|
+
|
|
47733
|
+
// ../agent-core/dist/prompt.js
|
|
47734
|
+
init_chunk_GI3ZGXTY();
|
|
47735
|
+
|
|
47736
|
+
// src/holder/agent-context.ts
|
|
47737
|
+
async function readText2(path) {
|
|
47738
|
+
return (0, import_promises33.readFile)(path, "utf8").then(
|
|
47739
|
+
(text2) => text2.trim(),
|
|
47740
|
+
() => null
|
|
47741
|
+
);
|
|
47256
47742
|
}
|
|
47257
|
-
function
|
|
47258
|
-
const
|
|
47259
|
-
|
|
47260
|
-
const
|
|
47261
|
-
|
|
47743
|
+
async function startCommandState(statusPath) {
|
|
47744
|
+
const [status, exit] = await Promise.all([readText2(statusPath), readText2(`${statusPath}.exit`)]);
|
|
47745
|
+
if (status === null || status === "started") return { state: "pending" };
|
|
47746
|
+
const failed = /^failed (\d+)$/.exec(status);
|
|
47747
|
+
if (failed) return { state: "failed", exitCode: Number(failed[1]) };
|
|
47748
|
+
if (exit === null) return { state: "running" };
|
|
47749
|
+
const code = Number(exit);
|
|
47750
|
+
return code === 0 ? { state: "exited_ok" } : { state: "failed", exitCode: code };
|
|
47751
|
+
}
|
|
47752
|
+
function createAgentContext(deps) {
|
|
47753
|
+
const statusPath = (0, import_node_path22.join)(deps.homeDir, ".alan", "start-commands.status");
|
|
47754
|
+
const logPath = (0, import_node_path22.join)(deps.homeDir, ".alan", "start-commands.log");
|
|
47755
|
+
return async (spec, problems) => {
|
|
47756
|
+
const file2 = (0, import_node_path22.join)(deps.dir, `${spec.conversationId}.json`);
|
|
47757
|
+
const saved = await readJsonFile(file2, agentContextSnapshotSchema);
|
|
47758
|
+
const known = saved.kind === "ok" ? saved.value : void 0;
|
|
47759
|
+
const hasEnvironment = (spec.agentContext ?? known)?.environment !== void 0;
|
|
47760
|
+
const start = hasEnvironment ? await startCommandState(statusPath) : void 0;
|
|
47761
|
+
const snapshot2 = agentContextSnapshot({
|
|
47762
|
+
spec,
|
|
47763
|
+
...spec.approvedWorkspacePaths?.[0] ? { workspaceRoot: spec.approvedWorkspacePaths[0] } : {},
|
|
47764
|
+
problems,
|
|
47765
|
+
...start ? { start } : {},
|
|
47766
|
+
startLogPath: logPath,
|
|
47767
|
+
...known ? { known } : {}
|
|
47768
|
+
});
|
|
47769
|
+
if (snapshot2 === null) return void 0;
|
|
47770
|
+
const rendered = renderAgentContext(snapshot2, known);
|
|
47771
|
+
return {
|
|
47772
|
+
full: rendered.full,
|
|
47773
|
+
...rendered.update ? { update: rendered.update } : {},
|
|
47774
|
+
save: () => writeJsonFileAtomic(file2, snapshot2)
|
|
47775
|
+
};
|
|
47776
|
+
};
|
|
47262
47777
|
}
|
|
47778
|
+
|
|
47779
|
+
// src/holder/checkout-refresh.ts
|
|
47780
|
+
var import_node_path25 = require("path");
|
|
47781
|
+
|
|
47782
|
+
// src/holder/claim-once.ts
|
|
47783
|
+
var import_node_crypto14 = require("crypto");
|
|
47784
|
+
var import_promises34 = require("fs/promises");
|
|
47785
|
+
var import_node_path23 = require("path");
|
|
47263
47786
|
async function claimOnce(dir, name) {
|
|
47264
47787
|
try {
|
|
47265
|
-
await (0,
|
|
47266
|
-
await (await (0,
|
|
47788
|
+
await (0, import_promises34.mkdir)(dir, { recursive: true, mode: 448 });
|
|
47789
|
+
await (await (0, import_promises34.open)((0, import_node_path23.join)(dir, name), "wx")).close();
|
|
47267
47790
|
return true;
|
|
47268
47791
|
} catch {
|
|
47269
47792
|
return false;
|
|
47270
47793
|
}
|
|
47271
47794
|
}
|
|
47795
|
+
function claimFirstLease(freshnessDir, path) {
|
|
47796
|
+
return claimOnce((0, import_node_path23.join)(freshnessDir, "leased"), (0, import_node_crypto14.createHash)("sha256").update(path).digest("hex"));
|
|
47797
|
+
}
|
|
47798
|
+
|
|
47799
|
+
// src/holder/requested-checkout.ts
|
|
47800
|
+
var import_promises35 = require("fs/promises");
|
|
47801
|
+
var import_node_path24 = require("path");
|
|
47802
|
+
var REMOTE2 = "origin";
|
|
47803
|
+
var REASON_MAX_CHARS = 200;
|
|
47804
|
+
function firstLine2(text2) {
|
|
47805
|
+
return (text2.trim().split("\n")[0] ?? "").slice(0, REASON_MAX_CHARS);
|
|
47806
|
+
}
|
|
47807
|
+
function reasonOf(output2, command) {
|
|
47808
|
+
return firstLine2(output2.stderr) || `git ${command} exited ${output2.exitCode}`;
|
|
47809
|
+
}
|
|
47810
|
+
function noted(situation, reason, action) {
|
|
47811
|
+
return { kind: "noted", problem: `${situation}: ${reason}`, action };
|
|
47812
|
+
}
|
|
47813
|
+
function notSwitched(checkout, current, reason) {
|
|
47814
|
+
const on = current ?? "a detached HEAD";
|
|
47815
|
+
return noted(
|
|
47816
|
+
`is on ${on}, not ${checkout.branch}, the branch picked for this chat`,
|
|
47817
|
+
reason,
|
|
47818
|
+
`Switch it to ${checkout.branch}`
|
|
47819
|
+
);
|
|
47820
|
+
}
|
|
47821
|
+
async function clone2(checkout, deps, signal) {
|
|
47822
|
+
const parent = (0, import_node_path24.dirname)(checkout.path);
|
|
47823
|
+
await (0, import_promises35.mkdir)(parent, { recursive: true });
|
|
47824
|
+
await assertValidBranch(deps.git, parent, checkout.branch, signal);
|
|
47825
|
+
const output2 = await deps.git.run(
|
|
47826
|
+
{
|
|
47827
|
+
cwd: parent,
|
|
47828
|
+
args: [
|
|
47829
|
+
"clone",
|
|
47830
|
+
"--quiet",
|
|
47831
|
+
"--no-tags",
|
|
47832
|
+
"--depth=1",
|
|
47833
|
+
"--branch",
|
|
47834
|
+
checkout.branch,
|
|
47835
|
+
"--",
|
|
47836
|
+
checkout.repoUrl,
|
|
47837
|
+
checkout.path
|
|
47838
|
+
],
|
|
47839
|
+
network: true
|
|
47840
|
+
},
|
|
47841
|
+
signal
|
|
47842
|
+
);
|
|
47843
|
+
if (output2.exitCode === 0) return { kind: "moved", how: "cloned" };
|
|
47844
|
+
return noted(
|
|
47845
|
+
`is missing, and cloning it on ${checkout.branch}, the branch picked for this chat, failed`,
|
|
47846
|
+
reasonOf(output2, "clone"),
|
|
47847
|
+
`Clone ${checkout.repoUrl} there`
|
|
47848
|
+
);
|
|
47849
|
+
}
|
|
47850
|
+
var SWITCHED = { kind: "moved", how: "switched" };
|
|
47851
|
+
function coversBranch(fetchConfig, branch) {
|
|
47852
|
+
return fetchConfig.split("\n").some(
|
|
47853
|
+
(refspec) => refspec === `+refs/heads/*:refs/remotes/${REMOTE2}/*` || refspec === `+refs/heads/${branch}:refs/remotes/${REMOTE2}/${branch}`
|
|
47854
|
+
);
|
|
47855
|
+
}
|
|
47856
|
+
async function fetchBranch(checkout, git, shallow, current) {
|
|
47857
|
+
const { branch } = checkout;
|
|
47858
|
+
const tracking = `refs/remotes/${REMOTE2}/${branch}`;
|
|
47859
|
+
const fetchConfig = await git(["config", "--get-all", `remote.${REMOTE2}.fetch`], {
|
|
47860
|
+
readOnly: true
|
|
47861
|
+
});
|
|
47862
|
+
if (!coversBranch(fetchConfig.stdout, branch)) {
|
|
47863
|
+
const added = await git(["remote", "set-branches", "--add", REMOTE2, branch]);
|
|
47864
|
+
if (added.exitCode !== 0) return notSwitched(checkout, current, reasonOf(added, "remote"));
|
|
47865
|
+
}
|
|
47866
|
+
const depth = shallow ? ["--depth=1"] : [];
|
|
47867
|
+
const fetched = await git(
|
|
47868
|
+
["fetch", "--no-tags", "--quiet", ...depth, REMOTE2, `refs/heads/${branch}:${tracking}`],
|
|
47869
|
+
{ network: true }
|
|
47870
|
+
);
|
|
47871
|
+
if (fetched.exitCode !== 0) return notSwitched(checkout, current, reasonOf(fetched, "fetch"));
|
|
47872
|
+
const tip = await git(["rev-parse", "--verify", tracking], { readOnly: true });
|
|
47873
|
+
if (tip.exitCode !== 0) return notSwitched(checkout, current, reasonOf(tip, "rev-parse"));
|
|
47874
|
+
return { kind: "fetched", tip: tip.stdout.trim() };
|
|
47875
|
+
}
|
|
47876
|
+
async function moveOnto(checkout, git, tip, current) {
|
|
47877
|
+
const { branch } = checkout;
|
|
47878
|
+
const local = await git(["rev-parse", "--verify", "-q", `refs/heads/${branch}`], {
|
|
47879
|
+
readOnly: true
|
|
47880
|
+
});
|
|
47881
|
+
if (local.exitCode !== 0) {
|
|
47882
|
+
const created = await git([
|
|
47883
|
+
"switch",
|
|
47884
|
+
"--quiet",
|
|
47885
|
+
"-c",
|
|
47886
|
+
branch,
|
|
47887
|
+
"--track",
|
|
47888
|
+
`${REMOTE2}/${branch}`
|
|
47889
|
+
]);
|
|
47890
|
+
return created.exitCode === 0 ? SWITCHED : notSwitched(checkout, current, reasonOf(created, "switch"));
|
|
47891
|
+
}
|
|
47892
|
+
const localHead = local.stdout.trim();
|
|
47893
|
+
const ancestor = localHead === tip || (await git(["merge-base", "--is-ancestor", localHead, tip], { readOnly: true })).exitCode === 0;
|
|
47894
|
+
if (!ancestor) {
|
|
47895
|
+
return notSwitched(
|
|
47896
|
+
checkout,
|
|
47897
|
+
current,
|
|
47898
|
+
`its local ${branch} has diverged from ${REMOTE2}/${branch}`
|
|
47899
|
+
);
|
|
47900
|
+
}
|
|
47901
|
+
const switched = await git(["switch", "--quiet", branch]);
|
|
47902
|
+
if (switched.exitCode !== 0) return notSwitched(checkout, current, reasonOf(switched, "switch"));
|
|
47903
|
+
if (localHead === tip) return SWITCHED;
|
|
47904
|
+
const merged = await git(["merge", "--quiet", "--ff-only", tip]);
|
|
47905
|
+
return merged.exitCode === 0 ? SWITCHED : noted(
|
|
47906
|
+
`is on ${branch} but behind ${REMOTE2}/${branch}`,
|
|
47907
|
+
reasonOf(merged, "merge"),
|
|
47908
|
+
"Run `git pull --ff-only` there"
|
|
47909
|
+
);
|
|
47910
|
+
}
|
|
47911
|
+
async function switchTo(checkout, current, operationId, deps, signal) {
|
|
47912
|
+
var _stack = [];
|
|
47913
|
+
try {
|
|
47914
|
+
const cwd = checkout.path;
|
|
47915
|
+
const git = (args, invocation = {}) => deps.git.run({ cwd, args, ...invocation }, signal);
|
|
47916
|
+
await assertValidBranch(deps.git, cwd, checkout.branch, signal);
|
|
47917
|
+
const refs = await git(
|
|
47918
|
+
["rev-parse", "--path-format=absolute", "--git-common-dir", "--is-shallow-repository"],
|
|
47919
|
+
{ readOnly: true }
|
|
47920
|
+
);
|
|
47921
|
+
if (refs.exitCode !== 0) return notSwitched(checkout, current, reasonOf(refs, "rev-parse"));
|
|
47922
|
+
const [commonDir = "", shallow] = refs.stdout.trim().split("\n");
|
|
47923
|
+
const attempt = await deps.locks.tryExclusive(commonDir, operationId);
|
|
47924
|
+
if (attempt.kind === "busy") {
|
|
47925
|
+
return notSwitched(checkout, current, "another git operation holds the checkout");
|
|
47926
|
+
}
|
|
47927
|
+
const _lock = __using(_stack, attempt.lock, true);
|
|
47928
|
+
const now = await readCheckoutStatus(deps.git, cwd, signal);
|
|
47929
|
+
if (now === null || now.dirty) {
|
|
47930
|
+
return notSwitched(checkout, now?.branch ?? current, "it has uncommitted changes");
|
|
47931
|
+
}
|
|
47932
|
+
const fetched = await fetchBranch(checkout, git, shallow === "true", now.branch);
|
|
47933
|
+
if (fetched.kind !== "fetched") return fetched;
|
|
47934
|
+
const outcome2 = await moveOnto(checkout, git, fetched.tip, now.branch);
|
|
47935
|
+
const after = await readCheckoutStatus(deps.git, cwd, signal);
|
|
47936
|
+
if (after?.branch === checkout.branch) {
|
|
47937
|
+
await recordCheckoutKept(deps.dir, cwd, "requested_branch");
|
|
47938
|
+
}
|
|
47939
|
+
return outcome2;
|
|
47940
|
+
} catch (_) {
|
|
47941
|
+
var _error = _, _hasError = true;
|
|
47942
|
+
} finally {
|
|
47943
|
+
var _promise2 = __callDispose(_stack, _error, _hasError);
|
|
47944
|
+
_promise2 && await _promise2;
|
|
47945
|
+
}
|
|
47946
|
+
}
|
|
47947
|
+
async function applyRequestedCheckout(checkout, spec, deps, signal) {
|
|
47948
|
+
try {
|
|
47949
|
+
if (!await isCheckout(checkout.path)) return await clone2(checkout, deps, signal);
|
|
47950
|
+
const status = await readCheckoutStatus(deps.git, checkout.path, signal);
|
|
47951
|
+
if (status === null) return notSwitched(checkout, null, "git status failed");
|
|
47952
|
+
if (status.branch === checkout.branch) return { kind: "on_branch" };
|
|
47953
|
+
if (status.dirty) return notSwitched(checkout, status.branch, "it has uncommitted changes");
|
|
47954
|
+
if (!await claimFirstLease(deps.dir, checkout.path)) {
|
|
47955
|
+
return notSwitched(
|
|
47956
|
+
checkout,
|
|
47957
|
+
status.branch,
|
|
47958
|
+
"an earlier conversation on this machine already uses it"
|
|
47959
|
+
);
|
|
47960
|
+
}
|
|
47961
|
+
return await switchTo(checkout, status.branch, `checkout-${spec.runId}`, deps, signal);
|
|
47962
|
+
} catch (error61) {
|
|
47963
|
+
return noted(
|
|
47964
|
+
`could not be put on ${checkout.branch}, the branch picked for this chat`,
|
|
47965
|
+
firstLine2(error61 instanceof Error ? error61.message : String(error61)) || "unknown error",
|
|
47966
|
+
"Check it"
|
|
47967
|
+
);
|
|
47968
|
+
}
|
|
47969
|
+
}
|
|
47970
|
+
|
|
47971
|
+
// src/holder/checkout-refresh.ts
|
|
47972
|
+
function short(sha) {
|
|
47973
|
+
return sha.slice(0, 12);
|
|
47974
|
+
}
|
|
47975
|
+
function staleCheckout(path, snapshot2, tip) {
|
|
47976
|
+
const checkout = snapshot2 === void 0 ? "is the environment snapshot's checkout" : `is the environment snapshot's checkout of ${snapshot2.branch} (commit ${short(snapshot2.head)})`;
|
|
47977
|
+
const base = snapshot2 === void 0 ? "its upstream" : `origin/${snapshot2.base}`;
|
|
47978
|
+
const remote = tip === void 0 ? "may be ahead" : `is ahead at ${short(tip)}`;
|
|
47979
|
+
return {
|
|
47980
|
+
path,
|
|
47981
|
+
problem: `${checkout}; ${base} ${remote}`,
|
|
47982
|
+
action: "Run `git pull --ff-only` there"
|
|
47983
|
+
};
|
|
47984
|
+
}
|
|
47272
47985
|
async function fastForward(freshness, operationId, deps, signal) {
|
|
47273
47986
|
var _stack = [];
|
|
47274
47987
|
try {
|
|
@@ -47293,10 +48006,7 @@ async function fastForward(freshness, operationId, deps, signal) {
|
|
|
47293
48006
|
}
|
|
47294
48007
|
}
|
|
47295
48008
|
async function atFirstLease(freshness, spec, deps, signal) {
|
|
47296
|
-
const first = await
|
|
47297
|
-
(0, import_node_path21.join)(deps.dir, "leased"),
|
|
47298
|
-
(0, import_node_crypto14.createHash)("sha256").update(freshness.path).digest("hex")
|
|
47299
|
-
);
|
|
48009
|
+
const first = await claimFirstLease(deps.dir, freshness.path);
|
|
47300
48010
|
switch (freshness.state) {
|
|
47301
48011
|
case "current":
|
|
47302
48012
|
case "kept":
|
|
@@ -47308,46 +48018,88 @@ async function atFirstLease(freshness, spec, deps, signal) {
|
|
|
47308
48018
|
return first && freshness.fetched && await fastForward(freshness, `refresh-${spec.runId}`, deps, signal) ? "moved" : "noted";
|
|
47309
48019
|
}
|
|
47310
48020
|
}
|
|
47311
|
-
function
|
|
48021
|
+
function problemFor(freshness) {
|
|
47312
48022
|
switch (freshness.state) {
|
|
47313
48023
|
case "behind":
|
|
47314
|
-
return
|
|
48024
|
+
return staleCheckout(freshness.path, freshness.snapshot, freshness.tip);
|
|
47315
48025
|
case "failed":
|
|
47316
|
-
return
|
|
48026
|
+
return staleCheckout(freshness.path, freshness.snapshot);
|
|
47317
48027
|
default:
|
|
47318
|
-
return
|
|
48028
|
+
return staleCheckout(freshness.path, void 0);
|
|
47319
48029
|
}
|
|
47320
48030
|
}
|
|
47321
48031
|
async function checkoutsOf(spec, leaseTargets) {
|
|
47322
48032
|
if (leaseTargets.length > 0 || spec.projectPath === void 0) return [...leaseTargets];
|
|
47323
48033
|
return checkoutsUnder(spec.projectPath);
|
|
47324
48034
|
}
|
|
47325
|
-
function
|
|
47326
|
-
|
|
47327
|
-
|
|
47328
|
-
|
|
47329
|
-
|
|
47330
|
-
|
|
47331
|
-
const freshness = await readCheckoutFreshness(deps.dir, target);
|
|
47332
|
-
if (freshness === null) continue;
|
|
47333
|
-
const outcome2 = await atFirstLease(freshness, spec, deps, signal).catch(
|
|
47334
|
-
() => "noted"
|
|
47335
|
-
);
|
|
47336
|
-
if (outcome2 === "noted") lines.push(lineFor(freshness));
|
|
47337
|
-
deps.log.info("workspace.refresh", {
|
|
48035
|
+
function requestedCheckoutsOf(spec, log) {
|
|
48036
|
+
const roots = spec.approvedWorkspacePaths ?? [];
|
|
48037
|
+
return (spec.requestedCheckouts ?? []).filter((checkout) => {
|
|
48038
|
+
const approved = roots.some((root) => isWithin(root, checkout.path, process.platform));
|
|
48039
|
+
if (!approved) {
|
|
48040
|
+
log.warn("workspace.requested_checkout_outside_workspace", {
|
|
47338
48041
|
runId: spec.runId,
|
|
47339
|
-
path:
|
|
47340
|
-
state: freshness.state,
|
|
47341
|
-
outcome: outcome2
|
|
48042
|
+
path: checkout.path
|
|
47342
48043
|
});
|
|
47343
48044
|
}
|
|
47344
|
-
return
|
|
48045
|
+
return approved;
|
|
48046
|
+
});
|
|
48047
|
+
}
|
|
48048
|
+
async function applyRequestedCheckouts(spec, deps, signal) {
|
|
48049
|
+
const settled2 = /* @__PURE__ */ new Set();
|
|
48050
|
+
const problems = [];
|
|
48051
|
+
for (const checkout of requestedCheckoutsOf(spec, deps.log)) {
|
|
48052
|
+
const outcome2 = await applyRequestedCheckout(checkout, spec, deps, signal);
|
|
48053
|
+
deps.log.info("workspace.requested_checkout", {
|
|
48054
|
+
runId: spec.runId,
|
|
48055
|
+
path: checkout.path,
|
|
48056
|
+
branch: checkout.branch,
|
|
48057
|
+
outcome: outcome2.kind,
|
|
48058
|
+
...outcome2.kind === "moved" ? { how: outcome2.how } : {}
|
|
48059
|
+
});
|
|
48060
|
+
if (outcome2.kind === "on_branch") continue;
|
|
48061
|
+
settled2.add((0, import_node_path25.resolve)(checkout.path));
|
|
48062
|
+
if (outcome2.kind === "noted") {
|
|
48063
|
+
problems.push({ path: checkout.path, problem: outcome2.problem, action: outcome2.action });
|
|
48064
|
+
}
|
|
48065
|
+
}
|
|
48066
|
+
return { settled: settled2, problems };
|
|
48067
|
+
}
|
|
48068
|
+
async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
|
|
48069
|
+
const problems = [];
|
|
48070
|
+
for (const target of targets) {
|
|
48071
|
+
if (settled2.has((0, import_node_path25.resolve)(target))) continue;
|
|
48072
|
+
const freshness = await readCheckoutFreshness(deps.dir, target);
|
|
48073
|
+
if (freshness === null) continue;
|
|
48074
|
+
const outcome2 = await atFirstLease(freshness, spec, deps, signal).catch(
|
|
48075
|
+
() => "noted"
|
|
48076
|
+
);
|
|
48077
|
+
if (outcome2 === "noted") problems.push(problemFor(freshness));
|
|
48078
|
+
deps.log.info("workspace.refresh", {
|
|
48079
|
+
runId: spec.runId,
|
|
48080
|
+
path: freshness.path,
|
|
48081
|
+
state: freshness.state,
|
|
48082
|
+
outcome: outcome2
|
|
48083
|
+
});
|
|
48084
|
+
}
|
|
48085
|
+
return problems;
|
|
48086
|
+
}
|
|
48087
|
+
function createCheckoutRefresh(deps) {
|
|
48088
|
+
return async (spec, leaseTargets, signal) => {
|
|
48089
|
+
if (spec.providerSessionId !== void 0) return [];
|
|
48090
|
+
if (!await claimOnce((0, import_node_path25.join)(deps.dir, "conversations"), spec.conversationId)) return [];
|
|
48091
|
+
const requested = await applyRequestedCheckouts(spec, deps, signal);
|
|
48092
|
+
const targets = await checkoutsOf(spec, leaseTargets);
|
|
48093
|
+
return [
|
|
48094
|
+
...requested.problems,
|
|
48095
|
+
...await refreshSnapshotCheckouts(spec, targets, requested.settled, deps, signal)
|
|
48096
|
+
];
|
|
47345
48097
|
};
|
|
47346
48098
|
}
|
|
47347
48099
|
|
|
47348
48100
|
// src/holder/lease.ts
|
|
47349
|
-
var
|
|
47350
|
-
var
|
|
48101
|
+
var import_promises36 = require("fs/promises");
|
|
48102
|
+
var import_node_path26 = require("path");
|
|
47351
48103
|
var LEASE_CHECK_EVERY_MS = 5e3;
|
|
47352
48104
|
var MAX_TRANSIENT_FAILURES = 3;
|
|
47353
48105
|
var BACKOFF_BASE_MS = 1e3;
|
|
@@ -47361,8 +48113,8 @@ function identityFailure(code, workspacePath) {
|
|
|
47361
48113
|
return { code, problemCode: "app.workspace.missing", message: MESSAGES[code], workspacePath };
|
|
47362
48114
|
}
|
|
47363
48115
|
async function fileIdentity(path) {
|
|
47364
|
-
const canonical = await (0,
|
|
47365
|
-
const info = await (0,
|
|
48116
|
+
const canonical = await (0, import_promises36.realpath)(path);
|
|
48117
|
+
const info = await (0, import_promises36.stat)(canonical, { bigint: true });
|
|
47366
48118
|
return `${canonical}:${info.dev}:${info.ino}`;
|
|
47367
48119
|
}
|
|
47368
48120
|
async function snapshot(git, path, signal) {
|
|
@@ -47381,7 +48133,7 @@ async function snapshot(git, path, signal) {
|
|
|
47381
48133
|
workspace: await fileIdentity(path),
|
|
47382
48134
|
repository: await fileIdentity(commonDir),
|
|
47383
48135
|
worktree: await fileIdentity(gitDir),
|
|
47384
|
-
commonDir: await (0,
|
|
48136
|
+
commonDir: await (0, import_promises36.realpath)(commonDir)
|
|
47385
48137
|
};
|
|
47386
48138
|
} catch {
|
|
47387
48139
|
return null;
|
|
@@ -47394,7 +48146,7 @@ async function gitValue(git, path, args, signal) {
|
|
|
47394
48146
|
}
|
|
47395
48147
|
async function pathExists(path) {
|
|
47396
48148
|
try {
|
|
47397
|
-
await (0,
|
|
48149
|
+
await (0, import_promises36.stat)(path);
|
|
47398
48150
|
return true;
|
|
47399
48151
|
} catch (error61) {
|
|
47400
48152
|
return errnoCode(error61) !== "ENOENT" && errnoCode(error61) !== "ENOTDIR";
|
|
@@ -47403,19 +48155,19 @@ async function pathExists(path) {
|
|
|
47403
48155
|
async function hasGitMarker(path) {
|
|
47404
48156
|
let directory;
|
|
47405
48157
|
try {
|
|
47406
|
-
directory = await (0,
|
|
48158
|
+
directory = await (0, import_promises36.realpath)(path);
|
|
47407
48159
|
} catch {
|
|
47408
48160
|
return true;
|
|
47409
48161
|
}
|
|
47410
48162
|
for (; ; ) {
|
|
47411
48163
|
try {
|
|
47412
|
-
await (0,
|
|
48164
|
+
await (0, import_promises36.stat)((0, import_node_path26.join)(directory, ".git"));
|
|
47413
48165
|
return true;
|
|
47414
48166
|
} catch (error61) {
|
|
47415
48167
|
const code = errnoCode(error61);
|
|
47416
48168
|
if (code !== "ENOENT" && code !== "ENOTDIR") return true;
|
|
47417
48169
|
}
|
|
47418
|
-
const parent = (0,
|
|
48170
|
+
const parent = (0, import_node_path26.dirname)(directory);
|
|
47419
48171
|
if (parent === directory) return false;
|
|
47420
48172
|
directory = parent;
|
|
47421
48173
|
}
|
|
@@ -47579,7 +48331,7 @@ function volumeRoot(path) {
|
|
|
47579
48331
|
}
|
|
47580
48332
|
async function exists(path) {
|
|
47581
48333
|
try {
|
|
47582
|
-
await (0,
|
|
48334
|
+
await (0, import_promises37.stat)(path);
|
|
47583
48335
|
return true;
|
|
47584
48336
|
} catch {
|
|
47585
48337
|
return false;
|
|
@@ -47587,10 +48339,10 @@ async function exists(path) {
|
|
|
47587
48339
|
}
|
|
47588
48340
|
async function inspectReadiness(path) {
|
|
47589
48341
|
try {
|
|
47590
|
-
if (!(await (0,
|
|
48342
|
+
if (!(await (0, import_promises37.stat)(path)).isDirectory()) {
|
|
47591
48343
|
return { ready: false, missing: true, message: MESSAGES2.missing };
|
|
47592
48344
|
}
|
|
47593
|
-
await (0,
|
|
48345
|
+
await (0, import_promises37.access)(path, import_node_fs9.constants.R_OK | import_node_fs9.constants.W_OK | import_node_fs9.constants.X_OK);
|
|
47594
48346
|
return { ready: true };
|
|
47595
48347
|
} catch (error61) {
|
|
47596
48348
|
const code = errnoCode(error61) ?? "";
|
|
@@ -47668,8 +48420,8 @@ async function admitDefaultWorkspace(spec, context, skills) {
|
|
|
47668
48420
|
const { env } = context;
|
|
47669
48421
|
const path = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os5.homedir)());
|
|
47670
48422
|
try {
|
|
47671
|
-
await (0,
|
|
47672
|
-
await (0,
|
|
48423
|
+
await (0, import_promises37.mkdir)(path, { recursive: true, mode: 448 });
|
|
48424
|
+
await (0, import_promises37.access)(path, import_node_fs9.constants.R_OK | import_node_fs9.constants.W_OK | import_node_fs9.constants.X_OK);
|
|
47673
48425
|
return {
|
|
47674
48426
|
kind: "admitted",
|
|
47675
48427
|
spec: { ...spec, projectPath: path },
|
|
@@ -47742,10 +48494,12 @@ async function admitRun(spec, context, signal) {
|
|
|
47742
48494
|
};
|
|
47743
48495
|
}
|
|
47744
48496
|
var PROBE_TIMEOUT_MS2 = 5e3;
|
|
48497
|
+
var CHECKOUT_LOCAL_TIMEOUT_MS = 6e4;
|
|
48498
|
+
var CHECKOUT_NETWORK_TIMEOUT_MS = 12e4;
|
|
47745
48499
|
function createHolderWorkspace(machine, clock, log) {
|
|
47746
48500
|
const platform = machine.platform ?? process.platform;
|
|
47747
48501
|
const git = createGitRunner({ env: machine.env, platform, localTimeoutMs: PROBE_TIMEOUT_MS2 });
|
|
47748
|
-
const locks = openRepositoryLocks({ dir: (0,
|
|
48502
|
+
const locks = openRepositoryLocks({ dir: (0, import_node_path27.join)(machine.stateDir, "locks"), clock, platform });
|
|
47749
48503
|
return {
|
|
47750
48504
|
admission: {
|
|
47751
48505
|
env: machine.env,
|
|
@@ -47757,7 +48511,7 @@ function createHolderWorkspace(machine, clock, log) {
|
|
|
47757
48511
|
),
|
|
47758
48512
|
approvedRoots: async () => {
|
|
47759
48513
|
const approved = await openApprovedPaths({
|
|
47760
|
-
file: (0,
|
|
48514
|
+
file: (0, import_node_path27.join)(machine.stateDir, "workspaces.json"),
|
|
47761
48515
|
log,
|
|
47762
48516
|
platform
|
|
47763
48517
|
});
|
|
@@ -47767,10 +48521,19 @@ function createHolderWorkspace(machine, clock, log) {
|
|
|
47767
48521
|
lease: { git, locks, clock, log, platform },
|
|
47768
48522
|
...machine.refreshesFirstCheckout === true ? {
|
|
47769
48523
|
refreshFirstCheckout: createCheckoutRefresh({
|
|
47770
|
-
git
|
|
48524
|
+
git: createGitRunner({
|
|
48525
|
+
env: machine.env,
|
|
48526
|
+
platform,
|
|
48527
|
+
localTimeoutMs: CHECKOUT_LOCAL_TIMEOUT_MS,
|
|
48528
|
+
networkTimeoutMs: CHECKOUT_NETWORK_TIMEOUT_MS
|
|
48529
|
+
}),
|
|
47771
48530
|
locks,
|
|
47772
48531
|
log,
|
|
47773
|
-
dir: (0,
|
|
48532
|
+
dir: (0, import_node_path27.join)(machine.stateDir, "checkout-freshness")
|
|
48533
|
+
}),
|
|
48534
|
+
prepareAgentContext: createAgentContext({
|
|
48535
|
+
dir: (0, import_node_path27.join)(machine.stateDir, "agent-context"),
|
|
48536
|
+
homeDir: machine.env.HOME || (0, import_node_os5.homedir)()
|
|
47774
48537
|
})
|
|
47775
48538
|
} : {}
|
|
47776
48539
|
};
|
|
@@ -47798,7 +48561,7 @@ async function respondToTurn(runningRunId, gate, driver, request2) {
|
|
|
47798
48561
|
}
|
|
47799
48562
|
|
|
47800
48563
|
// src/holder/session-facts.ts
|
|
47801
|
-
var
|
|
48564
|
+
var import_promises38 = require("fs/promises");
|
|
47802
48565
|
var CLI_RSS_CACHE_MS = 1e4;
|
|
47803
48566
|
var LOGIN_PROBLEM_PREFIX = "cli.auth.";
|
|
47804
48567
|
function isLoginFailure(result) {
|
|
@@ -47824,8 +48587,8 @@ function createSessionFacts(options) {
|
|
|
47824
48587
|
const path = await resolveCommandOnPath(command, env, platform);
|
|
47825
48588
|
if (path === null) return null;
|
|
47826
48589
|
try {
|
|
47827
|
-
const real = await (0,
|
|
47828
|
-
const info = await (0,
|
|
48590
|
+
const real = await (0, import_promises38.realpath)(path);
|
|
48591
|
+
const info = await (0, import_promises38.stat)(real);
|
|
47829
48592
|
return { command, key: `${real}:${info.ino}:${info.size}:${info.mtimeMs}` };
|
|
47830
48593
|
} catch {
|
|
47831
48594
|
return null;
|
|
@@ -47912,8 +48675,8 @@ function createSessionFacts(options) {
|
|
|
47912
48675
|
init_acp2();
|
|
47913
48676
|
|
|
47914
48677
|
// src/run-log/directory.ts
|
|
47915
|
-
var
|
|
47916
|
-
var
|
|
48678
|
+
var import_promises39 = require("fs/promises");
|
|
48679
|
+
var import_node_path28 = require("path");
|
|
47917
48680
|
init_runtime_v2();
|
|
47918
48681
|
init_zod();
|
|
47919
48682
|
var runMetaSchema = external_exports.object({
|
|
@@ -47935,17 +48698,17 @@ var runMetaSchema = external_exports.object({
|
|
|
47935
48698
|
}).optional()
|
|
47936
48699
|
});
|
|
47937
48700
|
function runDirectory(runsDir, runId) {
|
|
47938
|
-
const dir = (0,
|
|
48701
|
+
const dir = (0, import_node_path28.join)(runsDir, runId);
|
|
47939
48702
|
return {
|
|
47940
48703
|
dir,
|
|
47941
|
-
log: (0,
|
|
47942
|
-
upload: (0,
|
|
47943
|
-
meta: (0,
|
|
48704
|
+
log: (0, import_node_path28.join)(dir, "log.jsonl"),
|
|
48705
|
+
upload: (0, import_node_path28.join)(dir, "upload.json"),
|
|
48706
|
+
meta: (0, import_node_path28.join)(dir, "run.json")
|
|
47944
48707
|
};
|
|
47945
48708
|
}
|
|
47946
48709
|
async function isRunClaimed(runsDir, runId) {
|
|
47947
48710
|
try {
|
|
47948
|
-
return (await (0,
|
|
48711
|
+
return (await (0, import_promises39.stat)(runDirectory(runsDir, runId).log)).size > 0;
|
|
47949
48712
|
} catch (error61) {
|
|
47950
48713
|
if (errnoCode(error61) === "ENOENT") return false;
|
|
47951
48714
|
throw error61;
|
|
@@ -47953,8 +48716,8 @@ async function isRunClaimed(runsDir, runId) {
|
|
|
47953
48716
|
}
|
|
47954
48717
|
|
|
47955
48718
|
// src/run-log/conversation-index.ts
|
|
47956
|
-
var
|
|
47957
|
-
var
|
|
48719
|
+
var import_promises40 = require("fs/promises");
|
|
48720
|
+
var import_node_path29 = require("path");
|
|
47958
48721
|
init_runtime_v2();
|
|
47959
48722
|
init_zod();
|
|
47960
48723
|
var ORDINALS_PER_SHARD = 1e3;
|
|
@@ -47970,13 +48733,13 @@ var coverageSchema = external_exports.object({
|
|
|
47970
48733
|
nextExpectedOrdinal: external_exports.number().int().positive()
|
|
47971
48734
|
});
|
|
47972
48735
|
function conversationsDirectory(runsDir) {
|
|
47973
|
-
return (0,
|
|
48736
|
+
return (0, import_node_path29.join)((0, import_node_path29.dirname)(runsDir), "conversations");
|
|
47974
48737
|
}
|
|
47975
48738
|
function indexDirectory(runsDir, conversationId) {
|
|
47976
|
-
return (0,
|
|
48739
|
+
return (0, import_node_path29.join)(conversationsDirectory(runsDir), conversationId, "turn-index");
|
|
47977
48740
|
}
|
|
47978
48741
|
function shardPath(runsDir, conversationId, ordinal) {
|
|
47979
|
-
return (0,
|
|
48742
|
+
return (0, import_node_path29.join)(
|
|
47980
48743
|
indexDirectory(runsDir, conversationId),
|
|
47981
48744
|
`${Math.floor(ordinal / ORDINALS_PER_SHARD)}.jsonl`
|
|
47982
48745
|
);
|
|
@@ -47985,10 +48748,10 @@ async function indexConversationRun(runsDir, conversationId, ordinal, assistantO
|
|
|
47985
48748
|
const nextOrdinal = assistantOrdinal + 1;
|
|
47986
48749
|
if (nextOrdinal <= ordinal) throw new Error("Assistant order must follow the prompt");
|
|
47987
48750
|
const path = shardPath(runsDir, conversationId, ordinal);
|
|
47988
|
-
await (0,
|
|
47989
|
-
await (0,
|
|
48751
|
+
await (0, import_promises40.mkdir)((0, import_node_path29.dirname)(path), { recursive: true, mode: 448 });
|
|
48752
|
+
await (0, import_promises40.appendFile)(path, `${JSON.stringify({ ordinal, nextOrdinal, runId })}
|
|
47990
48753
|
`, { mode: 384 });
|
|
47991
|
-
const coveragePath = (0,
|
|
48754
|
+
const coveragePath = (0, import_node_path29.join)((0, import_node_path29.dirname)((0, import_node_path29.dirname)(path)), "coverage.json");
|
|
47992
48755
|
const coverage = await readJsonFile(coveragePath, coverageSchema);
|
|
47993
48756
|
const current = coverage.kind === "ok" ? coverage.value : null;
|
|
47994
48757
|
const next = nextCoverage(current, ordinal, nextOrdinal);
|
|
@@ -48032,7 +48795,7 @@ var decoder = new TextDecoder();
|
|
|
48032
48795
|
|
|
48033
48796
|
// src/run-log/writer.ts
|
|
48034
48797
|
var import_node_fs10 = require("fs");
|
|
48035
|
-
var
|
|
48798
|
+
var import_node_path30 = require("path");
|
|
48036
48799
|
init_runtime_v2();
|
|
48037
48800
|
function lastSeq(fd, size) {
|
|
48038
48801
|
for (const length of tailWindows(size)) {
|
|
@@ -48048,7 +48811,7 @@ function lastSeq(fd, size) {
|
|
|
48048
48811
|
throw new RuntimeFault("record_too_large", "Run log tail record is larger than any record");
|
|
48049
48812
|
}
|
|
48050
48813
|
function openRunLog(path, clock) {
|
|
48051
|
-
(0, import_node_fs10.mkdirSync)((0,
|
|
48814
|
+
(0, import_node_fs10.mkdirSync)((0, import_node_path30.dirname)(path), { recursive: true, mode: 448 });
|
|
48052
48815
|
const fd = (0, import_node_fs10.openSync)(path, "a+", 384);
|
|
48053
48816
|
let size = (0, import_node_fs10.fstatSync)(fd).size;
|
|
48054
48817
|
let seq = lastSeq(fd, size);
|
|
@@ -48226,8 +48989,12 @@ function fitForRunLog(update) {
|
|
|
48226
48989
|
async function runWithInputs({ spec, leaseTargets, skills }, context, sink, signal) {
|
|
48227
48990
|
var _stack = [];
|
|
48228
48991
|
try {
|
|
48229
|
-
const
|
|
48992
|
+
const workspace = context.workspace;
|
|
48993
|
+
const sessionContext = (workspace?.refreshFirstCheckout?.(spec, leaseTargets, signal) ?? Promise.resolve([])).catch((error61) => {
|
|
48230
48994
|
context.log.warn("workspace.refresh_failed", { runId: spec.runId, error: error61 });
|
|
48995
|
+
return [];
|
|
48996
|
+
}).then((problems) => workspace?.prepareAgentContext?.(spec, problems)).catch((error61) => {
|
|
48997
|
+
context.log.warn("holder.agent_context_failed", { runId: spec.runId, error: error61 });
|
|
48231
48998
|
return void 0;
|
|
48232
48999
|
});
|
|
48233
49000
|
let inputs;
|
|
@@ -48240,17 +49007,37 @@ async function runWithInputs({ spec, leaseTargets, skills }, context, sink, sign
|
|
|
48240
49007
|
message: `Could not fetch this run's attachments or provider credential: ${error61 instanceof Error ? error61.message : String(error61)}`
|
|
48241
49008
|
};
|
|
48242
49009
|
}
|
|
48243
|
-
const
|
|
49010
|
+
const agentContext = await sessionContext;
|
|
48244
49011
|
const prepared = __using(_stack, inputs, true);
|
|
48245
|
-
const run = (turnSink, turnSignal) =>
|
|
49012
|
+
const run = async (turnSink, turnSignal) => {
|
|
49013
|
+
const result = await context.driver.runTurn(
|
|
49014
|
+
spec,
|
|
49015
|
+
turnSink,
|
|
49016
|
+
turnSignal,
|
|
49017
|
+
agentContext === void 0 ? prepared : {
|
|
49018
|
+
...prepared,
|
|
49019
|
+
agentContext: {
|
|
49020
|
+
full: agentContext.full,
|
|
49021
|
+
...agentContext.update ? { update: agentContext.update } : {}
|
|
49022
|
+
}
|
|
49023
|
+
}
|
|
49024
|
+
);
|
|
49025
|
+
if (agentContext !== void 0 && result.outcome !== "rejected") {
|
|
49026
|
+
await agentContext.save().catch((error61) => {
|
|
49027
|
+
context.log.warn("holder.agent_context_save_failed", { runId: spec.runId, error: error61 });
|
|
49028
|
+
});
|
|
49029
|
+
}
|
|
49030
|
+
return result;
|
|
49031
|
+
};
|
|
49032
|
+
if (workspace === void 0) return await run(sink, signal);
|
|
49033
|
+
return await runLeased(
|
|
48246
49034
|
spec,
|
|
48247
|
-
|
|
48248
|
-
|
|
48249
|
-
|
|
49035
|
+
leaseTargets,
|
|
49036
|
+
{ ...context, lease: workspace.lease },
|
|
49037
|
+
sink,
|
|
49038
|
+
signal,
|
|
49039
|
+
run
|
|
48250
49040
|
);
|
|
48251
|
-
if (context.workspace === void 0) return await run(sink, signal);
|
|
48252
|
-
const leased = { ...context, lease: context.workspace.lease };
|
|
48253
|
-
return await runLeased(spec, leaseTargets, leased, sink, signal, run);
|
|
48254
49041
|
} catch (_) {
|
|
48255
49042
|
var _error = _, _hasError = true;
|
|
48256
49043
|
} finally {
|
|
@@ -48384,7 +49171,7 @@ async function runHolder({
|
|
|
48384
49171
|
try {
|
|
48385
49172
|
const identity = await readProcessIdentity(process.pid);
|
|
48386
49173
|
if (identity === null) throw new RuntimeFault("internal", "Cannot read own process identity");
|
|
48387
|
-
const _engines = __using(_stack, recordSpawnedEngines(engineRecordsPath((0,
|
|
49174
|
+
const _engines = __using(_stack, recordSpawnedEngines(engineRecordsPath((0, import_node_path31.dirname)(launch.statusPath)), clock, log));
|
|
48388
49175
|
const holder = {
|
|
48389
49176
|
state: "idle",
|
|
48390
49177
|
runId: null,
|
|
@@ -48580,16 +49367,16 @@ async function runHolder({
|
|
|
48580
49367
|
client.on("error", () => holder.clients.delete(client));
|
|
48581
49368
|
});
|
|
48582
49369
|
removeStaleEndpoint(launch.endpoint);
|
|
48583
|
-
await new Promise((
|
|
49370
|
+
await new Promise((resolve9, reject) => {
|
|
48584
49371
|
server.once("error", reject);
|
|
48585
|
-
server.listen(launch.endpoint, () =>
|
|
49372
|
+
server.listen(launch.endpoint, () => resolve9());
|
|
48586
49373
|
});
|
|
48587
49374
|
await writeStatus();
|
|
48588
49375
|
log.info("holder.ready", { conversationId: launch.conversationId, pid: identity.pid });
|
|
48589
|
-
await new Promise((
|
|
49376
|
+
await new Promise((resolve9) => exit.signal.addEventListener("abort", () => resolve9()));
|
|
48590
49377
|
await driver.suspend?.().catch((error61) => log.warn("holder.driver_suspend_failed", { error: error61 }));
|
|
48591
49378
|
for (const client of holder.clients) client.end();
|
|
48592
|
-
await new Promise((
|
|
49379
|
+
await new Promise((resolve9) => server.close(() => resolve9()));
|
|
48593
49380
|
(0, import_node_fs11.rmSync)(launch.statusPath, { force: true });
|
|
48594
49381
|
log.info("holder.suspended", { conversationId: launch.conversationId });
|
|
48595
49382
|
} catch (_) {
|
|
@@ -48729,7 +49516,7 @@ function loadRuntimeConfig(env = process.env, totalMemoryBytes = (0, import_node
|
|
|
48729
49516
|
providerProbes: ALAN_RUNTIME_PROVIDER_PROBES === "on",
|
|
48730
49517
|
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,
|
|
48731
49518
|
home,
|
|
48732
|
-
configHome: XDG_CONFIG_HOME ?? (0,
|
|
49519
|
+
configHome: XDG_CONFIG_HOME ?? (0, import_node_path33.join)(home, ".config"),
|
|
48733
49520
|
codexHome: resolveCodexHome(CODEX_HOME, home),
|
|
48734
49521
|
...githubProxyConfig({ ALAN_RUNTIME_GITHUB_PROXY, XDG_CONFIG_HOME, GH_CONFIG_DIR }, home),
|
|
48735
49522
|
gitGatewayUrl: ALAN_RUNTIME_GIT_GATEWAY_URL ?? null,
|
|
@@ -48739,13 +49526,13 @@ function loadRuntimeConfig(env = process.env, totalMemoryBytes = (0, import_node
|
|
|
48739
49526
|
};
|
|
48740
49527
|
}
|
|
48741
49528
|
function resolveCodexHome(configuredHome, home) {
|
|
48742
|
-
return configuredHome ?? (0,
|
|
49529
|
+
return configuredHome ?? (0, import_node_path33.join)(home, ".codex");
|
|
48743
49530
|
}
|
|
48744
49531
|
function githubProxyConfig(env, home) {
|
|
48745
|
-
const configHome = env.XDG_CONFIG_HOME ?? (0,
|
|
49532
|
+
const configHome = env.XDG_CONFIG_HOME ?? (0, import_node_path33.join)(home, ".config");
|
|
48746
49533
|
return {
|
|
48747
49534
|
githubProxy: env.ALAN_RUNTIME_GITHUB_PROXY === "on",
|
|
48748
|
-
ghConfigDir: env.GH_CONFIG_DIR ?? (0,
|
|
49535
|
+
ghConfigDir: env.GH_CONFIG_DIR ?? (0, import_node_path33.join)(configHome, "gh")
|
|
48749
49536
|
};
|
|
48750
49537
|
}
|
|
48751
49538
|
function serviceEnvironment(env, profile) {
|
|
@@ -48844,7 +49631,7 @@ async function loadStoredAccess(paths, access3 = { exec: systemExec }) {
|
|
|
48844
49631
|
}
|
|
48845
49632
|
|
|
48846
49633
|
// src/cli/commands/hold.ts
|
|
48847
|
-
var
|
|
49634
|
+
var import_node_path34 = require("path");
|
|
48848
49635
|
init_agent2();
|
|
48849
49636
|
init_runtime_v2();
|
|
48850
49637
|
async function machineAccess(paths, log, conversationId, transport) {
|
|
@@ -48902,7 +49689,7 @@ async function runHold(argv) {
|
|
|
48902
49689
|
const config2 = loadRuntimeConfig();
|
|
48903
49690
|
const paths = runtimePaths(config2.stateDir);
|
|
48904
49691
|
const log = __using(_stack, openFileLog(
|
|
48905
|
-
(0,
|
|
49692
|
+
(0, import_node_path34.join)(paths.logs, `holder-${launch.value.conversationId}.jsonl`),
|
|
48906
49693
|
config2.logLevel,
|
|
48907
49694
|
systemClock
|
|
48908
49695
|
));
|
|
@@ -48913,7 +49700,7 @@ async function runHold(argv) {
|
|
|
48913
49700
|
);
|
|
48914
49701
|
const transport = __using(_stack, createHttpTransport());
|
|
48915
49702
|
const access3 = await machineAccess(paths, log, launch.value.conversationId, transport);
|
|
48916
|
-
const credentialPath = (0,
|
|
49703
|
+
const credentialPath = (0, import_node_path34.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
|
|
48917
49704
|
const managedMcp = __using(_stack, access3.managedMcp === void 0 ? void 0 : createHelperMcpAccess({
|
|
48918
49705
|
managedMcp: access3.managedMcp,
|
|
48919
49706
|
conversationId: launch.value.conversationId,
|