@a5c-ai/babysitter-sdk 0.0.170-staging.b9ce0768 → 0.0.170-staging.bb2a8a61
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/cli/commands/hookLog.d.ts.map +1 -1
- package/dist/cli/commands/hookLog.js +5 -3
- package/dist/cli/commands/profile.js +3 -36
- package/dist/cli/commands/session.d.ts.map +1 -1
- package/dist/cli/commands/session.js +2 -1
- package/dist/cli/main.d.ts +3 -2
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +7 -14
- package/dist/cli/resolveInputPath.d.ts +61 -0
- package/dist/cli/resolveInputPath.d.ts.map +1 -0
- package/dist/cli/resolveInputPath.js +188 -0
- package/dist/harness/claudeCode.d.ts.map +1 -1
- package/dist/harness/claudeCode.js +23 -3
- package/dist/session/write.d.ts +2 -2
- package/dist/session/write.js +5 -5
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hookLog.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/hookLog.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"hookLog.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/hookLog.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf;AAoLD,wBAAsB,aAAa,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAwG7E"}
|
|
@@ -44,6 +44,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
44
44
|
exports.handleHookLog = handleHookLog;
|
|
45
45
|
const node_fs_1 = require("node:fs");
|
|
46
46
|
const path = __importStar(require("node:path"));
|
|
47
|
+
const resolveInputPath_1 = require("../resolveInputPath");
|
|
47
48
|
// ---------------------------------------------------------------------------
|
|
48
49
|
// Event label mapping (matches the label used in the original logger.sh)
|
|
49
50
|
// ---------------------------------------------------------------------------
|
|
@@ -255,9 +256,10 @@ async function handleHookLog(args) {
|
|
|
255
256
|
const logLine = formatLogLine(hookType, eventLabel, fields);
|
|
256
257
|
// Ensure log directory exists and append
|
|
257
258
|
try {
|
|
258
|
-
const
|
|
259
|
+
const resolvedLogFile = (0, resolveInputPath_1.resolveInputPath)(logFile);
|
|
260
|
+
const logDir = path.dirname(resolvedLogFile);
|
|
259
261
|
await node_fs_1.promises.mkdir(logDir, { recursive: true });
|
|
260
|
-
await node_fs_1.promises.appendFile(
|
|
262
|
+
await node_fs_1.promises.appendFile(resolvedLogFile, logLine + "\n", "utf8");
|
|
261
263
|
}
|
|
262
264
|
catch (e) {
|
|
263
265
|
const msg = e instanceof Error ? e.message : String(e);
|
|
@@ -275,7 +277,7 @@ async function handleHookLog(args) {
|
|
|
275
277
|
console.log(JSON.stringify({
|
|
276
278
|
hookType,
|
|
277
279
|
eventLabel,
|
|
278
|
-
logFile:
|
|
280
|
+
logFile: (0, resolveInputPath_1.resolveInputPath)(logFile),
|
|
279
281
|
logLine,
|
|
280
282
|
}));
|
|
281
283
|
}
|
|
@@ -8,39 +8,6 @@
|
|
|
8
8
|
* profile:merge --user|--project --input <file> [--dir <dir>] [--json]
|
|
9
9
|
* profile:render --user|--project [--dir <dir>] [--json]
|
|
10
10
|
*/
|
|
11
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
-
}
|
|
17
|
-
Object.defineProperty(o, k2, desc);
|
|
18
|
-
}) : (function(o, m, k, k2) {
|
|
19
|
-
if (k2 === undefined) k2 = k;
|
|
20
|
-
o[k2] = m[k];
|
|
21
|
-
}));
|
|
22
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
-
}) : function(o, v) {
|
|
25
|
-
o["default"] = v;
|
|
26
|
-
});
|
|
27
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
-
var ownKeys = function(o) {
|
|
29
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
-
var ar = [];
|
|
31
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
-
return ar;
|
|
33
|
-
};
|
|
34
|
-
return ownKeys(o);
|
|
35
|
-
};
|
|
36
|
-
return function (mod) {
|
|
37
|
-
if (mod && mod.__esModule) return mod;
|
|
38
|
-
var result = {};
|
|
39
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
-
__setModuleDefault(result, mod);
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
})();
|
|
44
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
12
|
exports.handleProfileRead = handleProfileRead;
|
|
46
13
|
exports.handleProfileWrite = handleProfileWrite;
|
|
@@ -48,7 +15,7 @@ exports.handleProfileMerge = handleProfileMerge;
|
|
|
48
15
|
exports.handleProfileRender = handleProfileRender;
|
|
49
16
|
exports.handleProfileCommand = handleProfileCommand;
|
|
50
17
|
const node_fs_1 = require("node:fs");
|
|
51
|
-
const
|
|
18
|
+
const resolveInputPath_1 = require("../resolveInputPath");
|
|
52
19
|
const userProfile_1 = require("../../profiles/userProfile");
|
|
53
20
|
const projectProfile_1 = require("../../profiles/projectProfile");
|
|
54
21
|
// ============================================================================
|
|
@@ -110,7 +77,7 @@ async function handleProfileWrite(args) {
|
|
|
110
77
|
}
|
|
111
78
|
let profileData;
|
|
112
79
|
try {
|
|
113
|
-
const raw = await node_fs_1.promises.readFile(
|
|
80
|
+
const raw = await node_fs_1.promises.readFile((0, resolveInputPath_1.resolveInputPath)(inputPath), "utf8");
|
|
114
81
|
profileData = JSON.parse(raw);
|
|
115
82
|
}
|
|
116
83
|
catch (error) {
|
|
@@ -151,7 +118,7 @@ async function handleProfileMerge(args) {
|
|
|
151
118
|
}
|
|
152
119
|
let updates;
|
|
153
120
|
try {
|
|
154
|
-
const raw = await node_fs_1.promises.readFile(
|
|
121
|
+
const raw = await node_fs_1.promises.readFile((0, resolveInputPath_1.resolveInputPath)(inputPath), "utf8");
|
|
155
122
|
updates = JSON.parse(raw);
|
|
156
123
|
}
|
|
157
124
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/session.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAwBH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CA0GjF;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoGtF;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CA0InF;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmElF;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAwGnF;AAED;;;GAGG;AACH,wBAAsB,2BAA2B,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyG3F;AAID,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,MAAM,GAAG;IACpE,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAoDA;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI7D;AAED,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,sBAAsB,GAC3B,MAAM,CA+CR;AAID,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,6BAA6B;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAcD;;;;GAIG;AACH,wBAAsB,6BAA6B,CACjD,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,MAAM,CAAC,CA+GjB"}
|
|
@@ -49,6 +49,7 @@ exports.handleSessionLastMessage = handleSessionLastMessage;
|
|
|
49
49
|
exports.handleSessionIterationMessage = handleSessionIterationMessage;
|
|
50
50
|
const node_fs_1 = require("node:fs");
|
|
51
51
|
const path = __importStar(require("node:path"));
|
|
52
|
+
const resolveInputPath_1 = require("../resolveInputPath");
|
|
52
53
|
const journal_1 = require("../../storage/journal");
|
|
53
54
|
const runFiles_1 = require("../../storage/runFiles");
|
|
54
55
|
const effectIndex_1 = require("../../runtime/replay/effectIndex");
|
|
@@ -765,7 +766,7 @@ function handleSessionLastMessage(args) {
|
|
|
765
766
|
hasPromise: false,
|
|
766
767
|
promiseValue: null,
|
|
767
768
|
};
|
|
768
|
-
const transcriptPath =
|
|
769
|
+
const transcriptPath = (0, resolveInputPath_1.resolveInputPath)(args.transcriptPath);
|
|
769
770
|
if (!(0, node_fs_1.existsSync)(transcriptPath)) {
|
|
770
771
|
result.error = 'TRANSCRIPT_NOT_FOUND';
|
|
771
772
|
if (args.json) {
|
package/dist/cli/main.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { collapseDoubledA5cRuns as _sharedCollapseDoubledA5cRuns } from "./resolveInputPath";
|
|
2
3
|
/**
|
|
3
4
|
* Resolve a run directory from a base directory and a user-provided argument.
|
|
4
5
|
*
|
|
@@ -10,8 +11,8 @@
|
|
|
10
11
|
* - If the resolved path doesn't exist, falls back to resolving from CWD.
|
|
11
12
|
*/
|
|
12
13
|
declare function resolveRunDir(baseDir: string, runDirArg?: string): string;
|
|
13
|
-
/** Collapse doubled ".a5c/runs" segments
|
|
14
|
-
declare
|
|
14
|
+
/** Collapse doubled ".a5c/runs" segments — delegates to shared utility. */
|
|
15
|
+
declare const collapseDoubledA5cRuns: typeof _sharedCollapseDoubledA5cRuns;
|
|
15
16
|
export { resolveRunDir as _resolveRunDir, collapseDoubledA5cRuns as _collapseDoubledA5cRuns };
|
|
16
17
|
export declare function createBabysitterCli(): {
|
|
17
18
|
run(argv?: string[]): Promise<number>;
|
package/dist/cli/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,sBAAsB,IAAI,6BAA6B,EAAoB,MAAM,oBAAoB,CAAC;AAsd/G;;;;;;;;;GASG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CA8BlE;AAOD,2EAA2E;AAC3E,QAAA,MAAM,sBAAsB,sCAAgC,CAAC;AA+9C7D,OAAO,EAAE,aAAa,IAAI,cAAc,EAAE,sBAAsB,IAAI,uBAAuB,EAAE,CAAC;AAE9F,wBAAgB,mBAAmB;eAEf,MAAM,EAAE,GAA2B,OAAO,CAAC,MAAM,CAAC;kBAmNpD,MAAM;EAIvB"}
|
package/dist/cli/main.js
CHANGED
|
@@ -34,13 +34,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports._collapseDoubledA5cRuns = void 0;
|
|
37
38
|
exports._resolveRunDir = resolveRunDir;
|
|
38
|
-
exports._collapseDoubledA5cRuns = collapseDoubledA5cRuns;
|
|
39
39
|
exports.createBabysitterCli = createBabysitterCli;
|
|
40
40
|
const node_fs_1 = require("node:fs");
|
|
41
41
|
const path = __importStar(require("node:path"));
|
|
42
42
|
const node_url_1 = require("node:url");
|
|
43
43
|
const crypto = __importStar(require("node:crypto"));
|
|
44
|
+
const resolveInputPath_1 = require("./resolveInputPath");
|
|
44
45
|
const commitEffectResult_1 = require("../runtime/commitEffectResult");
|
|
45
46
|
const createRun_1 = require("../runtime/createRun");
|
|
46
47
|
const effectIndex_1 = require("../runtime/replay/effectIndex");
|
|
@@ -446,17 +447,9 @@ function resolveRunDir(baseDir, runDirArg) {
|
|
|
446
447
|
function normalizePosix(p) {
|
|
447
448
|
return path.normalize(p).replace(/\\/g, "/").replace(/\/+$/, "");
|
|
448
449
|
}
|
|
449
|
-
/** Collapse doubled ".a5c/runs" segments
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const pattern = /([/\\]?\.a5c[/\\]runs)[/\\]\.a5c[/\\]runs([/\\]|$)/;
|
|
453
|
-
let result = p;
|
|
454
|
-
// Collapse repeatedly in case of triple+ duplication
|
|
455
|
-
while (pattern.test(result)) {
|
|
456
|
-
result = result.replace(pattern, "$1$2");
|
|
457
|
-
}
|
|
458
|
-
return result;
|
|
459
|
-
}
|
|
450
|
+
/** Collapse doubled ".a5c/runs" segments — delegates to shared utility. */
|
|
451
|
+
const collapseDoubledA5cRuns = resolveInputPath_1.collapseDoubledA5cRuns;
|
|
452
|
+
exports._collapseDoubledA5cRuns = collapseDoubledA5cRuns;
|
|
460
453
|
function expectFlagValue(args, index, flag) {
|
|
461
454
|
const value = args[index];
|
|
462
455
|
if (!value) {
|
|
@@ -646,7 +639,7 @@ function listModuleExports(mod) {
|
|
|
646
639
|
return keys.length > 0 ? keys.join(", ") : "(none)";
|
|
647
640
|
}
|
|
648
641
|
async function validateProcessEntrypoint(importPath, exportName) {
|
|
649
|
-
const resolvedPath = path.isAbsolute(importPath) ? importPath :
|
|
642
|
+
const resolvedPath = path.isAbsolute(importPath) ? importPath : (0, resolveInputPath_1.resolveInputPath)(importPath);
|
|
650
643
|
try {
|
|
651
644
|
await node_fs_1.promises.access(resolvedPath);
|
|
652
645
|
}
|
|
@@ -679,7 +672,7 @@ async function validateProcessEntrypoint(importPath, exportName) {
|
|
|
679
672
|
}
|
|
680
673
|
}
|
|
681
674
|
async function readInputsFile(filePath) {
|
|
682
|
-
const absolute =
|
|
675
|
+
const absolute = (0, resolveInputPath_1.resolveInputPath)(filePath);
|
|
683
676
|
let contents;
|
|
684
677
|
try {
|
|
685
678
|
contents = await node_fs_1.promises.readFile(absolute, "utf8");
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collapse doubled ".a5c/runs" segments in a path.
|
|
3
|
+
*
|
|
4
|
+
* When a relative path containing `.a5c/runs/...` is resolved from a working
|
|
5
|
+
* directory that is itself inside `.a5c/runs/`, the result can contain the
|
|
6
|
+
* segment twice (or more). This function collapses all consecutive duplications
|
|
7
|
+
* into a single occurrence.
|
|
8
|
+
*
|
|
9
|
+
* Handles both forward-slash (Unix) and back-slash (Windows) separators as
|
|
10
|
+
* well as mixed-separator paths.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* collapseDoubledA5cRuns("/project/.a5c/runs/.a5c/runs/01RUN")
|
|
14
|
+
* // => "/project/.a5c/runs/01RUN"
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* collapseDoubledA5cRuns("C:\\project\\.a5c\\runs\\.a5c\\runs\\01RUN")
|
|
18
|
+
* // => "C:\\project\\.a5c\\runs\\01RUN"
|
|
19
|
+
*/
|
|
20
|
+
export declare function collapseDoubledA5cRuns(p: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve an input file path robustly, accounting for the CLI being invoked
|
|
23
|
+
* from inside a task directory (or any subdirectory of `.a5c/runs/`).
|
|
24
|
+
*
|
|
25
|
+
* The standard `path.resolve(inputPath)` resolves relative to
|
|
26
|
+
* `process.cwd()`. When the working directory is a task directory such as
|
|
27
|
+
* `/project/.a5c/runs/RUN/tasks/TASK/`, resolving a relative path like
|
|
28
|
+
* `.a5c/runs/RUN/tasks/EFFECT/file.json` produces a doubled path:
|
|
29
|
+
* `/project/.a5c/runs/RUN/tasks/TASK/.a5c/runs/RUN/tasks/EFFECT/file.json`
|
|
30
|
+
*
|
|
31
|
+
* This function detects that situation and resolves relative to the project
|
|
32
|
+
* root instead.
|
|
33
|
+
*
|
|
34
|
+
* **Resolution rules (in order):**
|
|
35
|
+
* 1. `"-"` (stdin sentinel) — returned as-is.
|
|
36
|
+
* 2. Absolute paths (including Windows drive letters like `C:\`) — normalized
|
|
37
|
+
* and returned.
|
|
38
|
+
* 3. If `inputPath` contains a `.a5c/runs` segment **and** the current
|
|
39
|
+
* working directory is itself inside a `.a5c/runs` subtree — resolve
|
|
40
|
+
* relative to the detected project root.
|
|
41
|
+
* 4. Otherwise — standard `path.resolve(inputPath)`.
|
|
42
|
+
* 5. `collapseDoubledA5cRuns` is always applied as a final safety net.
|
|
43
|
+
*
|
|
44
|
+
* @param inputPath The raw path argument supplied by the user or script.
|
|
45
|
+
* @returns A fully resolved, absolute path (or `"-"` for stdin).
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // CWD = /project/.a5c/runs/RUN/tasks/TASK
|
|
49
|
+
* resolveInputPath(".a5c/runs/RUN/tasks/EFFECT/input.json")
|
|
50
|
+
* // => "/project/.a5c/runs/RUN/tasks/EFFECT/input.json"
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* resolveInputPath("/absolute/path/to/file.json")
|
|
54
|
+
* // => "/absolute/path/to/file.json"
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* resolveInputPath("-")
|
|
58
|
+
* // => "-"
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveInputPath(inputPath: string): string;
|
|
61
|
+
//# sourceMappingURL=resolveInputPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveInputPath.d.ts","sourceRoot":"","sources":["../../src/cli/resolveInputPath.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CASxD;AA4DD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAgC1D"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.collapseDoubledA5cRuns = collapseDoubledA5cRuns;
|
|
37
|
+
exports.resolveInputPath = resolveInputPath;
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const node_fs_1 = require("node:fs");
|
|
40
|
+
/**
|
|
41
|
+
* Collapse doubled ".a5c/runs" segments in a path.
|
|
42
|
+
*
|
|
43
|
+
* When a relative path containing `.a5c/runs/...` is resolved from a working
|
|
44
|
+
* directory that is itself inside `.a5c/runs/`, the result can contain the
|
|
45
|
+
* segment twice (or more). This function collapses all consecutive duplications
|
|
46
|
+
* into a single occurrence.
|
|
47
|
+
*
|
|
48
|
+
* Handles both forward-slash (Unix) and back-slash (Windows) separators as
|
|
49
|
+
* well as mixed-separator paths.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* collapseDoubledA5cRuns("/project/.a5c/runs/.a5c/runs/01RUN")
|
|
53
|
+
* // => "/project/.a5c/runs/01RUN"
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* collapseDoubledA5cRuns("C:\\project\\.a5c\\runs\\.a5c\\runs\\01RUN")
|
|
57
|
+
* // => "C:\\project\\.a5c\\runs\\01RUN"
|
|
58
|
+
*/
|
|
59
|
+
function collapseDoubledA5cRuns(p) {
|
|
60
|
+
// Match both forward and back-slash variants
|
|
61
|
+
const pattern = /([/\\]?\.a5c[/\\]runs)[/\\]\.a5c[/\\]runs([/\\]|$)/;
|
|
62
|
+
let result = p;
|
|
63
|
+
// Collapse repeatedly in case of triple+ duplication
|
|
64
|
+
while (pattern.test(result)) {
|
|
65
|
+
result = result.replace(pattern, "$1$2");
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Detect whether the given directory path sits inside a `.a5c/runs` subtree.
|
|
71
|
+
*
|
|
72
|
+
* Uses a platform-aware regex that matches both `/` and `\` separators so
|
|
73
|
+
* the check works on Windows as well as Unix.
|
|
74
|
+
*/
|
|
75
|
+
function isInsideA5cRuns(dir) {
|
|
76
|
+
const normalized = dir.replace(/\\/g, "/");
|
|
77
|
+
return /[/]\.a5c[/]runs[/]/.test(normalized + "/");
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Given a directory that is known to be inside `.a5c/runs/`, walk up the
|
|
81
|
+
* path to find the project root — i.e. the directory that **contains** the
|
|
82
|
+
* `.a5c` folder.
|
|
83
|
+
*
|
|
84
|
+
* The algorithm splits on the first `.a5c/runs` segment and returns the
|
|
85
|
+
* parent of `.a5c`. If no `.a5c` directory can be found on disk the
|
|
86
|
+
* function falls back to the split-based heuristic.
|
|
87
|
+
*
|
|
88
|
+
* @returns The project root directory, or `undefined` if it cannot be
|
|
89
|
+
* determined.
|
|
90
|
+
*/
|
|
91
|
+
function findProjectRoot(dir) {
|
|
92
|
+
// Normalize to forward slashes for splitting, but preserve original for
|
|
93
|
+
// path operations so we stay platform-correct.
|
|
94
|
+
const normalized = dir.replace(/\\/g, "/");
|
|
95
|
+
// Find the first occurrence of .a5c/runs (or .a5c\runs on Windows)
|
|
96
|
+
const marker = ".a5c/runs";
|
|
97
|
+
const idx = normalized.indexOf(marker);
|
|
98
|
+
if (idx === -1)
|
|
99
|
+
return undefined;
|
|
100
|
+
// The project root is the directory containing .a5c — everything before
|
|
101
|
+
// the `.a5c` segment.
|
|
102
|
+
const candidate = dir.substring(0, idx === 0 ? 0 : idx).replace(/[/\\]+$/, "");
|
|
103
|
+
if (candidate.length === 0) {
|
|
104
|
+
// Edge case: path starts with .a5c/runs (pure relative from project root)
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
// Sanity check: the candidate should contain a .a5c directory
|
|
108
|
+
const a5cDir = path.join(candidate, ".a5c");
|
|
109
|
+
try {
|
|
110
|
+
if ((0, node_fs_1.existsSync)(a5cDir)) {
|
|
111
|
+
return candidate;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Filesystem check failed — fall through to heuristic
|
|
116
|
+
}
|
|
117
|
+
// Return the candidate even if we can't verify via filesystem —
|
|
118
|
+
// the substring heuristic is reliable when the path truly contains
|
|
119
|
+
// .a5c/runs.
|
|
120
|
+
return candidate;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Resolve an input file path robustly, accounting for the CLI being invoked
|
|
124
|
+
* from inside a task directory (or any subdirectory of `.a5c/runs/`).
|
|
125
|
+
*
|
|
126
|
+
* The standard `path.resolve(inputPath)` resolves relative to
|
|
127
|
+
* `process.cwd()`. When the working directory is a task directory such as
|
|
128
|
+
* `/project/.a5c/runs/RUN/tasks/TASK/`, resolving a relative path like
|
|
129
|
+
* `.a5c/runs/RUN/tasks/EFFECT/file.json` produces a doubled path:
|
|
130
|
+
* `/project/.a5c/runs/RUN/tasks/TASK/.a5c/runs/RUN/tasks/EFFECT/file.json`
|
|
131
|
+
*
|
|
132
|
+
* This function detects that situation and resolves relative to the project
|
|
133
|
+
* root instead.
|
|
134
|
+
*
|
|
135
|
+
* **Resolution rules (in order):**
|
|
136
|
+
* 1. `"-"` (stdin sentinel) — returned as-is.
|
|
137
|
+
* 2. Absolute paths (including Windows drive letters like `C:\`) — normalized
|
|
138
|
+
* and returned.
|
|
139
|
+
* 3. If `inputPath` contains a `.a5c/runs` segment **and** the current
|
|
140
|
+
* working directory is itself inside a `.a5c/runs` subtree — resolve
|
|
141
|
+
* relative to the detected project root.
|
|
142
|
+
* 4. Otherwise — standard `path.resolve(inputPath)`.
|
|
143
|
+
* 5. `collapseDoubledA5cRuns` is always applied as a final safety net.
|
|
144
|
+
*
|
|
145
|
+
* @param inputPath The raw path argument supplied by the user or script.
|
|
146
|
+
* @returns A fully resolved, absolute path (or `"-"` for stdin).
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* // CWD = /project/.a5c/runs/RUN/tasks/TASK
|
|
150
|
+
* resolveInputPath(".a5c/runs/RUN/tasks/EFFECT/input.json")
|
|
151
|
+
* // => "/project/.a5c/runs/RUN/tasks/EFFECT/input.json"
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* resolveInputPath("/absolute/path/to/file.json")
|
|
155
|
+
* // => "/absolute/path/to/file.json"
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* resolveInputPath("-")
|
|
159
|
+
* // => "-"
|
|
160
|
+
*/
|
|
161
|
+
function resolveInputPath(inputPath) {
|
|
162
|
+
// 1. Stdin sentinel — pass through unchanged
|
|
163
|
+
if (inputPath === "-") {
|
|
164
|
+
return inputPath;
|
|
165
|
+
}
|
|
166
|
+
// 2. Absolute path (Unix or Windows drive letter) — normalize and return
|
|
167
|
+
if (path.isAbsolute(inputPath) || /^[A-Za-z]:[\\/]/.test(inputPath)) {
|
|
168
|
+
return collapseDoubledA5cRuns(path.normalize(inputPath));
|
|
169
|
+
}
|
|
170
|
+
// 3. Smart resolution when both inputPath and CWD are inside .a5c/runs
|
|
171
|
+
const inputNormalized = inputPath.replace(/\\/g, "/");
|
|
172
|
+
const hasA5cRuns = inputNormalized.includes(".a5c/runs") ||
|
|
173
|
+
inputPath.includes(".a5c\\runs");
|
|
174
|
+
if (hasA5cRuns) {
|
|
175
|
+
const cwd = process.cwd();
|
|
176
|
+
if (isInsideA5cRuns(cwd)) {
|
|
177
|
+
const projectRoot = findProjectRoot(cwd);
|
|
178
|
+
if (projectRoot) {
|
|
179
|
+
const resolved = path.resolve(projectRoot, inputPath);
|
|
180
|
+
return collapseDoubledA5cRuns(resolved);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// 4. Standard resolution relative to CWD
|
|
185
|
+
const resolved = path.resolve(inputPath);
|
|
186
|
+
// 5. Safety net — collapse any accidental doubling
|
|
187
|
+
return collapseDoubledA5cRuns(resolved);
|
|
188
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeCode.d.ts","sourceRoot":"","sources":["../../src/harness/claudeCode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA0BH,OAAO,KAAK,EACV,cAAc,EAIf,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"claudeCode.d.ts","sourceRoot":"","sources":["../../src/harness/claudeCode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA0BH,OAAO,KAAK,EACV,cAAc,EAIf,MAAM,SAAS,CAAC;AA8xBjB,wBAAgB,uBAAuB,IAAI,cAAc,CA4DxD"}
|
|
@@ -351,9 +351,26 @@ async function handleStopHookImpl(args) {
|
|
|
351
351
|
let entrypointImportPath;
|
|
352
352
|
if (runId) {
|
|
353
353
|
try {
|
|
354
|
-
|
|
354
|
+
let runDir = path.isAbsolute(runId)
|
|
355
355
|
? runId
|
|
356
356
|
: path.join(runsDir, runId);
|
|
357
|
+
// Fallback: if run.json not found at primary path, search common
|
|
358
|
+
// alternative locations (e.g. nested .a5c/.a5c/runs/ created when
|
|
359
|
+
// babysit skill installs SDK in .a5c/ and runs commands from there).
|
|
360
|
+
if (!(0, node_fs_1.existsSync)(path.join(runDir, "run.json")) && !path.isAbsolute(runId)) {
|
|
361
|
+
const alternatives = [
|
|
362
|
+
path.join(".a5c", ".a5c", "runs", runId),
|
|
363
|
+
path.join(".a5c", "runs", runId),
|
|
364
|
+
];
|
|
365
|
+
for (const alt of alternatives) {
|
|
366
|
+
const resolved = path.resolve(alt);
|
|
367
|
+
if (resolved !== path.resolve(runDir) && (0, node_fs_1.existsSync)(path.join(resolved, "run.json"))) {
|
|
368
|
+
log.info(`Run not found at ${runDir}, using fallback: ${resolved}`);
|
|
369
|
+
runDir = resolved;
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
357
374
|
const metadata = await (0, runFiles_1.readRunMetadata)(runDir);
|
|
358
375
|
entrypointImportPath = metadata?.entrypoint?.importPath;
|
|
359
376
|
const journal = await (0, journal_1.loadJournal)(runDir);
|
|
@@ -388,8 +405,9 @@ async function handleStopHookImpl(args) {
|
|
|
388
405
|
log.info("Completion proof available");
|
|
389
406
|
}
|
|
390
407
|
if (!runState) {
|
|
408
|
+
log.warn(`Run state unknown for ${runId} — allowing exit but preserving session file for recovery`);
|
|
391
409
|
if (verbose) {
|
|
392
|
-
process.stderr.write(`[hook:run stop] Run state is empty for ${runId}; run may be misconfigured\n`);
|
|
410
|
+
process.stderr.write(`[hook:run stop] Run state is empty for ${runId}; run may be misconfigured — preserving session file\n`);
|
|
393
411
|
}
|
|
394
412
|
if (runId) {
|
|
395
413
|
await appendStopHookEvent(path.join(runsDir, runId), {
|
|
@@ -402,7 +420,9 @@ async function handleStopHookImpl(args) {
|
|
|
402
420
|
hasPromise,
|
|
403
421
|
});
|
|
404
422
|
}
|
|
405
|
-
|
|
423
|
+
// Do NOT delete session file here — the run state may be temporarily
|
|
424
|
+
// unreadable (race with run:create, disk issue, etc.). Preserving the
|
|
425
|
+
// file allows session:associate or doctor to re-bind and recover.
|
|
406
426
|
process.stdout.write("{}\n");
|
|
407
427
|
return 0;
|
|
408
428
|
}
|
package/dist/session/write.d.ts
CHANGED
|
@@ -39,12 +39,12 @@ export declare function getCurrentTimestamp(): string;
|
|
|
39
39
|
export declare function isoToEpochSeconds(isoTimestamp: string): number | null;
|
|
40
40
|
/**
|
|
41
41
|
* Calculate iteration duration and update times array.
|
|
42
|
-
* Keeps only the last
|
|
42
|
+
* Keeps only the last 10 durations for runaway loop detection.
|
|
43
43
|
*/
|
|
44
44
|
export declare function updateIterationTimes(existingTimes: number[], lastIterationAt: string, currentTime: string): number[];
|
|
45
45
|
/**
|
|
46
46
|
* Check if average iteration time indicates runaway loop.
|
|
47
|
-
* Returns true if
|
|
47
|
+
* Returns true if at least 10 consecutive iterations averaged <= 15 seconds.
|
|
48
48
|
*/
|
|
49
49
|
export declare function isIterationTooFast(iterationTimes: number[]): boolean;
|
|
50
50
|
//# sourceMappingURL=write.d.ts.map
|
package/dist/session/write.js
CHANGED
|
@@ -166,7 +166,7 @@ function isoToEpochSeconds(isoTimestamp) {
|
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
168
|
* Calculate iteration duration and update times array.
|
|
169
|
-
* Keeps only the last
|
|
169
|
+
* Keeps only the last 10 durations for runaway loop detection.
|
|
170
170
|
*/
|
|
171
171
|
function updateIterationTimes(existingTimes, lastIterationAt, currentTime) {
|
|
172
172
|
const lastEpoch = isoToEpochSeconds(lastIterationAt);
|
|
@@ -179,15 +179,15 @@ function updateIterationTimes(existingTimes, lastIterationAt, currentTime) {
|
|
|
179
179
|
return existingTimes;
|
|
180
180
|
}
|
|
181
181
|
const newTimes = [...existingTimes, duration];
|
|
182
|
-
// Keep only last
|
|
183
|
-
return newTimes.slice(-
|
|
182
|
+
// Keep only last 10
|
|
183
|
+
return newTimes.slice(-10);
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
186
|
* Check if average iteration time indicates runaway loop.
|
|
187
|
-
* Returns true if
|
|
187
|
+
* Returns true if at least 10 consecutive iterations averaged <= 15 seconds.
|
|
188
188
|
*/
|
|
189
189
|
function isIterationTooFast(iterationTimes) {
|
|
190
|
-
if (iterationTimes.length <
|
|
190
|
+
if (iterationTimes.length < 10) {
|
|
191
191
|
return false;
|
|
192
192
|
}
|
|
193
193
|
const sum = iterationTimes.reduce((a, b) => a + b, 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a5c-ai/babysitter-sdk",
|
|
3
|
-
"version": "0.0.170-staging.
|
|
3
|
+
"version": "0.0.170-staging.bb2a8a61",
|
|
4
4
|
"description": "Storage and run-registry primitives for event-sourced babysitter workflows.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"ulid": "^2.3.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
30
|
-
"@typescript-eslint/parser": "^7.18.0",
|
|
31
29
|
"@types/fs-extra": "^11.0.4",
|
|
32
30
|
"@types/node": "^20.11.30",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
32
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
33
33
|
"eslint": "^8.57.0",
|
|
34
34
|
"rimraf": "^5.0.5",
|
|
35
35
|
"typescript": "^5.4.2",
|
|
36
|
-
"vitest": "^
|
|
36
|
+
"vitest": "^4.0.18"
|
|
37
37
|
}
|
|
38
38
|
}
|