@goondocks/myco 0.18.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-run-2NFYMQXW.js → agent-run-I4O2K2CK.js} +4 -4
- package/dist/{agent-tasks-MEIYLXGN.js → agent-tasks-UOW5BQIB.js} +4 -4
- package/dist/{chunk-JMOUFG6Y.js → chunk-44PZCAYS.js} +47 -5
- package/dist/chunk-44PZCAYS.js.map +1 -0
- package/dist/{chunk-JDI4DPWD.js → chunk-C3EGL5JX.js} +632 -145
- package/dist/chunk-C3EGL5JX.js.map +1 -0
- package/dist/{chunk-OW433Q4C.js → chunk-CURS2TNP.js} +44 -3
- package/dist/chunk-CURS2TNP.js.map +1 -0
- package/dist/{chunk-FABWUX5G.js → chunk-DPSLJ242.js} +16 -2
- package/dist/chunk-DPSLJ242.js.map +1 -0
- package/dist/{chunk-DLFDBKEV.js → chunk-LSP5HYOO.js} +17 -14
- package/dist/chunk-LSP5HYOO.js.map +1 -0
- package/dist/{chunk-VOCGURV7.js → chunk-N75GMQGA.js} +3 -3
- package/dist/{chunk-U7GJTVSX.js → chunk-RIDSOQDR.js} +20 -6
- package/dist/chunk-RIDSOQDR.js.map +1 -0
- package/dist/{chunk-KWTOCJLB.js → chunk-TCSVDQF5.js} +1128 -193
- package/dist/chunk-TCSVDQF5.js.map +1 -0
- package/dist/{chunk-55QEICRO.js → chunk-TLK46KKD.js} +2 -2
- package/dist/{chunk-NZI7WBZI.js → chunk-TOER6RNC.js} +21 -1
- package/dist/chunk-TOER6RNC.js.map +1 -0
- package/dist/{chunk-7OYXB2NM.js → chunk-TZAXQKO6.js} +5 -1
- package/dist/chunk-TZAXQKO6.js.map +1 -0
- package/dist/{chunk-EO2RQW4S.js → chunk-W7WENJ6F.js} +2 -2
- package/dist/{chunk-BUIR3JWM.js → chunk-XWOQL4XN.js} +2 -2
- package/dist/{chunk-PFWIPRF6.js → chunk-YZPI2Y3E.js} +2 -2
- package/dist/{cli-IIMBALPV.js → cli-D3TJYJ2U.js} +35 -35
- package/dist/{client-VZCUISHZ.js → client-4LLEXLVK.js} +3 -3
- package/dist/{detect-GEM3NVK6.js → detect-SZ2KDUF4.js} +2 -2
- package/dist/{doctor-QYD34X7Q.js → doctor-KCTXPX5D.js} +6 -6
- package/dist/{executor-NSPRTH4M.js → executor-UYIZC3L5.js} +83 -275
- package/dist/executor-UYIZC3L5.js.map +1 -0
- package/dist/{init-WYYL44KZ.js → init-QFNBKKDC.js} +7 -7
- package/dist/{llm-KEDHK3TQ.js → llm-SMA5ZEAW.js} +2 -2
- package/dist/{main-6PY3ITQ5.js → main-5THODR77.js} +427 -196
- package/dist/main-5THODR77.js.map +1 -0
- package/dist/{open-HRFMJDQX.js → open-7737CSPN.js} +4 -4
- package/dist/{post-compact-HT24YMAN.js → post-compact-2TJ5FPZH.js} +6 -6
- package/dist/{post-tool-use-DENRI5WB.js → post-tool-use-FRTSICC3.js} +5 -5
- package/dist/{post-tool-use-failure-A6SNJX42.js → post-tool-use-failure-KYO2NCNB.js} +6 -6
- package/dist/{pre-compact-3Q4BALCL.js → pre-compact-J6GCJEJR.js} +6 -6
- package/dist/{remove-YB5A6HY2.js → remove-3WZZC7AX.js} +5 -5
- package/dist/{restart-RGDVHELZ.js → restart-HUHEFOXU.js} +5 -5
- package/dist/{search-WOHT3G55.js → search-ZGN3LDXG.js} +5 -5
- package/dist/{server-6SUNYDV7.js → server-PTXLVVEE.js} +3 -3
- package/dist/{session-W3SKRFRV.js → session-7VV3IQMO.js} +5 -5
- package/dist/{session-end-OUTY7AFF.js → session-end-SMU55UCM.js} +5 -5
- package/dist/{session-start-5MB3LFOA.js → session-start-NIMWEOIZ.js} +16 -11
- package/dist/{session-start-5MB3LFOA.js.map → session-start-NIMWEOIZ.js.map} +1 -1
- package/dist/{setup-llm-ZMYGIQX5.js → setup-llm-7S3VPAPN.js} +4 -4
- package/dist/src/agent/definitions/tasks/extract-only.yaml +1 -1
- package/dist/src/agent/definitions/tasks/full-intelligence.yaml +10 -0
- package/dist/src/agent/definitions/tasks/skill-evolve.yaml +163 -49
- package/dist/src/agent/definitions/tasks/skill-generate.yaml +44 -27
- package/dist/src/agent/definitions/tasks/skill-survey.yaml +132 -138
- package/dist/src/agent/definitions/tasks/supersession-sweep.yaml +1 -1
- package/dist/src/cli.js +1 -1
- package/dist/src/daemon/main.js +1 -1
- package/dist/src/hooks/post-tool-use.js +1 -1
- package/dist/src/hooks/session-end.js +1 -1
- package/dist/src/hooks/session-start.js +1 -1
- package/dist/src/hooks/stop.js +1 -1
- package/dist/src/hooks/user-prompt-submit.js +1 -1
- package/dist/src/mcp/server.js +1 -1
- package/dist/src/symbionts/manifests/codex.yaml +45 -7
- package/dist/src/worker/src/index.ts +8 -2
- package/dist/src/worker/src/schema.ts +2 -0
- package/dist/{stats-DGI6B3HX.js → stats-GEOQ2DFF.js} +5 -5
- package/dist/{stop-YGHODSP7.js → stop-7AKYBJJ2.js} +5 -5
- package/dist/{stop-failure-7IJTPJ6W.js → stop-failure-NLE2EURG.js} +6 -6
- package/dist/{subagent-start-ZBQ5PJB5.js → subagent-start-LBNZF2TG.js} +6 -6
- package/dist/{subagent-stop-N2TDQU2D.js → subagent-stop-B2Z5GYAB.js} +6 -6
- package/dist/{task-completed-BDLMRSBB.js → task-completed-PO5TETJ7.js} +6 -6
- package/dist/{team-2ZFGTSIN.js → team-DPNP2RN7.js} +3 -3
- package/dist/ui/assets/{index-DtT9_nlT.js → index-CiI1fwas.js} +2 -2
- package/dist/ui/index.html +1 -1
- package/dist/{update-STLAN7LR.js → update-WBWB5URU.js} +5 -5
- package/dist/{user-prompt-submit-4IBFUYQ3.js → user-prompt-submit-IZJC3NV7.js} +11 -8
- package/dist/user-prompt-submit-IZJC3NV7.js.map +1 -0
- package/dist/{verify-EJYPO7QA.js → verify-FNSP62I3.js} +2 -2
- package/dist/{version-YPBIKH77.js → version-QEVU66NT.js} +2 -2
- package/package.json +7 -7
- package/dist/chunk-7OYXB2NM.js.map +0 -1
- package/dist/chunk-DLFDBKEV.js.map +0 -1
- package/dist/chunk-FABWUX5G.js.map +0 -1
- package/dist/chunk-JDI4DPWD.js.map +0 -1
- package/dist/chunk-JMOUFG6Y.js.map +0 -1
- package/dist/chunk-KWTOCJLB.js.map +0 -1
- package/dist/chunk-NZI7WBZI.js.map +0 -1
- package/dist/chunk-OW433Q4C.js.map +0 -1
- package/dist/chunk-U7GJTVSX.js.map +0 -1
- package/dist/executor-NSPRTH4M.js.map +0 -1
- package/dist/main-6PY3ITQ5.js.map +0 -1
- package/dist/user-prompt-submit-4IBFUYQ3.js.map +0 -1
- /package/dist/{agent-run-2NFYMQXW.js.map → agent-run-I4O2K2CK.js.map} +0 -0
- /package/dist/{agent-tasks-MEIYLXGN.js.map → agent-tasks-UOW5BQIB.js.map} +0 -0
- /package/dist/{chunk-VOCGURV7.js.map → chunk-N75GMQGA.js.map} +0 -0
- /package/dist/{chunk-55QEICRO.js.map → chunk-TLK46KKD.js.map} +0 -0
- /package/dist/{chunk-EO2RQW4S.js.map → chunk-W7WENJ6F.js.map} +0 -0
- /package/dist/{chunk-BUIR3JWM.js.map → chunk-XWOQL4XN.js.map} +0 -0
- /package/dist/{chunk-PFWIPRF6.js.map → chunk-YZPI2Y3E.js.map} +0 -0
- /package/dist/{cli-IIMBALPV.js.map → cli-D3TJYJ2U.js.map} +0 -0
- /package/dist/{client-VZCUISHZ.js.map → client-4LLEXLVK.js.map} +0 -0
- /package/dist/{detect-GEM3NVK6.js.map → detect-SZ2KDUF4.js.map} +0 -0
- /package/dist/{doctor-QYD34X7Q.js.map → doctor-KCTXPX5D.js.map} +0 -0
- /package/dist/{init-WYYL44KZ.js.map → init-QFNBKKDC.js.map} +0 -0
- /package/dist/{llm-KEDHK3TQ.js.map → llm-SMA5ZEAW.js.map} +0 -0
- /package/dist/{open-HRFMJDQX.js.map → open-7737CSPN.js.map} +0 -0
- /package/dist/{post-compact-HT24YMAN.js.map → post-compact-2TJ5FPZH.js.map} +0 -0
- /package/dist/{post-tool-use-DENRI5WB.js.map → post-tool-use-FRTSICC3.js.map} +0 -0
- /package/dist/{post-tool-use-failure-A6SNJX42.js.map → post-tool-use-failure-KYO2NCNB.js.map} +0 -0
- /package/dist/{pre-compact-3Q4BALCL.js.map → pre-compact-J6GCJEJR.js.map} +0 -0
- /package/dist/{remove-YB5A6HY2.js.map → remove-3WZZC7AX.js.map} +0 -0
- /package/dist/{restart-RGDVHELZ.js.map → restart-HUHEFOXU.js.map} +0 -0
- /package/dist/{search-WOHT3G55.js.map → search-ZGN3LDXG.js.map} +0 -0
- /package/dist/{server-6SUNYDV7.js.map → server-PTXLVVEE.js.map} +0 -0
- /package/dist/{session-W3SKRFRV.js.map → session-7VV3IQMO.js.map} +0 -0
- /package/dist/{session-end-OUTY7AFF.js.map → session-end-SMU55UCM.js.map} +0 -0
- /package/dist/{setup-llm-ZMYGIQX5.js.map → setup-llm-7S3VPAPN.js.map} +0 -0
- /package/dist/{stats-DGI6B3HX.js.map → stats-GEOQ2DFF.js.map} +0 -0
- /package/dist/{stop-YGHODSP7.js.map → stop-7AKYBJJ2.js.map} +0 -0
- /package/dist/{stop-failure-7IJTPJ6W.js.map → stop-failure-NLE2EURG.js.map} +0 -0
- /package/dist/{subagent-start-ZBQ5PJB5.js.map → subagent-start-LBNZF2TG.js.map} +0 -0
- /package/dist/{subagent-stop-N2TDQU2D.js.map → subagent-stop-B2Z5GYAB.js.map} +0 -0
- /package/dist/{task-completed-BDLMRSBB.js.map → task-completed-PO5TETJ7.js.map} +0 -0
- /package/dist/{team-2ZFGTSIN.js.map → team-DPNP2RN7.js.map} +0 -0
- /package/dist/{update-STLAN7LR.js.map → update-WBWB5URU.js.map} +0 -0
- /package/dist/{verify-EJYPO7QA.js.map → verify-FNSP62I3.js.map} +0 -0
- /package/dist/{version-YPBIKH77.js.map → version-QEVU66NT.js.map} +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
connectToDaemon
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-TLK46KKD.js";
|
|
5
5
|
import "./chunk-SAKJMNSR.js";
|
|
6
6
|
import "./chunk-WYOE4IAX.js";
|
|
7
7
|
import "./chunk-CML4MCYF.js";
|
|
8
8
|
import "./chunk-MYX5NCRH.js";
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-XWOQL4XN.js";
|
|
10
|
+
import "./chunk-W7WENJ6F.js";
|
|
11
11
|
import "./chunk-LPUQPDC2.js";
|
|
12
12
|
import "./chunk-CKJAWZQE.js";
|
|
13
13
|
import "./chunk-E7NUADTQ.js";
|
|
@@ -32,4 +32,4 @@ async function run(args, vaultDir) {
|
|
|
32
32
|
export {
|
|
33
33
|
run
|
|
34
34
|
};
|
|
35
|
-
//# sourceMappingURL=agent-run-
|
|
35
|
+
//# sourceMappingURL=agent-run-I4O2K2CK.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
connectToDaemon
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-TLK46KKD.js";
|
|
5
5
|
import "./chunk-SAKJMNSR.js";
|
|
6
6
|
import "./chunk-WYOE4IAX.js";
|
|
7
7
|
import "./chunk-CML4MCYF.js";
|
|
8
8
|
import "./chunk-MYX5NCRH.js";
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-XWOQL4XN.js";
|
|
10
|
+
import "./chunk-W7WENJ6F.js";
|
|
11
11
|
import "./chunk-LPUQPDC2.js";
|
|
12
12
|
import "./chunk-CKJAWZQE.js";
|
|
13
13
|
import "./chunk-E7NUADTQ.js";
|
|
@@ -178,4 +178,4 @@ async function run(args, vaultDir) {
|
|
|
178
178
|
export {
|
|
179
179
|
run
|
|
180
180
|
};
|
|
181
|
-
//# sourceMappingURL=agent-tasks-
|
|
181
|
+
//# sourceMappingURL=agent-tasks-UOW5BQIB.js.map
|
|
@@ -19,7 +19,7 @@ function evaluateSessionStartRules(manifests, detectedAgent, ctx) {
|
|
|
19
19
|
for (const rule of rules) {
|
|
20
20
|
if (rule.event !== "session_start") continue;
|
|
21
21
|
if (!scopePermits(rule, manifest.name, detectedAgent)) continue;
|
|
22
|
-
if (!whenMatches(rule, { prompt: "", transcriptPath: ctx.transcriptPath })) continue;
|
|
22
|
+
if (!whenMatches(rule, { prompt: "", transcriptPath: ctx.transcriptPath, transcriptMeta: ctx.transcriptMeta })) continue;
|
|
23
23
|
if (rule.action === "drop") {
|
|
24
24
|
return { action: "drop", reason: rule.reason };
|
|
25
25
|
}
|
|
@@ -32,8 +32,8 @@ function scopePermits(rule, owningAgent, detectedAgent) {
|
|
|
32
32
|
return owningAgent === detectedAgent;
|
|
33
33
|
}
|
|
34
34
|
function whenMatches(rule, ctx) {
|
|
35
|
-
const { prompt_starts_with, prompt_contains, transcript_path_missing } = rule.when;
|
|
36
|
-
const hasAnyCondition = prompt_starts_with !== void 0 || prompt_contains !== void 0 || transcript_path_missing !== void 0;
|
|
35
|
+
const { prompt_starts_with, prompt_contains, transcript_path_missing, transcript_meta_field_exists } = rule.when;
|
|
36
|
+
const hasAnyCondition = prompt_starts_with !== void 0 || prompt_contains !== void 0 || transcript_path_missing !== void 0 || transcript_meta_field_exists !== void 0;
|
|
37
37
|
if (!hasAnyCondition) return false;
|
|
38
38
|
if (prompt_starts_with && !ctx.prompt.startsWith(prompt_starts_with)) return false;
|
|
39
39
|
if (prompt_contains && !ctx.prompt.includes(prompt_contains)) return false;
|
|
@@ -42,8 +42,20 @@ function whenMatches(rule, ctx) {
|
|
|
42
42
|
if (transcript_path_missing && !missing) return false;
|
|
43
43
|
if (!transcript_path_missing && missing) return false;
|
|
44
44
|
}
|
|
45
|
+
if (transcript_meta_field_exists !== void 0) {
|
|
46
|
+
if (!ctx.transcriptMeta) return false;
|
|
47
|
+
if (!resolveMetaField(ctx.transcriptMeta, transcript_meta_field_exists)) return false;
|
|
48
|
+
}
|
|
45
49
|
return true;
|
|
46
50
|
}
|
|
51
|
+
function resolveMetaField(meta, fieldPath) {
|
|
52
|
+
let current = meta;
|
|
53
|
+
for (const part of fieldPath.split(".")) {
|
|
54
|
+
if (current === null || current === void 0 || typeof current !== "object") return void 0;
|
|
55
|
+
current = current[part];
|
|
56
|
+
}
|
|
57
|
+
return current;
|
|
58
|
+
}
|
|
47
59
|
function applyAction(rule, ctx) {
|
|
48
60
|
if (rule.action === "drop") {
|
|
49
61
|
return { action: "drop", reason: rule.reason };
|
|
@@ -58,8 +70,38 @@ function applyAction(rule, ctx) {
|
|
|
58
70
|
return { action: "rewrite", prompt: next, reason: rule.reason };
|
|
59
71
|
}
|
|
60
72
|
|
|
73
|
+
// src/hooks/transcript-meta.ts
|
|
74
|
+
import fs from "fs";
|
|
75
|
+
function readTranscriptMeta(transcriptPath) {
|
|
76
|
+
try {
|
|
77
|
+
const fd = fs.openSync(transcriptPath, "r");
|
|
78
|
+
try {
|
|
79
|
+
const buf = Buffer.alloc(131072);
|
|
80
|
+
const bytesRead = fs.readSync(fd, buf, 0, buf.length, 0);
|
|
81
|
+
if (bytesRead === 0) return null;
|
|
82
|
+
const chunk = buf.toString("utf-8", 0, bytesRead);
|
|
83
|
+
const newlineIdx = chunk.indexOf("\n");
|
|
84
|
+
const firstLine = newlineIdx >= 0 ? chunk.slice(0, newlineIdx) : chunk;
|
|
85
|
+
if (!firstLine) return null;
|
|
86
|
+
const entry = JSON.parse(firstLine);
|
|
87
|
+
if (entry?.type === "session_meta" && typeof entry.payload === "object") {
|
|
88
|
+
return entry.payload;
|
|
89
|
+
}
|
|
90
|
+
if (typeof entry === "object" && entry !== null) {
|
|
91
|
+
return entry;
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
} finally {
|
|
95
|
+
fs.closeSync(fd);
|
|
96
|
+
}
|
|
97
|
+
} catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
61
102
|
export {
|
|
62
103
|
evaluateUserPromptRules,
|
|
63
|
-
evaluateSessionStartRules
|
|
104
|
+
evaluateSessionStartRules,
|
|
105
|
+
readTranscriptMeta
|
|
64
106
|
};
|
|
65
|
-
//# sourceMappingURL=chunk-
|
|
107
|
+
//# sourceMappingURL=chunk-44PZCAYS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/capture-rules.ts","../src/hooks/transcript-meta.ts"],"sourcesContent":["/**\n * Generic capture-rule evaluator.\n *\n * Each symbiont manifest declares `capture.rules` — a list of `{ event,\n * when, action }` records that describe how Myco should filter captured\n * events for that agent. This module loads rules from every manifest\n * in one place and exposes a pure evaluator the hook handlers call\n * without knowing anything symbiont-specific.\n *\n * Adding a new symbiont's capture behavior is a YAML-only change: edit\n * that agent's manifest file, no hook or evaluator changes needed.\n *\n * Rule scope (`this_agent` vs `any_agent`) lets rules opt into running\n * even when agent detection itself fails — useful for ephemeral\n * sub-invocations that legitimately lack the signals we key on.\n *\n * Conditions should prefer structural signals (e.g.,\n * `transcript_path_missing`) over text matching so rules stay robust\n * across upstream agent updates.\n */\n\nimport type { CaptureRule, SymbiontManifest } from '../symbionts/manifest-schema.js';\n\n/** Structured context a rule can match against at UserPromptSubmit time. */\nexport interface UserPromptRuleContext {\n /** The user prompt text as received from the hook. */\n prompt: string;\n /** Transcript path from the hook payload, if any. Empty/undefined signals an ephemeral session. */\n transcriptPath?: string;\n /** Parsed first JSON line (session_meta) from the transcript, if available. */\n transcriptMeta?: Record<string, unknown>;\n}\n\n/** Structured context a rule can match against at SessionStart time. */\nexport interface SessionStartRuleContext {\n /** Transcript path from the hook payload, if any. Empty/undefined signals an ephemeral session. */\n transcriptPath?: string;\n /** Parsed first JSON line (session_meta) from the transcript, if available. */\n transcriptMeta?: Record<string, unknown>;\n}\n\n/** Outcome of evaluating user_prompt rules. */\nexport type UserPromptDecision =\n | { action: 'pass'; prompt: string }\n | { action: 'rewrite'; prompt: string; reason?: string }\n | { action: 'drop'; reason?: string };\n\n/** Outcome of evaluating session_start rules. No rewrite — there's no prompt text yet. */\nexport type SessionStartDecision =\n | { action: 'pass' }\n | { action: 'drop'; reason?: string };\n\n/**\n * Evaluate all user_prompt rules from every manifest against one context.\n *\n * Rules are checked in declaration order, first-match-wins. A rule only\n * fires when:\n * 1. its `event` is `user_prompt`,\n * 2. its scope permits it (see scope semantics in manifest-schema.ts),\n * 3. every condition in its `when` block matches the context.\n *\n * If no rule matches, the prompt passes through unchanged.\n */\nexport function evaluateUserPromptRules(\n manifests: SymbiontManifest[],\n detectedAgent: string,\n ctx: UserPromptRuleContext,\n): UserPromptDecision {\n for (const manifest of manifests) {\n const rules = manifest.capture?.rules ?? [];\n for (const rule of rules) {\n if (rule.event !== 'user_prompt') continue;\n if (!scopePermits(rule, manifest.name, detectedAgent)) continue;\n if (!whenMatches(rule, ctx)) continue;\n return applyAction(rule, ctx);\n }\n }\n return { action: 'pass', prompt: ctx.prompt };\n}\n\n/**\n * Evaluate all session_start rules from every manifest.\n *\n * Same first-match-wins semantics as user_prompt rules. The only action\n * session_start rules can take is `drop` — text rewriting doesn't apply\n * because there's no prompt text at SessionStart time. Rules that\n * specify prompt-based conditions (prompt_starts_with / prompt_contains)\n * match against an empty prompt here, so they'll never fire on the\n * session_start pass.\n *\n * Callers should skip session registration when the result is `drop`.\n */\nexport function evaluateSessionStartRules(\n manifests: SymbiontManifest[],\n detectedAgent: string,\n ctx: SessionStartRuleContext,\n): SessionStartDecision {\n for (const manifest of manifests) {\n const rules = manifest.capture?.rules ?? [];\n for (const rule of rules) {\n if (rule.event !== 'session_start') continue;\n if (!scopePermits(rule, manifest.name, detectedAgent)) continue;\n if (!whenMatches(rule, { prompt: '', transcriptPath: ctx.transcriptPath, transcriptMeta: ctx.transcriptMeta })) continue;\n if (rule.action === 'drop') {\n return { action: 'drop', reason: rule.reason };\n }\n // rewrite_prompt is meaningless at session_start — skip and let\n // later rules have a chance to match.\n }\n }\n return { action: 'pass' };\n}\n\nfunction scopePermits(rule: CaptureRule, owningAgent: string, detectedAgent: string): boolean {\n if (rule.scope === 'any_agent') return true;\n return owningAgent === detectedAgent;\n}\n\nfunction whenMatches(rule: CaptureRule, ctx: UserPromptRuleContext): boolean {\n const { prompt_starts_with, prompt_contains, transcript_path_missing, transcript_meta_field_exists } = rule.when;\n\n // Refuse rules with no conditions — prevents a mistyped YAML file from\n // accidentally creating a blanket \"drop everything\" rule.\n const hasAnyCondition =\n prompt_starts_with !== undefined ||\n prompt_contains !== undefined ||\n transcript_path_missing !== undefined ||\n transcript_meta_field_exists !== undefined;\n if (!hasAnyCondition) return false;\n\n if (prompt_starts_with && !ctx.prompt.startsWith(prompt_starts_with)) return false;\n if (prompt_contains && !ctx.prompt.includes(prompt_contains)) return false;\n\n if (transcript_path_missing !== undefined) {\n const missing = !ctx.transcriptPath || ctx.transcriptPath.length === 0;\n if (transcript_path_missing && !missing) return false;\n if (!transcript_path_missing && missing) return false;\n }\n\n if (transcript_meta_field_exists !== undefined) {\n if (!ctx.transcriptMeta) return false;\n if (!resolveMetaField(ctx.transcriptMeta, transcript_meta_field_exists)) return false;\n }\n\n return true;\n}\n\n/**\n * Navigate a dot-path (e.g. \"source.subagent\") into a nested object.\n * Returns the value if it exists and is truthy, undefined otherwise.\n */\nfunction resolveMetaField(meta: Record<string, unknown>, fieldPath: string): unknown {\n let current: unknown = meta;\n for (const part of fieldPath.split('.')) {\n if (current === null || current === undefined || typeof current !== 'object') return undefined;\n current = (current as Record<string, unknown>)[part];\n }\n return current;\n}\n\nfunction applyAction(rule: CaptureRule, ctx: UserPromptRuleContext): UserPromptDecision {\n if (rule.action === 'drop') {\n return { action: 'drop', reason: rule.reason };\n }\n // rewrite_prompt — keep only the substring after the extract_after marker.\n // If the marker isn't in the prompt, fall through to `pass` so we don't\n // accidentally blank out a prompt that turned out not to match after all.\n const marker = rule.extract_after;\n if (!marker) return { action: 'pass', prompt: ctx.prompt };\n const idx = ctx.prompt.indexOf(marker);\n if (idx === -1) return { action: 'pass', prompt: ctx.prompt };\n const after = ctx.prompt.slice(idx + marker.length);\n const next = rule.trim ? after.trim() : after;\n if (!next) return { action: 'pass', prompt: ctx.prompt };\n return { action: 'rewrite', prompt: next, reason: rule.reason };\n}\n","/**\n * Read the first JSON line (session_meta) from an agent's transcript file.\n *\n * Every supported agent writes a JSONL transcript where the first entry\n * is a `session_meta` record containing session identity, source info,\n * model, and other structural signals. This reader extracts that record\n * so capture rules can make decisions based on it — e.g., detecting\n * sub-agent thread spawns that have real transcript files but aren't\n * user-initiated sessions.\n *\n * Returns the parsed `payload` object from the session_meta entry, or\n * null if the file doesn't exist, isn't readable, or doesn't contain\n * valid session_meta JSON.\n */\n\nimport fs from 'node:fs';\n\n/**\n * Read and parse the session_meta payload from a transcript file.\n *\n * @param transcriptPath - Absolute path to the JSONL transcript.\n * @returns The session_meta payload object, or null on any failure.\n */\nexport function readTranscriptMeta(transcriptPath: string): Record<string, unknown> | null {\n try {\n const fd = fs.openSync(transcriptPath, 'r');\n try {\n // Read enough bytes for the first line. Session meta can be large\n // when it embeds the full system prompt (base_instructions) — Codex\n // sessions routinely exceed 16 KB. 128 KB covers all known cases.\n const buf = Buffer.alloc(131072);\n const bytesRead = fs.readSync(fd, buf, 0, buf.length, 0);\n if (bytesRead === 0) return null;\n\n const chunk = buf.toString('utf-8', 0, bytesRead);\n const newlineIdx = chunk.indexOf('\\n');\n const firstLine = newlineIdx >= 0 ? chunk.slice(0, newlineIdx) : chunk;\n if (!firstLine) return null;\n\n const entry = JSON.parse(firstLine);\n\n // session_meta entries have { type: \"session_meta\", payload: {...} }\n if (entry?.type === 'session_meta' && typeof entry.payload === 'object') {\n return entry.payload as Record<string, unknown>;\n }\n\n // Some agents may write the meta directly without the wrapper\n if (typeof entry === 'object' && entry !== null) {\n return entry as Record<string, unknown>;\n }\n\n return null;\n } finally {\n fs.closeSync(fd);\n }\n } catch {\n return null;\n }\n}\n"],"mappings":";;;AA+DO,SAAS,wBACd,WACA,eACA,KACoB;AACpB,aAAW,YAAY,WAAW;AAChC,UAAM,QAAQ,SAAS,SAAS,SAAS,CAAC;AAC1C,eAAW,QAAQ,OAAO;AACxB,UAAI,KAAK,UAAU,cAAe;AAClC,UAAI,CAAC,aAAa,MAAM,SAAS,MAAM,aAAa,EAAG;AACvD,UAAI,CAAC,YAAY,MAAM,GAAG,EAAG;AAC7B,aAAO,YAAY,MAAM,GAAG;AAAA,IAC9B;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,QAAQ,QAAQ,IAAI,OAAO;AAC9C;AAcO,SAAS,0BACd,WACA,eACA,KACsB;AACtB,aAAW,YAAY,WAAW;AAChC,UAAM,QAAQ,SAAS,SAAS,SAAS,CAAC;AAC1C,eAAW,QAAQ,OAAO;AACxB,UAAI,KAAK,UAAU,gBAAiB;AACpC,UAAI,CAAC,aAAa,MAAM,SAAS,MAAM,aAAa,EAAG;AACvD,UAAI,CAAC,YAAY,MAAM,EAAE,QAAQ,IAAI,gBAAgB,IAAI,gBAAgB,gBAAgB,IAAI,eAAe,CAAC,EAAG;AAChH,UAAI,KAAK,WAAW,QAAQ;AAC1B,eAAO,EAAE,QAAQ,QAAQ,QAAQ,KAAK,OAAO;AAAA,MAC/C;AAAA,IAGF;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,OAAO;AAC1B;AAEA,SAAS,aAAa,MAAmB,aAAqB,eAAgC;AAC5F,MAAI,KAAK,UAAU,YAAa,QAAO;AACvC,SAAO,gBAAgB;AACzB;AAEA,SAAS,YAAY,MAAmB,KAAqC;AAC3E,QAAM,EAAE,oBAAoB,iBAAiB,yBAAyB,6BAA6B,IAAI,KAAK;AAI5G,QAAM,kBACJ,uBAAuB,UACvB,oBAAoB,UACpB,4BAA4B,UAC5B,iCAAiC;AACnC,MAA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