@moxxy/sdk 0.1.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/dist/agent.d.ts +39 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +2 -0
- package/dist/agent.js.map +1 -0
- package/dist/cache-strategy.d.ts +35 -0
- package/dist/cache-strategy.d.ts.map +1 -0
- package/dist/cache-strategy.js +2 -0
- package/dist/cache-strategy.js.map +1 -0
- package/dist/channel.d.ts +146 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +2 -0
- package/dist/channel.js.map +1 -0
- package/dist/client-session.d.ts +83 -0
- package/dist/client-session.d.ts.map +1 -0
- package/dist/client-session.js +2 -0
- package/dist/client-session.js.map +1 -0
- package/dist/command.d.ts +90 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +15 -0
- package/dist/command.js.map +1 -0
- package/dist/compactor-helpers.d.ts +34 -0
- package/dist/compactor-helpers.d.ts.map +1 -0
- package/dist/compactor-helpers.js +156 -0
- package/dist/compactor-helpers.js.map +1 -0
- package/dist/compactor.d.ts +20 -0
- package/dist/compactor.d.ts.map +1 -0
- package/dist/compactor.js +2 -0
- package/dist/compactor.js.map +1 -0
- package/dist/define.d.ts +51 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +71 -0
- package/dist/define.js.map +1 -0
- package/dist/elision-helpers.d.ts +27 -0
- package/dist/elision-helpers.d.ts.map +1 -0
- package/dist/elision-helpers.js +109 -0
- package/dist/elision-helpers.js.map +1 -0
- package/dist/elision-state.d.ts +49 -0
- package/dist/elision-state.d.ts.map +1 -0
- package/dist/elision-state.js +144 -0
- package/dist/elision-state.js.map +1 -0
- package/dist/embedding-cache.d.ts +32 -0
- package/dist/embedding-cache.d.ts.map +1 -0
- package/dist/embedding-cache.js +0 -0
- package/dist/embedding-cache.js.map +1 -0
- package/dist/embedding.d.ts +21 -0
- package/dist/embedding.d.ts.map +1 -0
- package/dist/embedding.js +2 -0
- package/dist/embedding.js.map +1 -0
- package/dist/errors.d.ts +81 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +241 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +193 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/hooks.d.ts +52 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +2 -0
- package/dist/hooks.js.map +1 -0
- package/dist/ids.d.ts +18 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +7 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/install-hints.d.ts +26 -0
- package/dist/install-hints.d.ts.map +1 -0
- package/dist/install-hints.js +15 -0
- package/dist/install-hints.js.map +1 -0
- package/dist/isolation.d.ts +125 -0
- package/dist/isolation.d.ts.map +1 -0
- package/dist/isolation.js +11 -0
- package/dist/isolation.js.map +1 -0
- package/dist/log.d.ts +11 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +2 -0
- package/dist/log.js.map +1 -0
- package/dist/mode-helpers.d.ts +99 -0
- package/dist/mode-helpers.d.ts.map +1 -0
- package/dist/mode-helpers.js +368 -0
- package/dist/mode-helpers.js.map +1 -0
- package/dist/mode.d.ts +133 -0
- package/dist/mode.d.ts.map +1 -0
- package/dist/mode.js +2 -0
- package/dist/mode.js.map +1 -0
- package/dist/permission.d.ts +35 -0
- package/dist/permission.d.ts.map +1 -0
- package/dist/permission.js +2 -0
- package/dist/permission.js.map +1 -0
- package/dist/plugin.d.ts +88 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -0
- package/dist/provider-utils.d.ts +40 -0
- package/dist/provider-utils.d.ts.map +1 -0
- package/dist/provider-utils.js +163 -0
- package/dist/provider-utils.js.map +1 -0
- package/dist/provider.d.ts +219 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +2 -0
- package/dist/provider.js.map +1 -0
- package/dist/requirements.d.ts +22 -0
- package/dist/requirements.d.ts.map +1 -0
- package/dist/requirements.js +2 -0
- package/dist/requirements.js.map +1 -0
- package/dist/schemas.d.ts +228 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +88 -0
- package/dist/schemas.js.map +1 -0
- package/dist/session-like.d.ts +111 -0
- package/dist/session-like.d.ts.map +1 -0
- package/dist/session-like.js +2 -0
- package/dist/session-like.js.map +1 -0
- package/dist/skill.d.ts +30 -0
- package/dist/skill.d.ts.map +1 -0
- package/dist/skill.js +2 -0
- package/dist/skill.js.map +1 -0
- package/dist/subagent.d.ts +45 -0
- package/dist/subagent.d.ts.map +1 -0
- package/dist/subagent.js +11 -0
- package/dist/subagent.js.map +1 -0
- package/dist/token-accounting.d.ts +73 -0
- package/dist/token-accounting.d.ts.map +1 -0
- package/dist/token-accounting.js +129 -0
- package/dist/token-accounting.js.map +1 -0
- package/dist/tool-dispatch.d.ts +19 -0
- package/dist/tool-dispatch.d.ts.map +1 -0
- package/dist/tool-dispatch.js +118 -0
- package/dist/tool-dispatch.js.map +1 -0
- package/dist/tool-gating.d.ts +32 -0
- package/dist/tool-gating.d.ts.map +1 -0
- package/dist/tool-gating.js +83 -0
- package/dist/tool-gating.js.map +1 -0
- package/dist/tool.d.ts +166 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +2 -0
- package/dist/tool.js.map +1 -0
- package/dist/transcriber.d.ts +64 -0
- package/dist/transcriber.d.ts.map +1 -0
- package/dist/transcriber.js +21 -0
- package/dist/transcriber.js.map +1 -0
- package/dist/tunnel.d.ts +25 -0
- package/dist/tunnel.d.ts.map +1 -0
- package/dist/tunnel.js +2 -0
- package/dist/tunnel.js.map +1 -0
- package/dist/type-contracts.d.ts +2 -0
- package/dist/type-contracts.d.ts.map +1 -0
- package/dist/type-contracts.js +4 -0
- package/dist/type-contracts.js.map +1 -0
- package/dist/types.test-d.d.ts +2 -0
- package/dist/types.test-d.d.ts.map +1 -0
- package/dist/types.test-d.js +22 -0
- package/dist/types.test-d.js.map +1 -0
- package/dist/view-renderer.d.ts +97 -0
- package/dist/view-renderer.d.ts.map +1 -0
- package/dist/view-renderer.js +72 -0
- package/dist/view-renderer.js.map +1 -0
- package/package.json +38 -0
- package/src/agent.ts +38 -0
- package/src/cache-strategy.ts +39 -0
- package/src/channel.ts +158 -0
- package/src/client-session.ts +88 -0
- package/src/command.ts +86 -0
- package/src/compactor-helpers.test.ts +206 -0
- package/src/compactor-helpers.ts +163 -0
- package/src/compactor.ts +20 -0
- package/src/define.test.ts +76 -0
- package/src/define.ts +113 -0
- package/src/elision-helpers.ts +143 -0
- package/src/elision-state.ts +170 -0
- package/src/embedding-cache.ts +0 -0
- package/src/embedding.ts +22 -0
- package/src/errors.test.ts +176 -0
- package/src/errors.ts +308 -0
- package/src/events.ts +250 -0
- package/src/hooks.ts +54 -0
- package/src/ids.ts +16 -0
- package/src/index.ts +304 -0
- package/src/install-hints.ts +43 -0
- package/src/isolation.ts +148 -0
- package/src/log.ts +11 -0
- package/src/loop-helpers.test.ts +78 -0
- package/src/mode-helpers.ts +483 -0
- package/src/mode.ts +139 -0
- package/src/package-root.test.ts +40 -0
- package/src/permission.ts +37 -0
- package/src/plugin.ts +92 -0
- package/src/provider-utils.test.ts +84 -0
- package/src/provider-utils.ts +171 -0
- package/src/provider.ts +195 -0
- package/src/requirements.ts +35 -0
- package/src/schemas.test.ts +106 -0
- package/src/schemas.ts +97 -0
- package/src/session-like.ts +118 -0
- package/src/skill.ts +34 -0
- package/src/subagent.ts +46 -0
- package/src/token-accounting.test.ts +93 -0
- package/src/token-accounting.ts +202 -0
- package/src/token-efficiency.test.ts +459 -0
- package/src/tool-dispatch.ts +137 -0
- package/src/tool-gating.ts +107 -0
- package/src/tool.ts +175 -0
- package/src/transcriber.ts +71 -0
- package/src/tunnel.ts +26 -0
- package/src/type-contracts.ts +4 -0
- package/src/types.test-d.ts +29 -0
- package/src/view-renderer.test.ts +90 -0
- package/src/view-renderer.ts +156 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ProviderMessage, TokenUsage } from './provider.js';
|
|
2
|
+
import type { ModeContext } from './mode.js';
|
|
3
|
+
import type { StopReason } from './provider-utils.js';
|
|
4
|
+
import type { Skill } from './skill.js';
|
|
5
|
+
/**
|
|
6
|
+
* Shared bits used by every loop strategy: a typed tool-use struct and a
|
|
7
|
+
* common stream-collection helper that runs `onBeforeProviderCall` hooks
|
|
8
|
+
* and reduces a provider stream down to `{text, toolUses, stopReason}`.
|
|
9
|
+
*
|
|
10
|
+
* Lives in core (not in each loop package) so a new loop strategy stays
|
|
11
|
+
* consistent — and so behavioral fixes here propagate. Previously
|
|
12
|
+
* loop-plan-execute had its own copy that skipped the hook (audit bug).
|
|
13
|
+
*/
|
|
14
|
+
export interface CollectedToolUse {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly input: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** Appended to the system prompt while elision is active (see projection). */
|
|
20
|
+
export declare const ELISION_SYSTEM_NOTE: string;
|
|
21
|
+
/**
|
|
22
|
+
* Compose a model-facing system prompt that includes any base prompt
|
|
23
|
+
* plus a COMPACT skill index (name + description + triggers only).
|
|
24
|
+
*
|
|
25
|
+
* Lazy-loading design: the body is intentionally NOT inlined. The model
|
|
26
|
+
* matches user intent against the description/triggers, then calls the
|
|
27
|
+
* `load_skill` tool to fetch the body of the skill it picked. This keeps
|
|
28
|
+
* the system prompt small even with many skills installed and avoids
|
|
29
|
+
* paying for skill bodies the model never actually follows.
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildSystemPromptWithSkills(baseSystemPrompt: string | undefined, skills: ReadonlyArray<Skill>): string | undefined;
|
|
32
|
+
export interface ProjectMessagesOptions {
|
|
33
|
+
/** Optional system prompt; emitted as the first message when set. */
|
|
34
|
+
readonly systemPrompt?: string;
|
|
35
|
+
/** Optional trailing user message — useful for plan-execute's "Focus on this step now: X". */
|
|
36
|
+
readonly trailingUserText?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Project the session's event log to a flat list of ProviderMessages
|
|
40
|
+
* suitable for handing to `provider.stream`. Used by every loop strategy.
|
|
41
|
+
*
|
|
42
|
+
* Handles user_prompt, assistant_message, tool_call_requested (grouped
|
|
43
|
+
* into a single assistant message of tool_use blocks), and tool_result.
|
|
44
|
+
* Other event types are passed through as a no-op.
|
|
45
|
+
*
|
|
46
|
+
* This is THE projection every loop strategy uses; it honors compaction
|
|
47
|
+
* events, turn-boundary elision, and the orphan-tool_use fallback. It lives in
|
|
48
|
+
* the SDK so loop plugins stay independent of core.
|
|
49
|
+
*/
|
|
50
|
+
export interface ProjectedMessages {
|
|
51
|
+
readonly messages: ProviderMessage[];
|
|
52
|
+
/**
|
|
53
|
+
* Index (into `messages`) of the last message belonging to the stable,
|
|
54
|
+
* byte-identical prefix — i.e. produced entirely from events at or below the
|
|
55
|
+
* elision high-water mark (which only advances on whole-turn boundaries, so
|
|
56
|
+
* the cut never splits a message). -1 when no elision is active. The
|
|
57
|
+
* `stable-prefix` cache strategy places its long-lived cross-turn breakpoint
|
|
58
|
+
* here; see {@link collectProviderStream}'s `stablePrefixIndex` option.
|
|
59
|
+
*/
|
|
60
|
+
readonly stablePrefixIndex: number;
|
|
61
|
+
}
|
|
62
|
+
export declare function projectMessagesFromLog(ctx: Pick<ModeContext, 'log'>, opts?: ProjectMessagesOptions): ProviderMessage[];
|
|
63
|
+
/**
|
|
64
|
+
* Same projection as {@link projectMessagesFromLog} but also reports the
|
|
65
|
+
* stable-prefix boundary so the active cache strategy can place a cross-turn
|
|
66
|
+
* breakpoint. Modes that build messages this way should thread the returned
|
|
67
|
+
* `stablePrefixIndex` into {@link collectProviderStream}.
|
|
68
|
+
*/
|
|
69
|
+
export declare function projectMessages(ctx: Pick<ModeContext, 'log'>, opts?: ProjectMessagesOptions): ProjectedMessages;
|
|
70
|
+
export interface StreamResult {
|
|
71
|
+
readonly text: string;
|
|
72
|
+
readonly toolUses: ReadonlyArray<CollectedToolUse>;
|
|
73
|
+
readonly stopReason: StopReason;
|
|
74
|
+
readonly error: {
|
|
75
|
+
readonly message: string;
|
|
76
|
+
readonly retryable: boolean;
|
|
77
|
+
} | null;
|
|
78
|
+
/** Token usage reported by the provider on `message_end`, including cache hits/writes. */
|
|
79
|
+
readonly usage?: TokenUsage;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Pulls a provider stream, emits `assistant_chunk` events for text deltas,
|
|
83
|
+
* collects tool_use blocks, and returns the final `{text, toolUses, stopReason}`.
|
|
84
|
+
* Runs `onBeforeProviderCall` lifecycle hooks before the call.
|
|
85
|
+
*/
|
|
86
|
+
export declare function collectProviderStream(ctx: ModeContext, messages: ReadonlyArray<ProviderMessage>, opts?: {
|
|
87
|
+
iteration?: number;
|
|
88
|
+
includeTools?: boolean;
|
|
89
|
+
maxTokens?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Index (into `messages`) of the last stable-prefix message, from
|
|
92
|
+
* {@link projectMessages}. Passed to the active cache strategy as
|
|
93
|
+
* `stablePrefixMessageIndex` so it can place a long-lived cross-turn
|
|
94
|
+
* breakpoint at the elision boundary. Omit (or -1) when unknown — the
|
|
95
|
+
* strategy then falls back to its tools/system/tail breakpoints only.
|
|
96
|
+
*/
|
|
97
|
+
stablePrefixIndex?: number;
|
|
98
|
+
}): Promise<StreamResult>;
|
|
99
|
+
//# sourceMappingURL=mode-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mode-helpers.d.ts","sourceRoot":"","sources":["../src/mode-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA+B,eAAe,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,KAAK,EAAE,WAAW,EAA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aAAa,CAAC,gBAAgB,CAAC,CAAC;IACnD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjF,0FAA0F;IAC1F,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,aAAa,CAAC,eAAe,CAAC,EACxC,IAAI,GAAE;IACJ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACvB,GACL,OAAO,CAAC,YAAY,CAAC,CAoHvB"}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { computeElisionState, conversationalStub, conversationalStubbed, toolResultBytes, toolResultStub, toolResultStubbed, } from './elision-state.js';
|
|
2
|
+
import { applyLazyTools } from './tool-gating.js';
|
|
3
|
+
/** Appended to the system prompt while elision is active (see projection). */
|
|
4
|
+
export const ELISION_SYSTEM_NOTE = 'Context note: to stay within budget, older turns may appear as stubs like ' +
|
|
5
|
+
'`[output elided — recall("id") to view]` or `[elided user turn · recall({ seq: N })]`. ' +
|
|
6
|
+
'These are NOT the real content — call the `recall` tool with the given id/seq to fetch ' +
|
|
7
|
+
'the full text before relying on any detail from an elided turn. Recent turns are always ' +
|
|
8
|
+
'shown verbatim.';
|
|
9
|
+
/**
|
|
10
|
+
* Compose a model-facing system prompt that includes any base prompt
|
|
11
|
+
* plus a COMPACT skill index (name + description + triggers only).
|
|
12
|
+
*
|
|
13
|
+
* Lazy-loading design: the body is intentionally NOT inlined. The model
|
|
14
|
+
* matches user intent against the description/triggers, then calls the
|
|
15
|
+
* `load_skill` tool to fetch the body of the skill it picked. This keeps
|
|
16
|
+
* the system prompt small even with many skills installed and avoids
|
|
17
|
+
* paying for skill bodies the model never actually follows.
|
|
18
|
+
*/
|
|
19
|
+
export function buildSystemPromptWithSkills(baseSystemPrompt, skills) {
|
|
20
|
+
if (skills.length === 0)
|
|
21
|
+
return baseSystemPrompt;
|
|
22
|
+
const header = `## Available skills\n\n` +
|
|
23
|
+
`Each line below is a pre-authored playbook for a specific intent. ` +
|
|
24
|
+
`When the user's request matches one of these (by name, description, ` +
|
|
25
|
+
`or triggers), call \`load_skill({ name: "<skill-name>" })\` FIRST to ` +
|
|
26
|
+
`fetch the full instructions, then follow them verbatim. Prefer using ` +
|
|
27
|
+
`a skill over re-deriving the workflow with ad-hoc tools.\n`;
|
|
28
|
+
const entries = skills
|
|
29
|
+
.map((s) => {
|
|
30
|
+
const fm = s.frontmatter;
|
|
31
|
+
const triggerHint = fm.triggers?.length
|
|
32
|
+
? ` (triggers: ${fm.triggers.map((t) => `"${t}"`).join(', ')})`
|
|
33
|
+
: '';
|
|
34
|
+
return `- **${fm.name}** — ${fm.description}${triggerHint}`;
|
|
35
|
+
})
|
|
36
|
+
.join('\n');
|
|
37
|
+
const skillBlock = `${header}\n${entries}`;
|
|
38
|
+
return baseSystemPrompt ? `${baseSystemPrompt}\n\n${skillBlock}` : skillBlock;
|
|
39
|
+
}
|
|
40
|
+
function activeCompactionRanges(events) {
|
|
41
|
+
return events
|
|
42
|
+
.filter((event) => event.type === 'compaction' &&
|
|
43
|
+
event.tokensSaved > 0 &&
|
|
44
|
+
event.summary.trim().length > 0 &&
|
|
45
|
+
event.replacedRange[0] <= event.replacedRange[1])
|
|
46
|
+
.map((event) => ({
|
|
47
|
+
from: event.replacedRange[0],
|
|
48
|
+
to: event.replacedRange[1],
|
|
49
|
+
summary: event.summary,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
function eventInCompactionRange(seq, ranges) {
|
|
53
|
+
for (const range of ranges) {
|
|
54
|
+
if (seq >= range.from && seq <= range.to)
|
|
55
|
+
return range;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
export function projectMessagesFromLog(ctx, opts = {}) {
|
|
60
|
+
return projectMessages(ctx, opts).messages;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Same projection as {@link projectMessagesFromLog} but also reports the
|
|
64
|
+
* stable-prefix boundary so the active cache strategy can place a cross-turn
|
|
65
|
+
* breakpoint. Modes that build messages this way should thread the returned
|
|
66
|
+
* `stablePrefixIndex` into {@link collectProviderStream}.
|
|
67
|
+
*/
|
|
68
|
+
export function projectMessages(ctx, opts = {}) {
|
|
69
|
+
const allEvents = ctx.log.slice();
|
|
70
|
+
const compactions = activeCompactionRanges(allEvents);
|
|
71
|
+
const emittedCompactions = new Set();
|
|
72
|
+
const el = computeElisionState(allEvents);
|
|
73
|
+
const messages = [];
|
|
74
|
+
// The stable prefix is every message produced from events at/below the
|
|
75
|
+
// elision HWM. Record the latest such message index as we push.
|
|
76
|
+
let stablePrefixIndex = -1;
|
|
77
|
+
const recordStable = (maxSeq) => {
|
|
78
|
+
if (el.hwm >= 0 && maxSeq >= 0 && maxSeq <= el.hwm) {
|
|
79
|
+
stablePrefixIndex = messages.length - 1;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
if (opts.systemPrompt) {
|
|
83
|
+
// When elision is active, tell the model that older turns may be shown as
|
|
84
|
+
// stubs and how to expand them — so it recalls instead of hallucinating.
|
|
85
|
+
// Constant text → busts the system cache once (when elision starts), stable
|
|
86
|
+
// thereafter.
|
|
87
|
+
const sysText = el.hwm >= 0 ? `${opts.systemPrompt}\n\n${ELISION_SYSTEM_NOTE}` : opts.systemPrompt;
|
|
88
|
+
messages.push({ role: 'system', content: [{ type: 'text', text: sysText }] });
|
|
89
|
+
}
|
|
90
|
+
// Pre-scan: build the set of callIds that have a matching tool_result
|
|
91
|
+
// (or tool_call_denied) somewhere in the log. Used to synthesize a
|
|
92
|
+
// fallback `[interrupted]` tool_result for orphan tool_use blocks
|
|
93
|
+
// when the assistant message gets flushed.
|
|
94
|
+
//
|
|
95
|
+
// Without this fallback the provider rejects the whole conversation
|
|
96
|
+
// with "assistant message with 'tool_calls' must be followed by tool
|
|
97
|
+
// messages responding to each 'tool_call_id'". Orphans typically
|
|
98
|
+
// appear after a cancelled turn, an aborted process, or a tool
|
|
99
|
+
// exception that bypassed the loop's tool_result emit path.
|
|
100
|
+
const resolvedCallIds = new Set();
|
|
101
|
+
for (const e of allEvents) {
|
|
102
|
+
if (e.type === 'tool_result' || e.type === 'tool_call_denied') {
|
|
103
|
+
resolvedCallIds.add(e.callId);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
let pendingAssistant = null;
|
|
107
|
+
let pendingAssistantMaxSeq = -1;
|
|
108
|
+
const flush = () => {
|
|
109
|
+
if (!pendingAssistant)
|
|
110
|
+
return;
|
|
111
|
+
const flushed = pendingAssistant;
|
|
112
|
+
const groupMaxSeq = pendingAssistantMaxSeq;
|
|
113
|
+
pendingAssistant = null;
|
|
114
|
+
pendingAssistantMaxSeq = -1;
|
|
115
|
+
messages.push(flushed);
|
|
116
|
+
recordStable(groupMaxSeq);
|
|
117
|
+
// Synthesize fallback tool_result messages for any tool_use blocks
|
|
118
|
+
// whose callId never resolved in the event log. Has to land
|
|
119
|
+
// immediately after the assistant message (and before any
|
|
120
|
+
// subsequent user_prompt / assistant_message) so the provider sees
|
|
121
|
+
// a clean assistant→tool-result chain.
|
|
122
|
+
for (const block of flushed.content) {
|
|
123
|
+
if (block.type === 'tool_use' && !resolvedCallIds.has(block.id)) {
|
|
124
|
+
messages.push({
|
|
125
|
+
role: 'tool_result',
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: 'tool_result',
|
|
129
|
+
toolUseId: block.id,
|
|
130
|
+
content: '[tool call did not return a result — possibly interrupted or cancelled]',
|
|
131
|
+
isError: true,
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
recordStable(groupMaxSeq);
|
|
136
|
+
// Mark synthesized so we don't double-emit if the same orphan
|
|
137
|
+
// appears in multiple groups (defensive — shouldn't normally
|
|
138
|
+
// happen since each tool_call_requested has a unique callId).
|
|
139
|
+
resolvedCallIds.add(block.id);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
for (const e of allEvents) {
|
|
144
|
+
const compaction = eventInCompactionRange(e.seq, compactions);
|
|
145
|
+
if (compaction) {
|
|
146
|
+
if (!emittedCompactions.has(compaction)) {
|
|
147
|
+
emittedCompactions.add(compaction);
|
|
148
|
+
flush();
|
|
149
|
+
messages.push({
|
|
150
|
+
role: 'user',
|
|
151
|
+
content: [{ type: 'text', text: `[summary of earlier turns]\n${compaction.summary}` }],
|
|
152
|
+
});
|
|
153
|
+
recordStable(compaction.to);
|
|
154
|
+
}
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
switch (e.type) {
|
|
158
|
+
case 'user_prompt': {
|
|
159
|
+
flush();
|
|
160
|
+
// Elided + conversational: collapse to a stub (anchor/tiny kept full).
|
|
161
|
+
if (conversationalStubbed(e, el)) {
|
|
162
|
+
messages.push({
|
|
163
|
+
role: 'user',
|
|
164
|
+
content: [{ type: 'text', text: conversationalStub('user', e.seq) }],
|
|
165
|
+
});
|
|
166
|
+
recordStable(e.seq);
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
const blocks = [{ type: 'text', text: e.text }];
|
|
170
|
+
if (e.attachments) {
|
|
171
|
+
for (const att of e.attachments) {
|
|
172
|
+
if (att.kind === 'image') {
|
|
173
|
+
blocks.push({
|
|
174
|
+
type: 'image',
|
|
175
|
+
mediaType: att.mediaType ?? 'image/png',
|
|
176
|
+
data: att.content,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
blocks.push({
|
|
181
|
+
type: 'text',
|
|
182
|
+
text: `[${att.kind}${att.name ? ` ${att.name}` : ''}]\n${att.content}`,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
messages.push({ role: 'user', content: blocks });
|
|
188
|
+
recordStable(e.seq);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case 'assistant_message':
|
|
192
|
+
flush();
|
|
193
|
+
if (conversationalStubbed(e, el)) {
|
|
194
|
+
messages.push({
|
|
195
|
+
role: 'assistant',
|
|
196
|
+
content: [{ type: 'text', text: conversationalStub('assistant', e.seq) }],
|
|
197
|
+
});
|
|
198
|
+
recordStable(e.seq);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
messages.push({ role: 'assistant', content: [{ type: 'text', text: e.content }] });
|
|
202
|
+
recordStable(e.seq);
|
|
203
|
+
break;
|
|
204
|
+
case 'tool_call_requested': {
|
|
205
|
+
pendingAssistant ??= { role: 'assistant', content: [] };
|
|
206
|
+
pendingAssistantMaxSeq = Math.max(pendingAssistantMaxSeq, e.seq);
|
|
207
|
+
pendingAssistant.content.push({
|
|
208
|
+
type: 'tool_use',
|
|
209
|
+
id: e.callId,
|
|
210
|
+
name: e.name,
|
|
211
|
+
input: e.input,
|
|
212
|
+
});
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
case 'tool_result': {
|
|
216
|
+
flush();
|
|
217
|
+
// Stub bulky old tool output to a recall-able marker (decision shared
|
|
218
|
+
// with estimateContextTokens via toolResultStubbed).
|
|
219
|
+
let text;
|
|
220
|
+
if (toolResultStubbed(e, el)) {
|
|
221
|
+
const recalled = el.recalledCallIds.has(e.callId) || el.recalledSeqs.has(e.seq);
|
|
222
|
+
text = toolResultStub(e.callId, toolResultBytes(e.output), recalled);
|
|
223
|
+
}
|
|
224
|
+
else if (e.error) {
|
|
225
|
+
text = `[error:${e.error.kind}] ${e.error.message}`;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
text = typeof e.output === 'string' ? e.output : JSON.stringify(e.output ?? '');
|
|
229
|
+
}
|
|
230
|
+
messages.push({
|
|
231
|
+
role: 'tool_result',
|
|
232
|
+
content: [{ type: 'tool_result', toolUseId: e.callId, content: text, isError: !e.ok }],
|
|
233
|
+
});
|
|
234
|
+
recordStable(e.seq);
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
default:
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
flush();
|
|
242
|
+
if (opts.trailingUserText) {
|
|
243
|
+
// The trailing step nudge is volatile (changes per step), never part of
|
|
244
|
+
// the stable prefix — don't record it.
|
|
245
|
+
messages.push({ role: 'user', content: [{ type: 'text', text: opts.trailingUserText }] });
|
|
246
|
+
}
|
|
247
|
+
return { messages, stablePrefixIndex };
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Pulls a provider stream, emits `assistant_chunk` events for text deltas,
|
|
251
|
+
* collects tool_use blocks, and returns the final `{text, toolUses, stopReason}`.
|
|
252
|
+
* Runs `onBeforeProviderCall` lifecycle hooks before the call.
|
|
253
|
+
*/
|
|
254
|
+
export async function collectProviderStream(ctx, messages, opts = {}) {
|
|
255
|
+
// Lazy tool gating (opt-in): send only always-on + loaded tool schemas, and
|
|
256
|
+
// index the rest in the system prompt. Runs BEFORE cache planning since it
|
|
257
|
+
// rewrites the system message and the tool list.
|
|
258
|
+
let effectiveMessages = messages;
|
|
259
|
+
let toolList = opts.includeTools === false ? undefined : ctx.tools.list();
|
|
260
|
+
if (ctx.lazyTools && toolList) {
|
|
261
|
+
const gated = applyLazyTools(messages, toolList, ctx.log);
|
|
262
|
+
effectiveMessages = gated.messages;
|
|
263
|
+
toolList = gated.tools;
|
|
264
|
+
}
|
|
265
|
+
// Ask the active cache strategy where to place prompt-cache breakpoints.
|
|
266
|
+
// The strategy is provider-neutral (returns CacheHints); the provider
|
|
267
|
+
// translates them (Anthropic → cache_control). Falls back to no hints when
|
|
268
|
+
// no strategy is registered. The onBeforeProviderCall hook can still adjust.
|
|
269
|
+
const descriptor = ctx.provider.models.find((m) => m.id === ctx.model);
|
|
270
|
+
const cacheHints = ctx.cacheStrategy
|
|
271
|
+
? ctx.cacheStrategy.plan(effectiveMessages, {
|
|
272
|
+
model: ctx.model,
|
|
273
|
+
contextWindow: descriptor?.contextWindow ?? 0,
|
|
274
|
+
log: ctx.log,
|
|
275
|
+
...(opts.stablePrefixIndex != null && opts.stablePrefixIndex >= 0
|
|
276
|
+
? { stablePrefixMessageIndex: opts.stablePrefixIndex }
|
|
277
|
+
: {}),
|
|
278
|
+
})
|
|
279
|
+
: undefined;
|
|
280
|
+
const req = {
|
|
281
|
+
model: ctx.model,
|
|
282
|
+
system: ctx.systemPrompt,
|
|
283
|
+
messages: effectiveMessages,
|
|
284
|
+
...(toolList ? { tools: toolList } : {}),
|
|
285
|
+
...(cacheHints && cacheHints.length > 0 ? { cacheHints } : {}),
|
|
286
|
+
...(opts.maxTokens !== undefined ? { maxTokens: opts.maxTokens } : {}),
|
|
287
|
+
signal: ctx.signal,
|
|
288
|
+
};
|
|
289
|
+
const transformed = await ctx.hooks.dispatchBeforeProviderCall(req, {
|
|
290
|
+
sessionId: ctx.sessionId,
|
|
291
|
+
cwd: '',
|
|
292
|
+
log: ctx.log,
|
|
293
|
+
env: {},
|
|
294
|
+
turnId: ctx.turnId,
|
|
295
|
+
iteration: opts.iteration ?? 0,
|
|
296
|
+
});
|
|
297
|
+
let text = '';
|
|
298
|
+
const toolUses = new Map();
|
|
299
|
+
let stopReason = 'end_turn';
|
|
300
|
+
let error = null;
|
|
301
|
+
let usage;
|
|
302
|
+
let stream;
|
|
303
|
+
try {
|
|
304
|
+
stream = ctx.provider.stream(transformed);
|
|
305
|
+
}
|
|
306
|
+
catch (err) {
|
|
307
|
+
return {
|
|
308
|
+
text: '',
|
|
309
|
+
toolUses: [],
|
|
310
|
+
stopReason: 'error',
|
|
311
|
+
error: { message: err instanceof Error ? err.message : String(err), retryable: false },
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
for await (const event of stream) {
|
|
316
|
+
switch (event.type) {
|
|
317
|
+
case 'text_delta': {
|
|
318
|
+
text += event.delta;
|
|
319
|
+
await ctx.emit({
|
|
320
|
+
type: 'assistant_chunk',
|
|
321
|
+
sessionId: ctx.sessionId,
|
|
322
|
+
turnId: ctx.turnId,
|
|
323
|
+
source: 'model',
|
|
324
|
+
delta: event.delta,
|
|
325
|
+
});
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
case 'tool_use_start': {
|
|
329
|
+
toolUses.set(event.id, { name: event.name });
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
case 'tool_use_end': {
|
|
333
|
+
const existing = toolUses.get(event.id) ?? {};
|
|
334
|
+
toolUses.set(event.id, { ...existing, input: event.input });
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
case 'message_end': {
|
|
338
|
+
stopReason = event.stopReason;
|
|
339
|
+
if (event.usage)
|
|
340
|
+
usage = event.usage;
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
case 'error': {
|
|
344
|
+
error = { message: event.message, retryable: event.retryable };
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
case 'message_start':
|
|
348
|
+
case 'tool_use_delta':
|
|
349
|
+
default:
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
error = {
|
|
356
|
+
message: err instanceof Error ? err.message : String(err),
|
|
357
|
+
retryable: false,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
const finalToolUses = [];
|
|
361
|
+
for (const [id, partial] of toolUses) {
|
|
362
|
+
if (!partial.name)
|
|
363
|
+
continue;
|
|
364
|
+
finalToolUses.push({ id, name: partial.name, input: partial.input ?? {} });
|
|
365
|
+
}
|
|
366
|
+
return { text, toolUses: finalToolUses, stopReason, error, ...(usage ? { usage } : {}) };
|
|
367
|
+
}
|
|
368
|
+
//# sourceMappingURL=mode-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mode-helpers.js","sourceRoot":"","sources":["../src/mode-helpers.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAkBlD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAC9B,4EAA4E;IAC5E,yFAAyF;IACzF,yFAAyF;IACzF,0FAA0F;IAC1F,iBAAiB,CAAC;AAEpB;;;;;;;;;GASG;AACH,MAAM,UAAU,2BAA2B,CACzC,gBAAoC,EACpC,MAA4B;IAE5B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,gBAAgB,CAAC;IACjD,MAAM,MAAM,GACV,yBAAyB;QACzB,oEAAoE;QACpE,sEAAsE;QACtE,uEAAuE;QACvE,uEAAuE;QACvE,4DAA4D,CAAC;IAC/D,MAAM,OAAO,GAAG,MAAM;SACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,CAAC;QACzB,MAAM,WAAW,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM;YACrC,CAAC,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAC/D,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,OAAO,EAAE,CAAC,IAAI,QAAQ,EAAE,CAAC,WAAW,GAAG,WAAW,EAAE,CAAC;IAC9D,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IACd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K,GAAG;YACN,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;YACzD,SAAS,EAAE,KAAK;SACjB,CAAC;IACJ,CAAC;IAED,MAAM,aAAa,GAAuB,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,IAAI;YAAE,SAAS;QAC5B,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC3F,CAAC"}
|
package/dist/mode.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { CacheStrategyDef } from './cache-strategy.js';
|
|
2
|
+
import type { CompactorDef } from './compactor.js';
|
|
3
|
+
import type { EmittedEvent, MoxxyEvent } from './events.js';
|
|
4
|
+
import type { HookDispatcher } from './hooks.js';
|
|
5
|
+
import type { SessionId, TurnId } from './ids.js';
|
|
6
|
+
import type { EventLogReader } from './log.js';
|
|
7
|
+
import type { PermissionResolver } from './permission.js';
|
|
8
|
+
import type { LLMProvider } from './provider.js';
|
|
9
|
+
import type { Skill } from './skill.js';
|
|
10
|
+
import type { SubagentSpawner } from './subagent.js';
|
|
11
|
+
import type { ToolDef } from './tool.js';
|
|
12
|
+
export interface ToolRegistry {
|
|
13
|
+
list(): ReadonlyArray<ToolDef>;
|
|
14
|
+
get(name: string): ToolDef | undefined;
|
|
15
|
+
execute(name: string, input: unknown, signal: AbortSignal, opts?: ToolExecuteOpts): Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface ToolExecuteOpts {
|
|
18
|
+
readonly callId?: string;
|
|
19
|
+
readonly sessionId?: string;
|
|
20
|
+
readonly turnId?: string;
|
|
21
|
+
readonly log?: EventLogReader;
|
|
22
|
+
readonly cwd?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SkillRegistry {
|
|
25
|
+
list(): ReadonlyArray<Skill>;
|
|
26
|
+
get(id: string): Skill | undefined;
|
|
27
|
+
byName(name: string): Skill | undefined;
|
|
28
|
+
filterByTriggers(prompt: string): ReadonlyArray<Skill>;
|
|
29
|
+
}
|
|
30
|
+
export interface PluginHostHandle {
|
|
31
|
+
list(): ReadonlyArray<{
|
|
32
|
+
name: string;
|
|
33
|
+
version: string;
|
|
34
|
+
loaded: boolean;
|
|
35
|
+
}>;
|
|
36
|
+
reload(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Turn-boundary elision (context-on-demand) settings, resolved from config and
|
|
40
|
+
* carried on the ModeContext. All fields optional; {@link runElisionIfNeeded}
|
|
41
|
+
* applies defaults and floors (e.g. keepRecentTurns is floored at 2).
|
|
42
|
+
*/
|
|
43
|
+
export interface ElisionSettings {
|
|
44
|
+
readonly enabled?: boolean;
|
|
45
|
+
readonly keepRecentTurns?: number;
|
|
46
|
+
readonly minContextRatioToElide?: number;
|
|
47
|
+
readonly elideConversational?: boolean;
|
|
48
|
+
readonly conversationalRecallThreshold?: number;
|
|
49
|
+
readonly maxRecallBytes?: number;
|
|
50
|
+
readonly neverElideTools?: ReadonlyArray<string>;
|
|
51
|
+
}
|
|
52
|
+
export interface ModeContext {
|
|
53
|
+
readonly sessionId: SessionId;
|
|
54
|
+
readonly turnId: TurnId;
|
|
55
|
+
readonly model: string;
|
|
56
|
+
readonly systemPrompt?: string;
|
|
57
|
+
readonly provider: LLMProvider;
|
|
58
|
+
readonly tools: ToolRegistry;
|
|
59
|
+
readonly skills: SkillRegistry;
|
|
60
|
+
readonly log: EventLogReader;
|
|
61
|
+
readonly compactor: CompactorDef | null;
|
|
62
|
+
/** Active prompt-caching strategy (or null when none is registered). */
|
|
63
|
+
readonly cacheStrategy: CacheStrategyDef | null;
|
|
64
|
+
/** Elision (context-on-demand) settings; undefined → defaults apply. */
|
|
65
|
+
readonly elision?: ElisionSettings;
|
|
66
|
+
/** When true, send only always-on + loaded tool schemas; index the rest. */
|
|
67
|
+
readonly lazyTools?: boolean;
|
|
68
|
+
readonly permissions: PermissionResolver;
|
|
69
|
+
/**
|
|
70
|
+
* Optional generic "ask the user a question" gate. Any loop strategy can
|
|
71
|
+
* call this to surface a checkpoint to the user — plan-execute uses it
|
|
72
|
+
* after producing a plan, but a code-execution loop could use it for
|
|
73
|
+
* "run this command?" or a refactor loop for "apply this diff?". When
|
|
74
|
+
* absent (headless / non-TTY), strategies should proceed as if the user
|
|
75
|
+
* picked the default option, or fail closed depending on the strategy.
|
|
76
|
+
*/
|
|
77
|
+
readonly approval?: ApprovalResolver;
|
|
78
|
+
readonly hooks: HookDispatcher;
|
|
79
|
+
readonly pluginHost: PluginHostHandle;
|
|
80
|
+
readonly signal: AbortSignal;
|
|
81
|
+
readonly maxIterations?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Spawn one or more child agents that share the parent's registries
|
|
84
|
+
* but run in isolation. Children stream their events back to the
|
|
85
|
+
* parent log as `plugin_event` records with `subagent_*` subtypes.
|
|
86
|
+
* Absent in synthetic test contexts that don't model a full Session.
|
|
87
|
+
*/
|
|
88
|
+
readonly subagents?: SubagentSpawner;
|
|
89
|
+
emit(event: EmittedEvent): Promise<MoxxyEvent>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Generic approval-dialog request. The TUI renders `title` as the header,
|
|
93
|
+
* `body` as a verbatim block (plan text, diff, command preview, etc.), and
|
|
94
|
+
* a single-select list of `options`. An option may set `requestsText` so
|
|
95
|
+
* the dialog prompts for follow-up text after selection (e.g. redraft
|
|
96
|
+
* feedback). `kind` is a loose tag the dialog/CLI can use for styling.
|
|
97
|
+
*/
|
|
98
|
+
export interface ApprovalRequest {
|
|
99
|
+
readonly title: string;
|
|
100
|
+
readonly body: string;
|
|
101
|
+
readonly options: ReadonlyArray<ApprovalOption>;
|
|
102
|
+
readonly defaultOptionId?: string;
|
|
103
|
+
readonly kind?: string;
|
|
104
|
+
}
|
|
105
|
+
export interface ApprovalOption {
|
|
106
|
+
readonly id: string;
|
|
107
|
+
readonly label: string;
|
|
108
|
+
readonly hotkey?: string;
|
|
109
|
+
readonly description?: string;
|
|
110
|
+
readonly requestsText?: boolean;
|
|
111
|
+
readonly textPrompt?: string;
|
|
112
|
+
readonly danger?: boolean;
|
|
113
|
+
}
|
|
114
|
+
export interface ApprovalDecision {
|
|
115
|
+
readonly optionId: string;
|
|
116
|
+
/** Free-text follow-up the user typed when the option had `requestsText: true`. */
|
|
117
|
+
readonly text?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface ApprovalResolver {
|
|
120
|
+
readonly name: string;
|
|
121
|
+
confirm(req: ApprovalRequest): Promise<ApprovalDecision>;
|
|
122
|
+
}
|
|
123
|
+
export interface ModeDef {
|
|
124
|
+
readonly name: string;
|
|
125
|
+
/**
|
|
126
|
+
* One-line summary of what this mode does. Rendered next to the mode
|
|
127
|
+
* name in the TUI /mode picker so users have context without
|
|
128
|
+
* memorising plugin internals. Keep short — the picker truncates.
|
|
129
|
+
*/
|
|
130
|
+
readonly description?: string;
|
|
131
|
+
run(ctx: ModeContext): AsyncIterable<MoxxyEvent>;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mode.d.ts","sourceRoot":"","sources":["../src/mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,YA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