@tangle-network/agent-runtime 0.94.8 → 0.94.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.js +2 -2
- package/dist/candidate-execution/index.js +2 -2
- package/dist/{chunk-MSUWXCHD.js → chunk-33OG2NN3.js} +2 -2
- package/dist/{chunk-HKMKUESZ.js → chunk-37V4KQDC.js} +79 -79
- package/dist/chunk-37V4KQDC.js.map +1 -0
- package/dist/{chunk-FRXDOBFP.js → chunk-C3UKLQ54.js} +221 -21
- package/dist/chunk-C3UKLQ54.js.map +1 -0
- package/dist/{chunk-5BT2NMML.js → chunk-FTXM7Q7P.js} +2 -2
- package/dist/{chunk-TNUBPPZA.js → chunk-HGRW27YY.js} +2 -2
- package/dist/{chunk-KYPVUEJ4.js → chunk-MXBQNVFE.js} +3 -3
- package/dist/{chunk-7HH22XN4.js → chunk-YP6B7RZ2.js} +2 -2
- package/dist/chunk-YP6B7RZ2.js.map +1 -0
- package/dist/{completion-gate-tzwyyD-E.d.ts → completion-gate-BB4IZwyh.d.ts} +45 -11
- package/dist/{coordination-o0TzS7Ms.d.ts → coordination-CyVQ61My.d.ts} +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +7 -7
- package/dist/intelligence.js +1 -1
- package/dist/knowledge.d.ts +4 -3
- package/dist/knowledge.js +2 -2
- package/dist/{loop-runner-bin-iTSxSmpv.d.ts → loop-runner-bin-DA3ccCAs.d.ts} +1 -1
- package/dist/loop-runner-bin.d.ts +4 -3
- package/dist/loop-runner-bin.js +3 -3
- package/dist/loops.d.ts +9 -8
- package/dist/loops.js +2 -2
- package/dist/mcp/bin.js +1 -1
- package/dist/mcp/index.d.ts +5 -4
- package/dist/mcp/index.js +3 -3
- package/dist/{supervise-CRwaJIkd.d.ts → supervise-BaEsCHNh.d.ts} +2 -2
- package/dist/{worktree-fanout-BJy24LYe.d.ts → worktree-fanout-Do2YbtFD.d.ts} +11 -5
- package/package.json +1 -1
- package/dist/chunk-7HH22XN4.js.map +0 -1
- package/dist/chunk-FRXDOBFP.js.map +0 -1
- package/dist/chunk-HKMKUESZ.js.map +0 -1
- /package/dist/{chunk-MSUWXCHD.js.map → chunk-33OG2NN3.js.map} +0 -0
- /package/dist/{chunk-5BT2NMML.js.map → chunk-FTXM7Q7P.js.map} +0 -0
- /package/dist/{chunk-TNUBPPZA.js.map → chunk-HGRW27YY.js.map} +0 -0
- /package/dist/{chunk-KYPVUEJ4.js.map → chunk-MXBQNVFE.js.map} +0 -0
|
@@ -657,6 +657,7 @@ function errMessage(err) {
|
|
|
657
657
|
|
|
658
658
|
// src/mcp/worktree.ts
|
|
659
659
|
import { spawn } from "child_process";
|
|
660
|
+
import { isAbsolute, win32 } from "path";
|
|
660
661
|
async function runGitAsync(args, cwd, runner) {
|
|
661
662
|
if (runner) return runner(args, { cwd });
|
|
662
663
|
return new Promise((resolve, reject) => {
|
|
@@ -675,11 +676,14 @@ async function runGitAsync(args, cwd, runner) {
|
|
|
675
676
|
}
|
|
676
677
|
function ensureGitOk(step, result) {
|
|
677
678
|
if (result.exitCode !== 0) {
|
|
678
|
-
throw
|
|
679
|
-
`worktree: git ${step} failed (exit ${result.exitCode}): ${result.stderr.slice(0, 400)}`
|
|
680
|
-
);
|
|
679
|
+
throw gitFailure(step, result);
|
|
681
680
|
}
|
|
682
681
|
}
|
|
682
|
+
function gitFailure(step, result) {
|
|
683
|
+
return new Error(
|
|
684
|
+
`worktree: git ${step} failed (exit ${result.exitCode}): ${result.stderr.slice(0, 400)}`
|
|
685
|
+
);
|
|
686
|
+
}
|
|
683
687
|
async function createWorktree(options) {
|
|
684
688
|
const variants = options.variantsDir ?? ".agent-worktrees";
|
|
685
689
|
const baseRef = options.baseRef ?? "HEAD";
|
|
@@ -697,20 +701,59 @@ async function createWorktree(options) {
|
|
|
697
701
|
}
|
|
698
702
|
async function captureWorktreeDiff(options) {
|
|
699
703
|
const baseRef = options.baseRef ?? options.worktree.baseSha;
|
|
700
|
-
|
|
704
|
+
const pathspecs = worktreeDiffPathspecs(options.excludePaths ?? []);
|
|
705
|
+
const staged = await runGitAsync(
|
|
706
|
+
["add", "-A", ...pathspecs.length > 0 ? ["--", ".", ...pathspecs] : []],
|
|
707
|
+
options.worktree.path,
|
|
708
|
+
options.runGit
|
|
709
|
+
);
|
|
710
|
+
ensureGitOk("add -A", staged);
|
|
701
711
|
const patch = await runGitAsync(
|
|
702
|
-
["diff", "--cached", baseRef],
|
|
712
|
+
["diff", "--cached", baseRef, ...pathspecs.length > 0 ? ["--", ".", ...pathspecs] : []],
|
|
703
713
|
options.worktree.path,
|
|
704
714
|
options.runGit
|
|
705
715
|
);
|
|
716
|
+
ensureGitOk(`diff --cached ${baseRef}`, patch);
|
|
706
717
|
const shortstat = await runGitAsync(
|
|
707
|
-
[
|
|
718
|
+
[
|
|
719
|
+
"diff",
|
|
720
|
+
"--cached",
|
|
721
|
+
"--shortstat",
|
|
722
|
+
baseRef,
|
|
723
|
+
...pathspecs.length > 0 ? ["--", ".", ...pathspecs] : []
|
|
724
|
+
],
|
|
708
725
|
options.worktree.path,
|
|
709
726
|
options.runGit
|
|
710
727
|
);
|
|
728
|
+
ensureGitOk(`diff --cached --shortstat ${baseRef}`, shortstat);
|
|
711
729
|
const stats = parseShortstat(shortstat.stdout);
|
|
712
730
|
return { patch: patch.stdout, stats };
|
|
713
731
|
}
|
|
732
|
+
function worktreeDiffPathspecs(paths) {
|
|
733
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
734
|
+
for (const path2 of paths) {
|
|
735
|
+
if (typeof path2 !== "string" || path2.length === 0 || path2.includes("\\") || hasControlCharacter(path2) || isAbsolute(path2) || win32.isAbsolute(path2)) {
|
|
736
|
+
throw new Error(
|
|
737
|
+
`worktree: excluded path must be a canonical repository-relative path: ${path2}`
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
const segments = path2.split("/");
|
|
741
|
+
if (segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
742
|
+
throw new Error(
|
|
743
|
+
`worktree: excluded path must be a canonical repository-relative path: ${path2}`
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
normalized.add(path2);
|
|
747
|
+
}
|
|
748
|
+
return [...normalized].sort((left, right) => left.localeCompare(right)).map((path2) => `:(top,exclude,literal)${path2}`);
|
|
749
|
+
}
|
|
750
|
+
function hasControlCharacter(value) {
|
|
751
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
752
|
+
const code = value.charCodeAt(index);
|
|
753
|
+
if (code < 32 || code === 127) return true;
|
|
754
|
+
}
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
714
757
|
function parseShortstat(text) {
|
|
715
758
|
const out = { filesChanged: 0, insertions: 0, deletions: 0 };
|
|
716
759
|
const filesMatch = text.match(/(\d+)\s+files?\s+changed/);
|
|
@@ -726,19 +769,22 @@ async function removeWorktree(options) {
|
|
|
726
769
|
const args = ["worktree", "remove"];
|
|
727
770
|
if (force) args.push("--force");
|
|
728
771
|
args.push(options.worktree.path);
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
["branch", "-D", options.worktree.branch],
|
|
733
|
-
options.repoRoot,
|
|
734
|
-
options.runGit
|
|
735
|
-
).catch(() => void 0);
|
|
736
|
-
}
|
|
737
|
-
await runGitAsync(
|
|
772
|
+
const removal = await runGitAsync(args, options.repoRoot, options.runGit);
|
|
773
|
+
const removalError = removal.exitCode !== 0 && !/not a working tree/iu.test(removal.stderr) ? gitFailure(`worktree remove ${options.worktree.path}`, removal) : void 0;
|
|
774
|
+
const branchRemoval = await runGitAsync(
|
|
738
775
|
["branch", "-D", options.worktree.branch],
|
|
739
776
|
options.repoRoot,
|
|
740
777
|
options.runGit
|
|
741
|
-
)
|
|
778
|
+
);
|
|
779
|
+
const branchError = branchRemoval.exitCode !== 0 && !/branch .+ not found/iu.test(branchRemoval.stderr) ? gitFailure(`branch -D ${options.worktree.branch}`, branchRemoval) : void 0;
|
|
780
|
+
if (removalError && branchError) {
|
|
781
|
+
throw new AggregateError(
|
|
782
|
+
[removalError, branchError],
|
|
783
|
+
"worktree: failed to remove worktree and branch"
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
if (removalError) throw removalError;
|
|
787
|
+
if (branchError) throw branchError;
|
|
742
788
|
}
|
|
743
789
|
|
|
744
790
|
// src/runtime/router-client.ts
|
|
@@ -1960,6 +2006,11 @@ import { randomUUID } from "crypto";
|
|
|
1960
2006
|
|
|
1961
2007
|
// src/mcp/worktree-harness.ts
|
|
1962
2008
|
import { spawn as spawn2 } from "child_process";
|
|
2009
|
+
import { createHash } from "crypto";
|
|
2010
|
+
import {
|
|
2011
|
+
applyWorkspacePlan,
|
|
2012
|
+
materializeProfile
|
|
2013
|
+
} from "@tangle-network/agent-profile-materialize";
|
|
1963
2014
|
var defaultCheckOutputCap = 16e3;
|
|
1964
2015
|
async function runWorktreeHarness(opts) {
|
|
1965
2016
|
const runHarness = opts.runHarness ?? runLocalHarness;
|
|
@@ -1976,9 +2027,24 @@ async function runWorktreeHarness(opts) {
|
|
|
1976
2027
|
worktree,
|
|
1977
2028
|
repoRoot: opts.repoRoot,
|
|
1978
2029
|
...opts.runGit ? { runGit: opts.runGit } : {}
|
|
1979
|
-
})
|
|
2030
|
+
});
|
|
1980
2031
|
try {
|
|
1981
|
-
|
|
2032
|
+
assertSupportedWorktreeProfile(opts.profile, opts.harness);
|
|
2033
|
+
const resourceInstructions = resolveResourceInstructions(opts.profile);
|
|
2034
|
+
const workspaceProfile = materializationOnlyProfile(opts.profile);
|
|
2035
|
+
const plan = materializeProfile(workspaceProfile, opts.harness);
|
|
2036
|
+
if (plan.unsupported.length > 0) {
|
|
2037
|
+
throw new Error(
|
|
2038
|
+
`runWorktreeHarness: profile cannot be materialized for ${opts.harness}: ${plan.unsupported.map(({ dimension, reason }) => `${dimension}: ${reason}`).join("; ")}`
|
|
2039
|
+
);
|
|
2040
|
+
}
|
|
2041
|
+
assertSafeMaterializedPaths(plan);
|
|
2042
|
+
const applied = applyWorkspacePlan(plan, worktree.path);
|
|
2043
|
+
if (applied.unsupported.length > 0) {
|
|
2044
|
+
throw new Error("runWorktreeHarness: applied profile unexpectedly retained unsupported rows");
|
|
2045
|
+
}
|
|
2046
|
+
const invocationProfile = profileWithResourceInstructions(opts.profile, resourceInstructions);
|
|
2047
|
+
const { command, args } = harnessInvocation(opts.harness, invocationProfile, opts.taskPrompt, {
|
|
1982
2048
|
// This helper created the candidate worktree above; autonomous Claude
|
|
1983
2049
|
// edits are permitted only inside that isolated checkout.
|
|
1984
2050
|
dangerouslySkipPermissions: opts.harness === "claude",
|
|
@@ -1988,7 +2054,8 @@ async function runWorktreeHarness(opts) {
|
|
|
1988
2054
|
harness: opts.harness,
|
|
1989
2055
|
cwd: worktree.path,
|
|
1990
2056
|
taskPrompt: opts.taskPrompt,
|
|
1991
|
-
invocation: { command, args },
|
|
2057
|
+
invocation: { command, args: [...args, ...applied.flags] },
|
|
2058
|
+
env: { ...process.env, ...applied.env },
|
|
1992
2059
|
...opts.codexReproducible ? { codexReproducible: true } : {},
|
|
1993
2060
|
...opts.codexReadDeniedPaths ? { codexReadDeniedPaths: opts.codexReadDeniedPaths } : {},
|
|
1994
2061
|
...opts.harnessTimeoutMs !== void 0 ? { timeoutMs: opts.harnessTimeoutMs } : {},
|
|
@@ -1996,6 +2063,7 @@ async function runWorktreeHarness(opts) {
|
|
|
1996
2063
|
});
|
|
1997
2064
|
const diff = await captureWorktreeDiff({
|
|
1998
2065
|
worktree,
|
|
2066
|
+
excludePaths: applied.written,
|
|
1999
2067
|
...opts.runGit ? { runGit: opts.runGit } : {}
|
|
2000
2068
|
});
|
|
2001
2069
|
const checks = await runWorktreeChecks({
|
|
@@ -2011,6 +2079,7 @@ async function runWorktreeHarness(opts) {
|
|
|
2011
2079
|
branch: worktree.branch,
|
|
2012
2080
|
patch: diff.patch,
|
|
2013
2081
|
stats: diff.stats,
|
|
2082
|
+
profileMaterialization: profileMaterializationReceipt(applied, resourceInstructions),
|
|
2014
2083
|
harness: {
|
|
2015
2084
|
name: opts.harness,
|
|
2016
2085
|
exitCode: harnessResult.exitCode,
|
|
@@ -2037,10 +2106,141 @@ async function runWorktreeHarness(opts) {
|
|
|
2037
2106
|
};
|
|
2038
2107
|
return { worktree, result, cleanup };
|
|
2039
2108
|
} catch (err) {
|
|
2040
|
-
|
|
2109
|
+
try {
|
|
2110
|
+
await cleanup();
|
|
2111
|
+
} catch (cleanupError) {
|
|
2112
|
+
throw new AggregateError(
|
|
2113
|
+
[err, cleanupError],
|
|
2114
|
+
"runWorktreeHarness: run failed and worktree cleanup also failed"
|
|
2115
|
+
);
|
|
2116
|
+
}
|
|
2041
2117
|
throw err;
|
|
2042
2118
|
}
|
|
2043
2119
|
}
|
|
2120
|
+
function resolveResourceInstructions(profile) {
|
|
2121
|
+
const instructions = profile.resources?.instructions;
|
|
2122
|
+
if (instructions === void 0) return void 0;
|
|
2123
|
+
if (typeof instructions === "string")
|
|
2124
|
+
return instructions.trim().length > 0 ? instructions : void 0;
|
|
2125
|
+
if (instructions.kind === "inline" && typeof instructions.content === "string") {
|
|
2126
|
+
return instructions.content.trim().length > 0 ? instructions.content : void 0;
|
|
2127
|
+
}
|
|
2128
|
+
throw new Error(
|
|
2129
|
+
"runWorktreeHarness: resources.instructions must be a string or inline resource; remote refs require pre-resolution"
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
function profileWithResourceInstructions(profile, resourceInstructions) {
|
|
2133
|
+
let resources;
|
|
2134
|
+
if (profile.resources) {
|
|
2135
|
+
const { instructions: _instructions, ...structuralResources } = profile.resources;
|
|
2136
|
+
resources = structuralResources;
|
|
2137
|
+
}
|
|
2138
|
+
return {
|
|
2139
|
+
...profile,
|
|
2140
|
+
...resources ? { resources } : {},
|
|
2141
|
+
...resourceInstructions === void 0 ? {} : {
|
|
2142
|
+
prompt: {
|
|
2143
|
+
...profile.prompt,
|
|
2144
|
+
instructions: [...profile.prompt?.instructions ?? [], resourceInstructions]
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
function materializationOnlyProfile(profile) {
|
|
2150
|
+
const {
|
|
2151
|
+
prompt: _prompt,
|
|
2152
|
+
model: _model,
|
|
2153
|
+
resources: profileResources,
|
|
2154
|
+
...structuralProfile
|
|
2155
|
+
} = profile;
|
|
2156
|
+
let resources;
|
|
2157
|
+
if (profileResources) {
|
|
2158
|
+
const { instructions: _instructions, ...fileBackedResources } = profileResources;
|
|
2159
|
+
resources = fileBackedResources;
|
|
2160
|
+
}
|
|
2161
|
+
return {
|
|
2162
|
+
...structuralProfile,
|
|
2163
|
+
...resources ? { resources } : {}
|
|
2164
|
+
};
|
|
2165
|
+
}
|
|
2166
|
+
function assertSupportedWorktreeProfile(profile, harness) {
|
|
2167
|
+
const unsupportedAxes = [
|
|
2168
|
+
hasEntries(profile.tools) ? "tools" : null,
|
|
2169
|
+
hasEntries(profile.permissions) ? "permissions" : null,
|
|
2170
|
+
profile.connections && profile.connections.length > 0 ? "connections" : null,
|
|
2171
|
+
hasEntries(profile.confidential) ? "confidential" : null,
|
|
2172
|
+
hasEntries(profile.modes) ? "modes" : null,
|
|
2173
|
+
hasEntries(profile.extensions) ? "extensions" : null
|
|
2174
|
+
].filter((axis) => axis !== null);
|
|
2175
|
+
if (profile.model?.reasoningEffort !== void 0 && harness !== "codex") {
|
|
2176
|
+
unsupportedAxes.push("model.reasoningEffort");
|
|
2177
|
+
}
|
|
2178
|
+
for (const [name, server] of Object.entries(profile.mcp ?? {})) {
|
|
2179
|
+
const path2 = `mcp[${JSON.stringify(name)}]`;
|
|
2180
|
+
if (server.enabled === false && harness !== "opencode") {
|
|
2181
|
+
unsupportedAxes.push(`${path2}.enabled`);
|
|
2182
|
+
}
|
|
2183
|
+
if (hasEntries(server.headers) && harness === "codex") {
|
|
2184
|
+
unsupportedAxes.push(`${path2}.headers`);
|
|
2185
|
+
}
|
|
2186
|
+
if (server.cwd !== void 0 && harness === "opencode") {
|
|
2187
|
+
unsupportedAxes.push(`${path2}.cwd`);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
if (harness === "claude") {
|
|
2191
|
+
for (const [event, commands] of Object.entries(profile.hooks ?? {})) {
|
|
2192
|
+
for (const [index, command] of commands.entries()) {
|
|
2193
|
+
const path2 = `hooks[${JSON.stringify(event)}][${index}]`;
|
|
2194
|
+
if (hasEntries(command.env)) unsupportedAxes.push(`${path2}.env`);
|
|
2195
|
+
if (command.blocking !== void 0) unsupportedAxes.push(`${path2}.blocking`);
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
for (const [name, subagent] of Object.entries(profile.subagents ?? {})) {
|
|
2200
|
+
const path2 = `subagents[${JSON.stringify(name)}]`;
|
|
2201
|
+
if (hasEntries(subagent.permissions)) unsupportedAxes.push(`${path2}.permissions`);
|
|
2202
|
+
if (subagent.maxSteps !== void 0) unsupportedAxes.push(`${path2}.maxSteps`);
|
|
2203
|
+
if (hasEntries(subagent.tools) && harness !== "claude") {
|
|
2204
|
+
unsupportedAxes.push(`${path2}.tools`);
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
if (unsupportedAxes.length > 0) {
|
|
2208
|
+
throw new Error(
|
|
2209
|
+
`runWorktreeHarness: profile requests unsupported worktree behavior: ${unsupportedAxes.join(", ")}`
|
|
2210
|
+
);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
function hasEntries(value) {
|
|
2214
|
+
return value !== void 0 && Object.keys(value).length > 0;
|
|
2215
|
+
}
|
|
2216
|
+
function assertSafeMaterializedPaths(plan) {
|
|
2217
|
+
for (const file of plan.files) {
|
|
2218
|
+
if (file.relPath.split("/").some(isGitMetadataSegment)) {
|
|
2219
|
+
throw new Error(
|
|
2220
|
+
`runWorktreeHarness: profile file cannot target reserved Git metadata: ${file.relPath}`
|
|
2221
|
+
);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
function isGitMetadataSegment(segment) {
|
|
2226
|
+
const windowsCanonical = segment.replace(/[ .]+$/u, "").toLowerCase();
|
|
2227
|
+
return windowsCanonical === ".git" || windowsCanonical.startsWith(".git:");
|
|
2228
|
+
}
|
|
2229
|
+
function profileMaterializationReceipt(applied, resourceInstructions) {
|
|
2230
|
+
const instructionBytes = resourceInstructions === void 0 ? null : Buffer.from(resourceInstructions, "utf8");
|
|
2231
|
+
return {
|
|
2232
|
+
workspacePlanDigest: applied.workspacePlanDigest,
|
|
2233
|
+
writtenPaths: [...applied.written],
|
|
2234
|
+
unsupported: [...applied.unsupported],
|
|
2235
|
+
environmentNames: Object.keys(applied.env).sort(),
|
|
2236
|
+
flags: [...applied.flags],
|
|
2237
|
+
resourceInstructions: instructionBytes ? {
|
|
2238
|
+
delivery: "invocation-prompt",
|
|
2239
|
+
sha256: `sha256:${createHash("sha256").update(instructionBytes).digest("hex")}`,
|
|
2240
|
+
byteLength: instructionBytes.byteLength
|
|
2241
|
+
} : { delivery: "none", sha256: null, byteLength: 0 }
|
|
2242
|
+
};
|
|
2243
|
+
}
|
|
2044
2244
|
async function runWorktreeChecks(opts) {
|
|
2045
2245
|
if (opts.testCmd === void 0 && opts.typecheckCmd === void 0) return void 0;
|
|
2046
2246
|
const runCommand = opts.runCommand ?? defaultRunCommand;
|
|
@@ -6626,4 +6826,4 @@ export {
|
|
|
6626
6826
|
workerFromBackend,
|
|
6627
6827
|
supervise
|
|
6628
6828
|
};
|
|
6629
|
-
//# sourceMappingURL=chunk-
|
|
6829
|
+
//# sourceMappingURL=chunk-C3UKLQ54.js.map
|