@theokit/sdk 5.5.0 → 5.7.0
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/CHANGELOG.md +667 -0
- package/dist/{agent-CjMVbhhY.d.ts → agent-Bqzdhkqr.d.ts} +12 -3
- package/dist/{agent-DyB_lzrx.d.cts → agent-Dya5SmhY.d.cts} +12 -3
- package/dist/{agent-G3T7Q3SQ.js → agent-EQ5HKTWV.js} +15 -14
- package/dist/{agent-G3T7Q3SQ.js.map → agent-EQ5HKTWV.js.map} +1 -1
- package/dist/{agent-YWSIHHFM.cjs → agent-KA63WDQH.cjs} +16 -15
- package/dist/{agent-YWSIHHFM.cjs.map → agent-KA63WDQH.cjs.map} +1 -1
- package/dist/agent.d.ts +11 -0
- package/dist/{chunk-Z2JFX372.cjs → chunk-33A27NFX.cjs} +15 -15
- package/dist/{chunk-Z2JFX372.cjs.map → chunk-33A27NFX.cjs.map} +1 -1
- package/dist/{chunk-N6OOOYFZ.js → chunk-3VXQEQE4.js} +13 -4
- package/dist/chunk-3VXQEQE4.js.map +1 -0
- package/dist/{chunk-DZG77WU7.cjs → chunk-3XSWF5AP.cjs} +3 -3
- package/dist/{chunk-DZG77WU7.cjs.map → chunk-3XSWF5AP.cjs.map} +1 -1
- package/dist/{chunk-M3ZGRGOG.js → chunk-6JG2RFGK.js} +3 -3
- package/dist/{chunk-M3ZGRGOG.js.map → chunk-6JG2RFGK.js.map} +1 -1
- package/dist/{chunk-S6B5XYC3.js → chunk-7C3HWGCW.js} +33 -22
- package/dist/chunk-7C3HWGCW.js.map +1 -0
- package/dist/{chunk-LOHMT36V.cjs → chunk-7KBNBPFK.cjs} +75 -2
- package/dist/chunk-7KBNBPFK.cjs.map +1 -0
- package/dist/{chunk-UKJJRU7C.cjs → chunk-A575WPBL.cjs} +330 -129
- package/dist/chunk-A575WPBL.cjs.map +1 -0
- package/dist/{chunk-2XRAWOZZ.js → chunk-A6PDYH55.js} +74 -3
- package/dist/chunk-A6PDYH55.js.map +1 -0
- package/dist/{chunk-LX7SEXOQ.js → chunk-CA5VUAP3.js} +25 -7
- package/dist/chunk-CA5VUAP3.js.map +1 -0
- package/dist/{chunk-2QKV4CGK.js → chunk-CZWN4C6A.js} +3 -3
- package/dist/{chunk-2QKV4CGK.js.map → chunk-CZWN4C6A.js.map} +1 -1
- package/dist/chunk-DQNI52VV.js +20 -0
- package/dist/chunk-DQNI52VV.js.map +1 -0
- package/dist/{chunk-VPK6PHIE.cjs → chunk-E6QXZZKE.cjs} +8 -8
- package/dist/{chunk-VPK6PHIE.cjs.map → chunk-E6QXZZKE.cjs.map} +1 -1
- package/dist/{chunk-IU5N5224.cjs → chunk-EFETPSJZ.cjs} +17 -8
- package/dist/chunk-EFETPSJZ.cjs.map +1 -0
- package/dist/{chunk-2ZLQZHZC.cjs → chunk-ER5BOIYD.cjs} +4 -4
- package/dist/{chunk-2ZLQZHZC.cjs.map → chunk-ER5BOIYD.cjs.map} +1 -1
- package/dist/{chunk-ODBID5TG.js → chunk-FUUSIT2T.js} +234 -35
- package/dist/chunk-FUUSIT2T.js.map +1 -0
- package/dist/{chunk-VY6NKMOA.cjs → chunk-GK3UG7YQ.cjs} +34 -25
- package/dist/chunk-GK3UG7YQ.cjs.map +1 -0
- package/dist/{chunk-NQTNSHSB.cjs → chunk-HNAYCTX4.cjs} +5 -5
- package/dist/chunk-HNAYCTX4.cjs.map +1 -0
- package/dist/{chunk-QATRS7JD.cjs → chunk-MYJGWS2J.cjs} +26 -8
- package/dist/chunk-MYJGWS2J.cjs.map +1 -0
- package/dist/{chunk-KZSKIUXZ.js → chunk-N7VAE6DZ.js} +31 -3
- package/dist/chunk-N7VAE6DZ.js.map +1 -0
- package/dist/{chunk-7SZAV6QG.js → chunk-P5S3WCSZ.js} +3 -3
- package/dist/{chunk-7SZAV6QG.js.map → chunk-P5S3WCSZ.js.map} +1 -1
- package/dist/{chunk-HW7SEELD.cjs → chunk-QRVS2PRE.cjs} +31 -8
- package/dist/chunk-QRVS2PRE.cjs.map +1 -0
- package/dist/{chunk-SADXXGWU.js → chunk-R3LBRQAN.js} +3 -3
- package/dist/{chunk-NQTNSHSB.cjs.map → chunk-R3LBRQAN.js.map} +1 -1
- package/dist/{chunk-AYA65JA5.cjs → chunk-RWPLWMCZ.cjs} +25 -9
- package/dist/chunk-RWPLWMCZ.cjs.map +1 -0
- package/dist/{chunk-O7L7M42F.js → chunk-T3ZDEYTJ.js} +21 -5
- package/dist/chunk-T3ZDEYTJ.js.map +1 -0
- package/dist/{chunk-43YXGD3P.cjs → chunk-TY56BKSK.cjs} +8 -4
- package/dist/chunk-TY56BKSK.cjs.map +1 -0
- package/dist/chunk-UOLBAPDM.js +66 -0
- package/dist/chunk-UOLBAPDM.js.map +1 -0
- package/dist/{chunk-NSLHPAC7.js → chunk-X7EUUHXU.js} +6 -5
- package/dist/chunk-X7EUUHXU.js.map +1 -0
- package/dist/{chunk-WS5ULCL4.js → chunk-YRLI5DVC.js} +3 -3
- package/dist/{chunk-WS5ULCL4.js.map → chunk-YRLI5DVC.js.map} +1 -1
- package/dist/chunk-YYN6BB7R.cjs +24 -0
- package/dist/chunk-YYN6BB7R.cjs.map +1 -0
- package/dist/{chunk-C4ZQPWXJ.cjs → chunk-ZLMU5EU3.cjs} +33 -4
- package/dist/chunk-ZLMU5EU3.cjs.map +1 -0
- package/dist/{compact-session-7FMYJXQ7.cjs → compact-session-75KD2FCM.cjs} +15 -11
- package/dist/{compact-session-7FMYJXQ7.cjs.map → compact-session-75KD2FCM.cjs.map} +1 -1
- package/dist/{compact-session-YSEK7NQF.js → compact-session-QT6RJOKO.js} +3 -3
- package/dist/{compact-session-YSEK7NQF.js.map → compact-session-QT6RJOKO.js.map} +1 -1
- package/dist/context/index.cjs +11 -7
- package/dist/context/index.cjs.map +1 -1
- package/dist/context/index.js +7 -3
- package/dist/context/index.js.map +1 -1
- package/dist/context-7RP5JXGM.cjs +24 -0
- package/dist/{context-JTGSBJT6.cjs.map → context-7RP5JXGM.cjs.map} +1 -1
- package/dist/context-OJIIXJCV.js +7 -0
- package/dist/{context-3HPU754C.js.map → context-OJIIXJCV.js.map} +1 -1
- package/dist/{cron-Bgivg88c.d.cts → cron-BwxDUscv.d.cts} +1 -1
- package/dist/{cron-CNUa7PDo.d.ts → cron-D8uB1Xh5.d.ts} +1 -1
- package/dist/cron.cjs +15 -14
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +14 -13
- package/dist/eval.cjs +14 -13
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +13 -12
- package/dist/eval.js.map +1 -1
- package/dist/{index-manager-3UNPYH34.cjs → index-manager-W7RHSL6G.cjs} +6 -6
- package/dist/{index-manager-3UNPYH34.cjs.map → index-manager-W7RHSL6G.cjs.map} +1 -1
- package/dist/{index-manager-W7FDMGEG.js → index-manager-Z4XMRVWQ.js} +5 -5
- package/dist/{index-manager-W7FDMGEG.js.map → index-manager-Z4XMRVWQ.js.map} +1 -1
- package/dist/index.cjs +284 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +197 -5
- package/dist/index.d.ts +197 -5
- package/dist/index.js +249 -25
- package/dist/index.js.map +1 -1
- package/dist/{inject-session-PC73TMP2.cjs → inject-session-L6MIIELT.cjs} +4 -4
- package/dist/{inject-session-PC73TMP2.cjs.map → inject-session-L6MIIELT.cjs.map} +1 -1
- package/dist/{inject-session-J4LBWAPH.js → inject-session-XWWN4DAA.js} +3 -3
- package/dist/{inject-session-J4LBWAPH.js.map → inject-session-XWWN4DAA.js.map} +1 -1
- package/dist/internal/memory/storage/index.cjs +32 -32
- package/dist/internal/memory/storage/index.js +3 -3
- package/dist/internal/memory/storage/memory-root.d.cts +27 -0
- package/dist/internal/memory/storage/memory-root.d.ts +27 -0
- package/dist/internal/persistence/index.cjs +4 -4
- package/dist/internal/persistence/index.js +1 -1
- package/dist/internal/runtime/compat/foreign-config-sources.d.ts +17 -4
- package/dist/internal/runtime/compat/managed-settings.d.ts +80 -0
- package/dist/internal/runtime/context/context-discovery-runner.d.ts +14 -0
- package/dist/internal/runtime/context/context-discovery.d.ts +64 -0
- package/dist/internal/runtime/context/context-manager.d.ts +21 -1
- package/dist/internal/runtime/context/yaml-frontmatter.d.ts +6 -3
- package/dist/internal/runtime/hooks/hooks-executor.d.ts +13 -1
- package/dist/internal/runtime/hooks/hooks-source.d.ts +36 -1
- package/dist/internal/runtime/skills/discover-skills.d.ts +4 -0
- package/dist/internal/session/compact-session.d.ts +36 -0
- package/dist/project.cjs +3 -3
- package/dist/project.js +1 -1
- package/dist/skills.cjs +5 -5
- package/dist/skills.js +2 -2
- package/dist/subagents-loader-CJFYQQU2.js +7 -0
- package/dist/{subagents-loader-AIVDQ2D5.js.map → subagents-loader-CJFYQQU2.js.map} +1 -1
- package/dist/subagents-loader-MOO7DC4E.cjs +16 -0
- package/dist/{subagents-loader-DN4LETGL.cjs.map → subagents-loader-MOO7DC4E.cjs.map} +1 -1
- package/dist/subagents-loader.cjs +4 -4
- package/dist/subagents-loader.d.cts +1 -1
- package/dist/subagents-loader.d.ts +1 -1
- package/dist/subagents-loader.js +3 -3
- package/dist/types/agent.d.ts +7 -2
- package/docs/error-codes.md +20 -18
- package/docs/harness-capability-map.md +9 -1
- package/package.json +1 -1
- package/dist/chunk-2XRAWOZZ.js.map +0 -1
- package/dist/chunk-43YXGD3P.cjs.map +0 -1
- package/dist/chunk-AYA65JA5.cjs.map +0 -1
- package/dist/chunk-C4ZQPWXJ.cjs.map +0 -1
- package/dist/chunk-HW7SEELD.cjs.map +0 -1
- package/dist/chunk-IU5N5224.cjs.map +0 -1
- package/dist/chunk-JNAA4G4H.js +0 -43
- package/dist/chunk-JNAA4G4H.js.map +0 -1
- package/dist/chunk-KZSKIUXZ.js.map +0 -1
- package/dist/chunk-LOHMT36V.cjs.map +0 -1
- package/dist/chunk-LX7SEXOQ.js.map +0 -1
- package/dist/chunk-N6OOOYFZ.js.map +0 -1
- package/dist/chunk-NSLHPAC7.js.map +0 -1
- package/dist/chunk-O7L7M42F.js.map +0 -1
- package/dist/chunk-ODBID5TG.js.map +0 -1
- package/dist/chunk-QATRS7JD.cjs.map +0 -1
- package/dist/chunk-S6B5XYC3.js.map +0 -1
- package/dist/chunk-SADXXGWU.js.map +0 -1
- package/dist/chunk-UKJJRU7C.cjs.map +0 -1
- package/dist/chunk-VY6NKMOA.cjs.map +0 -1
- package/dist/context-3HPU754C.js +0 -6
- package/dist/context-JTGSBJT6.cjs +0 -23
- package/dist/subagents-loader-AIVDQ2D5.js +0 -7
- package/dist/subagents-loader-DN4LETGL.cjs +0 -16
|
@@ -50,12 +50,24 @@ export declare class HooksExecutor {
|
|
|
50
50
|
private readonly compatSources;
|
|
51
51
|
/** #631 — the consumer's chance to refuse a command before it is spawned. */
|
|
52
52
|
private readonly gate;
|
|
53
|
+
/**
|
|
54
|
+
* B-026 — the operator tier. `managedSettingsRoot` exists so the precedence rule is testable;
|
|
55
|
+
* production passes nothing and the platform path is resolved.
|
|
56
|
+
*/
|
|
57
|
+
private readonly policy;
|
|
53
58
|
private config;
|
|
54
59
|
constructor(cwd: string,
|
|
55
60
|
/** Declared foreign dialects (#524). Empty reads `.theokit/` only. */
|
|
56
61
|
compatSources?: readonly CompatSourceDeclaration[],
|
|
57
62
|
/** #631 — the consumer's chance to refuse a command before it is spawned. */
|
|
58
|
-
gate?: HookApprovalGate | undefined
|
|
63
|
+
gate?: HookApprovalGate | undefined,
|
|
64
|
+
/**
|
|
65
|
+
* B-026 — the operator tier. `managedSettingsRoot` exists so the precedence rule is testable;
|
|
66
|
+
* production passes nothing and the platform path is resolved.
|
|
67
|
+
*/
|
|
68
|
+
policy?: {
|
|
69
|
+
readonly managedSettingsRoot?: string;
|
|
70
|
+
});
|
|
59
71
|
initialize(settingSourcesIncludeProject: boolean): Promise<void>;
|
|
60
72
|
/** Fire every hook registered for `event` and aggregate the decisions. */
|
|
61
73
|
run(payload: HookPayload): Promise<HookExecutionResult>;
|
|
@@ -8,14 +8,49 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Consumed by `hooks-executor.ts` (runtime dispatch).
|
|
10
10
|
*
|
|
11
|
-
* Config
|
|
11
|
+
* Config SHAPE is Claude Code's `settings.json` hooks:
|
|
12
12
|
* { "hooks": { "PreToolUse": [ { "matcher": "shell",
|
|
13
13
|
* "hooks": [ { "type": "command", "command": "…", "timeout": 30 } ] } ] } }
|
|
14
14
|
*
|
|
15
|
+
* The shape, not the event COVERAGE. Four of the thirty-three documented events are fired by this
|
|
16
|
+
* runtime — see {@link CLAUDE_CODE_EVENT_MAP} for which, why the rest are refused rather than
|
|
17
|
+
* mapped, and the order in which they should be added. An event outside the set is reported to the
|
|
18
|
+
* operator rather than skipped in silence.
|
|
19
|
+
*
|
|
15
20
|
* @internal
|
|
16
21
|
*/
|
|
17
22
|
/** The five lifecycle events the SDK runtime actually fires. */
|
|
18
23
|
export type HookEvent = "preRun" | "postRun" | "preToolUse" | "postToolUse" | "stop";
|
|
24
|
+
/**
|
|
25
|
+
* The Claude Code event names this runtime actually FIRES, and the internal event each becomes.
|
|
26
|
+
*
|
|
27
|
+
* Exported so the supported set is stated rather than implied. It used to be private, and the
|
|
28
|
+
* docblock above claimed a shape "identical to Claude Code's `settings.json` hooks" while accepting
|
|
29
|
+
* four of the thirty-three documented events — a claim nothing could contradict.
|
|
30
|
+
*
|
|
31
|
+
* A Claude Code event with no firing point here — `SessionStart`, `SubagentStop`, `PreCompact`,
|
|
32
|
+
* `Notification`, `SessionEnd` among them — is skipped with a report rather than silently accepted,
|
|
33
|
+
* because it would never run.
|
|
34
|
+
*
|
|
35
|
+
* ## Why this map is not simply grown
|
|
36
|
+
*
|
|
37
|
+
* Mapping a name the runtime does not fire is strictly WORSE than refusing it. An operator declaring
|
|
38
|
+
* `PreCompact` today gets a report saying it will not fire; with the name mapped they would get
|
|
39
|
+
* silence and a guard that never runs — a declared veto that does not exist. The map grows when the
|
|
40
|
+
* seam exists, one event at a time.
|
|
41
|
+
*
|
|
42
|
+
* ## Priority, when it does grow
|
|
43
|
+
*
|
|
44
|
+
* The blocking events first. An unwired veto loses a CAPABILITY; an unwired observer loses a
|
|
45
|
+
* SIGNAL. Thirteen of the sixteen the spec marks "Can block? Yes" are unwired, and
|
|
46
|
+
* `tests/internal/runtime/hooks/the-supported-event-set-is-stated.test.ts` lists them in the order
|
|
47
|
+
* they should be taken, so the next person does not re-derive which is which.
|
|
48
|
+
*
|
|
49
|
+
* `postRun` is reachable through this SDK's own config and has no entry here on purpose: it fires
|
|
50
|
+
* per RUN, and no documented Claude Code event means that. `SessionEnd` is the near miss, and a
|
|
51
|
+
* session is not a run.
|
|
52
|
+
*/
|
|
53
|
+
export declare const CLAUDE_CODE_EVENT_MAP: Readonly<Record<string, HookEvent>>;
|
|
19
54
|
export interface HookCommand {
|
|
20
55
|
command: string;
|
|
21
56
|
matcher?: string;
|
|
@@ -13,6 +13,10 @@ export interface Skill {
|
|
|
13
13
|
source: string;
|
|
14
14
|
category?: string;
|
|
15
15
|
dependencies?: string[];
|
|
16
|
+
/** `disable-model-invocation: true` — the model is never told this skill exists. */
|
|
17
|
+
disableModelInvocation?: boolean;
|
|
18
|
+
/** `user-invocable: false` — carried for a host that has a picker; this SDK has no such surface. */
|
|
19
|
+
userInvocable?: boolean;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* Information passed to `onInvalidSkill` when a `SKILL.md` is present but its
|
|
@@ -30,6 +30,31 @@ export interface CompactResult {
|
|
|
30
30
|
}
|
|
31
31
|
/** Is this message a summary produced by a PRIOR compaction? (filtered from verbatim preservation). */
|
|
32
32
|
export declare function isCompactSummary(content: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* What a pre-compaction handler is told, and what it is given to bail out with.
|
|
35
|
+
*
|
|
36
|
+
* `trigger` is READ from the compaction that is happening, never inferred from the call site: the
|
|
37
|
+
* inference would be right today and silently wrong the first time a third caller appears.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export interface PreCompactContext {
|
|
42
|
+
/** The messages about to be summarised — what the handler gets a last look at. */
|
|
43
|
+
readonly messages: readonly CompressibleMessage[];
|
|
44
|
+
/** `manual` when a person asked, `auto` when a usage threshold did. */
|
|
45
|
+
readonly trigger: "manual" | "auto";
|
|
46
|
+
/** Aborted when the bound fires, so a long handler can stop rather than be merely ignored. */
|
|
47
|
+
readonly signal: AbortSignal;
|
|
48
|
+
}
|
|
49
|
+
/** @public */
|
|
50
|
+
export type PreCompactHandler = (ctx: PreCompactContext) => void | Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* The bound, in milliseconds, when the caller does not choose one.
|
|
53
|
+
*
|
|
54
|
+
* Same value as `@theokit/agents`' `withPreCompaction`, because B-082's requirement is the same
|
|
55
|
+
* contract as B-002 and not a second one.
|
|
56
|
+
*/
|
|
57
|
+
export declare const DEFAULT_PRE_COMPACT_TIMEOUT_MS = 30000;
|
|
33
58
|
/**
|
|
34
59
|
* Compact one session transcript: summarize the reconstructed history, then append (append-only)
|
|
35
60
|
* a `compact_boundary` + the replacement chain (recent user messages verbatim + marker'd summary).
|
|
@@ -42,6 +67,17 @@ export declare function compactSessionTranscript(opts: {
|
|
|
42
67
|
sessionId: string;
|
|
43
68
|
trigger: "manual" | "auto";
|
|
44
69
|
summarize: (messages: readonly CompressibleMessage[]) => Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Work to run before the transcript is rewritten, on the path the caller actually took.
|
|
72
|
+
*
|
|
73
|
+
* Absent, nothing is entered and the path is byte-identical to before B-082 — asserted by a test
|
|
74
|
+
* rather than left as an inference.
|
|
75
|
+
*/
|
|
76
|
+
onPreCompact?: PreCompactHandler;
|
|
77
|
+
/** Where a handler's failure or timeout is reported. Compaction proceeds either way. */
|
|
78
|
+
onPreCompactError?: (error: unknown) => void;
|
|
79
|
+
/** Overrides {@link DEFAULT_PRE_COMPACT_TIMEOUT_MS}. */
|
|
80
|
+
preCompactTimeoutMs?: number;
|
|
45
81
|
}): Promise<CompactResult>;
|
|
46
82
|
/**
|
|
47
83
|
* M50 review F6 (fixed by the probe) — the summarizer's provider route, PURE and unit-tested.
|
package/dist/project.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk7KBNBPFK_cjs = require('./chunk-7KBNBPFK.cjs');
|
|
4
4
|
var chunkJLRLCBJ4_cjs = require('./chunk-JLRLCBJ4.cjs');
|
|
5
5
|
var chunkJ7J7J2GN_cjs = require('./chunk-J7J7J2GN.cjs');
|
|
6
6
|
require('./chunk-6LHQPOMI.cjs');
|
|
@@ -11,7 +11,7 @@ var DEFAULT_FILENAME = "THEO.md";
|
|
|
11
11
|
async function readProjectInstructions(cwd, options) {
|
|
12
12
|
const filename = options?.filename ?? DEFAULT_FILENAME;
|
|
13
13
|
const scope = options?.scope ?? "nearest";
|
|
14
|
-
const paths =
|
|
14
|
+
const paths = chunk7KBNBPFK_cjs.walkUpForFile(cwd, filename, options?.stopDir);
|
|
15
15
|
const files = [];
|
|
16
16
|
for (const path of paths) {
|
|
17
17
|
try {
|
|
@@ -30,7 +30,7 @@ function reduceContent(files, scope) {
|
|
|
30
30
|
}
|
|
31
31
|
async function writeProjectInstructions(cwd, content, options) {
|
|
32
32
|
const filename = options?.filename ?? DEFAULT_FILENAME;
|
|
33
|
-
if (!
|
|
33
|
+
if (!chunk7KBNBPFK_cjs.isSafePattern(filename)) {
|
|
34
34
|
throw new chunkJ7J7J2GN_cjs.ConfigurationError(
|
|
35
35
|
`writeProjectInstructions: unsafe filename ${JSON.stringify(filename)} (no path traversal, separators, or absolute paths)`,
|
|
36
36
|
{ code: "unsafe_filename" }
|
package/dist/project.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { walkUpForFile, isSafePattern } from './chunk-
|
|
1
|
+
import { walkUpForFile, isSafePattern } from './chunk-A6PDYH55.js';
|
|
2
2
|
import { replaceFileAtomic } from './chunk-3JHIFQ4I.js';
|
|
3
3
|
import { ConfigurationError } from './chunk-ALUN2B4W.js';
|
|
4
4
|
import './chunk-CZJ6Q7CW.js';
|
package/dist/skills.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMYJGWS2J_cjs = require('./chunk-MYJGWS2J.cjs');
|
|
4
4
|
require('./chunk-7A6535RA.cjs');
|
|
5
5
|
require('./chunk-SA6K24NB.cjs');
|
|
6
|
-
require('./chunk-
|
|
6
|
+
require('./chunk-QRVS2PRE.cjs');
|
|
7
7
|
require('./chunk-J7J7J2GN.cjs');
|
|
8
8
|
require('./chunk-6LHQPOMI.cjs');
|
|
9
9
|
|
|
@@ -11,15 +11,15 @@ require('./chunk-6LHQPOMI.cjs');
|
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "buildSkillsBlock", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkMYJGWS2J_cjs.buildSkillsBlock; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "discoverSkills", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkMYJGWS2J_cjs.discoverSkills; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "loadSkillInstructions", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkMYJGWS2J_cjs.loadSkillInstructions; }
|
|
23
23
|
});
|
|
24
24
|
//# sourceMappingURL=skills.cjs.map
|
|
25
25
|
//# sourceMappingURL=skills.cjs.map
|
package/dist/skills.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { buildSkillsBlock, discoverSkills, loadSkillInstructions } from './chunk-
|
|
1
|
+
export { buildSkillsBlock, discoverSkills, loadSkillInstructions } from './chunk-CA5VUAP3.js';
|
|
2
2
|
import './chunk-EH6XD3FY.js';
|
|
3
3
|
import './chunk-UKMBRMGT.js';
|
|
4
|
-
import './chunk-
|
|
4
|
+
import './chunk-UOLBAPDM.js';
|
|
5
5
|
import './chunk-ALUN2B4W.js';
|
|
6
6
|
import './chunk-CZJ6Q7CW.js';
|
|
7
7
|
//# sourceMappingURL=skills.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { loadSubagents } from './chunk-T3ZDEYTJ.js';
|
|
2
|
+
import './chunk-X7EUUHXU.js';
|
|
3
|
+
import './chunk-UOLBAPDM.js';
|
|
4
|
+
import './chunk-ALUN2B4W.js';
|
|
5
|
+
import './chunk-CZJ6Q7CW.js';
|
|
6
|
+
//# sourceMappingURL=subagents-loader-CJFYQQU2.js.map
|
|
7
|
+
//# sourceMappingURL=subagents-loader-CJFYQQU2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"subagents-loader-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"subagents-loader-CJFYQQU2.js"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkRWPLWMCZ_cjs = require('./chunk-RWPLWMCZ.cjs');
|
|
4
|
+
require('./chunk-TY56BKSK.cjs');
|
|
5
|
+
require('./chunk-QRVS2PRE.cjs');
|
|
6
|
+
require('./chunk-J7J7J2GN.cjs');
|
|
7
|
+
require('./chunk-6LHQPOMI.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Object.defineProperty(exports, "loadSubagents", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkRWPLWMCZ_cjs.loadSubagents; }
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=subagents-loader-MOO7DC4E.cjs.map
|
|
16
|
+
//# sourceMappingURL=subagents-loader-MOO7DC4E.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"subagents-loader-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"subagents-loader-MOO7DC4E.cjs"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
5
|
-
require('./chunk-
|
|
3
|
+
var chunkRWPLWMCZ_cjs = require('./chunk-RWPLWMCZ.cjs');
|
|
4
|
+
require('./chunk-TY56BKSK.cjs');
|
|
5
|
+
require('./chunk-QRVS2PRE.cjs');
|
|
6
6
|
var chunkJ7J7J2GN_cjs = require('./chunk-J7J7J2GN.cjs');
|
|
7
7
|
require('./chunk-6LHQPOMI.cjs');
|
|
8
8
|
|
|
@@ -23,7 +23,7 @@ function resolveSources(options) {
|
|
|
23
23
|
}
|
|
24
24
|
async function discoverSubagents(cwd, options) {
|
|
25
25
|
const sources = resolveSources(options);
|
|
26
|
-
return
|
|
26
|
+
return chunkRWPLWMCZ_cjs.loadSubagents(cwd, sources.includes("project"), void 0, options?.compatSources ?? []);
|
|
27
27
|
}
|
|
28
28
|
async function loadSubagentDefinition(name, cwd, options) {
|
|
29
29
|
return (await discoverSubagents(cwd, options))[name];
|
package/dist/subagents-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { loadSubagents } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
import { loadSubagents } from './chunk-T3ZDEYTJ.js';
|
|
2
|
+
import './chunk-X7EUUHXU.js';
|
|
3
|
+
import './chunk-UOLBAPDM.js';
|
|
4
4
|
import { ConfigurationError } from './chunk-ALUN2B4W.js';
|
|
5
5
|
import './chunk-CZJ6Q7CW.js';
|
|
6
6
|
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type SettingSource = "project" | "user" | "team" | "mdm" | "plugins" | "a
|
|
|
31
31
|
*
|
|
32
32
|
* @public
|
|
33
33
|
*/
|
|
34
|
-
export type CompatSource = "claude-code" | "theokit" | CompatSourceAdapter;
|
|
34
|
+
export type CompatSource = "claude-code" | "theokit" | "agents" | "gemini" | "cursor" | CompatSourceAdapter;
|
|
35
35
|
/**
|
|
36
36
|
* A surface a foreign configuration source may be admitted to.
|
|
37
37
|
*
|
|
@@ -40,9 +40,14 @@ export type CompatSource = "claude-code" | "theokit" | CompatSourceAdapter;
|
|
|
40
40
|
* Reusing the skills you already wrote for another product is a reasonable thing to want, and it is
|
|
41
41
|
* not a reason to hand that product's directory the right to run commands.
|
|
42
42
|
*
|
|
43
|
+
* `context` is the foreign root's INSTRUCTIONS — `.claude/rules/*.md`. Same risk class as `skills`:
|
|
44
|
+
* text a cloned repository wrote, entering the system prompt as if the consumer had written it. It
|
|
45
|
+
* was missing until usetheokit/theokit-sdk#652, so the four surfaces above failed closed while this
|
|
46
|
+
* one was admitted by a path that consulted no grant at all.
|
|
47
|
+
*
|
|
43
48
|
* @public
|
|
44
49
|
*/
|
|
45
|
-
export type CompatSurface = "hooks" | "plugins" | "skills" | "subagents";
|
|
50
|
+
export type CompatSurface = "context" | "hooks" | "plugins" | "skills" | "subagents";
|
|
46
51
|
/**
|
|
47
52
|
* A foreign source admitted to named surfaces only.
|
|
48
53
|
*
|
package/docs/error-codes.md
CHANGED
|
@@ -6,7 +6,7 @@ Branch on `code`, never on the message: messages carry context (an id, a path, a
|
|
|
6
6
|
|
|
7
7
|
**Transport codes vs the rest.** `ErrorCode` in `errors.ts` is the small canonical union a provider failure maps onto — the codes marked *transport* below. Everything else is raised by a specific subsystem at a specific place, and a `catch` that only handles the union will meet them anyway.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
243 distinct code(s).
|
|
10
10
|
|
|
11
11
|
| Code | Kind | Raised by | Sites |
|
|
12
12
|
|---|---|---|---|
|
|
@@ -47,18 +47,18 @@ Branch on `code`, never on the message: messages carry context (an id, a path, a
|
|
|
47
47
|
| `cloud_stdio_cwd_rejected` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/validation/validate-agent-options.ts:121` |
|
|
48
48
|
| `compression_failed` | domain | — | `packages/sdk/src/internal/runtime/compression/compression-summarizer.ts:41` |
|
|
49
49
|
| `compression_model_unresolved` | domain | — | `packages/sdk/src/internal/runtime/compression/compression-model-registry.ts:102` +1 |
|
|
50
|
-
| `context_config_shape` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/context/context-manager.ts:
|
|
50
|
+
| `context_config_shape` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/context/context-manager.ts:288` |
|
|
51
51
|
| `context_frontmatter_invalid` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/context/context-frontmatter.ts:38` |
|
|
52
|
-
| `context_json_invalid` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/context/context-manager.ts:
|
|
53
|
-
| `context_read_error` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/context/context-manager.ts:
|
|
54
|
-
| `context_sources_shape` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/context/context-manager.ts:
|
|
52
|
+
| `context_json_invalid` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/context/context-manager.ts:282` |
|
|
53
|
+
| `context_read_error` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/context/context-manager.ts:269` |
|
|
54
|
+
| `context_sources_shape` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/context/context-manager.ts:309` |
|
|
55
55
|
| `credential_pool_ambiguous` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/validation/validate-agent-options.ts:68` +1 |
|
|
56
56
|
| `credential_pool_empty` | domain | ConfigurationError | `packages/sdk/src/internal/llm/credential-pool.ts:91` |
|
|
57
57
|
| `cron_ambiguous_target` | domain | ConfigurationError | `packages/sdk/src/cron.ts:215` |
|
|
58
58
|
| `cron_missing_message` | domain | ConfigurationError | `packages/sdk/src/cron.ts:233` +1 |
|
|
59
59
|
| `cron_no_target` | domain | ConfigurationError | `packages/sdk/src/cron.ts:221` +1 |
|
|
60
60
|
| `cron_workflow_message` | domain | ConfigurationError | `packages/sdk/src/cron.ts:227` |
|
|
61
|
-
| `duplicate_skill_name` | domain | ConfigurationError | `packages/sdk/src/define-skill-read-tool.ts:
|
|
61
|
+
| `duplicate_skill_name` | domain | ConfigurationError | `packages/sdk/src/define-skill-read-tool.ts:155` |
|
|
62
62
|
| `duplicate_tool_name` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/validation/validate-agent-options.ts:201` |
|
|
63
63
|
| `effective_tools_expected_options` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/validation/effective-tools.ts:102` +1 |
|
|
64
64
|
| `embedding_dimension_mismatch` | domain | ConfigurationError | `packages/sdk/src/internal/memory/lance-index.ts:146` +1 |
|
|
@@ -79,10 +79,11 @@ Branch on `code`, never on the message: messages carry context (an id, a path, a
|
|
|
79
79
|
| `handoff_target_required` | domain | ConfigurationError | `packages/sdk-handoff/src/handoff.ts:111` |
|
|
80
80
|
| `hitl_timeout` | domain | HitlTimeoutError | `packages/sdk/src/internal/runtime/tools/hitl-middleware.ts:42` +1 |
|
|
81
81
|
| `hook_denied` | domain | ConfigurationError | `packages/sdk/src/internal/local-agent/local-agent.ts:454` |
|
|
82
|
-
| `hooks_invalid_command` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/hooks/hooks-source.ts:
|
|
83
|
-
| `hooks_json_invalid` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/hooks/hooks-source.ts:
|
|
84
|
-
| `hooks_read_error` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/hooks/hooks-source.ts:
|
|
85
|
-
| `
|
|
82
|
+
| `hooks_invalid_command` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/hooks/hooks-source.ts:406` |
|
|
83
|
+
| `hooks_json_invalid` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/hooks/hooks-source.ts:252` +2 |
|
|
84
|
+
| `hooks_read_error` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/hooks/hooks-source.ts:243` |
|
|
85
|
+
| `hooks_unsupported_field` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/hooks/hooks-source.ts:384` |
|
|
86
|
+
| `hooks_unsupported_type` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/hooks/hooks-source.ts:400` |
|
|
86
87
|
| `interactive_unavailable` | domain | InteractiveUnavailableError | `packages/sdk/src/interactive/types.ts:28` +1 |
|
|
87
88
|
| `INTERNAL_SERVER_ERROR` | domain | — | `packages/sdk/src/server/errors-envelope.ts:100` |
|
|
88
89
|
| `invalid_argument` | domain | TheokitAgentError | `packages/sdk/src/compaction.ts:79` |
|
|
@@ -99,7 +100,7 @@ Branch on `code`, never on the message: messages carry context (an id, a path, a
|
|
|
99
100
|
| `invalid_input` | domain | MemoryAdapterError | `packages/memory-honcho/src/adapter.ts:98` +9 |
|
|
100
101
|
| `invalid_max_iterations` | domain | ConfigurationError | `packages/sdk/src/internal/local-agent/real-local-run.ts:71` |
|
|
101
102
|
| `invalid_memory_backend` | domain | ConfigurationError | `packages/sdk/src/internal/memory/index-manager-dispatch.ts:24` +1 |
|
|
102
|
-
| `invalid_memory_directory` | domain | ConfigurationError | `packages/sdk/src/internal/memory/storage/memory-root.ts:
|
|
103
|
+
| `invalid_memory_directory` | domain | ConfigurationError | `packages/sdk/src/internal/memory/storage/memory-root.ts:151` |
|
|
103
104
|
| `invalid_memory_kind` | domain | ConfigurationError | `packages/sdk/src/internal/memory/storage/markdown-store.ts:206` |
|
|
104
105
|
| `invalid_model_selection` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/model-selection.ts:21` |
|
|
105
106
|
| `invalid_processor_options` | domain | ConfigurationError | `packages/sdk/src/built-in-processors.ts:86` |
|
|
@@ -136,7 +137,7 @@ Branch on `code`, never on the message: messages carry context (an id, a path, a
|
|
|
136
137
|
| `migration_destination_exists` | domain | ConfigurationError | `packages/sdk/src/internal/memory/migrate-sqlite-to-lance.ts:159` +1 |
|
|
137
138
|
| `missing_api_key` | domain | AuthenticationError, ConfigurationError | `packages/sdk/src/internal/agent/helpers.ts:215` +2 |
|
|
138
139
|
| `missing_credential` | domain | AuthenticationError | `packages/sdk/src/internal/providers/builtin/openai-chatgpt.ts:72` |
|
|
139
|
-
| `missing_frontmatter` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/skill-frontmatter.ts:
|
|
140
|
+
| `missing_frontmatter` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/skill-frontmatter.ts:88` |
|
|
140
141
|
| `missing_model` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/validation/validate-agent-options.ts:35` |
|
|
141
142
|
| `model_unavailable` | domain | buildErrorMetadata | `packages/sdk/src/internal/error-mappers/ollama.ts:75` +1 |
|
|
142
143
|
| `network` | domain | MemoryAdapterError, buildErrorMetadata | `packages/memory-honcho/src/adapter.ts:258` +5 |
|
|
@@ -161,6 +162,7 @@ Branch on `code`, never on the message: messages carry context (an id, a path, a
|
|
|
161
162
|
| `parse_failed` | domain | — | `packages/sdk/src/errors.ts:653` |
|
|
162
163
|
| `path_traversal` | domain | — | `packages/sdk/src/internal/security/path-guard.ts:37` |
|
|
163
164
|
| `permission_enforcement_unavailable` | domain | ConfigurationError | `packages/acp/src/permission-plugin.ts:138` +1 |
|
|
165
|
+
| `permission_rule_invalid` | domain | ConfigurationError | `packages/sdk/src/permission-rules.ts:82` +2 |
|
|
164
166
|
| `personality_empty_body` | domain | ConfigurationError | `packages/sdk/src/internal/personality/registry.ts:117` |
|
|
165
167
|
| `personality_not_found` | domain | ConfigurationError | `packages/sdk/src/internal/personality/switch.ts:60` |
|
|
166
168
|
| `personality_reserved_name` | domain | ConfigurationError | `packages/sdk/src/internal/personality/registry.ts:110` |
|
|
@@ -184,7 +186,7 @@ Branch on `code`, never on the message: messages carry context (an id, a path, a
|
|
|
184
186
|
| `sandbox_derived_helper_failed` | domain | ConfigurationError | `packages/sdk/src/sandbox/types.ts:185` +1 |
|
|
185
187
|
| `sandbox_not_available` | domain | SandboxNotAvailableError | `packages/sdk/src/sandbox/types.ts:92` +1 |
|
|
186
188
|
| `sandbox_security` | domain | SandboxSecurityError | `packages/sdk/src/sandbox/types.ts:73` +1 |
|
|
187
|
-
| `schema_invalid` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/skill-frontmatter.ts:
|
|
189
|
+
| `schema_invalid` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/skill-frontmatter.ts:99` +5 |
|
|
188
190
|
| `server_error` | domain | buildErrorMetadata | `packages/sdk/src/internal/error-mappers/ollama.ts:92` +1 |
|
|
189
191
|
| `session_busy` | domain | — | `packages/sdk/src/internal/persistence/session-writer.ts:56` +1 |
|
|
190
192
|
| `sql_injection_blocked` | domain | ConfigurationError | `packages/sdk/src/internal/memory/lance-index.ts:256` +3 |
|
|
@@ -196,13 +198,13 @@ Branch on `code`, never on the message: messages carry context (an id, a path, a
|
|
|
196
198
|
| `ssrf_blocked` | domain | — | `packages/sdk-tools/src/internal/network-guard.ts:23` |
|
|
197
199
|
| `stream_idle_timeout` | domain | NetworkError | `packages/sdk/src/internal/llm/sse.ts:95` |
|
|
198
200
|
| `stream_truncated` | domain | NetworkError | `packages/sdk/src/internal/llm/anthropic.ts:184` +1 |
|
|
199
|
-
| `subagent_mcp_unsupported_local` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:
|
|
201
|
+
| `subagent_mcp_unsupported_local` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:207` |
|
|
200
202
|
| `subagent_missing_description` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/validation/validate-agent-options.ts:142` |
|
|
201
|
-
| `subagent_missing_frontmatter` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:
|
|
203
|
+
| `subagent_missing_frontmatter` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:284` |
|
|
202
204
|
| `subagent_missing_prompt` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/validation/validate-agent-options.ts:147` |
|
|
203
|
-
| `subagent_reasoning_effort_without_model` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:
|
|
204
|
-
| `subagent_sandbox_not_boolean` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:
|
|
205
|
-
| `subagent_unknown_field` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:
|
|
205
|
+
| `subagent_reasoning_effort_without_model` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:227` |
|
|
206
|
+
| `subagent_sandbox_not_boolean` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:247` |
|
|
207
|
+
| `subagent_unknown_field` | domain | ConfigurationError | `packages/sdk/src/internal/runtime/skills/subagents-loader.ts:192` |
|
|
206
208
|
| `subagent_unknown_setting_source` | domain | ConfigurationError | `packages/sdk/src/subagents-loader.ts:96` |
|
|
207
209
|
| `subscribe_baseUrl_missing` | domain | SubscriptionError | `packages/sdk/src/subscription/theokit-subscribe.ts:77` |
|
|
208
210
|
| `subscribe_name_invalid` | domain | SubscriptionError | `packages/sdk/src/subscription/theokit-subscribe.ts:72` |
|
|
@@ -4,7 +4,7 @@ Every public symbol the TheoKit workspace publishes, and the exact specifier to
|
|
|
4
4
|
|
|
5
5
|
A symbol listed under two specifiers is reachable from both, but that does NOT make the two interchangeable: a class emitted separately into a subpath entry is a distinct nominal type from the one in the root bundle, so passing one where the other is expected fails on a private field. When a symbol appears twice, import it and everything it is passed to from the SAME specifier.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
1212 export(s) across 46 entry point(s).
|
|
8
8
|
|
|
9
9
|
## `@theokit/acp`
|
|
10
10
|
|
|
@@ -200,6 +200,7 @@ A symbol listed under two specifiers is reachable from both, but that does NOT m
|
|
|
200
200
|
| `InteractionUpdate` | type | Lowest-level raw update from a run. |
|
|
201
201
|
| `InvalidateCacheOptions` | interface | Options for {@link SDKAgent.invalidateCache } . |
|
|
202
202
|
| `InvalidTaskIdError` | class | Thrown when a user-supplied task ID violates the grammar `^[a-z0-9][a-z0-9_-]*$` (D368) OR starts with a reserved adapter prefix (`wf-` / `b-` / `cron-`, EC-5). |
|
|
203
|
+
| `isInside` | function | Whether `child` is inside `parent`. |
|
|
203
204
|
| `isTransientError` | function | Is this error transient (worth retrying)? |
|
|
204
205
|
| `isValidTaskId` | function | Validates a task ID against the public grammar + reserved prefixes. |
|
|
205
206
|
| `JobQueue` | class | An in-process queue of background jobs with status tracking, cancellation, and an optional concurrency bound. |
|
|
@@ -218,6 +219,8 @@ A symbol listed under two specifiers is reachable from both, but that does NOT m
|
|
|
218
219
|
| `LiveSessionReason` | type | Why the destruction was refused. |
|
|
219
220
|
| `loadProjectEnv` | function | Read the project's `.env` into `env`, then restore every {@link SOVEREIGN_ENV_KEYS } entry to the value it had BEFORE the load — including restoring it to absent. |
|
|
220
221
|
| `LocalOptions` | interface | Local agent configuration. |
|
|
222
|
+
| `ManagedSettings` | interface | What an operator may impose. |
|
|
223
|
+
| `managedSettingsPathFor` | function | Where the platform keeps its managed settings. |
|
|
221
224
|
| `McpAuthConfig` | interface | OAuth-style auth bundle for HTTP/SSE MCP servers. |
|
|
222
225
|
| `McpHttpServerConfig` | type | HTTP or SSE MCP server. |
|
|
223
226
|
| `McpOAuthConfig` | interface | OAuth 2.1 PKCE flow descriptor. |
|
|
@@ -257,10 +260,13 @@ A symbol listed under two specifiers is reachable from both, but that does NOT m
|
|
|
257
260
|
| `normalizeUsage` | function | Convert a provider's raw `usage` object into the SDK's canonical `TokenUsage`. |
|
|
258
261
|
| `OTelSpan` | interface | The subset of the OpenTelemetry `Span` API this SDK calls. |
|
|
259
262
|
| `OutputProcessorContext` | interface | Context passed to {@link Processor.processOutput } . |
|
|
263
|
+
| `parsePermissionRules` | function | Parse a rule set into engine rules, DENY first. |
|
|
260
264
|
| `PartialToolCallUpdate` | interface | Tool call arguments streaming in incrementally. |
|
|
261
265
|
| `PermissionAction` | type | `PermissionEngine` — first-match permission rules for tool invocations. |
|
|
262
266
|
| `PermissionEngine` | class | Ordered first-match permission rules for tool invocations — the policy object you hand to `PermissionPlugin.create()` to have it enforced. |
|
|
263
267
|
| `PermissionEngineOptions` | interface | Options for {@link PermissionEngine } . |
|
|
268
|
+
| `PermissionFloorContext` | interface | Where the floor is anchored. |
|
|
269
|
+
| `permissionFloorReason` | function | Why this call may not be approved, or `undefined` when the floor has no objection. |
|
|
264
270
|
| `PermissionGate` | type | SE1 — the enriched `canUseTool` gate (the Anthropic-parity shape). |
|
|
265
271
|
| `PermissionGateContext` | interface | SE1 — context passed to the {@link PermissionGate } . |
|
|
266
272
|
| `PermissionGateDecision` | type | SE1 — the resolution of an `"ask"` verdict by the host gate. |
|
|
@@ -268,6 +274,7 @@ A symbol listed under two specifiers is reachable from both, but that does NOT m
|
|
|
268
274
|
| `PermissionPlugin` | class | SE36 — `PermissionPlugin.create` replaces `createPermissionPlugin` (ADR 0015). |
|
|
269
275
|
| `PermissionPluginOptions` | interface | Options for {@link createPermissionPlugin } . |
|
|
270
276
|
| `PermissionRule` | interface | One entry in a {@link PermissionEngine } 's ordered rule list. |
|
|
277
|
+
| `PermissionRuleSet` | interface | A policy as an operator writes it: three lists of rule strings. |
|
|
271
278
|
| `PersonalityPreset` | interface | Resolved personality preset surfaced via {@link SDKAgent.usePersonality } (Hermes #26, ADRs D160-D169). |
|
|
272
279
|
| `planReaping` | function | Sort artifacts into keep, reap, and undetermined — and delete nothing. |
|
|
273
280
|
| `Plugin` | type | SE36 — `Plugin.create` replaces `definePlugin` (ADR 0015). |
|
|
@@ -293,6 +300,7 @@ A symbol listed under two specifiers is reachable from both, but that does NOT m
|
|
|
293
300
|
| `ProviderTransform` | interface | M41 — the one OPTIONAL behavior seam on a provider profile. |
|
|
294
301
|
| `ProviderTransformContext` | interface | M41 (agent-builder provider framework) — the context a provider's `transform` receives per request. |
|
|
295
302
|
| `RateLimitError` | class | Too many requests or usage limits exceeded. |
|
|
303
|
+
| `readManagedSettings` | function | Read the deployed policy, or `{}` when none is. |
|
|
296
304
|
| `readSessionMessages` | function | Read the messages a session already contains, for a surface that needs to re-render it. |
|
|
297
305
|
| `ReadSessionMessagesOptions` | interface | Which session to read, in the terms a host already has. |
|
|
298
306
|
| `ReapableArtifact` | interface | One artifact the caller is considering deleting, described well enough to decide about. |
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/runtime/context/context-discovery.ts"],"names":[],"mappings":"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","file":"chunk-2XRAWOZZ.js","sourcesContent":["/**\n * Context file discovery (T1.1, ADRs D150 / D151).\n *\n * Discovers context files via three scopes:\n * - `cwd-only` — single dir, single path lookup\n * - `git-root-walk` — walk cwd → git-root, collect every directory's match\n * (nearest-first ordering)\n * - `globbed` — glob pattern relative to cwd (e.g. `.cursor/rules/*.mdc`)\n *\n * Pure `existsSync` checks — **no `.gitignore` parsing** (EC-A, KISS) and\n * **no invented `.theokitignore`** (EC-B). Paths normalized via\n * `realpath` to dedup symlink chains pointing to the same physical file\n * (EC-F). Git worktrees work transparently because `.git` exists as a\n * file in that case (EC-N).\n *\n * @internal\n */\n\nimport { existsSync, realpathSync } from \"node:fs\";\nimport { glob } from \"node:fs/promises\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\n\n/** Single filename (\"AGENTS.md\") or relative glob (\".cursor/rules/*.mdc\"). */\nexport type DiscoveryScope = \"cwd-only\" | \"git-root-walk\" | \"globbed\";\n\n/** Parser to apply once file is read. */\nexport type DiscoveryParser = \"plain-markdown\" | \"mdc\" | \"frontmatter-zod\" | \"rules-frontmatter\";\n\n/**\n * One kind of context file the runner knows how to find and read. The shipped registry is\n * `DEFAULT_DISCOVERY_SPECS`; a caller supplies its own array to change the set.\n *\n * `scope` decides how `pattern` is used and how many files a single spec can yield:\n * `cwd-only` looks for one path and stops, `git-root-walk` collects a match in every directory\n * from `cwd` up to the git root (nearest first), and `globbed` expands `pattern` as a glob\n * relative to `cwd`. So `pattern` is a filename for the first two and a glob for the third —\n * putting a glob on a walk scope silently finds nothing.\n *\n * `priority` orders the merged prompt, ascending, and is a plain number rather than an index, so\n * a new spec can be slotted between two existing ones. Lower means earlier and therefore more\n * general; later content wins on conflict.\n *\n * `parser` must match the file format — `plain-markdown` reads the whole file, `mdc` and\n * `rules-frontmatter` parse frontmatter and can DECLINE the file when its activation conditions\n * do not hold, and `frontmatter-zod` is the legacy path the runner currently skips entirely.\n *\n * `followImports` is honored only by `plain-markdown`, and turns `@path` directives in the body\n * into inlined content bounded by the import root. Setting it on a frontmatter parser does\n * nothing.\n *\n * `id` names the source in `<source name=\"\">` and in telemetry. When one spec matches files in\n * several directories, the runner suffixes it with the path relative to the git root to keep them\n * apart.\n *\n * @public — re-exported from `@theokit/sdk/context`, and therefore under semver.\n */\nexport interface DiscoverySpec {\n /** Stable identifier — used as `<source name=\"\">` and telemetry key. */\n readonly id: string;\n /** Priority for merge (lower = earlier in prompt). */\n readonly priority: number;\n /** Filename (cwd-only/git-root-walk) or glob (globbed). */\n readonly pattern: string;\n readonly scope: DiscoveryScope;\n readonly parser: DiscoveryParser;\n /** Whether to follow `@path` import directives (CLAUDE.md / GEMINI.md). */\n readonly followImports: boolean;\n}\n\n/**\n * The context files theokit looks for out of the box, in the order they are concatenated.\n *\n * Two things follow from the ordering. `AGENTS.md` comes first at priority 10 and `THEO.md` last,\n * so theokit-specific instruction wins over the vendor-neutral file on conflict. And the array is\n * consumed in the order written — the runner does not re-sort it — so a caller passing its own\n * array is responsible for keeping `priority` and array position consistent.\n *\n * `CLAUDE.md` and `GEMINI.md` are the only two entries with `followImports: true`, which means\n * they are the only files whose `@path` directives pull other files into the prompt. Those\n * imports cannot escape the import root.\n *\n * Frozen only by type: `ReadonlyArray` is a compile-time constraint, and the array and its\n * elements are not deep-frozen at runtime. Build a new array rather than mutating this one.\n *\n * @public — re-exported from `@theokit/sdk/context`, and therefore under semver.\n */\nexport const DEFAULT_DISCOVERY_SPECS: ReadonlyArray<DiscoverySpec> = [\n {\n id: \"AGENTS.md\",\n pattern: \"AGENTS.md\",\n scope: \"git-root-walk\",\n parser: \"plain-markdown\",\n followImports: false,\n priority: 10,\n },\n {\n id: \"GEMINI.md\",\n pattern: \"GEMINI.md\",\n scope: \"git-root-walk\",\n parser: \"plain-markdown\",\n followImports: true,\n priority: 20,\n },\n {\n id: \"CLAUDE.md\",\n pattern: \"CLAUDE.md\",\n scope: \"git-root-walk\",\n parser: \"plain-markdown\",\n followImports: true,\n priority: 30,\n },\n {\n id: \"cursor-rules\",\n pattern: \".cursor/rules/*.mdc\",\n scope: \"globbed\",\n parser: \"mdc\",\n followImports: false,\n priority: 40,\n },\n {\n id: \"theokit-rules\",\n pattern: \".theokit/rules/*.md\",\n scope: \"globbed\",\n parser: \"rules-frontmatter\",\n followImports: false,\n priority: 45,\n },\n {\n // Rules written for the Claude Code CLI. Measured 2026-08-26 over this repository's 32 rule\n // files: none carries frontmatter, and `rules-frontmatter` already reads a file without it as\n // `alwaysApply: true` — the format needed nothing, only a spec pointing at the directory.\n //\n // 47, not 46. Specs sort ascending and a context budget drops the tail first, so it must land\n // AFTER `.theokit/rules` (45) — the explicit namespace should survive a squeeze the borrowed one\n // does not. It must also leave a slot on BOTH sides: B-127 makes these numbers a public contract\n // precisely so a consumer can place its own source between two defaults, and 46 would have left\n // no room between 45 and itself. 47 keeps 46 free below and 48–49 free above.\n //\n // The reckoning B-127's docblock asks for: no published priority MOVES, so a consumer that chose\n // 46, 48 or 49 is unaffected. A consumer that had chosen 47 now collides — that is the cost of\n // an eighth default, paid once and recorded here rather than discovered later.\n id: \"claude-rules\",\n pattern: \".claude/rules/*.md\",\n scope: \"globbed\",\n parser: \"rules-frontmatter\",\n followImports: false,\n priority: 47,\n },\n {\n id: \"theokit-context\",\n pattern: \".theokit/context/*.md\",\n scope: \"globbed\",\n parser: \"frontmatter-zod\",\n followImports: false,\n priority: 50,\n },\n {\n // usetheokit/theokit-sdk#531 — THEO.md was the only context file that could not live at the\n // project root: every sibling here is `git-root-walk`, and this one was `cwd-only` pointed\n // at `.theokit/THEO.md` specifically, with no warning that a root THEO.md was inert.\n //\n // ADDED rather than moving the existing entry below: a project already using\n // `.theokit/THEO.md` keeps working unchanged. 55 sits between `theokit-context` (50) and the\n // existing `THEO.md` (60), leaving room on both sides — the numbering discipline\n // `claude-rules` (47) already established for this array.\n //\n // `followImports: true`, unlike the existing entry (`false`) and unlike `AGENTS.md`. This is\n // a DELIBERATE divergence between the two THEO.md specs, not an inconsistency: a root-level\n // file is edited by the same people, in the same place, as CLAUDE.md/GEMINI.md — the two\n // other root-level, human-facing files that both carry `followImports: true` — so it belongs\n // in their category rather than AGENTS.md's vendor-neutral, import-free one. Because this is a\n // NEW spec, choosing `true` here changes nothing for `.theokit/THEO.md`, which keeps `false`.\n id: \"THEO.md.root\",\n pattern: \"THEO.md\",\n scope: \"git-root-walk\",\n parser: \"plain-markdown\",\n followImports: true,\n priority: 55,\n },\n {\n id: \"THEO.md\",\n pattern: \".theokit/THEO.md\",\n scope: \"cwd-only\",\n parser: \"plain-markdown\",\n followImports: false,\n priority: 60,\n },\n];\n\nconst SAFE_FILENAME = /^[a-zA-Z0-9_.\\-/*]+$/;\nconst TRAVERSAL_RE = /(^|\\/)\\.\\.(\\/|$)/;\n\n/**\n * Reject patterns that contain path traversal (`..`) or non-allowed\n * characters (D81 parity, EC-4).\n *\n * @internal\n */\nexport function isSafePattern(pattern: string): boolean {\n if (typeof pattern !== \"string\" || pattern.length === 0) return false;\n if (TRAVERSAL_RE.test(pattern)) return false;\n if (isAbsolute(pattern)) return false;\n return SAFE_FILENAME.test(pattern);\n}\n\n/**\n * Walk upward from `cwd` looking for the closest directory containing\n * a `.git` entry (file OR directory — worktrees use a `.git` FILE,\n * EC-N). Returns the absolute path of that directory, or `undefined`\n * when no git root exists at or above `cwd`.\n *\n * @internal\n */\nexport function findGitRoot(cwd: string): string | undefined {\n if (typeof cwd !== \"string\" || cwd.length === 0) return undefined;\n let current = resolve(cwd);\n // Guard against infinite loops on weird filesystems.\n for (let i = 0; i < 64; i += 1) {\n if (existsSync(join(current, \".git\"))) return current;\n const parent = dirname(current);\n if (parent === current) return undefined;\n current = parent;\n }\n return undefined;\n}\n\n/**\n * Walk `cwd` upward to `stopDir` (inclusive) collecting every existing\n * occurrence of `filename`. Returns absolute, realpath-deduped paths in\n * nearest-first order (innermost dir first).\n *\n * No `.gitignore` parsing (EC-A). Realpath collapses symlink chains\n * pointing to the same physical file (EC-F). Filesystem races (file\n * deleted mid-walk) are skipped silently (EC-5).\n *\n * @internal\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: walk-up loop combines validation + realpath dedup + FS-race handling + stopDir guard in a single bounded loop; splitting fragments the dedup invariant.\nexport function walkUpForFile(\n cwd: string,\n filename: string,\n stopDir: string | undefined,\n): string[] {\n if (!isSafePattern(filename)) {\n return [];\n }\n const start = resolve(cwd);\n const stop = stopDir !== undefined ? resolve(stopDir) : undefined;\n const found: string[] = [];\n const seenReal = new Set<string>();\n let current = start;\n // 64-level depth cap.\n for (let i = 0; i < 64; i += 1) {\n const candidate = join(current, filename);\n if (existsSync(candidate)) {\n let real: string;\n try {\n real = realpathSync(candidate);\n } catch {\n // FS race (deleted mid-walk) — skip.\n real = candidate;\n }\n if (!seenReal.has(real)) {\n seenReal.add(real);\n found.push(real);\n }\n }\n if (stop !== undefined && current === stop) break;\n const parent = dirname(current);\n if (parent === current) break;\n current = parent;\n }\n return found;\n}\n\n/**\n * Glob-style discovery under `cwd` (e.g. `.cursor/rules/*.mdc`, `.theokit/rules/**\\/*.md`).\n * Returns absolute, lex-sorted paths.\n *\n * `*` matches within one path segment and `**` spans any depth, including zero — so\n * `.theokit/rules/**\\/*.md` finds `rules/top.md` as well as `rules/deep/nested/inner.md`, while\n * `.theokit/rules/*.md` keeps its flat meaning and finds only the first. That distinction is the\n * compatibility contract: every existing spec uses a single `*`, and widening it would silently\n * start absorbing nested files nobody chose to expose.\n *\n * ## Why this used to be flat, and what changed (B-119)\n *\n * The previous implementation split the pattern at its LAST `/`, treated the prefix as a literal\n * directory and did one `readdir` — documented as \"nested directories deferred to v2\" (EC-R). The\n * deferral was deliberate; what made it a defect was measured from a consumer. TheoCode's own rule\n * loader descends recursively, so migrating it onto the `theokit-rules` spec would have silently\n * dropped every nested rule — on the path that decides whether a repository's hooks execute. And a\n * pattern written to say so, `.theokit/rules/**\\/*.md`, resolved its directory part to a literal\n * `**` and matched NOTHING, not even the top-level file it matched before the globstar was added.\n *\n * ## Why the stdlib rather than a walker\n *\n * `fs.promises.glob` (Node ≥ 22, and this package requires ≥ 22.12) implements exactly these\n * semantics, verified against a fixture before adoption: `**\\/*.md` returns all three depths,\n * `*.md` returns one, and it emits no experimental warning. Writing a recursive walker here would\n * have been a third implementation of matching inside one package — the same duplication that let\n * the enumerator and the compiler in `context-glob.ts` disagree in the first place. `globToRegex`\n * stays where it belongs: deciding whether a rule APPLIES to a set of paths, which is a different\n * question from which files exist.\n *\n * `isSafePattern` still runs first and is unchanged, so `..` is refused before any I/O.\n *\n * @internal\n */\nexport async function walkUpForGlob(cwd: string, pattern: string): Promise<string[]> {\n if (!isSafePattern(pattern)) return [];\n const found: string[] = [];\n try {\n for await (const entry of glob(pattern, { cwd })) {\n found.push(resolve(cwd, entry));\n }\n } catch {\n // A pattern whose directory does not exist is the ordinary case — most projects have no\n // `.cursor/rules/`. Same outcome as matching nothing.\n return [];\n }\n // Sorted, because discovery order becomes prompt order and must not vary with the filesystem.\n //\n // The comparator is explicit and deliberately NOT `localeCompare`, which is the usual suggestion\n // for a bare `.sort()`. `localeCompare` orders by the machine's locale, so the same tree would\n // assemble a different prompt on a differently-configured machine — trading one source of\n // non-determinism for a subtler one. Code-unit ordering is what a bare `.sort()` already does for\n // strings; writing it out states the intent and keeps the result machine-independent.\n return found.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));\n}\n"]}
|