agent-relay 4.0.19 → 4.0.21
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/index.cjs +1407 -537
- package/dist/src/cli/commands/messaging.d.ts +44 -0
- package/dist/src/cli/commands/messaging.d.ts.map +1 -1
- package/dist/src/cli/commands/messaging.js +195 -8
- package/dist/src/cli/commands/messaging.js.map +1 -1
- package/dist/src/cli/commands/setup.d.ts +30 -1
- package/dist/src/cli/commands/setup.d.ts.map +1 -1
- package/dist/src/cli/commands/setup.js +102 -85
- package/dist/src/cli/commands/setup.js.map +1 -1
- package/node_modules/@agent-relay/cloud/dist/auth.d.ts +2 -2
- package/node_modules/@agent-relay/cloud/dist/auth.d.ts.map +1 -1
- package/node_modules/@agent-relay/cloud/dist/auth.js +108 -62
- package/node_modules/@agent-relay/cloud/dist/auth.js.map +1 -1
- package/node_modules/@agent-relay/cloud/package.json +2 -2
- package/node_modules/@agent-relay/config/package.json +1 -1
- package/node_modules/@agent-relay/hooks/package.json +4 -4
- package/node_modules/@agent-relay/sdk/dist/workflows/trajectory.d.ts +5 -35
- package/node_modules/@agent-relay/sdk/dist/workflows/trajectory.d.ts.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/workflows/trajectory.js +158 -292
- package/node_modules/@agent-relay/sdk/dist/workflows/trajectory.js.map +1 -1
- package/node_modules/@agent-relay/sdk/package.json +3 -2
- package/node_modules/@agent-relay/telemetry/package.json +1 -1
- package/node_modules/@agent-relay/trajectory/package.json +2 -2
- package/node_modules/@agent-relay/user-directory/package.json +2 -2
- package/node_modules/@agent-relay/utils/package.json +2 -2
- package/node_modules/@clack/core/CHANGELOG.md +200 -0
- package/node_modules/@clack/core/LICENSE +9 -0
- package/node_modules/@clack/core/README.md +22 -0
- package/node_modules/@clack/core/dist/index.cjs +15 -0
- package/node_modules/@clack/core/dist/index.cjs.map +1 -0
- package/node_modules/@clack/core/dist/index.d.cts +151 -0
- package/node_modules/@clack/core/dist/index.d.mts +151 -0
- package/node_modules/@clack/core/dist/index.d.ts +151 -0
- package/node_modules/@clack/core/dist/index.mjs +15 -0
- package/node_modules/@clack/core/dist/index.mjs.map +1 -0
- package/node_modules/@clack/core/package.json +62 -0
- package/node_modules/@clack/prompts/CHANGELOG.md +256 -0
- package/node_modules/@clack/prompts/LICENSE +23 -0
- package/node_modules/@clack/prompts/README.md +158 -0
- package/node_modules/@clack/prompts/dist/index.cjs +77 -0
- package/node_modules/@clack/prompts/dist/index.d.ts +106 -0
- package/node_modules/@clack/prompts/dist/index.mjs +77 -0
- package/node_modules/@clack/prompts/node_modules/is-unicode-supported/index.d.ts +12 -0
- package/node_modules/@clack/prompts/node_modules/is-unicode-supported/index.js +17 -0
- package/node_modules/@clack/prompts/node_modules/is-unicode-supported/license +9 -0
- package/node_modules/@clack/prompts/node_modules/is-unicode-supported/package.json +43 -0
- package/node_modules/@clack/prompts/node_modules/is-unicode-supported/readme.md +35 -0
- package/node_modules/@clack/prompts/package.json +65 -0
- package/node_modules/@smithy/config-resolver/package.json +2 -2
- package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
- package/node_modules/@smithy/util-endpoints/dist-cjs/index.js +154 -61
- package/node_modules/@smithy/util-endpoints/dist-es/bdd/BinaryDecisionDiagram.js +15 -0
- package/node_modules/@smithy/util-endpoints/dist-es/decideEndpoint.js +41 -0
- package/node_modules/@smithy/util-endpoints/dist-es/index.js +2 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/coalesce.js +8 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/index.js +3 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/ite.js +3 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/split.js +13 -0
- package/node_modules/@smithy/util-endpoints/dist-es/lib/substring.js +1 -1
- package/node_modules/@smithy/util-endpoints/dist-es/utils/endpointFunctions.js +4 -1
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateExpression.js +20 -5
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateTemplate.js +3 -6
- package/node_modules/@smithy/util-endpoints/dist-es/utils/getReferenceValue.js +1 -5
- package/node_modules/@smithy/util-endpoints/dist-types/bdd/BinaryDecisionDiagram.d.ts +22 -0
- package/node_modules/@smithy/util-endpoints/dist-types/decideEndpoint.d.ts +7 -0
- package/node_modules/@smithy/util-endpoints/dist-types/index.d.ts +2 -0
- package/node_modules/@smithy/util-endpoints/dist-types/lib/coalesce.d.ts +7 -0
- package/node_modules/@smithy/util-endpoints/dist-types/lib/index.d.ts +3 -0
- package/node_modules/@smithy/util-endpoints/dist-types/lib/ite.d.ts +6 -0
- package/node_modules/@smithy/util-endpoints/dist-types/lib/split.d.ts +11 -0
- package/node_modules/@smithy/util-endpoints/dist-types/utils/endpointFunctions.d.ts +4 -0
- package/node_modules/@smithy/util-endpoints/dist-types/utils/getReferenceValue.d.ts +3 -1
- package/node_modules/@smithy/util-endpoints/package.json +1 -1
- package/node_modules/agent-trajectories/README.md +562 -0
- package/node_modules/agent-trajectories/dist/chunk-W222QB6V.js +2036 -0
- package/node_modules/agent-trajectories/dist/chunk-W222QB6V.js.map +1 -0
- package/node_modules/agent-trajectories/dist/cli/index.d.ts +2 -0
- package/node_modules/agent-trajectories/dist/cli/index.js +4592 -0
- package/node_modules/agent-trajectories/dist/cli/index.js.map +1 -0
- package/node_modules/agent-trajectories/dist/index-7tzw_CMS.d.ts +1777 -0
- package/node_modules/agent-trajectories/dist/index.d.ts +90 -0
- package/node_modules/agent-trajectories/dist/index.js +73 -0
- package/node_modules/agent-trajectories/dist/index.js.map +1 -0
- package/node_modules/agent-trajectories/dist/sdk/index.d.ts +2 -0
- package/node_modules/agent-trajectories/dist/sdk/index.js +39 -0
- package/node_modules/agent-trajectories/dist/sdk/index.js.map +1 -0
- package/node_modules/agent-trajectories/package.json +72 -0
- package/node_modules/commander/LICENSE +22 -0
- package/node_modules/commander/Readme.md +1157 -0
- package/node_modules/commander/esm.mjs +16 -0
- package/node_modules/commander/index.js +24 -0
- package/node_modules/commander/lib/argument.js +149 -0
- package/node_modules/commander/lib/command.js +2509 -0
- package/node_modules/commander/lib/error.js +39 -0
- package/node_modules/commander/lib/help.js +520 -0
- package/node_modules/commander/lib/option.js +330 -0
- package/node_modules/commander/lib/suggestSimilar.js +101 -0
- package/node_modules/commander/package-support.json +16 -0
- package/node_modules/commander/package.json +84 -0
- package/node_modules/commander/typings/esm.d.mts +3 -0
- package/node_modules/commander/typings/index.d.ts +969 -0
- package/node_modules/picocolors/LICENSE +15 -0
- package/node_modules/picocolors/README.md +21 -0
- package/node_modules/picocolors/package.json +25 -0
- package/node_modules/picocolors/picocolors.browser.js +4 -0
- package/node_modules/picocolors/picocolors.d.ts +5 -0
- package/node_modules/picocolors/picocolors.js +75 -0
- package/node_modules/picocolors/types.d.ts +51 -0
- package/node_modules/sisteransi/license +21 -0
- package/node_modules/sisteransi/package.json +34 -0
- package/node_modules/sisteransi/readme.md +113 -0
- package/node_modules/sisteransi/src/index.js +58 -0
- package/node_modules/sisteransi/src/sisteransi.d.ts +35 -0
- package/package.json +10 -10
- package/packages/cloud/dist/auth.d.ts +2 -2
- package/packages/cloud/dist/auth.d.ts.map +1 -1
- package/packages/cloud/dist/auth.js +108 -62
- package/packages/cloud/dist/auth.js.map +1 -1
- package/packages/cloud/package.json +2 -2
- package/packages/config/package.json +1 -1
- package/packages/hooks/package.json +4 -4
- package/packages/sdk/dist/workflows/trajectory.d.ts +5 -35
- package/packages/sdk/dist/workflows/trajectory.d.ts.map +1 -1
- package/packages/sdk/dist/workflows/trajectory.js +158 -292
- package/packages/sdk/dist/workflows/trajectory.js.map +1 -1
- package/packages/sdk/package.json +3 -2
- package/packages/telemetry/package.json +1 -1
- package/packages/trajectory/package.json +2 -2
- package/packages/user-directory/package.json +2 -2
- package/packages/utils/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2237,7 +2237,7 @@ var require_websocket = __commonJS({
|
|
|
2237
2237
|
var http = require("http");
|
|
2238
2238
|
var net = require("net");
|
|
2239
2239
|
var tls = require("tls");
|
|
2240
|
-
var { randomBytes:
|
|
2240
|
+
var { randomBytes: randomBytes9, createHash: createHash3 } = require("crypto");
|
|
2241
2241
|
var { Duplex, Readable } = require("stream");
|
|
2242
2242
|
var { URL: URL2 } = require("url");
|
|
2243
2243
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -2767,7 +2767,7 @@ var require_websocket = __commonJS({
|
|
|
2767
2767
|
}
|
|
2768
2768
|
}
|
|
2769
2769
|
const defaultPort = isSecure ? 443 : 80;
|
|
2770
|
-
const key =
|
|
2770
|
+
const key = randomBytes9(16).toString("base64");
|
|
2771
2771
|
const request = isSecure ? https3.request : http.request;
|
|
2772
2772
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
2773
2773
|
let perMessageDeflate;
|
|
@@ -4531,15 +4531,15 @@ var require_route = __commonJS({
|
|
|
4531
4531
|
};
|
|
4532
4532
|
}
|
|
4533
4533
|
function wrapConversion(toModel, graph) {
|
|
4534
|
-
const
|
|
4534
|
+
const path24 = [graph[toModel].parent, toModel];
|
|
4535
4535
|
let fn2 = conversions[graph[toModel].parent][toModel];
|
|
4536
4536
|
let cur = graph[toModel].parent;
|
|
4537
4537
|
while (graph[cur].parent) {
|
|
4538
|
-
|
|
4538
|
+
path24.unshift(graph[cur].parent);
|
|
4539
4539
|
fn2 = link2(conversions[graph[cur].parent][cur], fn2);
|
|
4540
4540
|
cur = graph[cur].parent;
|
|
4541
4541
|
}
|
|
4542
|
-
fn2.conversion =
|
|
4542
|
+
fn2.conversion = path24;
|
|
4543
4543
|
return fn2;
|
|
4544
4544
|
}
|
|
4545
4545
|
module2.exports = function(fromModel) {
|
|
@@ -5505,7 +5505,7 @@ var require_ignore = __commonJS({
|
|
|
5505
5505
|
// path matching.
|
|
5506
5506
|
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
5507
5507
|
// @returns {TestResult} true if a file is ignored
|
|
5508
|
-
test(
|
|
5508
|
+
test(path24, checkUnignored, mode) {
|
|
5509
5509
|
let ignored = false;
|
|
5510
5510
|
let unignored = false;
|
|
5511
5511
|
let matchedRule;
|
|
@@ -5514,7 +5514,7 @@ var require_ignore = __commonJS({
|
|
|
5514
5514
|
if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
|
|
5515
5515
|
return;
|
|
5516
5516
|
}
|
|
5517
|
-
const matched = rule[mode].test(
|
|
5517
|
+
const matched = rule[mode].test(path24);
|
|
5518
5518
|
if (!matched) {
|
|
5519
5519
|
return;
|
|
5520
5520
|
}
|
|
@@ -5535,17 +5535,17 @@ var require_ignore = __commonJS({
|
|
|
5535
5535
|
var throwError = (message, Ctor) => {
|
|
5536
5536
|
throw new Ctor(message);
|
|
5537
5537
|
};
|
|
5538
|
-
var checkPath = (
|
|
5539
|
-
if (!isString(
|
|
5538
|
+
var checkPath = (path24, originalPath, doThrow) => {
|
|
5539
|
+
if (!isString(path24)) {
|
|
5540
5540
|
return doThrow(
|
|
5541
5541
|
`path must be a string, but got \`${originalPath}\``,
|
|
5542
5542
|
TypeError
|
|
5543
5543
|
);
|
|
5544
5544
|
}
|
|
5545
|
-
if (!
|
|
5545
|
+
if (!path24) {
|
|
5546
5546
|
return doThrow(`path must not be empty`, TypeError);
|
|
5547
5547
|
}
|
|
5548
|
-
if (checkPath.isNotRelative(
|
|
5548
|
+
if (checkPath.isNotRelative(path24)) {
|
|
5549
5549
|
const r = "`path.relative()`d";
|
|
5550
5550
|
return doThrow(
|
|
5551
5551
|
`path should be a ${r} string, but got "${originalPath}"`,
|
|
@@ -5554,7 +5554,7 @@ var require_ignore = __commonJS({
|
|
|
5554
5554
|
}
|
|
5555
5555
|
return true;
|
|
5556
5556
|
};
|
|
5557
|
-
var isNotRelative = (
|
|
5557
|
+
var isNotRelative = (path24) => REGEX_TEST_INVALID_PATH.test(path24);
|
|
5558
5558
|
checkPath.isNotRelative = isNotRelative;
|
|
5559
5559
|
checkPath.convert = (p2) => p2;
|
|
5560
5560
|
var Ignore = class {
|
|
@@ -5584,19 +5584,19 @@ var require_ignore = __commonJS({
|
|
|
5584
5584
|
}
|
|
5585
5585
|
// @returns {TestResult}
|
|
5586
5586
|
_test(originalPath, cache, checkUnignored, slices) {
|
|
5587
|
-
const
|
|
5587
|
+
const path24 = originalPath && checkPath.convert(originalPath);
|
|
5588
5588
|
checkPath(
|
|
5589
|
-
|
|
5589
|
+
path24,
|
|
5590
5590
|
originalPath,
|
|
5591
5591
|
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
5592
5592
|
);
|
|
5593
|
-
return this._t(
|
|
5593
|
+
return this._t(path24, cache, checkUnignored, slices);
|
|
5594
5594
|
}
|
|
5595
|
-
checkIgnore(
|
|
5596
|
-
if (!REGEX_TEST_TRAILING_SLASH.test(
|
|
5597
|
-
return this.test(
|
|
5595
|
+
checkIgnore(path24) {
|
|
5596
|
+
if (!REGEX_TEST_TRAILING_SLASH.test(path24)) {
|
|
5597
|
+
return this.test(path24);
|
|
5598
5598
|
}
|
|
5599
|
-
const slices =
|
|
5599
|
+
const slices = path24.split(SLASH).filter(Boolean);
|
|
5600
5600
|
slices.pop();
|
|
5601
5601
|
if (slices.length) {
|
|
5602
5602
|
const parent = this._t(
|
|
@@ -5609,18 +5609,18 @@ var require_ignore = __commonJS({
|
|
|
5609
5609
|
return parent;
|
|
5610
5610
|
}
|
|
5611
5611
|
}
|
|
5612
|
-
return this._rules.test(
|
|
5612
|
+
return this._rules.test(path24, false, MODE_CHECK_IGNORE);
|
|
5613
5613
|
}
|
|
5614
|
-
_t(
|
|
5615
|
-
if (
|
|
5616
|
-
return cache[
|
|
5614
|
+
_t(path24, cache, checkUnignored, slices) {
|
|
5615
|
+
if (path24 in cache) {
|
|
5616
|
+
return cache[path24];
|
|
5617
5617
|
}
|
|
5618
5618
|
if (!slices) {
|
|
5619
|
-
slices =
|
|
5619
|
+
slices = path24.split(SLASH).filter(Boolean);
|
|
5620
5620
|
}
|
|
5621
5621
|
slices.pop();
|
|
5622
5622
|
if (!slices.length) {
|
|
5623
|
-
return cache[
|
|
5623
|
+
return cache[path24] = this._rules.test(path24, checkUnignored, MODE_IGNORE);
|
|
5624
5624
|
}
|
|
5625
5625
|
const parent = this._t(
|
|
5626
5626
|
slices.join(SLASH) + SLASH,
|
|
@@ -5628,29 +5628,29 @@ var require_ignore = __commonJS({
|
|
|
5628
5628
|
checkUnignored,
|
|
5629
5629
|
slices
|
|
5630
5630
|
);
|
|
5631
|
-
return cache[
|
|
5631
|
+
return cache[path24] = parent.ignored ? parent : this._rules.test(path24, checkUnignored, MODE_IGNORE);
|
|
5632
5632
|
}
|
|
5633
|
-
ignores(
|
|
5634
|
-
return this._test(
|
|
5633
|
+
ignores(path24) {
|
|
5634
|
+
return this._test(path24, this._ignoreCache, false).ignored;
|
|
5635
5635
|
}
|
|
5636
5636
|
createFilter() {
|
|
5637
|
-
return (
|
|
5637
|
+
return (path24) => !this.ignores(path24);
|
|
5638
5638
|
}
|
|
5639
5639
|
filter(paths) {
|
|
5640
5640
|
return makeArray(paths).filter(this.createFilter());
|
|
5641
5641
|
}
|
|
5642
5642
|
// @returns {TestResult}
|
|
5643
|
-
test(
|
|
5644
|
-
return this._test(
|
|
5643
|
+
test(path24) {
|
|
5644
|
+
return this._test(path24, this._testCache, true);
|
|
5645
5645
|
}
|
|
5646
5646
|
};
|
|
5647
5647
|
var factory = (options) => new Ignore(options);
|
|
5648
|
-
var isPathValid = (
|
|
5648
|
+
var isPathValid = (path24) => checkPath(path24 && checkPath.convert(path24), path24, RETURN_FALSE);
|
|
5649
5649
|
var setupWindows = () => {
|
|
5650
5650
|
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
5651
5651
|
checkPath.convert = makePosix;
|
|
5652
5652
|
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
5653
|
-
checkPath.isNotRelative = (
|
|
5653
|
+
checkPath.isNotRelative = (path24) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path24) || isNotRelative(path24);
|
|
5654
5654
|
};
|
|
5655
5655
|
if (
|
|
5656
5656
|
// Detect `process` so that it can run in browsers.
|
|
@@ -5742,17 +5742,17 @@ var require_visit = __commonJS({
|
|
|
5742
5742
|
visit.BREAK = BREAK;
|
|
5743
5743
|
visit.SKIP = SKIP;
|
|
5744
5744
|
visit.REMOVE = REMOVE;
|
|
5745
|
-
function visit_(key, node, visitor,
|
|
5746
|
-
const ctrl = callVisitor(key, node, visitor,
|
|
5745
|
+
function visit_(key, node, visitor, path24) {
|
|
5746
|
+
const ctrl = callVisitor(key, node, visitor, path24);
|
|
5747
5747
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
5748
|
-
replaceNode(key,
|
|
5749
|
-
return visit_(key, ctrl, visitor,
|
|
5748
|
+
replaceNode(key, path24, ctrl);
|
|
5749
|
+
return visit_(key, ctrl, visitor, path24);
|
|
5750
5750
|
}
|
|
5751
5751
|
if (typeof ctrl !== "symbol") {
|
|
5752
5752
|
if (identity.isCollection(node)) {
|
|
5753
|
-
|
|
5753
|
+
path24 = Object.freeze(path24.concat(node));
|
|
5754
5754
|
for (let i = 0; i < node.items.length; ++i) {
|
|
5755
|
-
const ci2 = visit_(i, node.items[i], visitor,
|
|
5755
|
+
const ci2 = visit_(i, node.items[i], visitor, path24);
|
|
5756
5756
|
if (typeof ci2 === "number")
|
|
5757
5757
|
i = ci2 - 1;
|
|
5758
5758
|
else if (ci2 === BREAK)
|
|
@@ -5763,13 +5763,13 @@ var require_visit = __commonJS({
|
|
|
5763
5763
|
}
|
|
5764
5764
|
}
|
|
5765
5765
|
} else if (identity.isPair(node)) {
|
|
5766
|
-
|
|
5767
|
-
const ck = visit_("key", node.key, visitor,
|
|
5766
|
+
path24 = Object.freeze(path24.concat(node));
|
|
5767
|
+
const ck = visit_("key", node.key, visitor, path24);
|
|
5768
5768
|
if (ck === BREAK)
|
|
5769
5769
|
return BREAK;
|
|
5770
5770
|
else if (ck === REMOVE)
|
|
5771
5771
|
node.key = null;
|
|
5772
|
-
const cv = visit_("value", node.value, visitor,
|
|
5772
|
+
const cv = visit_("value", node.value, visitor, path24);
|
|
5773
5773
|
if (cv === BREAK)
|
|
5774
5774
|
return BREAK;
|
|
5775
5775
|
else if (cv === REMOVE)
|
|
@@ -5790,17 +5790,17 @@ var require_visit = __commonJS({
|
|
|
5790
5790
|
visitAsync.BREAK = BREAK;
|
|
5791
5791
|
visitAsync.SKIP = SKIP;
|
|
5792
5792
|
visitAsync.REMOVE = REMOVE;
|
|
5793
|
-
async function visitAsync_(key, node, visitor,
|
|
5794
|
-
const ctrl = await callVisitor(key, node, visitor,
|
|
5793
|
+
async function visitAsync_(key, node, visitor, path24) {
|
|
5794
|
+
const ctrl = await callVisitor(key, node, visitor, path24);
|
|
5795
5795
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
5796
|
-
replaceNode(key,
|
|
5797
|
-
return visitAsync_(key, ctrl, visitor,
|
|
5796
|
+
replaceNode(key, path24, ctrl);
|
|
5797
|
+
return visitAsync_(key, ctrl, visitor, path24);
|
|
5798
5798
|
}
|
|
5799
5799
|
if (typeof ctrl !== "symbol") {
|
|
5800
5800
|
if (identity.isCollection(node)) {
|
|
5801
|
-
|
|
5801
|
+
path24 = Object.freeze(path24.concat(node));
|
|
5802
5802
|
for (let i = 0; i < node.items.length; ++i) {
|
|
5803
|
-
const ci2 = await visitAsync_(i, node.items[i], visitor,
|
|
5803
|
+
const ci2 = await visitAsync_(i, node.items[i], visitor, path24);
|
|
5804
5804
|
if (typeof ci2 === "number")
|
|
5805
5805
|
i = ci2 - 1;
|
|
5806
5806
|
else if (ci2 === BREAK)
|
|
@@ -5811,13 +5811,13 @@ var require_visit = __commonJS({
|
|
|
5811
5811
|
}
|
|
5812
5812
|
}
|
|
5813
5813
|
} else if (identity.isPair(node)) {
|
|
5814
|
-
|
|
5815
|
-
const ck = await visitAsync_("key", node.key, visitor,
|
|
5814
|
+
path24 = Object.freeze(path24.concat(node));
|
|
5815
|
+
const ck = await visitAsync_("key", node.key, visitor, path24);
|
|
5816
5816
|
if (ck === BREAK)
|
|
5817
5817
|
return BREAK;
|
|
5818
5818
|
else if (ck === REMOVE)
|
|
5819
5819
|
node.key = null;
|
|
5820
|
-
const cv = await visitAsync_("value", node.value, visitor,
|
|
5820
|
+
const cv = await visitAsync_("value", node.value, visitor, path24);
|
|
5821
5821
|
if (cv === BREAK)
|
|
5822
5822
|
return BREAK;
|
|
5823
5823
|
else if (cv === REMOVE)
|
|
@@ -5844,23 +5844,23 @@ var require_visit = __commonJS({
|
|
|
5844
5844
|
}
|
|
5845
5845
|
return visitor;
|
|
5846
5846
|
}
|
|
5847
|
-
function callVisitor(key, node, visitor,
|
|
5847
|
+
function callVisitor(key, node, visitor, path24) {
|
|
5848
5848
|
if (typeof visitor === "function")
|
|
5849
|
-
return visitor(key, node,
|
|
5849
|
+
return visitor(key, node, path24);
|
|
5850
5850
|
if (identity.isMap(node))
|
|
5851
|
-
return visitor.Map?.(key, node,
|
|
5851
|
+
return visitor.Map?.(key, node, path24);
|
|
5852
5852
|
if (identity.isSeq(node))
|
|
5853
|
-
return visitor.Seq?.(key, node,
|
|
5853
|
+
return visitor.Seq?.(key, node, path24);
|
|
5854
5854
|
if (identity.isPair(node))
|
|
5855
|
-
return visitor.Pair?.(key, node,
|
|
5855
|
+
return visitor.Pair?.(key, node, path24);
|
|
5856
5856
|
if (identity.isScalar(node))
|
|
5857
|
-
return visitor.Scalar?.(key, node,
|
|
5857
|
+
return visitor.Scalar?.(key, node, path24);
|
|
5858
5858
|
if (identity.isAlias(node))
|
|
5859
|
-
return visitor.Alias?.(key, node,
|
|
5859
|
+
return visitor.Alias?.(key, node, path24);
|
|
5860
5860
|
return void 0;
|
|
5861
5861
|
}
|
|
5862
|
-
function replaceNode(key,
|
|
5863
|
-
const parent =
|
|
5862
|
+
function replaceNode(key, path24, node) {
|
|
5863
|
+
const parent = path24[path24.length - 1];
|
|
5864
5864
|
if (identity.isCollection(parent)) {
|
|
5865
5865
|
parent.items[key] = node;
|
|
5866
5866
|
} else if (identity.isPair(parent)) {
|
|
@@ -6468,10 +6468,10 @@ var require_Collection = __commonJS({
|
|
|
6468
6468
|
var createNode = require_createNode();
|
|
6469
6469
|
var identity = require_identity();
|
|
6470
6470
|
var Node = require_Node();
|
|
6471
|
-
function collectionFromPath(schema,
|
|
6471
|
+
function collectionFromPath(schema, path24, value) {
|
|
6472
6472
|
let v2 = value;
|
|
6473
|
-
for (let i =
|
|
6474
|
-
const k2 =
|
|
6473
|
+
for (let i = path24.length - 1; i >= 0; --i) {
|
|
6474
|
+
const k2 = path24[i];
|
|
6475
6475
|
if (typeof k2 === "number" && Number.isInteger(k2) && k2 >= 0) {
|
|
6476
6476
|
const a = [];
|
|
6477
6477
|
a[k2] = v2;
|
|
@@ -6490,7 +6490,7 @@ var require_Collection = __commonJS({
|
|
|
6490
6490
|
sourceObjects: /* @__PURE__ */ new Map()
|
|
6491
6491
|
});
|
|
6492
6492
|
}
|
|
6493
|
-
var isEmptyPath = (
|
|
6493
|
+
var isEmptyPath = (path24) => path24 == null || typeof path24 === "object" && !!path24[Symbol.iterator]().next().done;
|
|
6494
6494
|
var Collection = class extends Node.NodeBase {
|
|
6495
6495
|
constructor(type, schema) {
|
|
6496
6496
|
super(type);
|
|
@@ -6520,11 +6520,11 @@ var require_Collection = __commonJS({
|
|
|
6520
6520
|
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
6521
6521
|
* that already exists in the map.
|
|
6522
6522
|
*/
|
|
6523
|
-
addIn(
|
|
6524
|
-
if (isEmptyPath(
|
|
6523
|
+
addIn(path24, value) {
|
|
6524
|
+
if (isEmptyPath(path24))
|
|
6525
6525
|
this.add(value);
|
|
6526
6526
|
else {
|
|
6527
|
-
const [key, ...rest] =
|
|
6527
|
+
const [key, ...rest] = path24;
|
|
6528
6528
|
const node = this.get(key, true);
|
|
6529
6529
|
if (identity.isCollection(node))
|
|
6530
6530
|
node.addIn(rest, value);
|
|
@@ -6538,8 +6538,8 @@ var require_Collection = __commonJS({
|
|
|
6538
6538
|
* Removes a value from the collection.
|
|
6539
6539
|
* @returns `true` if the item was found and removed.
|
|
6540
6540
|
*/
|
|
6541
|
-
deleteIn(
|
|
6542
|
-
const [key, ...rest] =
|
|
6541
|
+
deleteIn(path24) {
|
|
6542
|
+
const [key, ...rest] = path24;
|
|
6543
6543
|
if (rest.length === 0)
|
|
6544
6544
|
return this.delete(key);
|
|
6545
6545
|
const node = this.get(key, true);
|
|
@@ -6553,8 +6553,8 @@ var require_Collection = __commonJS({
|
|
|
6553
6553
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
6554
6554
|
* `true` (collections are always returned intact).
|
|
6555
6555
|
*/
|
|
6556
|
-
getIn(
|
|
6557
|
-
const [key, ...rest] =
|
|
6556
|
+
getIn(path24, keepScalar) {
|
|
6557
|
+
const [key, ...rest] = path24;
|
|
6558
6558
|
const node = this.get(key, true);
|
|
6559
6559
|
if (rest.length === 0)
|
|
6560
6560
|
return !keepScalar && identity.isScalar(node) ? node.value : node;
|
|
@@ -6572,8 +6572,8 @@ var require_Collection = __commonJS({
|
|
|
6572
6572
|
/**
|
|
6573
6573
|
* Checks if the collection includes a value with the key `key`.
|
|
6574
6574
|
*/
|
|
6575
|
-
hasIn(
|
|
6576
|
-
const [key, ...rest] =
|
|
6575
|
+
hasIn(path24) {
|
|
6576
|
+
const [key, ...rest] = path24;
|
|
6577
6577
|
if (rest.length === 0)
|
|
6578
6578
|
return this.has(key);
|
|
6579
6579
|
const node = this.get(key, true);
|
|
@@ -6583,8 +6583,8 @@ var require_Collection = __commonJS({
|
|
|
6583
6583
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
6584
6584
|
* boolean to add/remove the item from the set.
|
|
6585
6585
|
*/
|
|
6586
|
-
setIn(
|
|
6587
|
-
const [key, ...rest] =
|
|
6586
|
+
setIn(path24, value) {
|
|
6587
|
+
const [key, ...rest] = path24;
|
|
6588
6588
|
if (rest.length === 0) {
|
|
6589
6589
|
this.set(key, value);
|
|
6590
6590
|
} else {
|
|
@@ -9096,9 +9096,9 @@ var require_Document = __commonJS({
|
|
|
9096
9096
|
this.contents.add(value);
|
|
9097
9097
|
}
|
|
9098
9098
|
/** Adds a value to the document. */
|
|
9099
|
-
addIn(
|
|
9099
|
+
addIn(path24, value) {
|
|
9100
9100
|
if (assertCollection(this.contents))
|
|
9101
|
-
this.contents.addIn(
|
|
9101
|
+
this.contents.addIn(path24, value);
|
|
9102
9102
|
}
|
|
9103
9103
|
/**
|
|
9104
9104
|
* Create a new `Alias` node, ensuring that the target `node` has the required anchor.
|
|
@@ -9173,14 +9173,14 @@ var require_Document = __commonJS({
|
|
|
9173
9173
|
* Removes a value from the document.
|
|
9174
9174
|
* @returns `true` if the item was found and removed.
|
|
9175
9175
|
*/
|
|
9176
|
-
deleteIn(
|
|
9177
|
-
if (Collection.isEmptyPath(
|
|
9176
|
+
deleteIn(path24) {
|
|
9177
|
+
if (Collection.isEmptyPath(path24)) {
|
|
9178
9178
|
if (this.contents == null)
|
|
9179
9179
|
return false;
|
|
9180
9180
|
this.contents = null;
|
|
9181
9181
|
return true;
|
|
9182
9182
|
}
|
|
9183
|
-
return assertCollection(this.contents) ? this.contents.deleteIn(
|
|
9183
|
+
return assertCollection(this.contents) ? this.contents.deleteIn(path24) : false;
|
|
9184
9184
|
}
|
|
9185
9185
|
/**
|
|
9186
9186
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
@@ -9195,10 +9195,10 @@ var require_Document = __commonJS({
|
|
|
9195
9195
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
9196
9196
|
* `true` (collections are always returned intact).
|
|
9197
9197
|
*/
|
|
9198
|
-
getIn(
|
|
9199
|
-
if (Collection.isEmptyPath(
|
|
9198
|
+
getIn(path24, keepScalar) {
|
|
9199
|
+
if (Collection.isEmptyPath(path24))
|
|
9200
9200
|
return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
|
|
9201
|
-
return identity.isCollection(this.contents) ? this.contents.getIn(
|
|
9201
|
+
return identity.isCollection(this.contents) ? this.contents.getIn(path24, keepScalar) : void 0;
|
|
9202
9202
|
}
|
|
9203
9203
|
/**
|
|
9204
9204
|
* Checks if the document includes a value with the key `key`.
|
|
@@ -9209,10 +9209,10 @@ var require_Document = __commonJS({
|
|
|
9209
9209
|
/**
|
|
9210
9210
|
* Checks if the document includes a value at `path`.
|
|
9211
9211
|
*/
|
|
9212
|
-
hasIn(
|
|
9213
|
-
if (Collection.isEmptyPath(
|
|
9212
|
+
hasIn(path24) {
|
|
9213
|
+
if (Collection.isEmptyPath(path24))
|
|
9214
9214
|
return this.contents !== void 0;
|
|
9215
|
-
return identity.isCollection(this.contents) ? this.contents.hasIn(
|
|
9215
|
+
return identity.isCollection(this.contents) ? this.contents.hasIn(path24) : false;
|
|
9216
9216
|
}
|
|
9217
9217
|
/**
|
|
9218
9218
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
@@ -9229,13 +9229,13 @@ var require_Document = __commonJS({
|
|
|
9229
9229
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
9230
9230
|
* boolean to add/remove the item from the set.
|
|
9231
9231
|
*/
|
|
9232
|
-
setIn(
|
|
9233
|
-
if (Collection.isEmptyPath(
|
|
9232
|
+
setIn(path24, value) {
|
|
9233
|
+
if (Collection.isEmptyPath(path24)) {
|
|
9234
9234
|
this.contents = value;
|
|
9235
9235
|
} else if (this.contents == null) {
|
|
9236
|
-
this.contents = Collection.collectionFromPath(this.schema, Array.from(
|
|
9236
|
+
this.contents = Collection.collectionFromPath(this.schema, Array.from(path24), value);
|
|
9237
9237
|
} else if (assertCollection(this.contents)) {
|
|
9238
|
-
this.contents.setIn(
|
|
9238
|
+
this.contents.setIn(path24, value);
|
|
9239
9239
|
}
|
|
9240
9240
|
}
|
|
9241
9241
|
/**
|
|
@@ -11192,9 +11192,9 @@ var require_cst_visit = __commonJS({
|
|
|
11192
11192
|
visit.BREAK = BREAK;
|
|
11193
11193
|
visit.SKIP = SKIP;
|
|
11194
11194
|
visit.REMOVE = REMOVE;
|
|
11195
|
-
visit.itemAtPath = (cst,
|
|
11195
|
+
visit.itemAtPath = (cst, path24) => {
|
|
11196
11196
|
let item = cst;
|
|
11197
|
-
for (const [field, index] of
|
|
11197
|
+
for (const [field, index] of path24) {
|
|
11198
11198
|
const tok = item?.[field];
|
|
11199
11199
|
if (tok && "items" in tok) {
|
|
11200
11200
|
item = tok.items[index];
|
|
@@ -11203,23 +11203,23 @@ var require_cst_visit = __commonJS({
|
|
|
11203
11203
|
}
|
|
11204
11204
|
return item;
|
|
11205
11205
|
};
|
|
11206
|
-
visit.parentCollection = (cst,
|
|
11207
|
-
const parent = visit.itemAtPath(cst,
|
|
11208
|
-
const field =
|
|
11206
|
+
visit.parentCollection = (cst, path24) => {
|
|
11207
|
+
const parent = visit.itemAtPath(cst, path24.slice(0, -1));
|
|
11208
|
+
const field = path24[path24.length - 1][0];
|
|
11209
11209
|
const coll = parent?.[field];
|
|
11210
11210
|
if (coll && "items" in coll)
|
|
11211
11211
|
return coll;
|
|
11212
11212
|
throw new Error("Parent collection not found");
|
|
11213
11213
|
};
|
|
11214
|
-
function _visit(
|
|
11215
|
-
let ctrl = visitor(item,
|
|
11214
|
+
function _visit(path24, item, visitor) {
|
|
11215
|
+
let ctrl = visitor(item, path24);
|
|
11216
11216
|
if (typeof ctrl === "symbol")
|
|
11217
11217
|
return ctrl;
|
|
11218
11218
|
for (const field of ["key", "value"]) {
|
|
11219
11219
|
const token = item[field];
|
|
11220
11220
|
if (token && "items" in token) {
|
|
11221
11221
|
for (let i = 0; i < token.items.length; ++i) {
|
|
11222
|
-
const ci2 = _visit(Object.freeze(
|
|
11222
|
+
const ci2 = _visit(Object.freeze(path24.concat([[field, i]])), token.items[i], visitor);
|
|
11223
11223
|
if (typeof ci2 === "number")
|
|
11224
11224
|
i = ci2 - 1;
|
|
11225
11225
|
else if (ci2 === BREAK)
|
|
@@ -11230,10 +11230,10 @@ var require_cst_visit = __commonJS({
|
|
|
11230
11230
|
}
|
|
11231
11231
|
}
|
|
11232
11232
|
if (typeof ctrl === "function" && field === "key")
|
|
11233
|
-
ctrl = ctrl(item,
|
|
11233
|
+
ctrl = ctrl(item, path24);
|
|
11234
11234
|
}
|
|
11235
11235
|
}
|
|
11236
|
-
return typeof ctrl === "function" ? ctrl(item,
|
|
11236
|
+
return typeof ctrl === "function" ? ctrl(item, path24) : ctrl;
|
|
11237
11237
|
}
|
|
11238
11238
|
exports2.visit = visit;
|
|
11239
11239
|
}
|
|
@@ -16708,7 +16708,7 @@ function delay2(time3) {
|
|
|
16708
16708
|
setTimeout(resolve4, time3);
|
|
16709
16709
|
});
|
|
16710
16710
|
}
|
|
16711
|
-
var import_node_util3, import_util6, import_os, import_string_decoder, import_stream2, import_rfdc,
|
|
16711
|
+
var import_node_util3, import_util6, import_os, import_string_decoder, import_stream2, import_rfdc, import_crypto2, ANSI_ESCAPE2, ANSI_ESCAPE_CODES, ListrEnvironmentVariables, ListrErrorTypes, ListrEventType, ListrRendererSelection, ListrTaskEventType, ListrTaskState, EventManager, BaseEventMap, CLEAR_LINE_REGEX, BELL_REGEX, color, FIGURES_MAIN, FIGURES_FALLBACK, figures, ListrLogLevels, LISTR_LOGGER_STYLE, LISTR_LOGGER_STDERR_LEVELS, ListrLogger, ProcessOutputBuffer, ProcessOutputStream, ProcessOutput, ListrPromptAdapter, Spinner, ListrDefaultRendererLogLevels, LISTR_DEFAULT_RENDERER_STYLE, PRESET_TIMER, PRESET_TIMESTAMP, DefaultRenderer, SilentRenderer, SimpleRenderer, TestRendererSerializer, TestRenderer, VerboseRenderer, RENDERERS, clone2, Concurrency, ListrError, ListrRendererError, PromptError, TaskWrapper, ListrTaskEventManager, Task, ListrEventManager, Listr;
|
|
16712
16712
|
var init_dist = __esm({
|
|
16713
16713
|
"node_modules/listr2/dist/index.mjs"() {
|
|
16714
16714
|
init_eventemitter3();
|
|
@@ -16718,7 +16718,7 @@ var init_dist = __esm({
|
|
|
16718
16718
|
import_string_decoder = require("string_decoder");
|
|
16719
16719
|
import_stream2 = require("stream");
|
|
16720
16720
|
import_rfdc = __toESM(require_rfdc(), 1);
|
|
16721
|
-
|
|
16721
|
+
import_crypto2 = require("crypto");
|
|
16722
16722
|
ANSI_ESCAPE2 = "\x1B[";
|
|
16723
16723
|
ANSI_ESCAPE_CODES = {
|
|
16724
16724
|
CURSOR_HIDE: ANSI_ESCAPE2 + "?25l",
|
|
@@ -18049,7 +18049,7 @@ var init_dist = __esm({
|
|
|
18049
18049
|
};
|
|
18050
18050
|
Task = class extends ListrTaskEventManager {
|
|
18051
18051
|
/** Unique id per task, can be used for identifying a Task. */
|
|
18052
|
-
id = (0,
|
|
18052
|
+
id = (0, import_crypto2.randomUUID)();
|
|
18053
18053
|
/** The current state of the task. */
|
|
18054
18054
|
state = ListrTaskState.WAITING;
|
|
18055
18055
|
/** Subtasks of the current task. */
|
|
@@ -18810,11 +18810,11 @@ var init_types = __esm({
|
|
|
18810
18810
|
});
|
|
18811
18811
|
|
|
18812
18812
|
// packages/memory/dist/adapters/inmemory.js
|
|
18813
|
-
var
|
|
18813
|
+
var import_node_crypto13, InMemoryAdapter;
|
|
18814
18814
|
var init_inmemory = __esm({
|
|
18815
18815
|
"packages/memory/dist/adapters/inmemory.js"() {
|
|
18816
18816
|
"use strict";
|
|
18817
|
-
|
|
18817
|
+
import_node_crypto13 = require("node:crypto");
|
|
18818
18818
|
InMemoryAdapter = class {
|
|
18819
18819
|
type = "inmemory";
|
|
18820
18820
|
memories = /* @__PURE__ */ new Map();
|
|
@@ -18829,7 +18829,7 @@ var init_inmemory = __esm({
|
|
|
18829
18829
|
async init() {
|
|
18830
18830
|
}
|
|
18831
18831
|
async add(content, options) {
|
|
18832
|
-
const id = (0,
|
|
18832
|
+
const id = (0, import_node_crypto13.randomUUID)();
|
|
18833
18833
|
const now = Date.now();
|
|
18834
18834
|
const entry = {
|
|
18835
18835
|
id,
|
|
@@ -19260,8 +19260,8 @@ var init_supermemory = __esm({
|
|
|
19260
19260
|
/**
|
|
19261
19261
|
* Make a fetch request to the Supermemory API
|
|
19262
19262
|
*/
|
|
19263
|
-
async fetch(
|
|
19264
|
-
const url2 = `${this.endpoint}${
|
|
19263
|
+
async fetch(path24, options) {
|
|
19264
|
+
const url2 = `${this.endpoint}${path24}`;
|
|
19265
19265
|
const controller = new AbortController();
|
|
19266
19266
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
19267
19267
|
try {
|
|
@@ -20388,7 +20388,7 @@ var BrokerTransport = class {
|
|
|
20388
20388
|
return this.baseUrl.replace(/^http/, "ws") + "/ws";
|
|
20389
20389
|
}
|
|
20390
20390
|
// ── HTTP ─────────────────────────────────────────────────────────────
|
|
20391
|
-
async request(
|
|
20391
|
+
async request(path24, init) {
|
|
20392
20392
|
const headers = new Headers(init?.headers);
|
|
20393
20393
|
if (!headers.has("Content-Type")) {
|
|
20394
20394
|
headers.set("Content-Type", "application/json");
|
|
@@ -20397,7 +20397,7 @@ var BrokerTransport = class {
|
|
|
20397
20397
|
headers.set("X-API-Key", this.apiKey);
|
|
20398
20398
|
}
|
|
20399
20399
|
const signal = init?.signal ?? AbortSignal.timeout(this.requestTimeoutMs);
|
|
20400
|
-
const res = await fetch(`${this.baseUrl}${
|
|
20400
|
+
const res = await fetch(`${this.baseUrl}${path24}`, { ...init, headers, signal });
|
|
20401
20401
|
if (!res.ok) {
|
|
20402
20402
|
let body;
|
|
20403
20403
|
try {
|
|
@@ -21650,8 +21650,8 @@ function getErrorMap() {
|
|
|
21650
21650
|
|
|
21651
21651
|
// node_modules/zod/v3/helpers/parseUtil.js
|
|
21652
21652
|
var makeIssue = (params) => {
|
|
21653
|
-
const { data, path:
|
|
21654
|
-
const fullPath = [...
|
|
21653
|
+
const { data, path: path24, errorMaps, issueData } = params;
|
|
21654
|
+
const fullPath = [...path24, ...issueData.path || []];
|
|
21655
21655
|
const fullIssue = {
|
|
21656
21656
|
...issueData,
|
|
21657
21657
|
path: fullPath
|
|
@@ -21767,11 +21767,11 @@ var errorUtil;
|
|
|
21767
21767
|
|
|
21768
21768
|
// node_modules/zod/v3/types.js
|
|
21769
21769
|
var ParseInputLazyPath = class {
|
|
21770
|
-
constructor(parent, value,
|
|
21770
|
+
constructor(parent, value, path24, key) {
|
|
21771
21771
|
this._cachedPath = [];
|
|
21772
21772
|
this.parent = parent;
|
|
21773
21773
|
this.data = value;
|
|
21774
|
-
this._path =
|
|
21774
|
+
this._path = path24;
|
|
21775
21775
|
this._key = key;
|
|
21776
21776
|
}
|
|
21777
21777
|
get path() {
|
|
@@ -28082,10 +28082,10 @@ function mergeDefs(...defs) {
|
|
|
28082
28082
|
function cloneDef(schema) {
|
|
28083
28083
|
return mergeDefs(schema._zod.def);
|
|
28084
28084
|
}
|
|
28085
|
-
function getElementAtPath(obj,
|
|
28086
|
-
if (!
|
|
28085
|
+
function getElementAtPath(obj, path24) {
|
|
28086
|
+
if (!path24)
|
|
28087
28087
|
return obj;
|
|
28088
|
-
return
|
|
28088
|
+
return path24.reduce((acc, key) => acc?.[key], obj);
|
|
28089
28089
|
}
|
|
28090
28090
|
function promiseAllObject(promisesObj) {
|
|
28091
28091
|
const keys = Object.keys(promisesObj);
|
|
@@ -28468,11 +28468,11 @@ function aborted(x, startIndex = 0) {
|
|
|
28468
28468
|
}
|
|
28469
28469
|
return false;
|
|
28470
28470
|
}
|
|
28471
|
-
function prefixIssues(
|
|
28471
|
+
function prefixIssues(path24, issues) {
|
|
28472
28472
|
return issues.map((iss) => {
|
|
28473
28473
|
var _a2;
|
|
28474
28474
|
(_a2 = iss).path ?? (_a2.path = []);
|
|
28475
|
-
iss.path.unshift(
|
|
28475
|
+
iss.path.unshift(path24);
|
|
28476
28476
|
return iss;
|
|
28477
28477
|
});
|
|
28478
28478
|
}
|
|
@@ -28655,7 +28655,7 @@ function formatError(error48, mapper = (issue2) => issue2.message) {
|
|
|
28655
28655
|
}
|
|
28656
28656
|
function treeifyError(error48, mapper = (issue2) => issue2.message) {
|
|
28657
28657
|
const result = { errors: [] };
|
|
28658
|
-
const processError = (error49,
|
|
28658
|
+
const processError = (error49, path24 = []) => {
|
|
28659
28659
|
var _a2, _b;
|
|
28660
28660
|
for (const issue2 of error49.issues) {
|
|
28661
28661
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
@@ -28665,7 +28665,7 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
|
|
|
28665
28665
|
} else if (issue2.code === "invalid_element") {
|
|
28666
28666
|
processError({ issues: issue2.issues }, issue2.path);
|
|
28667
28667
|
} else {
|
|
28668
|
-
const fullpath = [...
|
|
28668
|
+
const fullpath = [...path24, ...issue2.path];
|
|
28669
28669
|
if (fullpath.length === 0) {
|
|
28670
28670
|
result.errors.push(mapper(issue2));
|
|
28671
28671
|
continue;
|
|
@@ -28697,8 +28697,8 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
|
|
|
28697
28697
|
}
|
|
28698
28698
|
function toDotPath(_path) {
|
|
28699
28699
|
const segs = [];
|
|
28700
|
-
const
|
|
28701
|
-
for (const seg of
|
|
28700
|
+
const path24 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
28701
|
+
for (const seg of path24) {
|
|
28702
28702
|
if (typeof seg === "number")
|
|
28703
28703
|
segs.push(`[${seg}]`);
|
|
28704
28704
|
else if (typeof seg === "symbol")
|
|
@@ -40675,13 +40675,13 @@ function resolveRef(ref, ctx) {
|
|
|
40675
40675
|
if (!ref.startsWith("#")) {
|
|
40676
40676
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
40677
40677
|
}
|
|
40678
|
-
const
|
|
40679
|
-
if (
|
|
40678
|
+
const path24 = ref.slice(1).split("/").filter(Boolean);
|
|
40679
|
+
if (path24.length === 0) {
|
|
40680
40680
|
return ctx.rootSchema;
|
|
40681
40681
|
}
|
|
40682
40682
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
40683
|
-
if (
|
|
40684
|
-
const key =
|
|
40683
|
+
if (path24[0] === defsKey) {
|
|
40684
|
+
const key = path24[1];
|
|
40685
40685
|
if (!key || !ctx.defs[key]) {
|
|
40686
40686
|
throw new Error(`Reference not found: ${ref}`);
|
|
40687
40687
|
}
|
|
@@ -42831,8 +42831,8 @@ var HttpClient = class _HttpClient {
|
|
|
42831
42831
|
version: this._originVersion
|
|
42832
42832
|
}));
|
|
42833
42833
|
}
|
|
42834
|
-
async request(method,
|
|
42835
|
-
const url2 = new URL(
|
|
42834
|
+
async request(method, path24, body, query, options) {
|
|
42835
|
+
const url2 = new URL(path24, this._baseUrl);
|
|
42836
42836
|
if (query) {
|
|
42837
42837
|
for (const [k2, v2] of Object.entries(query)) {
|
|
42838
42838
|
if (v2 !== void 0)
|
|
@@ -42902,20 +42902,20 @@ var HttpClient = class _HttpClient {
|
|
|
42902
42902
|
return camelizeKeys(parsedData);
|
|
42903
42903
|
}
|
|
42904
42904
|
}
|
|
42905
|
-
get(
|
|
42906
|
-
return this.request("GET",
|
|
42905
|
+
get(path24, query, options) {
|
|
42906
|
+
return this.request("GET", path24, void 0, query, options);
|
|
42907
42907
|
}
|
|
42908
|
-
post(
|
|
42909
|
-
return this.request("POST",
|
|
42908
|
+
post(path24, body, options) {
|
|
42909
|
+
return this.request("POST", path24, body, void 0, options);
|
|
42910
42910
|
}
|
|
42911
|
-
patch(
|
|
42912
|
-
return this.request("PATCH",
|
|
42911
|
+
patch(path24, body, options) {
|
|
42912
|
+
return this.request("PATCH", path24, body, void 0, options);
|
|
42913
42913
|
}
|
|
42914
|
-
put(
|
|
42915
|
-
return this.request("PUT",
|
|
42914
|
+
put(path24, body, options) {
|
|
42915
|
+
return this.request("PUT", path24, body, void 0, options);
|
|
42916
42916
|
}
|
|
42917
|
-
async delete(
|
|
42918
|
-
await this.request("DELETE",
|
|
42917
|
+
async delete(path24, options) {
|
|
42918
|
+
await this.request("DELETE", path24, void 0, void 0, options);
|
|
42919
42919
|
}
|
|
42920
42920
|
};
|
|
42921
42921
|
|
|
@@ -45517,8 +45517,8 @@ function isAgentStep(step) {
|
|
|
45517
45517
|
|
|
45518
45518
|
// packages/sdk/dist/workflows/runner.js
|
|
45519
45519
|
var import_node_child_process7 = require("node:child_process");
|
|
45520
|
-
var
|
|
45521
|
-
var
|
|
45520
|
+
var import_node_crypto7 = require("node:crypto");
|
|
45521
|
+
var import_node_fs20 = require("node:fs");
|
|
45522
45522
|
var import_promises8 = require("node:fs/promises");
|
|
45523
45523
|
var import_node_os8 = require("node:os");
|
|
45524
45524
|
var import_node_path28 = __toESM(require("node:path"), 1);
|
|
@@ -45780,9 +45780,9 @@ async function resolveCli(cli) {
|
|
|
45780
45780
|
for (const binary of def.binaries) {
|
|
45781
45781
|
try {
|
|
45782
45782
|
const { stdout } = await execFileAsync("which", [binary]);
|
|
45783
|
-
const
|
|
45784
|
-
if (
|
|
45785
|
-
const result = { binary, path:
|
|
45783
|
+
const path24 = stdout.trim();
|
|
45784
|
+
if (path24) {
|
|
45785
|
+
const result = { binary, path: path24 };
|
|
45786
45786
|
resolveCache.set(cli, result);
|
|
45787
45787
|
return result;
|
|
45788
45788
|
}
|
|
@@ -45819,9 +45819,9 @@ function resolveCliSync(cli) {
|
|
|
45819
45819
|
for (const binary of def.binaries) {
|
|
45820
45820
|
try {
|
|
45821
45821
|
const stdout = execFileSync2("which", [binary], { stdio: ["pipe", "pipe", "ignore"] });
|
|
45822
|
-
const
|
|
45823
|
-
if (
|
|
45824
|
-
const result = { binary, path:
|
|
45822
|
+
const path24 = stdout.toString().trim();
|
|
45823
|
+
if (path24) {
|
|
45824
|
+
const result = { binary, path: path24 };
|
|
45825
45825
|
resolveCache.set(cli, result);
|
|
45826
45826
|
return result;
|
|
45827
45827
|
}
|
|
@@ -47035,8 +47035,8 @@ var RelayFileClient = class {
|
|
|
47035
47035
|
signal: options.signal
|
|
47036
47036
|
});
|
|
47037
47037
|
}
|
|
47038
|
-
async readFile(workspaceId,
|
|
47039
|
-
const query = buildQuery({ path:
|
|
47038
|
+
async readFile(workspaceId, path24, correlationId, signal) {
|
|
47039
|
+
const query = buildQuery({ path: path24 });
|
|
47040
47040
|
return this.request({
|
|
47041
47041
|
method: "GET",
|
|
47042
47042
|
path: `/v1/workspaces/${encodeURIComponent(workspaceId)}/fs/file${query}`,
|
|
@@ -47077,8 +47077,8 @@ var RelayFileClient = class {
|
|
|
47077
47077
|
});
|
|
47078
47078
|
}
|
|
47079
47079
|
async writeFile(input) {
|
|
47080
|
-
const { workspaceId, path:
|
|
47081
|
-
const query = buildQuery({ path:
|
|
47080
|
+
const { workspaceId, path: path24, correlationId, baseRevision, content, contentType, encoding, semantics, signal } = input;
|
|
47081
|
+
const query = buildQuery({ path: path24 });
|
|
47082
47082
|
return this.request({
|
|
47083
47083
|
method: "PUT",
|
|
47084
47084
|
path: `/v1/workspaces/${encodeURIComponent(workspaceId)}/fs/file${query}`,
|
|
@@ -53020,10 +53020,987 @@ function delay(ms2) {
|
|
|
53020
53020
|
}
|
|
53021
53021
|
|
|
53022
53022
|
// packages/sdk/dist/workflows/trajectory.js
|
|
53023
|
-
var
|
|
53024
|
-
|
|
53025
|
-
|
|
53026
|
-
var
|
|
53023
|
+
var import_node_path27 = require("node:path");
|
|
53024
|
+
|
|
53025
|
+
// node_modules/agent-trajectories/dist/chunk-W222QB6V.js
|
|
53026
|
+
var import_module = require("module");
|
|
53027
|
+
var import_crypto = require("crypto");
|
|
53028
|
+
var import_fs5 = require("fs");
|
|
53029
|
+
var import_promises7 = require("fs/promises");
|
|
53030
|
+
var import_path4 = require("path");
|
|
53031
|
+
var ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
53032
|
+
var ID_LENGTH = 12;
|
|
53033
|
+
function generateRandomId(length = ID_LENGTH) {
|
|
53034
|
+
let id = "";
|
|
53035
|
+
const randomValues = new Uint8Array(length);
|
|
53036
|
+
import_crypto.webcrypto.getRandomValues(randomValues);
|
|
53037
|
+
for (let i = 0; i < length; i++) {
|
|
53038
|
+
id += ALPHABET[randomValues[i] % ALPHABET.length];
|
|
53039
|
+
}
|
|
53040
|
+
return id;
|
|
53041
|
+
}
|
|
53042
|
+
function generateTrajectoryId() {
|
|
53043
|
+
return `traj_${generateRandomId()}`;
|
|
53044
|
+
}
|
|
53045
|
+
function generateChapterId() {
|
|
53046
|
+
return `chap_${generateRandomId()}`;
|
|
53047
|
+
}
|
|
53048
|
+
var TaskSourceSystemSchema = external_exports.union([
|
|
53049
|
+
external_exports.literal("beads"),
|
|
53050
|
+
external_exports.literal("github"),
|
|
53051
|
+
external_exports.literal("linear"),
|
|
53052
|
+
external_exports.literal("jira"),
|
|
53053
|
+
external_exports.literal("plain"),
|
|
53054
|
+
external_exports.string()
|
|
53055
|
+
// Allow custom systems
|
|
53056
|
+
]);
|
|
53057
|
+
var TaskSourceSchema = external_exports.object({
|
|
53058
|
+
system: TaskSourceSystemSchema,
|
|
53059
|
+
id: external_exports.string().min(1, "Task ID is required"),
|
|
53060
|
+
url: external_exports.string().url().optional()
|
|
53061
|
+
});
|
|
53062
|
+
var TaskReferenceSchema = external_exports.object({
|
|
53063
|
+
title: external_exports.string().min(1, "Trajectory title is required").max(500, "Trajectory title must be 500 characters or less"),
|
|
53064
|
+
description: external_exports.string().optional(),
|
|
53065
|
+
source: TaskSourceSchema.optional()
|
|
53066
|
+
});
|
|
53067
|
+
var TrajectoryStatusSchema = external_exports.enum([
|
|
53068
|
+
"active",
|
|
53069
|
+
"completed",
|
|
53070
|
+
"abandoned"
|
|
53071
|
+
]);
|
|
53072
|
+
var TrajectoryEventTypeSchema = external_exports.union([
|
|
53073
|
+
external_exports.literal("prompt"),
|
|
53074
|
+
external_exports.literal("thinking"),
|
|
53075
|
+
external_exports.literal("tool_call"),
|
|
53076
|
+
external_exports.literal("tool_result"),
|
|
53077
|
+
external_exports.literal("message_sent"),
|
|
53078
|
+
external_exports.literal("message_received"),
|
|
53079
|
+
external_exports.literal("decision"),
|
|
53080
|
+
external_exports.literal("finding"),
|
|
53081
|
+
external_exports.literal("reflection"),
|
|
53082
|
+
external_exports.literal("note"),
|
|
53083
|
+
external_exports.literal("error"),
|
|
53084
|
+
external_exports.string()
|
|
53085
|
+
// Allow event types emitted by other tools (e.g. agent-relay's completion-evidence / completion-marker). Downstream code filters to known types.
|
|
53086
|
+
]);
|
|
53087
|
+
var EventSignificanceSchema = external_exports.enum([
|
|
53088
|
+
"low",
|
|
53089
|
+
"medium",
|
|
53090
|
+
"high",
|
|
53091
|
+
"critical"
|
|
53092
|
+
]);
|
|
53093
|
+
var TrajectoryEventSchema = external_exports.object({
|
|
53094
|
+
ts: external_exports.number().int().positive(),
|
|
53095
|
+
type: TrajectoryEventTypeSchema,
|
|
53096
|
+
content: external_exports.string().min(1, "Event content is required"),
|
|
53097
|
+
raw: external_exports.unknown().optional(),
|
|
53098
|
+
significance: EventSignificanceSchema.optional(),
|
|
53099
|
+
tags: external_exports.array(external_exports.string()).optional(),
|
|
53100
|
+
confidence: external_exports.number().min(0, "Confidence must be between 0 and 1").max(1, "Confidence must be between 0 and 1").optional()
|
|
53101
|
+
});
|
|
53102
|
+
var AlternativeSchema = external_exports.object({
|
|
53103
|
+
option: external_exports.string().min(1, "Alternative option is required"),
|
|
53104
|
+
reason: external_exports.string().optional()
|
|
53105
|
+
});
|
|
53106
|
+
var DecisionSchema = external_exports.object({
|
|
53107
|
+
question: external_exports.string().min(1, "Decision question is required"),
|
|
53108
|
+
chosen: external_exports.string().min(1, "Chosen option is required"),
|
|
53109
|
+
alternatives: external_exports.array(external_exports.union([external_exports.string(), AlternativeSchema])),
|
|
53110
|
+
reasoning: external_exports.string().min(1, "Decision reasoning is required"),
|
|
53111
|
+
confidence: external_exports.number().min(0, "Confidence must be between 0 and 1").max(1, "Confidence must be between 0 and 1").optional()
|
|
53112
|
+
});
|
|
53113
|
+
var AgentParticipationSchema = external_exports.object({
|
|
53114
|
+
name: external_exports.string().min(1, "Agent name is required"),
|
|
53115
|
+
role: external_exports.string().min(1, "Agent role is required"),
|
|
53116
|
+
joinedAt: external_exports.string().datetime(),
|
|
53117
|
+
leftAt: external_exports.string().datetime().optional()
|
|
53118
|
+
});
|
|
53119
|
+
var ChapterSchema = external_exports.object({
|
|
53120
|
+
id: external_exports.string().min(1),
|
|
53121
|
+
title: external_exports.string().min(1, "Chapter title is required"),
|
|
53122
|
+
agentName: external_exports.string().min(1, "Agent name is required"),
|
|
53123
|
+
startedAt: external_exports.string().datetime(),
|
|
53124
|
+
endedAt: external_exports.string().datetime().optional(),
|
|
53125
|
+
events: external_exports.array(TrajectoryEventSchema)
|
|
53126
|
+
});
|
|
53127
|
+
var RetrospectiveSchema = external_exports.object({
|
|
53128
|
+
summary: external_exports.string().min(1, "Retrospective summary is required"),
|
|
53129
|
+
approach: external_exports.string().min(1, "Approach description is required"),
|
|
53130
|
+
decisions: external_exports.array(DecisionSchema).optional(),
|
|
53131
|
+
challenges: external_exports.array(external_exports.string()).optional(),
|
|
53132
|
+
learnings: external_exports.array(external_exports.string()).optional(),
|
|
53133
|
+
suggestions: external_exports.array(external_exports.string()).optional(),
|
|
53134
|
+
confidence: external_exports.number().min(0, "Confidence must be between 0 and 1").max(1, "Confidence must be between 0 and 1"),
|
|
53135
|
+
timeSpent: external_exports.string().optional()
|
|
53136
|
+
});
|
|
53137
|
+
var TraceRangeSchema = external_exports.object({
|
|
53138
|
+
start_line: external_exports.number().int().positive("Start line must be positive"),
|
|
53139
|
+
end_line: external_exports.number().int().positive("End line must be positive"),
|
|
53140
|
+
revision: external_exports.string().optional(),
|
|
53141
|
+
content_hash: external_exports.string().optional()
|
|
53142
|
+
});
|
|
53143
|
+
var ContributorTypeSchema = external_exports.enum([
|
|
53144
|
+
"human",
|
|
53145
|
+
"ai",
|
|
53146
|
+
"mixed",
|
|
53147
|
+
"unknown"
|
|
53148
|
+
]);
|
|
53149
|
+
var TraceContributorSchema = external_exports.object({
|
|
53150
|
+
type: ContributorTypeSchema,
|
|
53151
|
+
model_id: external_exports.string().max(250).optional()
|
|
53152
|
+
});
|
|
53153
|
+
var TraceConversationSchema = external_exports.object({
|
|
53154
|
+
contributor: TraceContributorSchema,
|
|
53155
|
+
url: external_exports.string().url().optional(),
|
|
53156
|
+
ranges: external_exports.array(TraceRangeSchema)
|
|
53157
|
+
});
|
|
53158
|
+
var TraceFileSchema = external_exports.object({
|
|
53159
|
+
path: external_exports.string().min(1, "File path is required"),
|
|
53160
|
+
conversations: external_exports.array(TraceConversationSchema)
|
|
53161
|
+
});
|
|
53162
|
+
var TraceRecordSchema = external_exports.object({
|
|
53163
|
+
version: external_exports.string().min(1, "Version is required"),
|
|
53164
|
+
id: external_exports.string().min(1, "Trace ID is required"),
|
|
53165
|
+
timestamp: external_exports.string().datetime(),
|
|
53166
|
+
trajectory: external_exports.string().optional(),
|
|
53167
|
+
files: external_exports.array(TraceFileSchema)
|
|
53168
|
+
});
|
|
53169
|
+
var TrajectoryTraceRefSchema = external_exports.object({
|
|
53170
|
+
startRef: external_exports.string().min(1, "Start ref is required"),
|
|
53171
|
+
endRef: external_exports.string().optional(),
|
|
53172
|
+
traceId: external_exports.string().optional()
|
|
53173
|
+
});
|
|
53174
|
+
var TrajectorySchema = external_exports.object({
|
|
53175
|
+
id: external_exports.string().regex(/^traj_[a-z0-9_]+$/, "Invalid trajectory ID format"),
|
|
53176
|
+
version: external_exports.literal(1),
|
|
53177
|
+
task: TaskReferenceSchema,
|
|
53178
|
+
status: TrajectoryStatusSchema,
|
|
53179
|
+
startedAt: external_exports.string().datetime(),
|
|
53180
|
+
completedAt: external_exports.string().datetime().optional(),
|
|
53181
|
+
agents: external_exports.array(AgentParticipationSchema),
|
|
53182
|
+
chapters: external_exports.array(ChapterSchema),
|
|
53183
|
+
retrospective: RetrospectiveSchema.optional(),
|
|
53184
|
+
commits: external_exports.array(external_exports.string()).default([]),
|
|
53185
|
+
filesChanged: external_exports.array(external_exports.string()).default([]),
|
|
53186
|
+
projectId: external_exports.string().optional(),
|
|
53187
|
+
workflowId: external_exports.string().optional(),
|
|
53188
|
+
tags: external_exports.array(external_exports.string()).default([]),
|
|
53189
|
+
_trace: TrajectoryTraceRefSchema.optional()
|
|
53190
|
+
});
|
|
53191
|
+
var CreateTrajectoryInputSchema = external_exports.object({
|
|
53192
|
+
title: external_exports.string().min(1, "Trajectory title is required").max(500, "Trajectory title must be 500 characters or less"),
|
|
53193
|
+
description: external_exports.string().optional(),
|
|
53194
|
+
source: TaskSourceSchema.optional(),
|
|
53195
|
+
projectId: external_exports.string().optional(),
|
|
53196
|
+
tags: external_exports.array(external_exports.string()).optional()
|
|
53197
|
+
});
|
|
53198
|
+
var AddChapterInputSchema = external_exports.object({
|
|
53199
|
+
title: external_exports.string().min(1, "Chapter title is required"),
|
|
53200
|
+
agentName: external_exports.string().min(1, "Agent name is required")
|
|
53201
|
+
});
|
|
53202
|
+
var AddEventInputSchema = external_exports.object({
|
|
53203
|
+
type: TrajectoryEventTypeSchema,
|
|
53204
|
+
content: external_exports.string().min(1, "Event content is required"),
|
|
53205
|
+
raw: external_exports.unknown().optional(),
|
|
53206
|
+
significance: EventSignificanceSchema.optional(),
|
|
53207
|
+
tags: external_exports.array(external_exports.string()).optional()
|
|
53208
|
+
});
|
|
53209
|
+
var CompleteTrajectoryInputSchema = external_exports.object({
|
|
53210
|
+
summary: external_exports.string().min(1, "Retrospective summary is required"),
|
|
53211
|
+
approach: external_exports.string().min(1, "Approach description is required"),
|
|
53212
|
+
decisions: external_exports.array(DecisionSchema).optional(),
|
|
53213
|
+
challenges: external_exports.array(external_exports.string()).optional(),
|
|
53214
|
+
learnings: external_exports.array(external_exports.string()).optional(),
|
|
53215
|
+
suggestions: external_exports.array(external_exports.string()).optional(),
|
|
53216
|
+
confidence: external_exports.number().min(0, "Confidence must be between 0 and 1").max(1, "Confidence must be between 0 and 1")
|
|
53217
|
+
});
|
|
53218
|
+
var TrajectoryQuerySchema = external_exports.object({
|
|
53219
|
+
status: TrajectoryStatusSchema.optional(),
|
|
53220
|
+
since: external_exports.string().datetime().optional(),
|
|
53221
|
+
until: external_exports.string().datetime().optional(),
|
|
53222
|
+
limit: external_exports.number().int().positive().max(100).optional(),
|
|
53223
|
+
offset: external_exports.number().int().nonnegative().optional(),
|
|
53224
|
+
sortBy: external_exports.enum(["startedAt", "completedAt", "title"]).optional(),
|
|
53225
|
+
sortOrder: external_exports.enum(["asc", "desc"]).optional()
|
|
53226
|
+
});
|
|
53227
|
+
function validateTrajectory(data) {
|
|
53228
|
+
const result = TrajectorySchema.safeParse(data);
|
|
53229
|
+
if (result.success) {
|
|
53230
|
+
return { success: true, data: result.data };
|
|
53231
|
+
}
|
|
53232
|
+
return { success: false, errors: result.error };
|
|
53233
|
+
}
|
|
53234
|
+
var TrajectoryError = class extends Error {
|
|
53235
|
+
constructor(message, code, suggestion) {
|
|
53236
|
+
super(message);
|
|
53237
|
+
this.code = code;
|
|
53238
|
+
this.suggestion = suggestion;
|
|
53239
|
+
this.name = "TrajectoryError";
|
|
53240
|
+
}
|
|
53241
|
+
};
|
|
53242
|
+
function createTrajectory(input) {
|
|
53243
|
+
const validation = CreateTrajectoryInputSchema.safeParse(input);
|
|
53244
|
+
if (!validation.success) {
|
|
53245
|
+
const firstError = validation.error.errors[0];
|
|
53246
|
+
throw new TrajectoryError(
|
|
53247
|
+
firstError.message,
|
|
53248
|
+
"VALIDATION_ERROR",
|
|
53249
|
+
"Check your input and try again"
|
|
53250
|
+
);
|
|
53251
|
+
}
|
|
53252
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
53253
|
+
return {
|
|
53254
|
+
id: generateTrajectoryId(),
|
|
53255
|
+
version: 1,
|
|
53256
|
+
task: {
|
|
53257
|
+
title: input.title,
|
|
53258
|
+
description: input.description,
|
|
53259
|
+
source: input.source
|
|
53260
|
+
},
|
|
53261
|
+
status: "active",
|
|
53262
|
+
startedAt: now,
|
|
53263
|
+
agents: [],
|
|
53264
|
+
chapters: [],
|
|
53265
|
+
commits: [],
|
|
53266
|
+
filesChanged: [],
|
|
53267
|
+
projectId: input.projectId ?? process.cwd(),
|
|
53268
|
+
tags: input.tags ?? []
|
|
53269
|
+
};
|
|
53270
|
+
}
|
|
53271
|
+
function addChapter(trajectory2, input) {
|
|
53272
|
+
if (trajectory2.status === "completed") {
|
|
53273
|
+
throw new TrajectoryError(
|
|
53274
|
+
"Cannot add chapter to completed trajectory",
|
|
53275
|
+
"TRAJECTORY_ALREADY_COMPLETED",
|
|
53276
|
+
"Start a new trajectory instead"
|
|
53277
|
+
);
|
|
53278
|
+
}
|
|
53279
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
53280
|
+
const updatedChapters = trajectory2.chapters.map((chapter, index) => {
|
|
53281
|
+
if (index === trajectory2.chapters.length - 1 && !chapter.endedAt) {
|
|
53282
|
+
return { ...chapter, endedAt: now };
|
|
53283
|
+
}
|
|
53284
|
+
return chapter;
|
|
53285
|
+
});
|
|
53286
|
+
const newChapter = {
|
|
53287
|
+
id: generateChapterId(),
|
|
53288
|
+
title: input.title,
|
|
53289
|
+
agentName: input.agentName,
|
|
53290
|
+
startedAt: now,
|
|
53291
|
+
events: []
|
|
53292
|
+
};
|
|
53293
|
+
let updatedAgents = trajectory2.agents;
|
|
53294
|
+
const agentExists = trajectory2.agents.some((a) => a.name === input.agentName);
|
|
53295
|
+
if (!agentExists) {
|
|
53296
|
+
const isFirstAgent = trajectory2.agents.length === 0;
|
|
53297
|
+
updatedAgents = [
|
|
53298
|
+
...trajectory2.agents,
|
|
53299
|
+
{
|
|
53300
|
+
name: input.agentName,
|
|
53301
|
+
role: isFirstAgent ? "lead" : "contributor",
|
|
53302
|
+
joinedAt: now
|
|
53303
|
+
}
|
|
53304
|
+
];
|
|
53305
|
+
}
|
|
53306
|
+
return {
|
|
53307
|
+
...trajectory2,
|
|
53308
|
+
agents: updatedAgents,
|
|
53309
|
+
chapters: [...updatedChapters, newChapter]
|
|
53310
|
+
};
|
|
53311
|
+
}
|
|
53312
|
+
function addEvent(trajectory2, input) {
|
|
53313
|
+
let updatedTrajectory = trajectory2;
|
|
53314
|
+
if (trajectory2.chapters.length === 0) {
|
|
53315
|
+
updatedTrajectory = addChapter(trajectory2, {
|
|
53316
|
+
title: "Work",
|
|
53317
|
+
agentName: "default"
|
|
53318
|
+
});
|
|
53319
|
+
}
|
|
53320
|
+
const event = {
|
|
53321
|
+
ts: Date.now(),
|
|
53322
|
+
type: input.type,
|
|
53323
|
+
content: input.content,
|
|
53324
|
+
raw: input.raw,
|
|
53325
|
+
significance: input.significance,
|
|
53326
|
+
tags: input.tags
|
|
53327
|
+
};
|
|
53328
|
+
const chapters = [...updatedTrajectory.chapters];
|
|
53329
|
+
const lastChapter = chapters[chapters.length - 1];
|
|
53330
|
+
chapters[chapters.length - 1] = {
|
|
53331
|
+
...lastChapter,
|
|
53332
|
+
events: [...lastChapter.events, event]
|
|
53333
|
+
};
|
|
53334
|
+
return {
|
|
53335
|
+
...updatedTrajectory,
|
|
53336
|
+
chapters
|
|
53337
|
+
};
|
|
53338
|
+
}
|
|
53339
|
+
function completeTrajectory(trajectory2, input) {
|
|
53340
|
+
if (trajectory2.status === "completed") {
|
|
53341
|
+
throw new TrajectoryError(
|
|
53342
|
+
"Trajectory is already completed",
|
|
53343
|
+
"TRAJECTORY_ALREADY_COMPLETED",
|
|
53344
|
+
"Start a new trajectory instead"
|
|
53345
|
+
);
|
|
53346
|
+
}
|
|
53347
|
+
const validation = CompleteTrajectoryInputSchema.safeParse(input);
|
|
53348
|
+
if (!validation.success) {
|
|
53349
|
+
const firstError = validation.error.errors[0];
|
|
53350
|
+
throw new TrajectoryError(
|
|
53351
|
+
firstError.message,
|
|
53352
|
+
"VALIDATION_ERROR",
|
|
53353
|
+
"Check your input and try again"
|
|
53354
|
+
);
|
|
53355
|
+
}
|
|
53356
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
53357
|
+
const chapters = trajectory2.chapters.map((chapter, index) => {
|
|
53358
|
+
if (index === trajectory2.chapters.length - 1 && !chapter.endedAt) {
|
|
53359
|
+
return { ...chapter, endedAt: now };
|
|
53360
|
+
}
|
|
53361
|
+
return chapter;
|
|
53362
|
+
});
|
|
53363
|
+
return {
|
|
53364
|
+
...trajectory2,
|
|
53365
|
+
status: "completed",
|
|
53366
|
+
completedAt: now,
|
|
53367
|
+
chapters,
|
|
53368
|
+
retrospective: {
|
|
53369
|
+
summary: input.summary,
|
|
53370
|
+
approach: input.approach,
|
|
53371
|
+
decisions: input.decisions,
|
|
53372
|
+
challenges: input.challenges,
|
|
53373
|
+
learnings: input.learnings,
|
|
53374
|
+
suggestions: input.suggestions,
|
|
53375
|
+
confidence: input.confidence
|
|
53376
|
+
}
|
|
53377
|
+
};
|
|
53378
|
+
}
|
|
53379
|
+
function abandonTrajectory(trajectory2, reason) {
|
|
53380
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
53381
|
+
const chapters = trajectory2.chapters.map((chapter, index) => {
|
|
53382
|
+
if (index === trajectory2.chapters.length - 1 && !chapter.endedAt) {
|
|
53383
|
+
return { ...chapter, endedAt: now };
|
|
53384
|
+
}
|
|
53385
|
+
return chapter;
|
|
53386
|
+
});
|
|
53387
|
+
let updatedChapters = chapters;
|
|
53388
|
+
if (reason && chapters.length > 0) {
|
|
53389
|
+
const lastChapter = chapters[chapters.length - 1];
|
|
53390
|
+
updatedChapters = [
|
|
53391
|
+
...chapters.slice(0, -1),
|
|
53392
|
+
{
|
|
53393
|
+
...lastChapter,
|
|
53394
|
+
events: [
|
|
53395
|
+
...lastChapter.events,
|
|
53396
|
+
{
|
|
53397
|
+
ts: Date.now(),
|
|
53398
|
+
type: "note",
|
|
53399
|
+
content: `Abandoned: ${reason}`,
|
|
53400
|
+
significance: "high"
|
|
53401
|
+
}
|
|
53402
|
+
]
|
|
53403
|
+
}
|
|
53404
|
+
];
|
|
53405
|
+
}
|
|
53406
|
+
return {
|
|
53407
|
+
...trajectory2,
|
|
53408
|
+
status: "abandoned",
|
|
53409
|
+
completedAt: now,
|
|
53410
|
+
chapters: updatedChapters
|
|
53411
|
+
};
|
|
53412
|
+
}
|
|
53413
|
+
function exportToMarkdown(trajectory2) {
|
|
53414
|
+
const lines = [];
|
|
53415
|
+
lines.push(`# Trajectory: ${trajectory2.task.title}`);
|
|
53416
|
+
lines.push("");
|
|
53417
|
+
lines.push(`> **Status:** ${formatStatus(trajectory2.status)}`);
|
|
53418
|
+
if (trajectory2.task.source) {
|
|
53419
|
+
const linkText = trajectory2.task.source.url ? `[${trajectory2.task.source.id}](${trajectory2.task.source.url})` : trajectory2.task.source.id;
|
|
53420
|
+
lines.push(`> **Task:** ${linkText}`);
|
|
53421
|
+
}
|
|
53422
|
+
if (trajectory2.retrospective?.confidence !== void 0) {
|
|
53423
|
+
lines.push(
|
|
53424
|
+
`> **Confidence:** ${Math.round(trajectory2.retrospective.confidence * 100)}%`
|
|
53425
|
+
);
|
|
53426
|
+
}
|
|
53427
|
+
lines.push(`> **Started:** ${formatDate(trajectory2.startedAt)}`);
|
|
53428
|
+
if (trajectory2.completedAt) {
|
|
53429
|
+
lines.push(`> **Completed:** ${formatDate(trajectory2.completedAt)}`);
|
|
53430
|
+
}
|
|
53431
|
+
lines.push("");
|
|
53432
|
+
if (trajectory2.retrospective) {
|
|
53433
|
+
lines.push("---");
|
|
53434
|
+
lines.push("");
|
|
53435
|
+
lines.push("## Summary");
|
|
53436
|
+
lines.push("");
|
|
53437
|
+
lines.push(trajectory2.retrospective.summary);
|
|
53438
|
+
lines.push("");
|
|
53439
|
+
if (trajectory2.retrospective.approach) {
|
|
53440
|
+
lines.push(`**Approach:** ${trajectory2.retrospective.approach}`);
|
|
53441
|
+
lines.push("");
|
|
53442
|
+
}
|
|
53443
|
+
}
|
|
53444
|
+
const decisions = extractDecisions(trajectory2);
|
|
53445
|
+
if (decisions.length > 0) {
|
|
53446
|
+
lines.push("---");
|
|
53447
|
+
lines.push("");
|
|
53448
|
+
lines.push("## Key Decisions");
|
|
53449
|
+
lines.push("");
|
|
53450
|
+
for (const decision of decisions) {
|
|
53451
|
+
lines.push(`### ${decision.question}`);
|
|
53452
|
+
lines.push(`- **Chose:** ${decision.chosen}`);
|
|
53453
|
+
if (decision.alternatives.length > 0) {
|
|
53454
|
+
const altStrings = decision.alternatives.map(
|
|
53455
|
+
(a) => typeof a === "string" ? a : a.option
|
|
53456
|
+
);
|
|
53457
|
+
lines.push(`- **Rejected:** ${altStrings.join(", ")}`);
|
|
53458
|
+
}
|
|
53459
|
+
lines.push(`- **Reasoning:** ${decision.reasoning}`);
|
|
53460
|
+
lines.push("");
|
|
53461
|
+
}
|
|
53462
|
+
}
|
|
53463
|
+
if (trajectory2.chapters.length > 0) {
|
|
53464
|
+
lines.push("---");
|
|
53465
|
+
lines.push("");
|
|
53466
|
+
lines.push("## Chapters");
|
|
53467
|
+
lines.push("");
|
|
53468
|
+
trajectory2.chapters.forEach((chapter, index) => {
|
|
53469
|
+
lines.push(`### ${index + 1}. ${chapter.title}`);
|
|
53470
|
+
lines.push(`*Agent: ${chapter.agentName}*`);
|
|
53471
|
+
lines.push("");
|
|
53472
|
+
if (chapter.events.length > 0) {
|
|
53473
|
+
const significantEvents = chapter.events.filter(
|
|
53474
|
+
(e) => e.significance === "high" || e.significance === "critical" || e.type === "decision"
|
|
53475
|
+
);
|
|
53476
|
+
if (significantEvents.length > 0) {
|
|
53477
|
+
for (const event of significantEvents) {
|
|
53478
|
+
lines.push(`- ${event.content}`);
|
|
53479
|
+
}
|
|
53480
|
+
lines.push("");
|
|
53481
|
+
}
|
|
53482
|
+
}
|
|
53483
|
+
});
|
|
53484
|
+
}
|
|
53485
|
+
if (trajectory2.retrospective?.challenges && trajectory2.retrospective.challenges.length > 0) {
|
|
53486
|
+
lines.push("---");
|
|
53487
|
+
lines.push("");
|
|
53488
|
+
lines.push("## Challenges");
|
|
53489
|
+
lines.push("");
|
|
53490
|
+
for (const challenge of trajectory2.retrospective.challenges) {
|
|
53491
|
+
lines.push(`- ${challenge}`);
|
|
53492
|
+
}
|
|
53493
|
+
lines.push("");
|
|
53494
|
+
}
|
|
53495
|
+
if (trajectory2.retrospective?.learnings && trajectory2.retrospective.learnings.length > 0) {
|
|
53496
|
+
lines.push("---");
|
|
53497
|
+
lines.push("");
|
|
53498
|
+
lines.push("## Learnings");
|
|
53499
|
+
lines.push("");
|
|
53500
|
+
for (const learning of trajectory2.retrospective.learnings) {
|
|
53501
|
+
lines.push(`- ${learning}`);
|
|
53502
|
+
}
|
|
53503
|
+
lines.push("");
|
|
53504
|
+
}
|
|
53505
|
+
if (trajectory2.retrospective?.suggestions && trajectory2.retrospective.suggestions.length > 0) {
|
|
53506
|
+
lines.push("---");
|
|
53507
|
+
lines.push("");
|
|
53508
|
+
lines.push("## Suggestions");
|
|
53509
|
+
lines.push("");
|
|
53510
|
+
for (const suggestion of trajectory2.retrospective.suggestions) {
|
|
53511
|
+
lines.push(`- ${suggestion}`);
|
|
53512
|
+
}
|
|
53513
|
+
lines.push("");
|
|
53514
|
+
}
|
|
53515
|
+
if (trajectory2.commits.length > 0 || trajectory2.filesChanged.length > 0) {
|
|
53516
|
+
lines.push("---");
|
|
53517
|
+
lines.push("");
|
|
53518
|
+
lines.push("## Artifacts");
|
|
53519
|
+
lines.push("");
|
|
53520
|
+
if (trajectory2.commits.length > 0) {
|
|
53521
|
+
lines.push(`**Commits:** ${trajectory2.commits.join(", ")}`);
|
|
53522
|
+
}
|
|
53523
|
+
if (trajectory2.filesChanged.length > 0) {
|
|
53524
|
+
lines.push(`**Files changed:** ${trajectory2.filesChanged.length}`);
|
|
53525
|
+
}
|
|
53526
|
+
lines.push("");
|
|
53527
|
+
}
|
|
53528
|
+
return lines.join("\n");
|
|
53529
|
+
}
|
|
53530
|
+
function formatStatus(status) {
|
|
53531
|
+
switch (status) {
|
|
53532
|
+
case "active":
|
|
53533
|
+
return "\u{1F504} Active";
|
|
53534
|
+
case "completed":
|
|
53535
|
+
return "\u2705 Completed";
|
|
53536
|
+
case "abandoned":
|
|
53537
|
+
return "\u274C Abandoned";
|
|
53538
|
+
default:
|
|
53539
|
+
return status;
|
|
53540
|
+
}
|
|
53541
|
+
}
|
|
53542
|
+
function formatDate(isoString) {
|
|
53543
|
+
const date5 = new Date(isoString);
|
|
53544
|
+
return date5.toLocaleDateString("en-US", {
|
|
53545
|
+
year: "numeric",
|
|
53546
|
+
month: "long",
|
|
53547
|
+
day: "numeric",
|
|
53548
|
+
hour: "2-digit",
|
|
53549
|
+
minute: "2-digit"
|
|
53550
|
+
});
|
|
53551
|
+
}
|
|
53552
|
+
function extractDecisions(trajectory2) {
|
|
53553
|
+
const decisions = [];
|
|
53554
|
+
if (trajectory2.retrospective?.decisions) {
|
|
53555
|
+
decisions.push(...trajectory2.retrospective.decisions);
|
|
53556
|
+
}
|
|
53557
|
+
for (const chapter of trajectory2.chapters) {
|
|
53558
|
+
for (const event of chapter.events) {
|
|
53559
|
+
if (event.type === "decision" && event.raw) {
|
|
53560
|
+
const raw = event.raw;
|
|
53561
|
+
if (raw.question && raw.chosen && raw.reasoning) {
|
|
53562
|
+
if (!decisions.some((d) => d.question === raw.question)) {
|
|
53563
|
+
decisions.push(raw);
|
|
53564
|
+
}
|
|
53565
|
+
}
|
|
53566
|
+
}
|
|
53567
|
+
}
|
|
53568
|
+
}
|
|
53569
|
+
return decisions;
|
|
53570
|
+
}
|
|
53571
|
+
function expandPath(path24) {
|
|
53572
|
+
if (path24.startsWith("~")) {
|
|
53573
|
+
return (0, import_path4.join)(process.env.HOME ?? "", path24.slice(1));
|
|
53574
|
+
}
|
|
53575
|
+
return path24;
|
|
53576
|
+
}
|
|
53577
|
+
var FileStorage = class {
|
|
53578
|
+
baseDir;
|
|
53579
|
+
trajectoriesDir;
|
|
53580
|
+
activeDir;
|
|
53581
|
+
completedDir;
|
|
53582
|
+
indexPath;
|
|
53583
|
+
constructor(baseDir) {
|
|
53584
|
+
this.baseDir = baseDir ?? process.cwd();
|
|
53585
|
+
const dataDir = process.env.TRAJECTORIES_DATA_DIR;
|
|
53586
|
+
if (dataDir) {
|
|
53587
|
+
this.trajectoriesDir = expandPath(dataDir);
|
|
53588
|
+
} else {
|
|
53589
|
+
this.trajectoriesDir = (0, import_path4.join)(this.baseDir, ".trajectories");
|
|
53590
|
+
}
|
|
53591
|
+
this.activeDir = (0, import_path4.join)(this.trajectoriesDir, "active");
|
|
53592
|
+
this.completedDir = (0, import_path4.join)(this.trajectoriesDir, "completed");
|
|
53593
|
+
this.indexPath = (0, import_path4.join)(this.trajectoriesDir, "index.json");
|
|
53594
|
+
}
|
|
53595
|
+
/**
|
|
53596
|
+
* Initialize storage directories
|
|
53597
|
+
*/
|
|
53598
|
+
async initialize() {
|
|
53599
|
+
await (0, import_promises7.mkdir)(this.trajectoriesDir, { recursive: true });
|
|
53600
|
+
await (0, import_promises7.mkdir)(this.activeDir, { recursive: true });
|
|
53601
|
+
await (0, import_promises7.mkdir)(this.completedDir, { recursive: true });
|
|
53602
|
+
if (!(0, import_fs5.existsSync)(this.indexPath)) {
|
|
53603
|
+
await this.saveIndex({
|
|
53604
|
+
version: 1,
|
|
53605
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
53606
|
+
trajectories: {}
|
|
53607
|
+
});
|
|
53608
|
+
}
|
|
53609
|
+
await this.reconcileIndex();
|
|
53610
|
+
}
|
|
53611
|
+
/**
|
|
53612
|
+
* Scan active/ and completed/ recursively and add any trajectory files
|
|
53613
|
+
* missing from the index. Existing entries are preserved — reconcile
|
|
53614
|
+
* only adds, never removes.
|
|
53615
|
+
*
|
|
53616
|
+
* Handles three on-disk layouts in completed/:
|
|
53617
|
+
* - flat: completed/{id}.json (legacy workforce data)
|
|
53618
|
+
* - monthly: completed/YYYY-MM/{id}.json (current save() writes)
|
|
53619
|
+
* - nested: completed/.../{id}.json (defensive — any depth)
|
|
53620
|
+
*
|
|
53621
|
+
* Returns a ReconcileSummary so tests and CLI wrappers can observe
|
|
53622
|
+
* outcomes without parsing logs. Only writes the index if anything was
|
|
53623
|
+
* added.
|
|
53624
|
+
*/
|
|
53625
|
+
async reconcileIndex() {
|
|
53626
|
+
const summary = {
|
|
53627
|
+
scanned: 0,
|
|
53628
|
+
added: 0,
|
|
53629
|
+
alreadyIndexed: 0,
|
|
53630
|
+
skippedMalformedJson: 0,
|
|
53631
|
+
skippedSchemaViolation: 0,
|
|
53632
|
+
skippedIoError: 0
|
|
53633
|
+
};
|
|
53634
|
+
const index = await this.loadIndex();
|
|
53635
|
+
const before = Object.keys(index.trajectories).length;
|
|
53636
|
+
const discovered = [];
|
|
53637
|
+
try {
|
|
53638
|
+
const activeFiles = await (0, import_promises7.readdir)(this.activeDir);
|
|
53639
|
+
for (const file2 of activeFiles) {
|
|
53640
|
+
if (!file2.endsWith(".json")) continue;
|
|
53641
|
+
discovered.push((0, import_path4.join)(this.activeDir, file2));
|
|
53642
|
+
}
|
|
53643
|
+
} catch (error48) {
|
|
53644
|
+
if (error48.code !== "ENOENT") throw error48;
|
|
53645
|
+
}
|
|
53646
|
+
await this.walkJsonFilesInto(this.completedDir, discovered);
|
|
53647
|
+
for (const filePath of discovered) {
|
|
53648
|
+
summary.scanned += 1;
|
|
53649
|
+
const result = await this.readTrajectoryFile(filePath);
|
|
53650
|
+
if (!result.ok) {
|
|
53651
|
+
if (result.reason === "malformed_json") {
|
|
53652
|
+
summary.skippedMalformedJson += 1;
|
|
53653
|
+
} else if (result.reason === "schema_violation") {
|
|
53654
|
+
summary.skippedSchemaViolation += 1;
|
|
53655
|
+
} else {
|
|
53656
|
+
summary.skippedIoError += 1;
|
|
53657
|
+
}
|
|
53658
|
+
continue;
|
|
53659
|
+
}
|
|
53660
|
+
const trajectory2 = result.trajectory;
|
|
53661
|
+
if (index.trajectories[trajectory2.id]) {
|
|
53662
|
+
summary.alreadyIndexed += 1;
|
|
53663
|
+
continue;
|
|
53664
|
+
}
|
|
53665
|
+
index.trajectories[trajectory2.id] = {
|
|
53666
|
+
title: trajectory2.task.title,
|
|
53667
|
+
status: trajectory2.status,
|
|
53668
|
+
startedAt: trajectory2.startedAt,
|
|
53669
|
+
completedAt: trajectory2.completedAt,
|
|
53670
|
+
path: filePath
|
|
53671
|
+
};
|
|
53672
|
+
summary.added += 1;
|
|
53673
|
+
}
|
|
53674
|
+
if (Object.keys(index.trajectories).length !== before) {
|
|
53675
|
+
await this.saveIndex(index);
|
|
53676
|
+
}
|
|
53677
|
+
const hadSkips = summary.skippedMalformedJson + summary.skippedSchemaViolation + summary.skippedIoError > 0;
|
|
53678
|
+
if (summary.added > 0 || hadSkips) {
|
|
53679
|
+
const parts = [`reconciled ${summary.added}/${summary.scanned}`];
|
|
53680
|
+
if (summary.skippedMalformedJson > 0) {
|
|
53681
|
+
parts.push(`malformed: ${summary.skippedMalformedJson}`);
|
|
53682
|
+
}
|
|
53683
|
+
if (summary.skippedSchemaViolation > 0) {
|
|
53684
|
+
parts.push(`invalid: ${summary.skippedSchemaViolation}`);
|
|
53685
|
+
}
|
|
53686
|
+
if (summary.skippedIoError > 0) {
|
|
53687
|
+
parts.push(`io: ${summary.skippedIoError}`);
|
|
53688
|
+
}
|
|
53689
|
+
console.warn(`[trajectories] ${parts.join(", ")}`);
|
|
53690
|
+
}
|
|
53691
|
+
return summary;
|
|
53692
|
+
}
|
|
53693
|
+
/**
|
|
53694
|
+
* Recursively collect all .json file paths under `dir` into `out`.
|
|
53695
|
+
* Silently treats a missing directory as empty.
|
|
53696
|
+
*/
|
|
53697
|
+
async walkJsonFilesInto(dir, out) {
|
|
53698
|
+
let entries;
|
|
53699
|
+
try {
|
|
53700
|
+
entries = await (0, import_promises7.readdir)(dir, { withFileTypes: true });
|
|
53701
|
+
} catch (error48) {
|
|
53702
|
+
if (error48.code === "ENOENT") return;
|
|
53703
|
+
throw error48;
|
|
53704
|
+
}
|
|
53705
|
+
for (const entry of entries) {
|
|
53706
|
+
const entryPath = (0, import_path4.join)(dir, entry.name);
|
|
53707
|
+
if (entry.isDirectory()) {
|
|
53708
|
+
await this.walkJsonFilesInto(entryPath, out);
|
|
53709
|
+
} else if (entry.isFile() && entry.name.endsWith(".json")) {
|
|
53710
|
+
out.push(entryPath);
|
|
53711
|
+
}
|
|
53712
|
+
}
|
|
53713
|
+
}
|
|
53714
|
+
/**
|
|
53715
|
+
* Save a trajectory.
|
|
53716
|
+
*
|
|
53717
|
+
* Validates the input against the trajectory schema before touching
|
|
53718
|
+
* disk. Closes the historical read/write asymmetry where save() would
|
|
53719
|
+
* happily write data that the reader then rejected, producing files
|
|
53720
|
+
* that could never be loaded back.
|
|
53721
|
+
*/
|
|
53722
|
+
async save(input) {
|
|
53723
|
+
const validation = validateTrajectory(input);
|
|
53724
|
+
if (!validation.success) {
|
|
53725
|
+
const issues = validation.errors?.issues.map((issue2) => {
|
|
53726
|
+
const path24 = issue2.path.length > 0 ? issue2.path.join(".") : "root";
|
|
53727
|
+
return `${path24}: ${issue2.message}`;
|
|
53728
|
+
}).join("; ") ?? "unknown validation error";
|
|
53729
|
+
throw new Error(`Cannot save invalid trajectory: ${issues}`);
|
|
53730
|
+
}
|
|
53731
|
+
const trajectory2 = validation.data;
|
|
53732
|
+
const isCompleted = trajectory2.status === "completed" || trajectory2.status === "abandoned";
|
|
53733
|
+
let filePath;
|
|
53734
|
+
if (isCompleted) {
|
|
53735
|
+
const date5 = new Date(trajectory2.completedAt ?? trajectory2.startedAt);
|
|
53736
|
+
const monthDir = (0, import_path4.join)(
|
|
53737
|
+
this.completedDir,
|
|
53738
|
+
`${date5.getFullYear()}-${String(date5.getMonth() + 1).padStart(2, "0")}`
|
|
53739
|
+
);
|
|
53740
|
+
await (0, import_promises7.mkdir)(monthDir, { recursive: true });
|
|
53741
|
+
filePath = (0, import_path4.join)(monthDir, `${trajectory2.id}.json`);
|
|
53742
|
+
const activePath = (0, import_path4.join)(this.activeDir, `${trajectory2.id}.json`);
|
|
53743
|
+
if ((0, import_fs5.existsSync)(activePath)) {
|
|
53744
|
+
await (0, import_promises7.unlink)(activePath);
|
|
53745
|
+
}
|
|
53746
|
+
const mdPath = (0, import_path4.join)(monthDir, `${trajectory2.id}.md`);
|
|
53747
|
+
const markdown = exportToMarkdown(trajectory2);
|
|
53748
|
+
await (0, import_promises7.writeFile)(mdPath, markdown, "utf-8");
|
|
53749
|
+
} else {
|
|
53750
|
+
filePath = (0, import_path4.join)(this.activeDir, `${trajectory2.id}.json`);
|
|
53751
|
+
}
|
|
53752
|
+
await (0, import_promises7.writeFile)(filePath, JSON.stringify(trajectory2, null, 2), "utf-8");
|
|
53753
|
+
await this.updateIndex(trajectory2, filePath);
|
|
53754
|
+
}
|
|
53755
|
+
/**
|
|
53756
|
+
* Get a trajectory by ID
|
|
53757
|
+
*/
|
|
53758
|
+
async get(id) {
|
|
53759
|
+
const activePath = (0, import_path4.join)(this.activeDir, `${id}.json`);
|
|
53760
|
+
if ((0, import_fs5.existsSync)(activePath)) {
|
|
53761
|
+
return this.readTrajectoryOrNull(activePath);
|
|
53762
|
+
}
|
|
53763
|
+
const index = await this.loadIndex();
|
|
53764
|
+
const entry = index.trajectories[id];
|
|
53765
|
+
if (entry?.path && (0, import_fs5.existsSync)(entry.path)) {
|
|
53766
|
+
return this.readTrajectoryOrNull(entry.path);
|
|
53767
|
+
}
|
|
53768
|
+
try {
|
|
53769
|
+
const flatPath = (0, import_path4.join)(this.completedDir, `${id}.json`);
|
|
53770
|
+
if ((0, import_fs5.existsSync)(flatPath)) {
|
|
53771
|
+
return this.readTrajectoryOrNull(flatPath);
|
|
53772
|
+
}
|
|
53773
|
+
const months = await (0, import_promises7.readdir)(this.completedDir);
|
|
53774
|
+
for (const month of months) {
|
|
53775
|
+
const filePath = (0, import_path4.join)(this.completedDir, month, `${id}.json`);
|
|
53776
|
+
if ((0, import_fs5.existsSync)(filePath)) {
|
|
53777
|
+
return this.readTrajectoryOrNull(filePath);
|
|
53778
|
+
}
|
|
53779
|
+
}
|
|
53780
|
+
} catch (error48) {
|
|
53781
|
+
if (error48.code !== "ENOENT") {
|
|
53782
|
+
console.error("Error searching completed trajectories:", error48);
|
|
53783
|
+
}
|
|
53784
|
+
}
|
|
53785
|
+
return null;
|
|
53786
|
+
}
|
|
53787
|
+
/**
|
|
53788
|
+
* Get the currently active trajectory
|
|
53789
|
+
*/
|
|
53790
|
+
async getActive() {
|
|
53791
|
+
try {
|
|
53792
|
+
const files = await (0, import_promises7.readdir)(this.activeDir);
|
|
53793
|
+
const jsonFiles = files.filter((f2) => f2.endsWith(".json"));
|
|
53794
|
+
if (jsonFiles.length === 0) {
|
|
53795
|
+
return null;
|
|
53796
|
+
}
|
|
53797
|
+
let mostRecent = null;
|
|
53798
|
+
let mostRecentTime = 0;
|
|
53799
|
+
for (const file2 of jsonFiles) {
|
|
53800
|
+
const trajectory2 = await this.readTrajectoryOrNull(
|
|
53801
|
+
(0, import_path4.join)(this.activeDir, file2)
|
|
53802
|
+
);
|
|
53803
|
+
if (trajectory2) {
|
|
53804
|
+
const startTime = new Date(trajectory2.startedAt).getTime();
|
|
53805
|
+
if (startTime > mostRecentTime) {
|
|
53806
|
+
mostRecentTime = startTime;
|
|
53807
|
+
mostRecent = trajectory2;
|
|
53808
|
+
}
|
|
53809
|
+
}
|
|
53810
|
+
}
|
|
53811
|
+
return mostRecent;
|
|
53812
|
+
} catch (error48) {
|
|
53813
|
+
if (error48.code === "ENOENT") {
|
|
53814
|
+
return null;
|
|
53815
|
+
}
|
|
53816
|
+
console.error("Error reading active trajectories:", error48);
|
|
53817
|
+
return null;
|
|
53818
|
+
}
|
|
53819
|
+
}
|
|
53820
|
+
/**
|
|
53821
|
+
* List trajectories with optional filtering
|
|
53822
|
+
*/
|
|
53823
|
+
async list(query) {
|
|
53824
|
+
const index = await this.loadIndex();
|
|
53825
|
+
let entries = Object.entries(index.trajectories);
|
|
53826
|
+
if (query.status) {
|
|
53827
|
+
entries = entries.filter(([, entry]) => entry.status === query.status);
|
|
53828
|
+
}
|
|
53829
|
+
if (query.since) {
|
|
53830
|
+
const sinceTime = new Date(query.since).getTime();
|
|
53831
|
+
entries = entries.filter(
|
|
53832
|
+
([, entry]) => new Date(entry.startedAt).getTime() >= sinceTime
|
|
53833
|
+
);
|
|
53834
|
+
}
|
|
53835
|
+
if (query.until) {
|
|
53836
|
+
const untilTime = new Date(query.until).getTime();
|
|
53837
|
+
entries = entries.filter(
|
|
53838
|
+
([, entry]) => new Date(entry.startedAt).getTime() <= untilTime
|
|
53839
|
+
);
|
|
53840
|
+
}
|
|
53841
|
+
const sortBy = query.sortBy ?? "startedAt";
|
|
53842
|
+
const sortOrder = query.sortOrder ?? "desc";
|
|
53843
|
+
entries.sort((a, b2) => {
|
|
53844
|
+
const aVal = a[1][sortBy] ?? "";
|
|
53845
|
+
const bVal = b2[1][sortBy] ?? "";
|
|
53846
|
+
const cmp = String(aVal).localeCompare(String(bVal));
|
|
53847
|
+
return sortOrder === "asc" ? cmp : -cmp;
|
|
53848
|
+
});
|
|
53849
|
+
const offset = query.offset ?? 0;
|
|
53850
|
+
const limit = query.limit ?? 50;
|
|
53851
|
+
entries = entries.slice(offset, offset + limit);
|
|
53852
|
+
return Promise.all(
|
|
53853
|
+
entries.map(async ([id, entry]) => {
|
|
53854
|
+
const trajectory2 = await this.get(id);
|
|
53855
|
+
return {
|
|
53856
|
+
id,
|
|
53857
|
+
title: entry.title,
|
|
53858
|
+
status: entry.status,
|
|
53859
|
+
startedAt: entry.startedAt,
|
|
53860
|
+
completedAt: entry.completedAt,
|
|
53861
|
+
confidence: trajectory2?.retrospective?.confidence,
|
|
53862
|
+
chapterCount: trajectory2?.chapters.length ?? 0,
|
|
53863
|
+
decisionCount: trajectory2?.chapters.reduce(
|
|
53864
|
+
(count, chapter) => count + chapter.events.filter((e) => e.type === "decision").length,
|
|
53865
|
+
0
|
|
53866
|
+
) ?? 0
|
|
53867
|
+
};
|
|
53868
|
+
})
|
|
53869
|
+
);
|
|
53870
|
+
}
|
|
53871
|
+
/**
|
|
53872
|
+
* Delete a trajectory
|
|
53873
|
+
*/
|
|
53874
|
+
async delete(id) {
|
|
53875
|
+
const activePath = (0, import_path4.join)(this.activeDir, `${id}.json`);
|
|
53876
|
+
if ((0, import_fs5.existsSync)(activePath)) {
|
|
53877
|
+
await (0, import_promises7.unlink)(activePath);
|
|
53878
|
+
}
|
|
53879
|
+
const index = await this.loadIndex();
|
|
53880
|
+
const entry = index.trajectories[id];
|
|
53881
|
+
if (entry?.path && (0, import_fs5.existsSync)(entry.path)) {
|
|
53882
|
+
await (0, import_promises7.unlink)(entry.path);
|
|
53883
|
+
const mdPath = entry.path.replace(".json", ".md");
|
|
53884
|
+
if ((0, import_fs5.existsSync)(mdPath)) {
|
|
53885
|
+
await (0, import_promises7.unlink)(mdPath);
|
|
53886
|
+
}
|
|
53887
|
+
}
|
|
53888
|
+
delete index.trajectories[id];
|
|
53889
|
+
await this.saveIndex(index);
|
|
53890
|
+
}
|
|
53891
|
+
/**
|
|
53892
|
+
* Search trajectories by text
|
|
53893
|
+
*/
|
|
53894
|
+
async search(text, options) {
|
|
53895
|
+
const allTrajectories = await this.list({});
|
|
53896
|
+
const searchLower = text.toLowerCase();
|
|
53897
|
+
const limit = options?.limit ?? 20;
|
|
53898
|
+
const matches = [];
|
|
53899
|
+
for (const summary of allTrajectories) {
|
|
53900
|
+
if (matches.length >= limit) break;
|
|
53901
|
+
if (summary.title.toLowerCase().includes(searchLower)) {
|
|
53902
|
+
matches.push(summary);
|
|
53903
|
+
continue;
|
|
53904
|
+
}
|
|
53905
|
+
const trajectory2 = await this.get(summary.id);
|
|
53906
|
+
if (!trajectory2) continue;
|
|
53907
|
+
if (trajectory2.retrospective?.summary.toLowerCase().includes(searchLower)) {
|
|
53908
|
+
matches.push(summary);
|
|
53909
|
+
continue;
|
|
53910
|
+
}
|
|
53911
|
+
const hasMatchingDecision = trajectory2.chapters.some(
|
|
53912
|
+
(chapter) => chapter.events.some(
|
|
53913
|
+
(event) => event.type === "decision" && event.content.toLowerCase().includes(searchLower)
|
|
53914
|
+
)
|
|
53915
|
+
);
|
|
53916
|
+
if (hasMatchingDecision) {
|
|
53917
|
+
matches.push(summary);
|
|
53918
|
+
}
|
|
53919
|
+
}
|
|
53920
|
+
return matches;
|
|
53921
|
+
}
|
|
53922
|
+
/**
|
|
53923
|
+
* Close storage (no-op for file storage)
|
|
53924
|
+
*/
|
|
53925
|
+
async close() {
|
|
53926
|
+
}
|
|
53927
|
+
// Private helpers
|
|
53928
|
+
/**
|
|
53929
|
+
* Read a trajectory file and return a tagged result so callers can
|
|
53930
|
+
* distinguish missing files, malformed JSON, and schema violations.
|
|
53931
|
+
*
|
|
53932
|
+
* Does NOT log. Callers choose whether to warn, swallow, or throw.
|
|
53933
|
+
*/
|
|
53934
|
+
async readTrajectoryFile(path24) {
|
|
53935
|
+
let content;
|
|
53936
|
+
try {
|
|
53937
|
+
content = await (0, import_promises7.readFile)(path24, "utf-8");
|
|
53938
|
+
} catch (error48) {
|
|
53939
|
+
return { ok: false, reason: "io_error", path: path24, error: error48 };
|
|
53940
|
+
}
|
|
53941
|
+
let data;
|
|
53942
|
+
try {
|
|
53943
|
+
data = JSON.parse(content);
|
|
53944
|
+
} catch (error48) {
|
|
53945
|
+
return { ok: false, reason: "malformed_json", path: path24, error: error48 };
|
|
53946
|
+
}
|
|
53947
|
+
const validation = validateTrajectory(data);
|
|
53948
|
+
if (validation.success) {
|
|
53949
|
+
return { ok: true, trajectory: validation.data };
|
|
53950
|
+
}
|
|
53951
|
+
return {
|
|
53952
|
+
ok: false,
|
|
53953
|
+
reason: "schema_violation",
|
|
53954
|
+
path: path24,
|
|
53955
|
+
error: validation.errors
|
|
53956
|
+
};
|
|
53957
|
+
}
|
|
53958
|
+
/**
|
|
53959
|
+
* Convenience wrapper for callers that only care whether they got a
|
|
53960
|
+
* trajectory. Returns null for any failure and writes nothing to the
|
|
53961
|
+
* console — so nothing leaks into test output or the CLI spinner.
|
|
53962
|
+
*/
|
|
53963
|
+
async readTrajectoryOrNull(path24) {
|
|
53964
|
+
const result = await this.readTrajectoryFile(path24);
|
|
53965
|
+
return result.ok ? result.trajectory : null;
|
|
53966
|
+
}
|
|
53967
|
+
async loadIndex() {
|
|
53968
|
+
try {
|
|
53969
|
+
const content = await (0, import_promises7.readFile)(this.indexPath, "utf-8");
|
|
53970
|
+
return JSON.parse(content);
|
|
53971
|
+
} catch (error48) {
|
|
53972
|
+
if (error48.code !== "ENOENT") {
|
|
53973
|
+
console.error(
|
|
53974
|
+
"Error loading trajectory index, using empty index:",
|
|
53975
|
+
error48
|
|
53976
|
+
);
|
|
53977
|
+
}
|
|
53978
|
+
return {
|
|
53979
|
+
version: 1,
|
|
53980
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
53981
|
+
trajectories: {}
|
|
53982
|
+
};
|
|
53983
|
+
}
|
|
53984
|
+
}
|
|
53985
|
+
async saveIndex(index) {
|
|
53986
|
+
index.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
53987
|
+
await (0, import_promises7.writeFile)(this.indexPath, JSON.stringify(index, null, 2), "utf-8");
|
|
53988
|
+
}
|
|
53989
|
+
async updateIndex(trajectory2, filePath) {
|
|
53990
|
+
const index = await this.loadIndex();
|
|
53991
|
+
index.trajectories[trajectory2.id] = {
|
|
53992
|
+
title: trajectory2.task.title,
|
|
53993
|
+
status: trajectory2.status,
|
|
53994
|
+
startedAt: trajectory2.startedAt,
|
|
53995
|
+
completedAt: trajectory2.completedAt,
|
|
53996
|
+
path: filePath
|
|
53997
|
+
};
|
|
53998
|
+
await this.saveIndex(index);
|
|
53999
|
+
}
|
|
54000
|
+
};
|
|
54001
|
+
var require22 = (0, import_module.createRequire)(import_meta_url);
|
|
54002
|
+
|
|
54003
|
+
// packages/sdk/dist/workflows/trajectory.js
|
|
53027
54004
|
function classifyFailure(error48) {
|
|
53028
54005
|
const e = error48.toLowerCase();
|
|
53029
54006
|
if (e.includes("timed out") || e.includes("timeout"))
|
|
@@ -53041,30 +54018,84 @@ function classifyFailure(error48) {
|
|
|
53041
54018
|
function diagnosisFor(cause, outcome) {
|
|
53042
54019
|
switch (cause) {
|
|
53043
54020
|
case "timeout":
|
|
53044
|
-
|
|
53045
|
-
return `Non-interactive agent timed out \u2014 the task is likely too large or complex for a single subprocess call. Consider pre-reading large files in a deterministic step and injecting only the relevant excerpt via {{steps.X.output}}.`;
|
|
53046
|
-
}
|
|
53047
|
-
return `Interactive agent timed out \u2014 it may have gone idle, failed to self-terminate, or the task scope was too broad. Check if the agent was waiting for relay signals that never arrived.`;
|
|
54021
|
+
return outcome.nonInteractive ? "Non-interactive agent timed out \u2014 the task is likely too large or complex for a single subprocess call. Consider pre-reading large files in a deterministic step and injecting only the relevant excerpt via {{steps.X.output}}." : "Interactive agent timed out \u2014 it may have gone idle, failed to self-terminate, or the task scope was too broad. Check if the agent was waiting for relay signals that never arrived.";
|
|
53048
54022
|
case "verification_mismatch":
|
|
53049
54023
|
return `Agent completed but did not output the expected sentinel "${outcome.verificationValue ?? "(unknown)"}". The task prompt may not clearly specify the required output format, or the agent produced correct work but did not emit the signal.`;
|
|
53050
54024
|
case "spawn_failed":
|
|
53051
|
-
return
|
|
54025
|
+
return "The agent process could not be started \u2014 the CLI binary may be missing from PATH or the working directory is incorrect.";
|
|
53052
54026
|
case "exit_nonzero":
|
|
53053
|
-
return
|
|
54027
|
+
return "The agent process exited with a non-zero exit code. Check stderr for the root cause.";
|
|
53054
54028
|
case "aborted":
|
|
53055
|
-
return
|
|
54029
|
+
return "The step was cancelled (user interrupt or upstream abort).";
|
|
53056
54030
|
default:
|
|
53057
|
-
return
|
|
53058
|
-
}
|
|
53059
|
-
}
|
|
54031
|
+
return "Unexpected failure. Review the error and step definition.";
|
|
54032
|
+
}
|
|
54033
|
+
}
|
|
54034
|
+
function buildSynthesis(label, outcomes, unblocks) {
|
|
54035
|
+
const completed = outcomes.filter((o) => o.status === "completed");
|
|
54036
|
+
const failed = outcomes.filter((o) => o.status === "failed");
|
|
54037
|
+
const retried = outcomes.filter((o) => o.attempts > 1 && o.status !== "failed");
|
|
54038
|
+
const parts = [`${label} resolved.`, `${completed.length}/${outcomes.length} steps completed.`];
|
|
54039
|
+
if (failed.length > 0)
|
|
54040
|
+
parts.push(`${failed.length} step(s) failed: ${failed.map((s3) => s3.name).join(", ")}.`);
|
|
54041
|
+
if (retried.length > 0)
|
|
54042
|
+
parts.push(`${retried.length} step(s) required retries: ${retried.map((s3) => s3.name).join(", ")}.`);
|
|
54043
|
+
else if (failed.length === 0)
|
|
54044
|
+
parts.push("All steps completed on first attempt.");
|
|
54045
|
+
if (unblocks?.length)
|
|
54046
|
+
parts.push(`Unblocking: ${unblocks.join(", ")}.`);
|
|
54047
|
+
return parts.join(" ");
|
|
54048
|
+
}
|
|
54049
|
+
function computeConfidence(outcomes) {
|
|
54050
|
+
if (outcomes.length === 0)
|
|
54051
|
+
return 0.7;
|
|
54052
|
+
const total = outcomes.length;
|
|
54053
|
+
const completed = outcomes.filter((o) => o.status === "completed").length;
|
|
54054
|
+
const firstAttempt = outcomes.filter((o) => o.attempts === 1 && o.status === "completed").length;
|
|
54055
|
+
const verified = outcomes.filter((o) => o.verificationPassed).length;
|
|
54056
|
+
return Math.min(1, 0.5 * (completed / total) + 0.25 * (firstAttempt / total) + 0.25 * (verified / total));
|
|
54057
|
+
}
|
|
54058
|
+
function formatElapsed(elapsed, long) {
|
|
54059
|
+
return elapsed > 6e4 ? `${Math.round(elapsed / 6e4)}${long ? " minutes" : "min"}` : `${Math.round(elapsed / 1e3)}${long ? " seconds" : "s"}`;
|
|
54060
|
+
}
|
|
54061
|
+
function buildRunSummary(outcomes, startTime) {
|
|
54062
|
+
const completed = outcomes.filter((o) => o.status === "completed");
|
|
54063
|
+
const failed = outcomes.filter((o) => o.status === "failed");
|
|
54064
|
+
const skipped = outcomes.filter((o) => o.status === "skipped");
|
|
54065
|
+
const elapsedStr = formatElapsed(Date.now() - startTime, false);
|
|
54066
|
+
if (failed.length === 0) {
|
|
54067
|
+
const retried = completed.filter((o) => o.attempts > 1);
|
|
54068
|
+
const base = `All ${completed.length} steps completed in ${elapsedStr}.`;
|
|
54069
|
+
return retried.length > 0 ? `${base} ${retried.length} step(s) needed retries: ${retried.map((o) => o.name).join(", ")}.` : base;
|
|
54070
|
+
}
|
|
54071
|
+
const firstFailure = failed[0];
|
|
54072
|
+
const cause = classifyFailure(firstFailure.error ?? "");
|
|
54073
|
+
const cascaded = skipped.length > 0 ? ` Caused ${skipped.length} downstream step(s) to be skipped: ${skipped.map((o) => o.name).join(", ")}.` : "";
|
|
54074
|
+
return `Failed at "${firstFailure.name}" [${cause}] after ${elapsedStr}.${cascaded} ${completed.length}/${outcomes.length} steps completed before failure.`;
|
|
54075
|
+
}
|
|
54076
|
+
function extractLearnings(outcomes) {
|
|
54077
|
+
const learnings = [];
|
|
54078
|
+
const timeouts = outcomes.filter((o) => o.status === "failed" && classifyFailure(o.error ?? "") === "timeout");
|
|
54079
|
+
if (timeouts.some((o) => o.nonInteractive))
|
|
54080
|
+
learnings.push(`Non-interactive agent timeouts detected (${timeouts.map((o) => o.name).join(", ")}). Use deterministic steps to pre-read files and inject content \u2014 non-interactive agents should not discover information via tools.`);
|
|
54081
|
+
const verifyFails = outcomes.filter((o) => o.status === "failed" && classifyFailure(o.error ?? "") === "verification_mismatch");
|
|
54082
|
+
if (verifyFails.length > 0)
|
|
54083
|
+
learnings.push(`Verification mismatch on: ${verifyFails.map((o) => `"${o.name}" (expected "${o.verificationValue ?? "?"}")`).join(", ")}. Make the required output format more explicit in the task prompt.`);
|
|
54084
|
+
const retried = outcomes.filter((o) => o.attempts > 1 && o.status === "completed");
|
|
54085
|
+
if (retried.length > 0)
|
|
54086
|
+
learnings.push(`${retried.map((o) => `"${o.name}" (${o.attempts} attempts)`).join(", ")} succeeded after retries \u2014 consider adding clearer output instructions to reduce retries.`);
|
|
54087
|
+
return learnings;
|
|
54088
|
+
}
|
|
54089
|
+
var extractChallenges = (outcomes) => outcomes.filter((o) => o.status === "failed").map((step) => diagnosisFor(classifyFailure(step.error ?? ""), step));
|
|
53060
54090
|
var WorkflowTrajectory = class {
|
|
53061
54091
|
trajectory = null;
|
|
53062
|
-
|
|
54092
|
+
storage;
|
|
54093
|
+
storageInit;
|
|
53063
54094
|
enabled;
|
|
53064
54095
|
reflectOnBarriers;
|
|
53065
54096
|
reflectOnConverge;
|
|
53066
54097
|
autoDecisions;
|
|
53067
|
-
|
|
54098
|
+
storageBaseDir;
|
|
53068
54099
|
runId;
|
|
53069
54100
|
startTime = 0;
|
|
53070
54101
|
swarmPattern = "dag";
|
|
@@ -53075,100 +54106,73 @@ var WorkflowTrajectory = class {
|
|
|
53075
54106
|
this.reflectOnConverge = cfg.reflectOnConverge !== false;
|
|
53076
54107
|
this.autoDecisions = cfg.autoDecisions !== false;
|
|
53077
54108
|
this.runId = runId;
|
|
53078
|
-
|
|
54109
|
+
const dataDir = process.env.TRAJECTORIES_DATA_DIR ?? (0, import_node_path27.join)(cwd, ".trajectories");
|
|
54110
|
+
this.storageBaseDir = process.env.TRAJECTORIES_DATA_DIR ? (0, import_node_path27.dirname)(dataDir) : cwd;
|
|
53079
54111
|
}
|
|
53080
|
-
// ── Lifecycle ──────────────────────────────────────────────────────────────
|
|
53081
|
-
/** Start the trajectory (called at run:started). */
|
|
53082
54112
|
async start(workflowName, stepCount, trackInfo, description, pattern) {
|
|
53083
54113
|
if (!this.enabled)
|
|
53084
54114
|
return;
|
|
53085
54115
|
this.startTime = Date.now();
|
|
53086
54116
|
this.swarmPattern = pattern ?? "dag";
|
|
53087
|
-
|
|
53088
|
-
|
|
53089
|
-
|
|
53090
|
-
|
|
53091
|
-
|
|
53092
|
-
|
|
53093
|
-
|
|
53094
|
-
}
|
|
53095
|
-
|
|
53096
|
-
|
|
53097
|
-
|
|
53098
|
-
|
|
53099
|
-
};
|
|
54117
|
+
this.trajectory = createTrajectory({
|
|
54118
|
+
title: workflowName,
|
|
54119
|
+
description,
|
|
54120
|
+
source: { system: "workflow-runner", id: this.runId }
|
|
54121
|
+
});
|
|
54122
|
+
const workflowId = process.env.TRAJECTORIES_WORKFLOW_ID?.trim();
|
|
54123
|
+
if (workflowId)
|
|
54124
|
+
this.trajectory = { ...this.trajectory, workflowId };
|
|
54125
|
+
this.trajectory.agents.push({
|
|
54126
|
+
name: "orchestrator",
|
|
54127
|
+
role: "workflow-runner",
|
|
54128
|
+
joinedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
54129
|
+
});
|
|
53100
54130
|
this.openChapter("Planning", "orchestrator");
|
|
53101
|
-
if (description)
|
|
54131
|
+
if (description)
|
|
53102
54132
|
this.addEvent("note", `Purpose: ${description.trim()}`);
|
|
53103
|
-
}
|
|
53104
54133
|
this.addEvent("note", `Approach: ${stepCount}-step ${this.swarmPattern} workflow${trackInfo ? ` \u2014 ${trackInfo}` : ""}`);
|
|
53105
54134
|
await this.flush();
|
|
53106
54135
|
}
|
|
53107
|
-
// ── Chapters ───────────────────────────────────────────────────────────────
|
|
53108
|
-
/** Begin a new parallel track chapter. */
|
|
53109
54136
|
async beginTrack(trackName) {
|
|
53110
|
-
if (
|
|
53111
|
-
|
|
53112
|
-
|
|
53113
|
-
|
|
53114
|
-
await this.flush();
|
|
54137
|
+
if (this.enabled && this.trajectory) {
|
|
54138
|
+
this.openChapter(`Execution: ${trackName}`, "orchestrator");
|
|
54139
|
+
await this.flush();
|
|
54140
|
+
}
|
|
53115
54141
|
}
|
|
53116
|
-
/** Begin a convergence chapter (after barrier/parallel completion). */
|
|
53117
54142
|
async beginConvergence(label) {
|
|
53118
|
-
if (
|
|
53119
|
-
|
|
53120
|
-
|
|
53121
|
-
|
|
53122
|
-
await this.flush();
|
|
53123
|
-
}
|
|
53124
|
-
/** Begin the retrospective chapter. */
|
|
53125
|
-
openRetrospective() {
|
|
53126
|
-
if (!this.trajectory)
|
|
53127
|
-
return;
|
|
53128
|
-
this.closeCurrentChapter();
|
|
53129
|
-
this.openChapter("Retrospective", "orchestrator");
|
|
54143
|
+
if (this.enabled && this.trajectory) {
|
|
54144
|
+
this.openChapter(`Convergence: ${label}`, "orchestrator");
|
|
54145
|
+
await this.flush();
|
|
54146
|
+
}
|
|
53130
54147
|
}
|
|
53131
|
-
// ── Step events ────────────────────────────────────────────────────────────
|
|
53132
|
-
/** Record step started — captures intent, not just assignment. */
|
|
53133
54148
|
async stepStarted(step, agent, participants) {
|
|
53134
54149
|
if (!this.enabled || !this.trajectory)
|
|
53135
54150
|
return;
|
|
53136
54151
|
await this.registerAgent(agent, participants?.role ?? step.agent ?? "deterministic");
|
|
53137
|
-
if (participants?.owner && participants.owner !== agent)
|
|
54152
|
+
if (participants?.owner && participants.owner !== agent)
|
|
53138
54153
|
await this.registerAgent(participants.owner, "owner");
|
|
53139
|
-
|
|
53140
|
-
if (participants?.specialist) {
|
|
54154
|
+
if (participants?.specialist)
|
|
53141
54155
|
await this.registerAgent(participants.specialist, "specialist");
|
|
53142
|
-
|
|
53143
|
-
if (participants?.reviewer) {
|
|
54156
|
+
if (participants?.reviewer)
|
|
53144
54157
|
await this.registerAgent(participants.reviewer, "reviewer");
|
|
53145
|
-
}
|
|
53146
|
-
this.closeCurrentChapter();
|
|
53147
54158
|
this.openChapter(`Execution: ${step.name}`, agent);
|
|
53148
54159
|
const intent = step.task ? step.task.trim().split(/\n|\.(?=\s)/)[0].trim().slice(0, 120) : `${step.type ?? "deterministic"} step`;
|
|
53149
54160
|
this.addEvent("note", `"${step.name}": ${intent}`, void 0, { agent });
|
|
53150
54161
|
await this.flush();
|
|
53151
54162
|
}
|
|
53152
54163
|
async registerAgent(name, role) {
|
|
53153
|
-
if (!this.enabled || !this.trajectory)
|
|
54164
|
+
if (!this.enabled || !this.trajectory || this.trajectory.agents.some((agent) => agent.name === name))
|
|
53154
54165
|
return;
|
|
53155
|
-
|
|
53156
|
-
|
|
53157
|
-
name,
|
|
53158
|
-
role,
|
|
53159
|
-
joinedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
53160
|
-
});
|
|
53161
|
-
await this.flush();
|
|
53162
|
-
}
|
|
54166
|
+
this.trajectory.agents.push({ name, role, joinedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
54167
|
+
await this.flush();
|
|
53163
54168
|
}
|
|
53164
54169
|
async stepSupervisionAssigned(step, supervised) {
|
|
53165
54170
|
if (!this.enabled || !this.trajectory)
|
|
53166
54171
|
return;
|
|
53167
54172
|
await this.registerAgent(supervised.owner.name, "owner");
|
|
53168
54173
|
await this.registerAgent(supervised.specialist.name, "specialist");
|
|
53169
|
-
if (supervised.reviewer?.name)
|
|
54174
|
+
if (supervised.reviewer?.name)
|
|
53170
54175
|
await this.registerAgent(supervised.reviewer.name, "reviewer");
|
|
53171
|
-
}
|
|
53172
54176
|
const reviewerNote = supervised.reviewer?.name ? `, reviewer=${supervised.reviewer.name}` : "";
|
|
53173
54177
|
this.addEvent("decision", `"${step.name}" supervision assigned \u2192 owner=${supervised.owner.name}, specialist=${supervised.specialist.name}${reviewerNote}`, "medium", {
|
|
53174
54178
|
owner: supervised.owner.name,
|
|
@@ -53200,31 +54204,20 @@ var WorkflowTrajectory = class {
|
|
|
53200
54204
|
const modeLabel = decision.mode === "marker" ? "marker-based" : `${decision.mode}-based`;
|
|
53201
54205
|
const reason = decision.reason ? ` \u2014 ${decision.reason}` : "";
|
|
53202
54206
|
const evidence = this.formatCompletionEvidenceSummary(decision.evidence);
|
|
53203
|
-
|
|
53204
|
-
this.addEvent(decision.mode === "marker" ? "completion-marker" : "completion-evidence", `"${stepName}" ${modeLabel} completion${reason}${evidenceSuffix}`, "medium", {
|
|
53205
|
-
stepName,
|
|
53206
|
-
completionMode: decision.mode,
|
|
53207
|
-
reason: decision.reason,
|
|
53208
|
-
evidence: decision.evidence
|
|
53209
|
-
});
|
|
54207
|
+
this.addEvent(decision.mode === "marker" ? "completion-marker" : "completion-evidence", `"${stepName}" ${modeLabel} completion${reason}${evidence ? ` (${evidence})` : ""}`, "medium", { stepName, completionMode: decision.mode, reason: decision.reason, evidence: decision.evidence });
|
|
53210
54208
|
await this.flush();
|
|
53211
54209
|
}
|
|
53212
|
-
/** Record step completed — captures what was accomplished. */
|
|
53213
54210
|
async stepCompleted(step, output, attempt, decision) {
|
|
53214
54211
|
if (!this.enabled || !this.trajectory)
|
|
53215
54212
|
return;
|
|
53216
|
-
|
|
53217
|
-
|
|
54213
|
+
if (decision)
|
|
54214
|
+
await this.stepCompletionDecision(step.name, decision);
|
|
54215
|
+
const lines = output.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
53218
54216
|
const lastMeaningful = lines.at(-1) ?? "";
|
|
53219
54217
|
const completion = lastMeaningful.length > 0 && lastMeaningful.length < 100 ? lastMeaningful : output.trim().slice(0, 120) || "(no output)";
|
|
53220
|
-
|
|
53221
|
-
await this.stepCompletionDecision(step.name, decision);
|
|
53222
|
-
}
|
|
53223
|
-
const modeSuffix = decision ? ` [${decision.mode}]` : "";
|
|
53224
|
-
this.addEvent("finding", `"${step.name}" completed${suffix}${modeSuffix} \u2192 ${completion}`, "medium");
|
|
54218
|
+
this.addEvent("finding", `"${step.name}" completed${attempt > 1 ? ` (after ${attempt} attempts)` : ""}${decision ? ` [${decision.mode}]` : ""} \u2192 ${completion}`, "medium");
|
|
53225
54219
|
await this.flush();
|
|
53226
54220
|
}
|
|
53227
|
-
/** Record step failed — categorizes root cause for actionable diagnosis. */
|
|
53228
54221
|
async stepFailed(step, error48, attempt, maxRetries, outcome) {
|
|
53229
54222
|
if (!this.enabled || !this.trajectory)
|
|
53230
54223
|
return;
|
|
@@ -53246,44 +54239,30 @@ var WorkflowTrajectory = class {
|
|
|
53246
54239
|
});
|
|
53247
54240
|
await this.flush();
|
|
53248
54241
|
}
|
|
53249
|
-
/** Record step skipped — note the cascade impact. */
|
|
53250
54242
|
async stepSkipped(step, reason) {
|
|
53251
|
-
if (
|
|
53252
|
-
|
|
53253
|
-
|
|
53254
|
-
|
|
54243
|
+
if (this.enabled && this.trajectory) {
|
|
54244
|
+
this.addEvent("note", `"${step.name}" skipped \u2014 ${reason}`);
|
|
54245
|
+
await this.flush();
|
|
54246
|
+
}
|
|
53255
54247
|
}
|
|
53256
|
-
/** Record step retrying. */
|
|
53257
54248
|
async stepRetrying(step, attempt, maxRetries) {
|
|
53258
|
-
if (
|
|
53259
|
-
|
|
53260
|
-
|
|
53261
|
-
|
|
54249
|
+
if (this.enabled && this.trajectory) {
|
|
54250
|
+
this.addEvent("note", `"${step.name}" retrying (attempt ${attempt}/${maxRetries + 1})`);
|
|
54251
|
+
await this.flush();
|
|
54252
|
+
}
|
|
53262
54253
|
}
|
|
53263
|
-
// ── Reflections ────────────────────────────────────────────────────────────
|
|
53264
|
-
/** Record a reflection at a convergence point. */
|
|
53265
54254
|
async reflect(synthesis, confidence, focalPoints) {
|
|
53266
54255
|
if (!this.enabled || !this.trajectory)
|
|
53267
54256
|
return;
|
|
53268
|
-
|
|
53269
|
-
if (focalPoints?.length) {
|
|
53270
|
-
raw.focalPoints = focalPoints;
|
|
53271
|
-
}
|
|
53272
|
-
this.addEvent("reflection", synthesis, "high", raw);
|
|
54257
|
+
this.addEvent("reflection", synthesis, "high", focalPoints?.length ? { confidence, focalPoints } : { confidence });
|
|
53273
54258
|
await this.flush();
|
|
53274
54259
|
}
|
|
53275
|
-
/** Synthesize and reflect after a set of steps complete (barrier or parallel convergence). */
|
|
53276
54260
|
async synthesizeAndReflect(label, outcomes, unblocks) {
|
|
53277
54261
|
if (!this.enabled || !this.trajectory)
|
|
53278
54262
|
return;
|
|
53279
|
-
const synthesis = this.buildSynthesis(label, outcomes, unblocks);
|
|
53280
|
-
const confidence = this.computeConfidence(outcomes);
|
|
53281
|
-
const focalPoints = outcomes.map((o) => `${o.name}: ${o.status}`);
|
|
53282
54263
|
await this.beginConvergence(label);
|
|
53283
|
-
await this.reflect(
|
|
54264
|
+
await this.reflect(buildSynthesis(label, outcomes, unblocks), computeConfidence(outcomes), outcomes.map((o) => `${o.name}: ${o.status}`));
|
|
53284
54265
|
}
|
|
53285
|
-
// ── Decisions ──────────────────────────────────────────────────────────────
|
|
53286
|
-
/** Record an orchestrator decision. */
|
|
53287
54266
|
async decide(question, chosen, reasoning) {
|
|
53288
54267
|
if (!this.enabled || !this.trajectory || !this.autoDecisions)
|
|
53289
54268
|
return;
|
|
@@ -53294,52 +54273,39 @@ var WorkflowTrajectory = class {
|
|
|
53294
54273
|
});
|
|
53295
54274
|
await this.flush();
|
|
53296
54275
|
}
|
|
53297
|
-
// ── Completion ─────────────────────────────────────────────────────────────
|
|
53298
|
-
/** Complete the trajectory with a summary. */
|
|
53299
54276
|
async complete(summary, confidence, meta3) {
|
|
53300
54277
|
if (!this.enabled || !this.trajectory)
|
|
53301
54278
|
return;
|
|
53302
|
-
this.
|
|
53303
|
-
|
|
53304
|
-
|
|
53305
|
-
this.addEvent("reflection", `${summary} (completed in ${elapsedStr})`, "high");
|
|
53306
|
-
this.trajectory.status = "completed";
|
|
53307
|
-
this.trajectory.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
53308
|
-
this.trajectory.retrospective = {
|
|
54279
|
+
this.openChapter("Retrospective", "orchestrator");
|
|
54280
|
+
this.addEvent("reflection", `${summary} (completed in ${formatElapsed(Date.now() - this.startTime, true)})`, "high");
|
|
54281
|
+
this.trajectory = completeTrajectory(this.trajectory, {
|
|
53309
54282
|
summary,
|
|
53310
|
-
approach:
|
|
54283
|
+
approach: this.buildApproach(),
|
|
53311
54284
|
confidence,
|
|
53312
54285
|
learnings: meta3?.learnings,
|
|
53313
54286
|
challenges: meta3?.challenges
|
|
53314
|
-
};
|
|
53315
|
-
this.closeCurrentChapter();
|
|
54287
|
+
});
|
|
53316
54288
|
await this.flush();
|
|
53317
|
-
await this.moveToCompleted();
|
|
53318
54289
|
}
|
|
53319
|
-
/** Abandon the trajectory. */
|
|
53320
54290
|
async abandon(reason, meta3) {
|
|
53321
54291
|
if (!this.enabled || !this.trajectory)
|
|
53322
54292
|
return;
|
|
53323
|
-
const elapsed = Date.now() - this.startTime;
|
|
53324
|
-
const elapsedStr = elapsed > 6e4 ? `${Math.round(elapsed / 6e4)} minutes` : `${Math.round(elapsed / 1e3)} seconds`;
|
|
53325
54293
|
const summary = meta3?.summary ?? `Workflow abandoned: ${reason}`;
|
|
53326
|
-
this.
|
|
53327
|
-
this.addEvent("reflection", `${summary} (abandoned after ${
|
|
54294
|
+
this.openChapter("Retrospective", "orchestrator");
|
|
54295
|
+
this.addEvent("reflection", `${summary} (abandoned after ${formatElapsed(Date.now() - this.startTime, true)})`, "high");
|
|
53328
54296
|
this.addEvent("error", `Workflow abandoned: ${reason}`, "high");
|
|
53329
|
-
this.trajectory
|
|
53330
|
-
|
|
53331
|
-
|
|
53332
|
-
|
|
53333
|
-
|
|
53334
|
-
|
|
53335
|
-
|
|
53336
|
-
|
|
54297
|
+
this.trajectory = {
|
|
54298
|
+
...abandonTrajectory(this.trajectory),
|
|
54299
|
+
retrospective: {
|
|
54300
|
+
summary,
|
|
54301
|
+
approach: this.buildApproach(),
|
|
54302
|
+
confidence: meta3?.confidence ?? 0,
|
|
54303
|
+
learnings: meta3?.learnings,
|
|
54304
|
+
challenges: meta3?.challenges
|
|
54305
|
+
}
|
|
53337
54306
|
};
|
|
53338
|
-
this.closeCurrentChapter();
|
|
53339
54307
|
await this.flush();
|
|
53340
|
-
await this.moveToCompleted();
|
|
53341
54308
|
}
|
|
53342
|
-
// ── Getters ────────────────────────────────────────────────────────────────
|
|
53343
54309
|
isEnabled() {
|
|
53344
54310
|
return this.enabled;
|
|
53345
54311
|
}
|
|
@@ -53352,117 +54318,33 @@ var WorkflowTrajectory = class {
|
|
|
53352
54318
|
getTrajectoryId() {
|
|
53353
54319
|
return this.trajectory?.id ?? null;
|
|
53354
54320
|
}
|
|
53355
|
-
// ── Synthesis helpers ──────────────────────────────────────────────────────
|
|
53356
54321
|
buildSynthesis(label, outcomes, unblocks) {
|
|
53357
|
-
|
|
53358
|
-
const failed = outcomes.filter((o) => o.status === "failed");
|
|
53359
|
-
const retried = outcomes.filter((o) => o.attempts > 1 && o.status !== "failed");
|
|
53360
|
-
const parts = [`${label} resolved.`, `${completed.length}/${outcomes.length} steps completed.`];
|
|
53361
|
-
if (failed.length > 0) {
|
|
53362
|
-
parts.push(`${failed.length} step(s) failed: ${failed.map((s3) => s3.name).join(", ")}.`);
|
|
53363
|
-
}
|
|
53364
|
-
if (retried.length > 0) {
|
|
53365
|
-
parts.push(`${retried.length} step(s) required retries: ${retried.map((s3) => s3.name).join(", ")}.`);
|
|
53366
|
-
} else if (failed.length === 0) {
|
|
53367
|
-
parts.push("All steps completed on first attempt.");
|
|
53368
|
-
}
|
|
53369
|
-
if (unblocks?.length) {
|
|
53370
|
-
parts.push(`Unblocking: ${unblocks.join(", ")}.`);
|
|
53371
|
-
}
|
|
53372
|
-
return parts.join(" ");
|
|
54322
|
+
return buildSynthesis(label, outcomes, unblocks);
|
|
53373
54323
|
}
|
|
53374
54324
|
computeConfidence(outcomes) {
|
|
53375
|
-
|
|
53376
|
-
return 0.7;
|
|
53377
|
-
const total = outcomes.length;
|
|
53378
|
-
const completed = outcomes.filter((o) => o.status === "completed").length;
|
|
53379
|
-
const firstAttempt = outcomes.filter((o) => o.attempts === 1 && o.status === "completed").length;
|
|
53380
|
-
const verified = outcomes.filter((o) => o.verificationPassed).length;
|
|
53381
|
-
const completionRate = completed / total;
|
|
53382
|
-
return Math.min(1, 0.5 * completionRate + firstAttempt / total * 0.25 + verified / total * 0.25);
|
|
54325
|
+
return computeConfidence(outcomes);
|
|
53383
54326
|
}
|
|
53384
54327
|
buildRunSummary(outcomes) {
|
|
53385
|
-
|
|
53386
|
-
const failed = outcomes.filter((o) => o.status === "failed");
|
|
53387
|
-
const skipped = outcomes.filter((o) => o.status === "skipped");
|
|
53388
|
-
const elapsed = Date.now() - this.startTime;
|
|
53389
|
-
const elapsedStr = elapsed > 6e4 ? `${Math.round(elapsed / 6e4)}min` : `${Math.round(elapsed / 1e3)}s`;
|
|
53390
|
-
if (failed.length === 0) {
|
|
53391
|
-
const retried = completed.filter((o) => o.attempts > 1);
|
|
53392
|
-
const base = `All ${completed.length} steps completed in ${elapsedStr}.`;
|
|
53393
|
-
return retried.length > 0 ? `${base} ${retried.length} step(s) needed retries: ${retried.map((o) => o.name).join(", ")}.` : base;
|
|
53394
|
-
}
|
|
53395
|
-
const firstFailure = failed[0];
|
|
53396
|
-
const cause = classifyFailure(firstFailure.error ?? "");
|
|
53397
|
-
const cascaded = skipped.length > 0 ? ` Caused ${skipped.length} downstream step(s) to be skipped: ${skipped.map((o) => o.name).join(", ")}.` : "";
|
|
53398
|
-
return `Failed at "${firstFailure.name}" [${cause}] after ${elapsedStr}.${cascaded} ${completed.length}/${outcomes.length} steps completed before failure.`;
|
|
54328
|
+
return buildRunSummary(outcomes, this.startTime);
|
|
53399
54329
|
}
|
|
53400
54330
|
extractLearnings(outcomes) {
|
|
53401
|
-
|
|
53402
|
-
const timeouts = outcomes.filter((o) => o.status === "failed" && classifyFailure(o.error ?? "") === "timeout");
|
|
53403
|
-
if (timeouts.some((o) => o.nonInteractive)) {
|
|
53404
|
-
learnings.push(`Non-interactive agent timeouts detected (${timeouts.map((o) => o.name).join(", ")}). Use deterministic steps to pre-read files and inject content \u2014 non-interactive agents should not discover information via tools.`);
|
|
53405
|
-
}
|
|
53406
|
-
const verifyFails = outcomes.filter((o) => o.status === "failed" && classifyFailure(o.error ?? "") === "verification_mismatch");
|
|
53407
|
-
if (verifyFails.length > 0) {
|
|
53408
|
-
learnings.push(`Verification mismatch on: ${verifyFails.map((o) => `"${o.name}" (expected "${o.verificationValue ?? "?"}")`).join(", ")}. Make the required output format more explicit in the task prompt.`);
|
|
53409
|
-
}
|
|
53410
|
-
const retried = outcomes.filter((o) => o.attempts > 1 && o.status === "completed");
|
|
53411
|
-
if (retried.length > 0) {
|
|
53412
|
-
learnings.push(`${retried.map((o) => `"${o.name}" (${o.attempts} attempts)`).join(", ")} succeeded after retries \u2014 consider adding clearer output instructions to reduce retries.`);
|
|
53413
|
-
}
|
|
53414
|
-
return learnings;
|
|
54331
|
+
return extractLearnings(outcomes);
|
|
53415
54332
|
}
|
|
53416
54333
|
extractChallenges(outcomes) {
|
|
53417
|
-
|
|
53418
|
-
const failed = outcomes.filter((o) => o.status === "failed");
|
|
53419
|
-
for (const step of failed) {
|
|
53420
|
-
const cause = classifyFailure(step.error ?? "");
|
|
53421
|
-
challenges.push(diagnosisFor(cause, step));
|
|
53422
|
-
}
|
|
53423
|
-
return challenges;
|
|
54334
|
+
return extractChallenges(outcomes);
|
|
53424
54335
|
}
|
|
53425
|
-
// ── Internal helpers ───────────────────────────────────────────────────────
|
|
53426
54336
|
openChapter(title, agentName) {
|
|
53427
54337
|
if (!this.trajectory)
|
|
53428
54338
|
return;
|
|
53429
|
-
|
|
53430
|
-
id: `ch_${(0, import_node_crypto7.randomBytes)(4).toString("hex")}`,
|
|
53431
|
-
title,
|
|
53432
|
-
agentName,
|
|
53433
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
53434
|
-
events: []
|
|
53435
|
-
};
|
|
53436
|
-
this.trajectory.chapters.push(chapter);
|
|
53437
|
-
this.currentChapterId = chapter.id;
|
|
53438
|
-
}
|
|
53439
|
-
closeCurrentChapter() {
|
|
53440
|
-
if (!this.trajectory || !this.currentChapterId)
|
|
53441
|
-
return;
|
|
53442
|
-
const chapter = this.trajectory.chapters.find((c) => c.id === this.currentChapterId);
|
|
53443
|
-
if (chapter && !chapter.endedAt) {
|
|
53444
|
-
chapter.endedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
53445
|
-
}
|
|
53446
|
-
this.currentChapterId = null;
|
|
54339
|
+
this.trajectory = addChapter(this.trajectory, { title, agentName });
|
|
53447
54340
|
}
|
|
53448
54341
|
addEvent(type, content, significance, raw) {
|
|
53449
54342
|
if (!this.trajectory)
|
|
53450
54343
|
return;
|
|
53451
|
-
|
|
53452
|
-
|
|
53453
|
-
|
|
53454
|
-
|
|
53455
|
-
}
|
|
53456
|
-
const event = {
|
|
53457
|
-
ts: Date.now(),
|
|
53458
|
-
type,
|
|
53459
|
-
content
|
|
53460
|
-
};
|
|
53461
|
-
if (significance)
|
|
53462
|
-
event.significance = significance;
|
|
53463
|
-
if (raw)
|
|
53464
|
-
event.raw = raw;
|
|
53465
|
-
chapter.events.push(event);
|
|
54344
|
+
this.trajectory = addEvent(this.trajectory, { type, content, significance, raw });
|
|
54345
|
+
}
|
|
54346
|
+
buildApproach() {
|
|
54347
|
+
return `${this.swarmPattern} workflow (${this.trajectory?.agents.filter((a) => a.role !== "workflow-runner").length ?? 0} agents)`;
|
|
53466
54348
|
}
|
|
53467
54349
|
formatCompletionEvidenceSummary(evidence) {
|
|
53468
54350
|
if (!evidence)
|
|
@@ -53480,29 +54362,17 @@ var WorkflowTrajectory = class {
|
|
|
53480
54362
|
parts.push(`exit=${evidence.exitCode}`);
|
|
53481
54363
|
return parts.length > 0 ? parts.join("; ") : void 0;
|
|
53482
54364
|
}
|
|
54365
|
+
async ensureStorage() {
|
|
54366
|
+
this.storage ??= new FileStorage(this.storageBaseDir);
|
|
54367
|
+
this.storageInit ??= this.storage.initialize();
|
|
54368
|
+
await this.storageInit;
|
|
54369
|
+
}
|
|
53483
54370
|
async flush() {
|
|
53484
54371
|
if (!this.trajectory)
|
|
53485
54372
|
return;
|
|
53486
54373
|
try {
|
|
53487
|
-
|
|
53488
|
-
await (
|
|
53489
|
-
const filePath = import_node_path27.default.join(activeDir, `${this.trajectory.id}.json`);
|
|
53490
|
-
await (0, import_promises7.writeFile)(filePath, JSON.stringify(this.trajectory, null, 2), "utf-8");
|
|
53491
|
-
} catch {
|
|
53492
|
-
}
|
|
53493
|
-
}
|
|
53494
|
-
async moveToCompleted() {
|
|
53495
|
-
if (!this.trajectory)
|
|
53496
|
-
return;
|
|
53497
|
-
try {
|
|
53498
|
-
const activeDir = import_node_path27.default.join(this.dataDir, "active");
|
|
53499
|
-
const completedDir = import_node_path27.default.join(this.dataDir, "completed");
|
|
53500
|
-
await (0, import_promises7.mkdir)(completedDir, { recursive: true });
|
|
53501
|
-
const activePath = import_node_path27.default.join(activeDir, `${this.trajectory.id}.json`);
|
|
53502
|
-
const completedPath = import_node_path27.default.join(completedDir, `${this.trajectory.id}.json`);
|
|
53503
|
-
if ((0, import_node_fs20.existsSync)(activePath)) {
|
|
53504
|
-
await (0, import_promises7.rename)(activePath, completedPath);
|
|
53505
|
-
}
|
|
54374
|
+
await this.ensureStorage();
|
|
54375
|
+
await this.storage?.save(this.trajectory);
|
|
53506
54376
|
} catch {
|
|
53507
54377
|
}
|
|
53508
54378
|
}
|
|
@@ -53693,7 +54563,7 @@ var WorkflowRunner = class _WorkflowRunner {
|
|
|
53693
54563
|
const abs = import_node_path28.default.resolve(baseCwd, expanded);
|
|
53694
54564
|
resolved.set(pd.name, abs);
|
|
53695
54565
|
const isRequired = pd.required !== false;
|
|
53696
|
-
if (!(0,
|
|
54566
|
+
if (!(0, import_node_fs20.existsSync)(abs)) {
|
|
53697
54567
|
if (isRequired) {
|
|
53698
54568
|
errors.push(`Path "${pd.name}" resolves to "${abs}" which does not exist (required)`);
|
|
53699
54569
|
} else {
|
|
@@ -54328,12 +55198,12 @@ ${next}` : next;
|
|
|
54328
55198
|
}
|
|
54329
55199
|
captureFileSnapshot(root) {
|
|
54330
55200
|
const snapshot = /* @__PURE__ */ new Map();
|
|
54331
|
-
if (!(0,
|
|
55201
|
+
if (!(0, import_node_fs20.existsSync)(root))
|
|
54332
55202
|
return snapshot;
|
|
54333
55203
|
const visit = (currentPath) => {
|
|
54334
55204
|
let entries;
|
|
54335
55205
|
try {
|
|
54336
|
-
entries = (0,
|
|
55206
|
+
entries = (0, import_node_fs20.readdirSync)(currentPath, { withFileTypes: true });
|
|
54337
55207
|
} catch {
|
|
54338
55208
|
return;
|
|
54339
55209
|
}
|
|
@@ -54347,7 +55217,7 @@ ${next}` : next;
|
|
|
54347
55217
|
continue;
|
|
54348
55218
|
}
|
|
54349
55219
|
try {
|
|
54350
|
-
const stats = (0,
|
|
55220
|
+
const stats = (0, import_node_fs20.statSync)(fullPath);
|
|
54351
55221
|
if (!stats.isFile())
|
|
54352
55222
|
continue;
|
|
54353
55223
|
snapshot.set(fullPath, { mtimeMs: stats.mtimeMs, size: stats.size });
|
|
@@ -54356,7 +55226,7 @@ ${next}` : next;
|
|
|
54356
55226
|
}
|
|
54357
55227
|
};
|
|
54358
55228
|
try {
|
|
54359
|
-
const stats = (0,
|
|
55229
|
+
const stats = (0, import_node_fs20.statSync)(root);
|
|
54360
55230
|
if (stats.isFile()) {
|
|
54361
55231
|
snapshot.set(root, { mtimeMs: stats.mtimeMs, size: stats.size });
|
|
54362
55232
|
return snapshot;
|
|
@@ -54477,7 +55347,7 @@ ${next}` : next;
|
|
|
54477
55347
|
this.relayApiKey = envKey;
|
|
54478
55348
|
return;
|
|
54479
55349
|
}
|
|
54480
|
-
const workspaceName = `relay-${channel}-${(0,
|
|
55350
|
+
const workspaceName = `relay-${channel}-${(0, import_node_crypto7.randomBytes)(4).toString("hex")}`;
|
|
54481
55351
|
const baseUrl = this.relayOptions.env?.RELAYCAST_BASE_URL ?? process.env.RELAYCAST_BASE_URL ?? "https://api.relaycast.dev";
|
|
54482
55352
|
const res = await fetch(`${baseUrl}/v1/workspaces`, {
|
|
54483
55353
|
method: "POST",
|
|
@@ -54538,7 +55408,7 @@ ${next}` : next;
|
|
|
54538
55408
|
...this.getRelayEnv() ?? {}
|
|
54539
55409
|
};
|
|
54540
55410
|
const result = await provisionWorkflowAgents({
|
|
54541
|
-
secret: this.envSecrets?.RELAY_AUTH_SECRET ?? relayEnv.RELAY_AUTH_SECRET ?? (0,
|
|
55411
|
+
secret: this.envSecrets?.RELAY_AUTH_SECRET ?? relayEnv.RELAY_AUTH_SECRET ?? (0, import_node_crypto7.randomBytes)(32).toString("hex"),
|
|
54542
55412
|
workspace: this.workspaceId,
|
|
54543
55413
|
projectDir: this.cwd,
|
|
54544
55414
|
relayfileBaseUrl: relayEnv.RELAYFILE_BASE_URL ?? "http://127.0.0.1:8080",
|
|
@@ -54578,7 +55448,7 @@ ${next}` : next;
|
|
|
54578
55448
|
} catch (err) {
|
|
54579
55449
|
if (err instanceof RelayError && err.code === "name_conflict") {
|
|
54580
55450
|
registration = await rc.agents.register({
|
|
54581
|
-
name: `WorkflowRunner-${(0,
|
|
55451
|
+
name: `WorkflowRunner-${(0, import_node_crypto7.randomBytes)(4).toString("hex")}`,
|
|
54582
55452
|
type: "agent"
|
|
54583
55453
|
});
|
|
54584
55454
|
} else {
|
|
@@ -54822,14 +55692,14 @@ ${err.suggestion}`);
|
|
|
54822
55692
|
for (const agent of resolved.agents) {
|
|
54823
55693
|
if (agent.cwd) {
|
|
54824
55694
|
const resolvedCwd = import_node_path28.default.resolve(this.cwd, agent.cwd);
|
|
54825
|
-
if (!(0,
|
|
55695
|
+
if (!(0, import_node_fs20.existsSync)(resolvedCwd)) {
|
|
54826
55696
|
warnings.push(`Agent "${agent.name}" cwd "${agent.cwd}" resolves to "${resolvedCwd}" which does not exist`);
|
|
54827
55697
|
}
|
|
54828
55698
|
}
|
|
54829
55699
|
if (agent.additionalPaths) {
|
|
54830
55700
|
for (const ap of agent.additionalPaths) {
|
|
54831
55701
|
const resolvedPath = import_node_path28.default.resolve(this.cwd, ap);
|
|
54832
|
-
if (!(0,
|
|
55702
|
+
if (!(0, import_node_fs20.existsSync)(resolvedPath)) {
|
|
54833
55703
|
warnings.push(`Agent "${agent.name}" additionalPath "${ap}" resolves to "${resolvedPath}" which does not exist`);
|
|
54834
55704
|
}
|
|
54835
55705
|
}
|
|
@@ -57020,9 +57890,9 @@ WORKER COMPLETION CONTRACT:
|
|
|
57020
57890
|
promptTaskText: taskText
|
|
57021
57891
|
};
|
|
57022
57892
|
}
|
|
57023
|
-
const taskTmpDir = (0,
|
|
57893
|
+
const taskTmpDir = (0, import_node_fs20.mkdtempSync)(import_node_path28.default.join((0, import_node_os8.tmpdir)(), "relay-pty-task-"));
|
|
57024
57894
|
const taskTmpFile = import_node_path28.default.join(taskTmpDir, `${agentName}-${Date.now()}.txt`);
|
|
57025
|
-
(0,
|
|
57895
|
+
(0, import_node_fs20.writeFileSync)(taskTmpFile, taskText, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
57026
57896
|
const promptTaskText = `TASK_FILE:${taskTmpFile}
|
|
57027
57897
|
Read that file completely before taking any action.
|
|
57028
57898
|
Treat the file contents as the full workflow task and follow them exactly.
|
|
@@ -57428,7 +58298,7 @@ DO NOT:
|
|
|
57428
58298
|
const { cmd, args } = _WorkflowRunner.buildNonInteractiveCommand(agentDef.cli, taskWithDeliverable, modelArgs);
|
|
57429
58299
|
const logsDir = this.getWorkerLogsDir();
|
|
57430
58300
|
const logPath = import_node_path28.default.join(logsDir, `${agentName}.log`);
|
|
57431
|
-
const logStream = (0,
|
|
58301
|
+
const logStream = (0, import_node_fs20.createWriteStream)(logPath, { flags: "a" });
|
|
57432
58302
|
this.registerWorker(agentName, agentDef.cli, step.task ?? "", void 0, false);
|
|
57433
58303
|
let stopHeartbeat;
|
|
57434
58304
|
if (this.relayApiKey) {
|
|
@@ -57591,7 +58461,7 @@ DO NOT:
|
|
|
57591
58461
|
const preparedTask = this.prepareInteractiveSpawnTask(agentName, taskWithExit);
|
|
57592
58462
|
this.ptyOutputBuffers.set(agentName, []);
|
|
57593
58463
|
const logsDir = this.getWorkerLogsDir();
|
|
57594
|
-
const logStream = (0,
|
|
58464
|
+
const logStream = (0, import_node_fs20.createWriteStream)(import_node_path28.default.join(logsDir, `${agentName}.log`), { flags: "a" });
|
|
57595
58465
|
this.ptyLogStreams.set(agentName, logStream);
|
|
57596
58466
|
this.ptyListeners.set(agentName, (chunk) => {
|
|
57597
58467
|
const stripped = _WorkflowRunner.stripAnsi(chunk);
|
|
@@ -57644,11 +58514,11 @@ DO NOT:
|
|
|
57644
58514
|
oldLogStream.end();
|
|
57645
58515
|
this.ptyLogStreams.delete(oldName);
|
|
57646
58516
|
try {
|
|
57647
|
-
(0,
|
|
58517
|
+
(0, import_node_fs20.renameSync)(oldLogPath, newLogPath);
|
|
57648
58518
|
} catch {
|
|
57649
58519
|
}
|
|
57650
58520
|
}
|
|
57651
|
-
const newLogStream = (0,
|
|
58521
|
+
const newLogStream = (0, import_node_fs20.createWriteStream)(newLogPath, { flags: "a" });
|
|
57652
58522
|
this.ptyLogStreams.set(agent.name, newLogStream);
|
|
57653
58523
|
const oldListener = this.ptyListeners.get(oldName);
|
|
57654
58524
|
if (oldListener) {
|
|
@@ -57756,7 +58626,7 @@ DO NOT:
|
|
|
57756
58626
|
output = ptyChunks.join("");
|
|
57757
58627
|
} else {
|
|
57758
58628
|
const summaryPath = import_node_path28.default.join(this.summaryDir, `${step.name}.md`);
|
|
57759
|
-
output = (0,
|
|
58629
|
+
output = (0, import_node_fs20.existsSync)(summaryPath) ? await (0, import_promises8.readFile)(summaryPath, "utf-8") : exitResult === "timeout" ? "Agent completed (released after idle timeout)" : exitResult === "released" ? "Agent completed (idle \u2014 treated as done)" : `Agent exited (${exitResult})`;
|
|
57760
58630
|
}
|
|
57761
58631
|
if (ptyChunks.length === 0) {
|
|
57762
58632
|
this.captureStepTerminalEvidence(evidenceStepName, { stdout: output, combined: output }, { exitCode: agent?.exitCode, exitSignal: agent?.exitSignal }, {
|
|
@@ -58261,16 +59131,16 @@ ${excerpt}` : "";
|
|
|
58261
59131
|
if (!target)
|
|
58262
59132
|
return;
|
|
58263
59133
|
try {
|
|
58264
|
-
(0,
|
|
58265
|
-
(0,
|
|
59134
|
+
(0, import_node_fs20.mkdirSync)(import_node_path28.default.dirname(target), { recursive: true });
|
|
59135
|
+
(0, import_node_fs20.writeFileSync)(target, runId + "\n", "utf8");
|
|
58266
59136
|
} catch {
|
|
58267
59137
|
}
|
|
58268
59138
|
}
|
|
58269
59139
|
generateId() {
|
|
58270
|
-
return (0,
|
|
59140
|
+
return (0, import_node_crypto7.randomBytes)(12).toString("hex");
|
|
58271
59141
|
}
|
|
58272
59142
|
generateShortId() {
|
|
58273
|
-
return (0,
|
|
59143
|
+
return (0, import_node_crypto7.randomBytes)(4).toString("hex");
|
|
58274
59144
|
}
|
|
58275
59145
|
/** Strip ANSI escape codes from terminal output — delegates to pty.ts canonical regex. */
|
|
58276
59146
|
static stripAnsi(text) {
|
|
@@ -58378,7 +59248,7 @@ ${excerpt}` : "";
|
|
|
58378
59248
|
const outputPath = import_node_path28.default.join(this.getStepOutputDir(runId), `${stepName}.md`);
|
|
58379
59249
|
try {
|
|
58380
59250
|
const dir = this.getStepOutputDir(runId);
|
|
58381
|
-
(0,
|
|
59251
|
+
(0, import_node_fs20.mkdirSync)(dir, { recursive: true });
|
|
58382
59252
|
const cleaned = _WorkflowRunner.stripAnsi(output);
|
|
58383
59253
|
await (0, import_promises8.writeFile)(outputPath, cleaned);
|
|
58384
59254
|
} catch {
|
|
@@ -58407,7 +59277,7 @@ ${preview}
|
|
|
58407
59277
|
async persistAgentReport(runId, stepName, report) {
|
|
58408
59278
|
const reportPath = import_node_path28.default.join(this.getStepOutputDir(runId), `${stepName}.report.json`);
|
|
58409
59279
|
try {
|
|
58410
|
-
(0,
|
|
59280
|
+
(0, import_node_fs20.mkdirSync)(this.getStepOutputDir(runId), { recursive: true });
|
|
58411
59281
|
await (0, import_promises8.writeFile)(reportPath, JSON.stringify(report, null, 2), "utf8");
|
|
58412
59282
|
} catch {
|
|
58413
59283
|
}
|
|
@@ -58416,17 +59286,17 @@ ${preview}
|
|
|
58416
59286
|
findMostRecentRunWithSteps(stepNames) {
|
|
58417
59287
|
try {
|
|
58418
59288
|
const baseDir = import_node_path28.default.join(this.cwd, ".agent-relay", "step-outputs");
|
|
58419
|
-
if (!(0,
|
|
59289
|
+
if (!(0, import_node_fs20.existsSync)(baseDir))
|
|
58420
59290
|
return void 0;
|
|
58421
|
-
const entries = (0,
|
|
59291
|
+
const entries = (0, import_node_fs20.readdirSync)(baseDir);
|
|
58422
59292
|
let best;
|
|
58423
59293
|
for (const entry of entries) {
|
|
58424
59294
|
const dirPath = import_node_path28.default.join(baseDir, entry);
|
|
58425
59295
|
try {
|
|
58426
|
-
const stat2 = (0,
|
|
59296
|
+
const stat2 = (0, import_node_fs20.statSync)(dirPath);
|
|
58427
59297
|
if (!stat2.isDirectory())
|
|
58428
59298
|
continue;
|
|
58429
|
-
const hasAny = [...stepNames].some((name) => (0,
|
|
59299
|
+
const hasAny = [...stepNames].some((name) => (0, import_node_fs20.existsSync)(import_node_path28.default.join(dirPath, `${name}.md`)));
|
|
58430
59300
|
if (!hasAny)
|
|
58431
59301
|
continue;
|
|
58432
59302
|
if (!best || stat2.mtimeMs > best.mtime) {
|
|
@@ -58445,9 +59315,9 @@ ${preview}
|
|
|
58445
59315
|
loadStepOutput(runId, stepName) {
|
|
58446
59316
|
try {
|
|
58447
59317
|
const filePath = import_node_path28.default.join(this.getStepOutputDir(runId), `${stepName}.md`);
|
|
58448
|
-
if (!(0,
|
|
59318
|
+
if (!(0, import_node_fs20.existsSync)(filePath))
|
|
58449
59319
|
return void 0;
|
|
58450
|
-
return (0,
|
|
59320
|
+
return (0, import_node_fs20.readFileSync)(filePath, "utf-8");
|
|
58451
59321
|
} catch {
|
|
58452
59322
|
return void 0;
|
|
58453
59323
|
}
|
|
@@ -58469,14 +59339,14 @@ ${preview}
|
|
|
58469
59339
|
}
|
|
58470
59340
|
reconstructRunFromCache(runId, config2) {
|
|
58471
59341
|
const stepOutputDir = this.getStepOutputDir(runId);
|
|
58472
|
-
if (!(0,
|
|
59342
|
+
if (!(0, import_node_fs20.existsSync)(stepOutputDir))
|
|
58473
59343
|
return null;
|
|
58474
59344
|
let resumeConfig = config2 ?? this.currentConfig;
|
|
58475
59345
|
if (!resumeConfig) {
|
|
58476
59346
|
const yamlPath = import_node_path28.default.join(this.cwd, "relay.yaml");
|
|
58477
|
-
if ((0,
|
|
59347
|
+
if ((0, import_node_fs20.existsSync)(yamlPath)) {
|
|
58478
59348
|
try {
|
|
58479
|
-
const raw = (0,
|
|
59349
|
+
const raw = (0, import_node_fs20.readFileSync)(yamlPath, "utf-8");
|
|
58480
59350
|
resumeConfig = this.parseYamlString(raw, yamlPath);
|
|
58481
59351
|
} catch {
|
|
58482
59352
|
return null;
|
|
@@ -58487,7 +59357,7 @@ ${preview}
|
|
|
58487
59357
|
}
|
|
58488
59358
|
let entries;
|
|
58489
59359
|
try {
|
|
58490
|
-
entries = (0,
|
|
59360
|
+
entries = (0, import_node_fs20.readdirSync)(stepOutputDir, { withFileTypes: true });
|
|
58491
59361
|
} catch {
|
|
58492
59362
|
return null;
|
|
58493
59363
|
}
|
|
@@ -58504,8 +59374,8 @@ ${preview}
|
|
|
58504
59374
|
try {
|
|
58505
59375
|
const mdPath = import_node_path28.default.join(stepOutputDir, `${stepName}.md`);
|
|
58506
59376
|
const reportPath = import_node_path28.default.join(stepOutputDir, `${stepName}.report.json`);
|
|
58507
|
-
const mdStat = (0,
|
|
58508
|
-
const reportStat = (0,
|
|
59377
|
+
const mdStat = (0, import_node_fs20.existsSync)(mdPath) ? (0, import_node_fs20.statSync)(mdPath) : null;
|
|
59378
|
+
const reportStat = (0, import_node_fs20.existsSync)(reportPath) ? (0, import_node_fs20.statSync)(reportPath) : null;
|
|
58509
59379
|
const mtime = Math.max(mdStat?.mtimeMs ?? 0, reportStat?.mtimeMs ?? 0);
|
|
58510
59380
|
if (mtime > 0) {
|
|
58511
59381
|
stepMtimes.set(stepName, new Date(mtime).toISOString());
|
|
@@ -58558,7 +59428,7 @@ ${preview}
|
|
|
58558
59428
|
/** Get or create the worker logs directory (.agent-relay/team/worker-logs) */
|
|
58559
59429
|
getWorkerLogsDir() {
|
|
58560
59430
|
const logsDir = import_node_path28.default.join(this.cwd, ".agent-relay", "team", "worker-logs");
|
|
58561
|
-
(0,
|
|
59431
|
+
(0, import_node_fs20.mkdirSync)(logsDir, { recursive: true });
|
|
58562
59432
|
return logsDir;
|
|
58563
59433
|
}
|
|
58564
59434
|
/** Register a spawned agent in workers.json so `agents:kill` can find it. */
|
|
@@ -58574,7 +59444,7 @@ ${preview}
|
|
|
58574
59444
|
this.activeWorkers.set(agentName, workerEntry);
|
|
58575
59445
|
this.workersFileLock = this.workersFileLock.then(() => {
|
|
58576
59446
|
try {
|
|
58577
|
-
(0,
|
|
59447
|
+
(0, import_node_fs20.mkdirSync)(import_node_path28.default.dirname(this.workersPath), { recursive: true });
|
|
58578
59448
|
const existing = this.readWorkers().filter((w2) => w2.name !== agentName);
|
|
58579
59449
|
existing.push({ name: agentName, ...workerEntry });
|
|
58580
59450
|
this.writeWorkers(existing);
|
|
@@ -58596,21 +59466,21 @@ ${preview}
|
|
|
58596
59466
|
}
|
|
58597
59467
|
readWorkers() {
|
|
58598
59468
|
try {
|
|
58599
|
-
if (!(0,
|
|
59469
|
+
if (!(0, import_node_fs20.existsSync)(this.workersPath))
|
|
58600
59470
|
return [];
|
|
58601
|
-
const raw = JSON.parse((0,
|
|
59471
|
+
const raw = JSON.parse((0, import_node_fs20.readFileSync)(this.workersPath, "utf-8"));
|
|
58602
59472
|
return Array.isArray(raw?.workers) ? raw.workers : [];
|
|
58603
59473
|
} catch {
|
|
58604
59474
|
return [];
|
|
58605
59475
|
}
|
|
58606
59476
|
}
|
|
58607
59477
|
writeWorkers(workers) {
|
|
58608
|
-
(0,
|
|
59478
|
+
(0, import_node_fs20.writeFileSync)(this.workersPath, JSON.stringify({ workers }, null, 2));
|
|
58609
59479
|
}
|
|
58610
59480
|
};
|
|
58611
59481
|
|
|
58612
59482
|
// packages/sdk/dist/workflows/file-db.js
|
|
58613
|
-
var
|
|
59483
|
+
var import_node_fs21 = require("node:fs");
|
|
58614
59484
|
var import_node_path29 = __toESM(require("node:path"), 1);
|
|
58615
59485
|
var JsonFileWorkflowDb = class {
|
|
58616
59486
|
filePath;
|
|
@@ -58621,7 +59491,7 @@ var JsonFileWorkflowDb = class {
|
|
|
58621
59491
|
this.filePath = filePath;
|
|
58622
59492
|
let writable = false;
|
|
58623
59493
|
try {
|
|
58624
|
-
(0,
|
|
59494
|
+
(0, import_node_fs21.mkdirSync)(import_node_path29.default.dirname(filePath), { recursive: true });
|
|
58625
59495
|
writable = true;
|
|
58626
59496
|
} catch {
|
|
58627
59497
|
}
|
|
@@ -58634,7 +59504,7 @@ var JsonFileWorkflowDb = class {
|
|
|
58634
59504
|
hasStepOutputs(runId) {
|
|
58635
59505
|
try {
|
|
58636
59506
|
const dir = import_node_path29.default.join(import_node_path29.default.dirname(this.filePath), "step-outputs", runId);
|
|
58637
|
-
return (0,
|
|
59507
|
+
return (0, import_node_fs21.existsSync)(dir) && (0, import_node_fs21.readdirSync)(dir).length > 0;
|
|
58638
59508
|
} catch {
|
|
58639
59509
|
return false;
|
|
58640
59510
|
}
|
|
@@ -58644,7 +59514,7 @@ var JsonFileWorkflowDb = class {
|
|
|
58644
59514
|
if (!this.writable)
|
|
58645
59515
|
return;
|
|
58646
59516
|
try {
|
|
58647
|
-
(0,
|
|
59517
|
+
(0, import_node_fs21.appendFileSync)(this.filePath, JSON.stringify(entry) + "\n", "utf8");
|
|
58648
59518
|
} catch (err) {
|
|
58649
59519
|
if (!this.appendFailedOnce) {
|
|
58650
59520
|
this.appendFailedOnce = true;
|
|
@@ -58658,7 +59528,7 @@ var JsonFileWorkflowDb = class {
|
|
|
58658
59528
|
const steps = /* @__PURE__ */ new Map();
|
|
58659
59529
|
let raw = "";
|
|
58660
59530
|
try {
|
|
58661
|
-
raw = (0,
|
|
59531
|
+
raw = (0, import_node_fs21.readFileSync)(this.filePath, "utf8");
|
|
58662
59532
|
} catch {
|
|
58663
59533
|
return { runs, steps };
|
|
58664
59534
|
}
|
|
@@ -59260,7 +60130,7 @@ function workflow(name) {
|
|
|
59260
60130
|
}
|
|
59261
60131
|
|
|
59262
60132
|
// packages/sdk/dist/workflows/coordinator.js
|
|
59263
|
-
var
|
|
60133
|
+
var import_node_crypto8 = require("node:crypto");
|
|
59264
60134
|
var import_node_events3 = require("node:events");
|
|
59265
60135
|
var PATTERN_HEURISTICS = [
|
|
59266
60136
|
// ── Dependency-based patterns (highest priority) ──────────────────────
|
|
@@ -59615,7 +60485,7 @@ var SwarmCoordinator = class extends import_node_events3.EventEmitter {
|
|
|
59615
60485
|
}
|
|
59616
60486
|
// ── Lifecycle: create run ───────────────────────────────────────────────
|
|
59617
60487
|
async createRun(workspaceId, config2) {
|
|
59618
|
-
const id = `run_${Date.now()}_${(0,
|
|
60488
|
+
const id = `run_${Date.now()}_${(0, import_node_crypto8.randomBytes)(4).toString("hex")}`;
|
|
59619
60489
|
const pattern = this.selectPattern(config2);
|
|
59620
60490
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
59621
60491
|
const { rows } = await this.db.query(`INSERT INTO workflow_runs (id, workspace_id, workflow_name, pattern, status, config, started_at, created_at, updated_at)
|
|
@@ -59654,7 +60524,7 @@ var SwarmCoordinator = class extends import_node_events3.EventEmitter {
|
|
|
59654
60524
|
const created = [];
|
|
59655
60525
|
for (const wf of workflows) {
|
|
59656
60526
|
for (const step of wf.steps) {
|
|
59657
|
-
const id = `step_${Date.now()}_${(0,
|
|
60527
|
+
const id = `step_${Date.now()}_${(0, import_node_crypto8.randomBytes)(4).toString("hex")}`;
|
|
59658
60528
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
59659
60529
|
const { rows } = await this.db.query(`INSERT INTO workflow_steps (id, run_id, step_name, agent_name, status, task, depends_on, created_at, updated_at)
|
|
59660
60530
|
VALUES ($1, $2, $3, $4, 'pending', $5, $6, $7, $7)
|
|
@@ -59831,7 +60701,7 @@ var SwarmCoordinator = class extends import_node_events3.EventEmitter {
|
|
|
59831
60701
|
};
|
|
59832
60702
|
|
|
59833
60703
|
// packages/sdk/dist/workflows/barrier.js
|
|
59834
|
-
var
|
|
60704
|
+
var import_node_crypto9 = require("node:crypto");
|
|
59835
60705
|
var import_node_events4 = require("node:events");
|
|
59836
60706
|
var BarrierManager = class extends import_node_events4.EventEmitter {
|
|
59837
60707
|
db;
|
|
@@ -59847,7 +60717,7 @@ var BarrierManager = class extends import_node_events4.EventEmitter {
|
|
|
59847
60717
|
* Create a barrier for a workflow run.
|
|
59848
60718
|
*/
|
|
59849
60719
|
async createBarrier(runId, definition) {
|
|
59850
|
-
const id = `bar_${Date.now()}_${(0,
|
|
60720
|
+
const id = `bar_${Date.now()}_${(0, import_node_crypto9.randomBytes)(4).toString("hex")}`;
|
|
59851
60721
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
59852
60722
|
const mode = definition.mode ?? "all";
|
|
59853
60723
|
const { rows } = await this.db.query(`INSERT INTO workflow_barriers (id, run_id, barrier_name, wait_for, resolved, is_satisfied, timeout_ms, created_at, updated_at)
|
|
@@ -59981,7 +60851,7 @@ var BarrierManager = class extends import_node_events4.EventEmitter {
|
|
|
59981
60851
|
};
|
|
59982
60852
|
|
|
59983
60853
|
// packages/sdk/dist/workflows/state.js
|
|
59984
|
-
var
|
|
60854
|
+
var import_node_crypto10 = require("node:crypto");
|
|
59985
60855
|
var import_node_events5 = require("node:events");
|
|
59986
60856
|
var StateStore = class extends import_node_events5.EventEmitter {
|
|
59987
60857
|
db;
|
|
@@ -60024,7 +60894,7 @@ var StateStore = class extends import_node_events5.EventEmitter {
|
|
|
60024
60894
|
const namespace = options.namespace ?? this.defaultNamespace;
|
|
60025
60895
|
const ttlMs = options.ttlMs ?? this.defaultTtlMs;
|
|
60026
60896
|
const expiresAt = ttlMs ? new Date(Date.now() + ttlMs).toISOString() : null;
|
|
60027
|
-
const id = `st_${Date.now()}_${(0,
|
|
60897
|
+
const id = `st_${Date.now()}_${(0, import_node_crypto10.randomBytes)(4).toString("hex")}`;
|
|
60028
60898
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
60029
60899
|
const { rows } = await this.db.query(`INSERT INTO swarm_state (id, run_id, namespace, key, value, expires_at, created_at, updated_at)
|
|
60030
60900
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $7)
|
|
@@ -60112,7 +60982,7 @@ var StateStore = class extends import_node_events5.EventEmitter {
|
|
|
60112
60982
|
};
|
|
60113
60983
|
|
|
60114
60984
|
// packages/sdk/dist/workflows/templates.js
|
|
60115
|
-
var
|
|
60985
|
+
var import_node_fs22 = require("node:fs");
|
|
60116
60986
|
var import_node_path31 = __toESM(require("node:path"), 1);
|
|
60117
60987
|
var import_node_url2 = require("node:url");
|
|
60118
60988
|
var import_yaml4 = __toESM(require_dist(), 1);
|
|
@@ -60216,9 +61086,9 @@ var TemplateRegistry = class {
|
|
|
60216
61086
|
throw new Error(`Invalid template name: "${templateName}" contains path separators or traversal sequences`);
|
|
60217
61087
|
}
|
|
60218
61088
|
this.validateRelayConfig(parsed, url2);
|
|
60219
|
-
await
|
|
61089
|
+
await import_node_fs22.promises.mkdir(this.customTemplatesDir, { recursive: true });
|
|
60220
61090
|
const targetPath = import_node_path31.default.join(this.customTemplatesDir, `${templateName}.yaml`);
|
|
60221
|
-
await
|
|
61091
|
+
await import_node_fs22.promises.writeFile(targetPath, (0, import_yaml4.stringify)(parsed), "utf-8");
|
|
60222
61092
|
return targetPath;
|
|
60223
61093
|
}
|
|
60224
61094
|
isTemplateShorthand(input) {
|
|
@@ -60247,7 +61117,7 @@ var TemplateRegistry = class {
|
|
|
60247
61117
|
import_node_path31.default.resolve(currentDir, "../workflows/builtin-templates")
|
|
60248
61118
|
];
|
|
60249
61119
|
for (const candidate of candidates) {
|
|
60250
|
-
if ((0,
|
|
61120
|
+
if ((0, import_node_fs22.existsSync)(candidate)) {
|
|
60251
61121
|
return candidate;
|
|
60252
61122
|
}
|
|
60253
61123
|
}
|
|
@@ -60269,7 +61139,7 @@ var TemplateRegistry = class {
|
|
|
60269
61139
|
for (const ext of YAML_EXTENSIONS) {
|
|
60270
61140
|
const candidate = import_node_path31.default.join(directory, `${templateName}${ext}`);
|
|
60271
61141
|
try {
|
|
60272
|
-
const stat2 = await
|
|
61142
|
+
const stat2 = await import_node_fs22.promises.stat(candidate);
|
|
60273
61143
|
if (stat2.isFile()) {
|
|
60274
61144
|
return candidate;
|
|
60275
61145
|
}
|
|
@@ -60279,7 +61149,7 @@ var TemplateRegistry = class {
|
|
|
60279
61149
|
return void 0;
|
|
60280
61150
|
}
|
|
60281
61151
|
async readTemplateFile(templatePath) {
|
|
60282
|
-
const raw = await
|
|
61152
|
+
const raw = await import_node_fs22.promises.readFile(templatePath, "utf-8");
|
|
60283
61153
|
const parsed = (0, import_yaml4.parse)(raw);
|
|
60284
61154
|
if (!isRecord(parsed)) {
|
|
60285
61155
|
throw new Error(`Template at ${templatePath} is not a YAML object`);
|
|
@@ -60472,7 +61342,7 @@ var TemplateRegistry = class {
|
|
|
60472
61342
|
}
|
|
60473
61343
|
async safeReadDir(directory) {
|
|
60474
61344
|
try {
|
|
60475
|
-
return await
|
|
61345
|
+
return await import_node_fs22.promises.readdir(directory);
|
|
60476
61346
|
} catch {
|
|
60477
61347
|
return [];
|
|
60478
61348
|
}
|
|
@@ -60639,7 +61509,7 @@ function isValidAgentName(name) {
|
|
|
60639
61509
|
}
|
|
60640
61510
|
|
|
60641
61511
|
// packages/utils/dist/logger.js
|
|
60642
|
-
var
|
|
61512
|
+
var import_node_fs23 = __toESM(require("node:fs"), 1);
|
|
60643
61513
|
var import_node_path32 = __toESM(require("node:path"), 1);
|
|
60644
61514
|
function getLogFile() {
|
|
60645
61515
|
return process.env.AGENT_RELAY_LOG_FILE;
|
|
@@ -60659,8 +61529,8 @@ var LEVEL_PRIORITY = {
|
|
|
60659
61529
|
var createdLogDirs = /* @__PURE__ */ new Set();
|
|
60660
61530
|
function ensureLogDir(logFile) {
|
|
60661
61531
|
const logDir = import_node_path32.default.dirname(logFile);
|
|
60662
|
-
if (!createdLogDirs.has(logDir) && !
|
|
60663
|
-
|
|
61532
|
+
if (!createdLogDirs.has(logDir) && !import_node_fs23.default.existsSync(logDir)) {
|
|
61533
|
+
import_node_fs23.default.mkdirSync(logDir, { recursive: true });
|
|
60664
61534
|
createdLogDirs.add(logDir);
|
|
60665
61535
|
}
|
|
60666
61536
|
}
|
|
@@ -60689,7 +61559,7 @@ function log(level, component, msg, extra) {
|
|
|
60689
61559
|
const logFile = getLogFile();
|
|
60690
61560
|
if (logFile) {
|
|
60691
61561
|
ensureLogDir(logFile);
|
|
60692
|
-
|
|
61562
|
+
import_node_fs23.default.appendFileSync(logFile, formatted + "\n");
|
|
60693
61563
|
return;
|
|
60694
61564
|
}
|
|
60695
61565
|
if (level === "ERROR" || level === "WARN") {
|
|
@@ -60960,7 +61830,7 @@ function benchmarkPatterns(iterations = 1e4) {
|
|
|
60960
61830
|
|
|
60961
61831
|
// packages/utils/dist/command-resolver.js
|
|
60962
61832
|
var import_node_child_process8 = require("node:child_process");
|
|
60963
|
-
var
|
|
61833
|
+
var import_node_fs24 = __toESM(require("node:fs"), 1);
|
|
60964
61834
|
function resolveCommand(command) {
|
|
60965
61835
|
if (command.startsWith("/")) {
|
|
60966
61836
|
return resolveSymlinks(command);
|
|
@@ -60986,7 +61856,7 @@ function resolveCommand(command) {
|
|
|
60986
61856
|
}
|
|
60987
61857
|
function resolveSymlinks(filePath) {
|
|
60988
61858
|
try {
|
|
60989
|
-
const resolved =
|
|
61859
|
+
const resolved = import_node_fs24.default.realpathSync(filePath);
|
|
60990
61860
|
if (resolved !== filePath && process.env.DEBUG_SPAWN === "1") {
|
|
60991
61861
|
console.log(`[command-resolver] Resolved symlink: ${filePath} -> ${resolved}`);
|
|
60992
61862
|
}
|
|
@@ -61012,7 +61882,7 @@ function commandExists(command) {
|
|
|
61012
61882
|
|
|
61013
61883
|
// packages/utils/dist/git-remote.js
|
|
61014
61884
|
var fs8 = __toESM(require("node:fs"), 1);
|
|
61015
|
-
var
|
|
61885
|
+
var path20 = __toESM(require("node:path"), 1);
|
|
61016
61886
|
var import_node_child_process9 = require("node:child_process");
|
|
61017
61887
|
function parseGitRemoteUrl(url2) {
|
|
61018
61888
|
if (!url2)
|
|
@@ -61029,7 +61899,7 @@ function parseGitRemoteUrl(url2) {
|
|
|
61029
61899
|
}
|
|
61030
61900
|
function getGitRemoteUrl(workingDirectory, remoteName = "origin") {
|
|
61031
61901
|
try {
|
|
61032
|
-
const gitDir =
|
|
61902
|
+
const gitDir = path20.join(workingDirectory, ".git");
|
|
61033
61903
|
if (!fs8.existsSync(gitDir)) {
|
|
61034
61904
|
return null;
|
|
61035
61905
|
}
|
|
@@ -61042,7 +61912,7 @@ function getGitRemoteUrl(workingDirectory, remoteName = "origin") {
|
|
|
61042
61912
|
return result.trim() || null;
|
|
61043
61913
|
} catch {
|
|
61044
61914
|
try {
|
|
61045
|
-
const configPath =
|
|
61915
|
+
const configPath = path20.join(workingDirectory, ".git", "config");
|
|
61046
61916
|
if (!fs8.existsSync(configPath)) {
|
|
61047
61917
|
return null;
|
|
61048
61918
|
}
|
|
@@ -61063,13 +61933,13 @@ function getRepoFullName(workingDirectory) {
|
|
|
61063
61933
|
return parseGitRemoteUrl(remoteUrl);
|
|
61064
61934
|
}
|
|
61065
61935
|
function findGitRoot(startPath) {
|
|
61066
|
-
let currentPath =
|
|
61067
|
-
const root =
|
|
61936
|
+
let currentPath = path20.resolve(startPath);
|
|
61937
|
+
const root = path20.parse(currentPath).root;
|
|
61068
61938
|
while (currentPath !== root) {
|
|
61069
|
-
if (fs8.existsSync(
|
|
61939
|
+
if (fs8.existsSync(path20.join(currentPath, ".git"))) {
|
|
61070
61940
|
return currentPath;
|
|
61071
61941
|
}
|
|
61072
|
-
currentPath =
|
|
61942
|
+
currentPath = path20.dirname(currentPath);
|
|
61073
61943
|
}
|
|
61074
61944
|
return null;
|
|
61075
61945
|
}
|
|
@@ -61086,7 +61956,7 @@ function getRepoFullNameFromPath(workingDirectory) {
|
|
|
61086
61956
|
}
|
|
61087
61957
|
|
|
61088
61958
|
// packages/utils/dist/update-checker.js
|
|
61089
|
-
var
|
|
61959
|
+
var import_node_fs25 = __toESM(require("node:fs"), 1);
|
|
61090
61960
|
var import_node_path33 = __toESM(require("node:path"), 1);
|
|
61091
61961
|
var import_node_https2 = __toESM(require("node:https"), 1);
|
|
61092
61962
|
var import_node_os10 = __toESM(require("node:os"), 1);
|
|
@@ -61101,9 +61971,9 @@ function getCachePath() {
|
|
|
61101
61971
|
function readCache() {
|
|
61102
61972
|
try {
|
|
61103
61973
|
const cachePath = getCachePath();
|
|
61104
|
-
if (!
|
|
61974
|
+
if (!import_node_fs25.default.existsSync(cachePath))
|
|
61105
61975
|
return null;
|
|
61106
|
-
const data =
|
|
61976
|
+
const data = import_node_fs25.default.readFileSync(cachePath, "utf-8");
|
|
61107
61977
|
return JSON.parse(data);
|
|
61108
61978
|
} catch {
|
|
61109
61979
|
return null;
|
|
@@ -61113,10 +61983,10 @@ function writeCache(cache) {
|
|
|
61113
61983
|
try {
|
|
61114
61984
|
const cachePath = getCachePath();
|
|
61115
61985
|
const cacheDir = import_node_path33.default.dirname(cachePath);
|
|
61116
|
-
if (!
|
|
61117
|
-
|
|
61986
|
+
if (!import_node_fs25.default.existsSync(cacheDir)) {
|
|
61987
|
+
import_node_fs25.default.mkdirSync(cacheDir, { recursive: true });
|
|
61118
61988
|
}
|
|
61119
|
-
|
|
61989
|
+
import_node_fs25.default.writeFileSync(cachePath, JSON.stringify(cache, null, 2));
|
|
61120
61990
|
} catch {
|
|
61121
61991
|
}
|
|
61122
61992
|
}
|
|
@@ -61234,10 +62104,10 @@ function checkForUpdatesInBackground(currentVersion) {
|
|
|
61234
62104
|
}
|
|
61235
62105
|
|
|
61236
62106
|
// packages/utils/dist/error-tracking.js
|
|
61237
|
-
var
|
|
62107
|
+
var import_node_crypto11 = require("node:crypto");
|
|
61238
62108
|
function generateErrorId() {
|
|
61239
62109
|
const timestamp = Math.floor(Date.now() / 1e3);
|
|
61240
|
-
const random = (0,
|
|
62110
|
+
const random = (0, import_node_crypto11.randomBytes)(2).toString("hex");
|
|
61241
62111
|
return `ERR-${timestamp}-${random}`;
|
|
61242
62112
|
}
|
|
61243
62113
|
function createTraceableError(message, context = {}, originalError) {
|
|
@@ -61395,7 +62265,7 @@ function validateModelForCli(cli, model) {
|
|
|
61395
62265
|
}
|
|
61396
62266
|
|
|
61397
62267
|
// packages/utils/dist/relay-pty-path.js
|
|
61398
|
-
var
|
|
62268
|
+
var import_node_fs26 = __toESM(require("node:fs"), 1);
|
|
61399
62269
|
var import_node_os11 = __toESM(require("node:os"), 1);
|
|
61400
62270
|
var import_node_path34 = __toESM(require("node:path"), 1);
|
|
61401
62271
|
var SUPPORTED_PLATFORMS = {
|
|
@@ -61456,12 +62326,12 @@ function findRelayPtyBinary(callerDirname) {
|
|
|
61456
62326
|
const home = process.env.HOME || process.env.USERPROFILE || "";
|
|
61457
62327
|
if (home) {
|
|
61458
62328
|
const npxCacheBase = import_node_path34.default.join(home, ".npm", "_npx");
|
|
61459
|
-
if (
|
|
62329
|
+
if (import_node_fs26.default.existsSync(npxCacheBase)) {
|
|
61460
62330
|
try {
|
|
61461
|
-
const entries =
|
|
62331
|
+
const entries = import_node_fs26.default.readdirSync(npxCacheBase);
|
|
61462
62332
|
for (const entry of entries) {
|
|
61463
62333
|
const npxPackage = import_node_path34.default.join(npxCacheBase, entry, "node_modules", "agent-relay");
|
|
61464
|
-
if (
|
|
62334
|
+
if (import_node_fs26.default.existsSync(npxPackage)) {
|
|
61465
62335
|
packageRoots.push(npxPackage);
|
|
61466
62336
|
}
|
|
61467
62337
|
}
|
|
@@ -61519,7 +62389,7 @@ function findRelayPtyBinary(callerDirname) {
|
|
|
61519
62389
|
}
|
|
61520
62390
|
function isExecutable2(filePath) {
|
|
61521
62391
|
try {
|
|
61522
|
-
|
|
62392
|
+
import_node_fs26.default.accessSync(filePath, import_node_fs26.default.constants.X_OK);
|
|
61523
62393
|
return true;
|
|
61524
62394
|
} catch {
|
|
61525
62395
|
return false;
|
|
@@ -61528,9 +62398,9 @@ function isExecutable2(filePath) {
|
|
|
61528
62398
|
function isPlatformCompatibleBinary(filePath) {
|
|
61529
62399
|
let fd;
|
|
61530
62400
|
try {
|
|
61531
|
-
fd =
|
|
62401
|
+
fd = import_node_fs26.default.openSync(filePath, "r");
|
|
61532
62402
|
const header = Buffer.alloc(4);
|
|
61533
|
-
const bytesRead =
|
|
62403
|
+
const bytesRead = import_node_fs26.default.readSync(fd, header, 0, 4, 0);
|
|
61534
62404
|
if (bytesRead < 4) {
|
|
61535
62405
|
return false;
|
|
61536
62406
|
}
|
|
@@ -61548,7 +62418,7 @@ function isPlatformCompatibleBinary(filePath) {
|
|
|
61548
62418
|
} finally {
|
|
61549
62419
|
if (fd !== void 0) {
|
|
61550
62420
|
try {
|
|
61551
|
-
|
|
62421
|
+
import_node_fs26.default.closeSync(fd);
|
|
61552
62422
|
} catch {
|
|
61553
62423
|
}
|
|
61554
62424
|
}
|
|
@@ -61579,7 +62449,7 @@ function clearBinaryCache() {
|
|
|
61579
62449
|
|
|
61580
62450
|
// packages/utils/dist/client-helpers.js
|
|
61581
62451
|
var import_node_net = require("node:net");
|
|
61582
|
-
var
|
|
62452
|
+
var import_node_crypto12 = require("node:crypto");
|
|
61583
62453
|
|
|
61584
62454
|
// packages/utils/dist/legacy-protocol.js
|
|
61585
62455
|
var PROTOCOL_VERSION2 = 1;
|
|
@@ -61706,14 +62576,14 @@ function createRequestHandler(socketPath, envelope, options) {
|
|
|
61706
62576
|
});
|
|
61707
62577
|
}
|
|
61708
62578
|
function generateRequestId(prefix = "") {
|
|
61709
|
-
return `${prefix}${Date.now().toString(36)}-${(0,
|
|
62579
|
+
return `${prefix}${Date.now().toString(36)}-${(0, import_node_crypto12.randomUUID)().slice(0, 8)}`;
|
|
61710
62580
|
}
|
|
61711
62581
|
|
|
61712
62582
|
// packages/hooks/dist/types.js
|
|
61713
62583
|
var HOOK_ABI_VERSION = PROTOCOL_VERSION;
|
|
61714
62584
|
|
|
61715
62585
|
// packages/hooks/dist/registry.js
|
|
61716
|
-
var
|
|
62586
|
+
var import_node_crypto14 = require("node:crypto");
|
|
61717
62587
|
var InMemoryHookMemory = class {
|
|
61718
62588
|
store = /* @__PURE__ */ new Map();
|
|
61719
62589
|
get(key) {
|
|
@@ -61762,8 +62632,8 @@ var HookRegistry = class {
|
|
|
61762
62632
|
injectFn;
|
|
61763
62633
|
sendFn;
|
|
61764
62634
|
constructor(options = {}) {
|
|
61765
|
-
this.sessionId = (0,
|
|
61766
|
-
this.agentId = options.agentId ?? (0,
|
|
62635
|
+
this.sessionId = (0, import_node_crypto14.randomUUID)();
|
|
62636
|
+
this.agentId = options.agentId ?? (0, import_node_crypto14.randomUUID)();
|
|
61767
62637
|
this.agentName = options.agentName ?? "agent";
|
|
61768
62638
|
this.workingDir = options.workingDir ?? process.cwd();
|
|
61769
62639
|
this.projectId = options.projectId ?? "default";
|
|
@@ -62167,9 +63037,9 @@ var HookRegistry = class {
|
|
|
62167
63037
|
var import_node_child_process10 = require("node:child_process");
|
|
62168
63038
|
|
|
62169
63039
|
// packages/config/dist/project-namespace.js
|
|
62170
|
-
var
|
|
63040
|
+
var import_node_crypto15 = __toESM(require("node:crypto"), 1);
|
|
62171
63041
|
var import_node_path35 = __toESM(require("node:path"), 1);
|
|
62172
|
-
var
|
|
63042
|
+
var import_node_fs27 = __toESM(require("node:fs"), 1);
|
|
62173
63043
|
var import_node_os12 = __toESM(require("node:os"), 1);
|
|
62174
63044
|
function getGlobalBaseDir2() {
|
|
62175
63045
|
if (process.env.AGENT_RELAY_DATA_DIR) {
|
|
@@ -62185,7 +63055,7 @@ var GLOBAL_BASE_DIR2 = getGlobalBaseDir2();
|
|
|
62185
63055
|
var PROJECT_DATA_DIR = ".agent-relay";
|
|
62186
63056
|
function hashPath(projectPath) {
|
|
62187
63057
|
const normalized = import_node_path35.default.resolve(projectPath);
|
|
62188
|
-
const hash2 =
|
|
63058
|
+
const hash2 = import_node_crypto15.default.createHash("sha256").update(normalized).digest("hex");
|
|
62189
63059
|
return hash2.substring(0, 12);
|
|
62190
63060
|
}
|
|
62191
63061
|
function findProjectRoot(startDir = process.cwd()) {
|
|
@@ -62197,7 +63067,7 @@ function findProjectRoot(startDir = process.cwd()) {
|
|
|
62197
63067
|
const markers = [".git", "package.json", "Cargo.toml", "go.mod", "pyproject.toml", ".agent-relay"];
|
|
62198
63068
|
while (current !== root) {
|
|
62199
63069
|
for (const marker of markers) {
|
|
62200
|
-
if (
|
|
63070
|
+
if (import_node_fs27.default.existsSync(import_node_path35.default.join(current, marker))) {
|
|
62201
63071
|
return current;
|
|
62202
63072
|
}
|
|
62203
63073
|
}
|
|
@@ -62220,10 +63090,10 @@ function getProjectPaths2(projectRoot) {
|
|
|
62220
63090
|
}
|
|
62221
63091
|
|
|
62222
63092
|
// packages/config/dist/trajectory-config.js
|
|
62223
|
-
var
|
|
63093
|
+
var import_node_fs28 = require("node:fs");
|
|
62224
63094
|
var import_node_path36 = require("node:path");
|
|
62225
63095
|
var import_node_os13 = require("node:os");
|
|
62226
|
-
var
|
|
63096
|
+
var import_node_crypto16 = require("node:crypto");
|
|
62227
63097
|
function getAgentRelayConfigDir() {
|
|
62228
63098
|
return process.env.AGENT_RELAY_CONFIG_DIR ?? (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".config", "agent-relay");
|
|
62229
63099
|
}
|
|
@@ -62235,7 +63105,7 @@ function readRelayConfig(projectRoot) {
|
|
|
62235
63105
|
const configPath = getRelayConfigPath(projectRoot);
|
|
62236
63106
|
if (configCache && configCache.path === configPath) {
|
|
62237
63107
|
try {
|
|
62238
|
-
const stat2 = (0,
|
|
63108
|
+
const stat2 = (0, import_node_fs28.statSync)(configPath);
|
|
62239
63109
|
if (stat2.mtimeMs === configCache.mtime) {
|
|
62240
63110
|
return configCache.config;
|
|
62241
63111
|
}
|
|
@@ -62243,13 +63113,13 @@ function readRelayConfig(projectRoot) {
|
|
|
62243
63113
|
}
|
|
62244
63114
|
}
|
|
62245
63115
|
try {
|
|
62246
|
-
if (!(0,
|
|
63116
|
+
if (!(0, import_node_fs28.existsSync)(configPath)) {
|
|
62247
63117
|
return {};
|
|
62248
63118
|
}
|
|
62249
|
-
const content = (0,
|
|
63119
|
+
const content = (0, import_node_fs28.readFileSync)(configPath, "utf-8");
|
|
62250
63120
|
const config2 = JSON.parse(content);
|
|
62251
63121
|
try {
|
|
62252
|
-
const stat2 = (0,
|
|
63122
|
+
const stat2 = (0, import_node_fs28.statSync)(configPath);
|
|
62253
63123
|
configCache = { path: configPath, config: config2, mtime: stat2.mtimeMs };
|
|
62254
63124
|
} catch {
|
|
62255
63125
|
}
|
|
@@ -62265,7 +63135,7 @@ function shouldStoreInRepo(projectRoot) {
|
|
|
62265
63135
|
}
|
|
62266
63136
|
function getProjectHash(projectRoot) {
|
|
62267
63137
|
const root = projectRoot ?? getProjectPaths2().projectRoot;
|
|
62268
|
-
return (0,
|
|
63138
|
+
return (0, import_node_crypto16.createHash)("sha256").update(root).digest("hex").slice(0, 16);
|
|
62269
63139
|
}
|
|
62270
63140
|
function getUserTrajectoriesDir(projectRoot) {
|
|
62271
63141
|
const projectHash = getProjectHash(projectRoot);
|
|
@@ -62383,7 +63253,7 @@ async function recordMessage(direction, from, to2, body) {
|
|
|
62383
63253
|
const content = `Message ${direction}: ${direction === "sent" ? `\u2192 ${to2}` : `\u2190 ${from}`}: ${body.slice(0, 100)}${body.length > 100 ? "..." : ""}`;
|
|
62384
63254
|
return recordEvent(content, "observation");
|
|
62385
63255
|
}
|
|
62386
|
-
async function
|
|
63256
|
+
async function completeTrajectory2(options = {}) {
|
|
62387
63257
|
const args = ["complete"];
|
|
62388
63258
|
if (options.summary) {
|
|
62389
63259
|
args.push("--summary", options.summary);
|
|
@@ -62400,7 +63270,7 @@ async function completeTrajectory(options = {}) {
|
|
|
62400
63270
|
const result = await runTrail(args);
|
|
62401
63271
|
return { success: result.success, error: result.error };
|
|
62402
63272
|
}
|
|
62403
|
-
async function
|
|
63273
|
+
async function abandonTrajectory2(reason) {
|
|
62404
63274
|
const args = ["abandon"];
|
|
62405
63275
|
if (reason) {
|
|
62406
63276
|
args.push("--reason", reason);
|
|
@@ -62686,7 +63556,7 @@ var TrajectoryIntegration = class {
|
|
|
62686
63556
|
async complete(options) {
|
|
62687
63557
|
if (!await this.isAvailable())
|
|
62688
63558
|
return false;
|
|
62689
|
-
const result = await
|
|
63559
|
+
const result = await completeTrajectory2(options);
|
|
62690
63560
|
if (result.success) {
|
|
62691
63561
|
this.currentPhase = null;
|
|
62692
63562
|
}
|
|
@@ -62698,7 +63568,7 @@ var TrajectoryIntegration = class {
|
|
|
62698
63568
|
async abandon(reason) {
|
|
62699
63569
|
if (!await this.isAvailable())
|
|
62700
63570
|
return false;
|
|
62701
|
-
const result = await
|
|
63571
|
+
const result = await abandonTrajectory2(reason);
|
|
62702
63572
|
if (result.success) {
|
|
62703
63573
|
this.currentPhase = null;
|
|
62704
63574
|
}
|
|
@@ -62754,16 +63624,16 @@ function createTrajectoryHooks(options) {
|
|
|
62754
63624
|
}
|
|
62755
63625
|
function createSessionStartHook2(state) {
|
|
62756
63626
|
return async (ctx) => {
|
|
62757
|
-
const { trajectory, options } = state;
|
|
63627
|
+
const { trajectory: trajectory2, options } = state;
|
|
62758
63628
|
if (ctx.task) {
|
|
62759
|
-
const success2 = await
|
|
63629
|
+
const success2 = await trajectory2.initialize(ctx.task, ctx.taskId, ctx.taskSource);
|
|
62760
63630
|
if (success2) {
|
|
62761
63631
|
console.log(`[trajectory] Started tracking: ${ctx.task}`);
|
|
62762
63632
|
}
|
|
62763
63633
|
} else {
|
|
62764
|
-
await
|
|
63634
|
+
await trajectory2.initialize();
|
|
62765
63635
|
}
|
|
62766
|
-
if (options.injectInstructions &&
|
|
63636
|
+
if (options.injectInstructions && trajectory2.isTrailInstalledSync()) {
|
|
62767
63637
|
const instructions = getCompactTrailInstructions();
|
|
62768
63638
|
return { inject: `
|
|
62769
63639
|
${instructions}
|
|
@@ -62773,8 +63643,8 @@ ${instructions}
|
|
|
62773
63643
|
}
|
|
62774
63644
|
function createSessionEndHook2(state) {
|
|
62775
63645
|
return async (ctx) => {
|
|
62776
|
-
const { trajectory, options } = state;
|
|
62777
|
-
if (!
|
|
63646
|
+
const { trajectory: trajectory2, options } = state;
|
|
63647
|
+
if (!trajectory2.hasActiveTrajectory()) {
|
|
62778
63648
|
return;
|
|
62779
63649
|
}
|
|
62780
63650
|
if (ctx.graceful) {
|
|
@@ -62790,28 +63660,28 @@ Or if you need to document learnings:
|
|
|
62790
63660
|
trail decision "Key choice" --reasoning "Why"
|
|
62791
63661
|
`
|
|
62792
63662
|
};
|
|
62793
|
-
await
|
|
63663
|
+
await trajectory2.complete({
|
|
62794
63664
|
summary: `Session ended after ${durationSeconds}s`
|
|
62795
63665
|
});
|
|
62796
63666
|
return result;
|
|
62797
63667
|
} else {
|
|
62798
|
-
await
|
|
63668
|
+
await trajectory2.complete({
|
|
62799
63669
|
summary: `Session ended gracefully`
|
|
62800
63670
|
});
|
|
62801
63671
|
}
|
|
62802
63672
|
} else {
|
|
62803
|
-
await
|
|
63673
|
+
await trajectory2.abandon("Session terminated");
|
|
62804
63674
|
}
|
|
62805
63675
|
};
|
|
62806
63676
|
}
|
|
62807
63677
|
function createOutputHook2(state) {
|
|
62808
63678
|
return async (ctx) => {
|
|
62809
|
-
const { trajectory, options } = state;
|
|
63679
|
+
const { trajectory: trajectory2, options } = state;
|
|
62810
63680
|
if (options.autoDetectPhase) {
|
|
62811
63681
|
const detectedPhase = detectPhaseFromContent(ctx.content);
|
|
62812
63682
|
if (detectedPhase && detectedPhase !== state.lastDetectedPhase) {
|
|
62813
63683
|
state.lastDetectedPhase = detectedPhase;
|
|
62814
|
-
await
|
|
63684
|
+
await trajectory2.transition(detectedPhase, "Auto-detected from output");
|
|
62815
63685
|
}
|
|
62816
63686
|
}
|
|
62817
63687
|
if (options.detectTools) {
|
|
@@ -62821,7 +63691,7 @@ function createOutputHook2(state) {
|
|
|
62821
63691
|
if (!state.seenTools.has(key)) {
|
|
62822
63692
|
state.seenTools.add(key);
|
|
62823
63693
|
const statusLabel = tool.status === "completed" ? " (completed)" : "";
|
|
62824
|
-
await
|
|
63694
|
+
await trajectory2.event(`Tool: ${tool.tool}${statusLabel}`, "tool_call");
|
|
62825
63695
|
}
|
|
62826
63696
|
}
|
|
62827
63697
|
}
|
|
@@ -62831,7 +63701,7 @@ function createOutputHook2(state) {
|
|
|
62831
63701
|
if (!state.seenErrors.has(error48.message)) {
|
|
62832
63702
|
state.seenErrors.add(error48.message);
|
|
62833
63703
|
const prefix = error48.type === "warning" ? "Warning" : "Error";
|
|
62834
|
-
await
|
|
63704
|
+
await trajectory2.event(`${prefix}: ${error48.message}`, "error");
|
|
62835
63705
|
}
|
|
62836
63706
|
}
|
|
62837
63707
|
}
|
|
@@ -62839,22 +63709,22 @@ function createOutputHook2(state) {
|
|
|
62839
63709
|
}
|
|
62840
63710
|
function createMessageReceivedHook(state) {
|
|
62841
63711
|
return async (ctx) => {
|
|
62842
|
-
const { trajectory, options } = state;
|
|
62843
|
-
await
|
|
63712
|
+
const { trajectory: trajectory2, options } = state;
|
|
63713
|
+
await trajectory2.message("received", ctx.from, options.agentName, ctx.body);
|
|
62844
63714
|
};
|
|
62845
63715
|
}
|
|
62846
63716
|
function createMessageSentHook(state) {
|
|
62847
63717
|
return async (ctx) => {
|
|
62848
|
-
const { trajectory, options } = state;
|
|
62849
|
-
await
|
|
63718
|
+
const { trajectory: trajectory2, options } = state;
|
|
63719
|
+
await trajectory2.message("sent", options.agentName, ctx.to, ctx.body);
|
|
62850
63720
|
};
|
|
62851
63721
|
}
|
|
62852
63722
|
function getTrajectoryHooks(projectId, agentName) {
|
|
62853
63723
|
return createTrajectoryHooks({ projectId, agentName });
|
|
62854
63724
|
}
|
|
62855
63725
|
function isTrajectoryTrackingAvailable(projectId, agentName) {
|
|
62856
|
-
const
|
|
62857
|
-
return
|
|
63726
|
+
const trajectory2 = getTrajectoryIntegration(projectId, agentName);
|
|
63727
|
+
return trajectory2.isTrailInstalledSync();
|
|
62858
63728
|
}
|
|
62859
63729
|
|
|
62860
63730
|
// packages/hooks/dist/emitter.js
|
|
@@ -62914,7 +63784,7 @@ var HookEmitter = class {
|
|
|
62914
63784
|
};
|
|
62915
63785
|
|
|
62916
63786
|
// packages/hooks/dist/inbox-check/utils.js
|
|
62917
|
-
var
|
|
63787
|
+
var import_node_fs29 = require("node:fs");
|
|
62918
63788
|
var import_node_path37 = require("node:path");
|
|
62919
63789
|
var DEFAULT_INBOX_DIR = "/tmp/agent-relay";
|
|
62920
63790
|
function getAgentName() {
|
|
@@ -62928,13 +63798,13 @@ function getInboxPath(config2) {
|
|
|
62928
63798
|
return (0, import_node_path37.join)(config2.inboxDir, agentName, "inbox.md");
|
|
62929
63799
|
}
|
|
62930
63800
|
function inboxExists(inboxPath) {
|
|
62931
|
-
return (0,
|
|
63801
|
+
return (0, import_node_fs29.existsSync)(inboxPath);
|
|
62932
63802
|
}
|
|
62933
63803
|
function readInbox(inboxPath) {
|
|
62934
63804
|
if (!inboxExists(inboxPath)) {
|
|
62935
63805
|
return "";
|
|
62936
63806
|
}
|
|
62937
|
-
return (0,
|
|
63807
|
+
return (0, import_node_fs29.readFileSync)(inboxPath, "utf-8");
|
|
62938
63808
|
}
|
|
62939
63809
|
function hasUnreadMessages(inboxPath) {
|
|
62940
63810
|
const content = readInbox(inboxPath);
|