forked from doctly/switchboard
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsubagent-attribution.js
More file actions
27 lines (24 loc) · 1.03 KB
/
Copy pathsubagent-attribution.js
File metadata and controls
27 lines (24 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Pure transcript-path -> parent attribution — see .ai/contexts/subagent-observability.md
'use strict';
// basename must be "agent-<id>.jsonl" — see read-session-file.js:enumerateSessionFiles
function agentIdFromBasename(basename) {
if (typeof basename !== 'string' || !basename.endsWith('.jsonl')) return null;
const base = basename.slice(0, -'.jsonl'.length);
const m = base.match(/^agent-(.+)$/);
return m ? m[1] : null;
}
// parts: [folder, ...rest] — both real layouts, null otherwise; see .ai/contexts/subagent-observability.md
function subagentParentFromParts(parts) {
if (!Array.isArray(parts) || parts.length < 3) return null;
const rest = parts.slice(1);
const agentId = agentIdFromBasename(rest[rest.length - 1]);
if (!agentId) return null;
if (rest.length === 3 && rest[1] === 'subagents') {
return { parentSessionId: rest[0], agentId };
}
if (rest.length === 2) {
return { parentSessionId: rest[0], agentId };
}
return null;
}
module.exports = { subagentParentFromParts, agentIdFromBasename };