opencode-dux 1.0.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/LICENSE +21 -0
- package/README.md +452 -0
- package/dist/agents/descriptions.d.ts +6 -0
- package/dist/agents/designer.d.ts +2 -0
- package/dist/agents/explorer.d.ts +2 -0
- package/dist/agents/fixer.d.ts +2 -0
- package/dist/agents/index.d.ts +22 -0
- package/dist/agents/interpreter.d.ts +2 -0
- package/dist/agents/librarian.d.ts +2 -0
- package/dist/agents/oracle.d.ts +2 -0
- package/dist/agents/orchestrator.d.ts +27 -0
- package/dist/agents/overrides.d.ts +18 -0
- package/dist/agents/prompt-blocks.d.ts +97 -0
- package/dist/agents/steward.d.ts +3 -0
- package/dist/cli/config-io.d.ts +24 -0
- package/dist/cli/config-manager.d.ts +4 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +1006 -0
- package/dist/cli/install.d.ts +2 -0
- package/dist/cli/mcps.d.ts +13 -0
- package/dist/cli/model-key-normalization.d.ts +1 -0
- package/dist/cli/paths.d.ts +35 -0
- package/dist/cli/providers.d.ts +137 -0
- package/dist/cli/skills.d.ts +22 -0
- package/dist/cli/system.d.ts +5 -0
- package/dist/cli/types.d.ts +38 -0
- package/dist/config/constants.d.ts +12 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/loader.d.ts +40 -0
- package/dist/config/runtime-preset.d.ts +12 -0
- package/dist/config/schema.d.ts +281 -0
- package/dist/config/utils.d.ts +10 -0
- package/dist/discovery/local/types.d.ts +79 -0
- package/dist/discovery/local.d.ts +73 -0
- package/dist/discovery/mcp-servers.d.ts +88 -0
- package/dist/discovery/skills.d.ts +94 -0
- package/dist/hooks/apply-patch/codec.d.ts +7 -0
- package/dist/hooks/apply-patch/errors.d.ts +25 -0
- package/dist/hooks/apply-patch/execution-context.d.ts +27 -0
- package/dist/hooks/apply-patch/index.d.ts +15 -0
- package/dist/hooks/apply-patch/matching.d.ts +26 -0
- package/dist/hooks/apply-patch/operations.d.ts +3 -0
- package/dist/hooks/apply-patch/patch.d.ts +2 -0
- package/dist/hooks/apply-patch/prepared-changes.d.ts +17 -0
- package/dist/hooks/apply-patch/resolution.d.ts +19 -0
- package/dist/hooks/apply-patch/rewrite.d.ts +7 -0
- package/dist/hooks/apply-patch/test-helpers.d.ts +6 -0
- package/dist/hooks/apply-patch/types.d.ts +80 -0
- package/dist/hooks/auto-update-checker/cache.d.ts +11 -0
- package/dist/hooks/auto-update-checker/checker.d.ts +32 -0
- package/dist/hooks/auto-update-checker/constants.d.ts +11 -0
- package/dist/hooks/auto-update-checker/index.d.ts +18 -0
- package/dist/hooks/auto-update-checker/types.d.ts +22 -0
- package/dist/hooks/chat-headers.d.ts +16 -0
- package/dist/hooks/context-pressure-reminder/index.d.ts +33 -0
- package/dist/hooks/delegate-task-retry/guidance.d.ts +2 -0
- package/dist/hooks/delegate-task-retry/hook.d.ts +8 -0
- package/dist/hooks/delegate-task-retry/index.d.ts +4 -0
- package/dist/hooks/delegate-task-retry/patterns.d.ts +11 -0
- package/dist/hooks/filter-available-skills/index.d.ts +32 -0
- package/dist/hooks/foreground-fallback/index.d.ts +72 -0
- package/dist/hooks/image-hook.d.ts +5 -0
- package/dist/hooks/index.d.ts +14 -0
- package/dist/hooks/json-error-recovery/hook.d.ts +18 -0
- package/dist/hooks/json-error-recovery/index.d.ts +1 -0
- package/dist/hooks/phase-reminder/index.d.ts +26 -0
- package/dist/hooks/post-file-tool-nudge/index.d.ts +19 -0
- package/dist/hooks/task-session-manager/index.d.ts +52 -0
- package/dist/hooks/todo-continuation/index.d.ts +53 -0
- package/dist/hooks/todo-continuation/todo-hygiene.d.ts +35 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +31782 -0
- package/dist/mcp/context7.d.ts +6 -0
- package/dist/mcp/grep-app.d.ts +6 -0
- package/dist/mcp/index.d.ts +13 -0
- package/dist/mcp/types.d.ts +12 -0
- package/dist/mcp/websearch.d.ts +9 -0
- package/dist/skills/registry.d.ts +29 -0
- package/dist/subscriptions/accounts-store.d.ts +57 -0
- package/dist/subscriptions/index.d.ts +13 -0
- package/dist/subscriptions/neuralwatt-scraper.d.ts +14 -0
- package/dist/subscriptions/opencode-go-scraper.d.ts +27 -0
- package/dist/subscriptions/types.d.ts +115 -0
- package/dist/subscriptions/usage-service.d.ts +74 -0
- package/dist/tools/ast-grep/cli.d.ts +15 -0
- package/dist/tools/ast-grep/constants.d.ts +25 -0
- package/dist/tools/ast-grep/downloader.d.ts +5 -0
- package/dist/tools/ast-grep/index.d.ts +10 -0
- package/dist/tools/ast-grep/tools.d.ts +3 -0
- package/dist/tools/ast-grep/types.d.ts +30 -0
- package/dist/tools/ast-grep/utils.d.ts +4 -0
- package/dist/tools/delegate.d.ts +14 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/preset-manager.d.ts +27 -0
- package/dist/tools/smartfetch/binary.d.ts +3 -0
- package/dist/tools/smartfetch/cache.d.ts +6 -0
- package/dist/tools/smartfetch/constants.d.ts +12 -0
- package/dist/tools/smartfetch/index.d.ts +3 -0
- package/dist/tools/smartfetch/network.d.ts +38 -0
- package/dist/tools/smartfetch/secondary-model.d.ts +28 -0
- package/dist/tools/smartfetch/tool.d.ts +3 -0
- package/dist/tools/smartfetch/types.d.ts +122 -0
- package/dist/tools/smartfetch/utils.d.ts +18 -0
- package/dist/tui-state.d.ts +168 -0
- package/dist/tui.d.ts +37 -0
- package/dist/tui.js +1896 -0
- package/dist/utils/agent-variant.d.ts +63 -0
- package/dist/utils/compat.d.ts +30 -0
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/internal-initiator.d.ts +6 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/polling.d.ts +21 -0
- package/dist/utils/session-manager.d.ts +55 -0
- package/dist/utils/session.d.ts +90 -0
- package/dist/utils/subagent-depth.d.ts +35 -0
- package/dist/utils/system-collapse.d.ts +6 -0
- package/dist/utils/task.d.ts +4 -0
- package/dist/utils/zip-extractor.d.ts +1 -0
- package/index.ts +1 -0
- package/opencode-dux.schema.json +634 -0
- package/package.json +103 -0
- package/src/agents/descriptions.ts +55 -0
- package/src/agents/designer.test.ts +86 -0
- package/src/agents/designer.ts +154 -0
- package/src/agents/display-name.test.ts +186 -0
- package/src/agents/explorer.test.ts +79 -0
- package/src/agents/explorer.ts +144 -0
- package/src/agents/fixer.test.ts +79 -0
- package/src/agents/fixer.ts +145 -0
- package/src/agents/index.test.ts +472 -0
- package/src/agents/index.ts +248 -0
- package/src/agents/interpreter.ts +136 -0
- package/src/agents/librarian.test.ts +80 -0
- package/src/agents/librarian.ts +145 -0
- package/src/agents/oracle.test.ts +89 -0
- package/src/agents/oracle.ts +184 -0
- package/src/agents/orchestrator.test.ts +116 -0
- package/src/agents/orchestrator.ts +574 -0
- package/src/agents/overrides.ts +95 -0
- package/src/agents/prompt-blocks.test.ts +114 -0
- package/src/agents/prompt-blocks.ts +640 -0
- package/src/agents/steward.ts +146 -0
- package/src/cli/config-io.test.ts +536 -0
- package/src/cli/config-io.ts +473 -0
- package/src/cli/config-manager.test.ts +141 -0
- package/src/cli/config-manager.ts +4 -0
- package/src/cli/index.ts +88 -0
- package/src/cli/install.ts +282 -0
- package/src/cli/mcps.test.ts +62 -0
- package/src/cli/mcps.ts +39 -0
- package/src/cli/model-key-normalization.test.ts +21 -0
- package/src/cli/model-key-normalization.ts +60 -0
- package/src/cli/paths.test.ts +167 -0
- package/src/cli/paths.ts +144 -0
- package/src/cli/providers.test.ts +118 -0
- package/src/cli/providers.ts +141 -0
- package/src/cli/skills.test.ts +111 -0
- package/src/cli/skills.ts +103 -0
- package/src/cli/system.test.ts +91 -0
- package/src/cli/system.ts +180 -0
- package/src/cli/types.ts +43 -0
- package/src/config/constants.ts +58 -0
- package/src/config/index.ts +4 -0
- package/src/config/loader.test.ts +1194 -0
- package/src/config/loader.ts +269 -0
- package/src/config/model-resolution.test.ts +176 -0
- package/src/config/runtime-preset.test.ts +61 -0
- package/src/config/runtime-preset.ts +37 -0
- package/src/config/schema.ts +248 -0
- package/src/config/utils.test.ts +41 -0
- package/src/config/utils.ts +23 -0
- package/src/discovery/local/types.ts +85 -0
- package/src/discovery/local.ts +322 -0
- package/src/discovery/mcp-servers.ts +804 -0
- package/src/discovery/skills.ts +959 -0
- package/src/hooks/apply-patch/codec.test.ts +184 -0
- package/src/hooks/apply-patch/codec.ts +352 -0
- package/src/hooks/apply-patch/errors.ts +117 -0
- package/src/hooks/apply-patch/execution-context.ts +432 -0
- package/src/hooks/apply-patch/hook.test.ts +768 -0
- package/src/hooks/apply-patch/index.ts +126 -0
- package/src/hooks/apply-patch/matching.test.ts +215 -0
- package/src/hooks/apply-patch/matching.ts +586 -0
- package/src/hooks/apply-patch/operations.test.ts +1535 -0
- package/src/hooks/apply-patch/operations.ts +3 -0
- package/src/hooks/apply-patch/patch.ts +9 -0
- package/src/hooks/apply-patch/prepared-changes.ts +400 -0
- package/src/hooks/apply-patch/resolution.test.ts +420 -0
- package/src/hooks/apply-patch/resolution.ts +437 -0
- package/src/hooks/apply-patch/rewrite.ts +496 -0
- package/src/hooks/apply-patch/test-helpers.ts +52 -0
- package/src/hooks/apply-patch/types.ts +111 -0
- package/src/hooks/auto-update-checker/cache.test.ts +179 -0
- package/src/hooks/auto-update-checker/cache.ts +188 -0
- package/src/hooks/auto-update-checker/checker.test.ts +159 -0
- package/src/hooks/auto-update-checker/checker.ts +308 -0
- package/src/hooks/auto-update-checker/constants.ts +33 -0
- package/src/hooks/auto-update-checker/index.test.ts +282 -0
- package/src/hooks/auto-update-checker/index.ts +225 -0
- package/src/hooks/auto-update-checker/types.ts +26 -0
- package/src/hooks/chat-headers.test.ts +236 -0
- package/src/hooks/chat-headers.ts +97 -0
- package/src/hooks/context-pressure-reminder/index.test.ts +179 -0
- package/src/hooks/context-pressure-reminder/index.ts +137 -0
- package/src/hooks/delegate-task-retry/guidance.ts +41 -0
- package/src/hooks/delegate-task-retry/hook.ts +23 -0
- package/src/hooks/delegate-task-retry/index.test.ts +38 -0
- package/src/hooks/delegate-task-retry/index.ts +7 -0
- package/src/hooks/delegate-task-retry/patterns.ts +79 -0
- package/src/hooks/filter-available-skills/index.test.ts +297 -0
- package/src/hooks/filter-available-skills/index.ts +160 -0
- package/src/hooks/foreground-fallback/index.test.ts +624 -0
- package/src/hooks/foreground-fallback/index.ts +374 -0
- package/src/hooks/image-hook.ts +6 -0
- package/src/hooks/index.ts +17 -0
- package/src/hooks/json-error-recovery/hook.ts +73 -0
- package/src/hooks/json-error-recovery/index.test.ts +111 -0
- package/src/hooks/json-error-recovery/index.ts +6 -0
- package/src/hooks/phase-reminder/index.test.ts +74 -0
- package/src/hooks/phase-reminder/index.ts +85 -0
- package/src/hooks/post-file-tool-nudge/index.test.ts +94 -0
- package/src/hooks/post-file-tool-nudge/index.ts +63 -0
- package/src/hooks/task-session-manager/index.test.ts +833 -0
- package/src/hooks/task-session-manager/index.ts +434 -0
- package/src/hooks/todo-continuation/index.test.ts +3026 -0
- package/src/hooks/todo-continuation/index.ts +878 -0
- package/src/hooks/todo-continuation/todo-hygiene.test.ts +204 -0
- package/src/hooks/todo-continuation/todo-hygiene.ts +207 -0
- package/src/index.ts +1672 -0
- package/src/mcp/context7.ts +14 -0
- package/src/mcp/grep-app.ts +11 -0
- package/src/mcp/index.test.ts +96 -0
- package/src/mcp/index.ts +66 -0
- package/src/mcp/types.ts +16 -0
- package/src/mcp/websearch.ts +47 -0
- package/src/skills/codemap/README.md +60 -0
- package/src/skills/codemap/SKILL.md +174 -0
- package/src/skills/codemap/scripts/codemap.mjs +483 -0
- package/src/skills/codemap/scripts/codemap.test.ts +129 -0
- package/src/skills/registry.ts +218 -0
- package/src/skills/simplify/README.md +19 -0
- package/src/skills/simplify/SKILL.md +138 -0
- package/src/subscriptions/accounts-store.test.ts +236 -0
- package/src/subscriptions/accounts-store.ts +184 -0
- package/src/subscriptions/index.ts +30 -0
- package/src/subscriptions/neuralwatt-scraper.ts +108 -0
- package/src/subscriptions/opencode-go-scraper.ts +301 -0
- package/src/subscriptions/types.ts +145 -0
- package/src/subscriptions/usage-service.test.ts +202 -0
- package/src/subscriptions/usage-service.ts +651 -0
- package/src/tools/ast-grep/cli.ts +257 -0
- package/src/tools/ast-grep/constants.ts +214 -0
- package/src/tools/ast-grep/downloader.ts +131 -0
- package/src/tools/ast-grep/index.ts +24 -0
- package/src/tools/ast-grep/tools.ts +117 -0
- package/src/tools/ast-grep/types.ts +51 -0
- package/src/tools/ast-grep/utils.ts +126 -0
- package/src/tools/delegate-handoff.test.ts +18 -0
- package/src/tools/delegate.ts +508 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/preset-manager.test.ts +795 -0
- package/src/tools/preset-manager.ts +332 -0
- package/src/tools/smartfetch/binary.ts +58 -0
- package/src/tools/smartfetch/cache.test.ts +34 -0
- package/src/tools/smartfetch/cache.ts +112 -0
- package/src/tools/smartfetch/constants.ts +29 -0
- package/src/tools/smartfetch/index.ts +8 -0
- package/src/tools/smartfetch/network.test.ts +178 -0
- package/src/tools/smartfetch/network.ts +614 -0
- package/src/tools/smartfetch/secondary-model.test.ts +85 -0
- package/src/tools/smartfetch/secondary-model.ts +276 -0
- package/src/tools/smartfetch/tool.test.ts +60 -0
- package/src/tools/smartfetch/tool.ts +832 -0
- package/src/tools/smartfetch/types.ts +135 -0
- package/src/tools/smartfetch/utils.test.ts +24 -0
- package/src/tools/smartfetch/utils.ts +456 -0
- package/src/tui-state.test.ts +867 -0
- package/src/tui-state.ts +1255 -0
- package/src/tui.test.ts +336 -0
- package/src/tui.ts +1539 -0
- package/src/utils/agent-variant.test.ts +244 -0
- package/src/utils/agent-variant.ts +187 -0
- package/src/utils/compat.ts +91 -0
- package/src/utils/env.ts +12 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/internal-initiator.ts +28 -0
- package/src/utils/logger.test.ts +220 -0
- package/src/utils/logger.ts +136 -0
- package/src/utils/polling.test.ts +191 -0
- package/src/utils/polling.ts +67 -0
- package/src/utils/session-manager.test.ts +173 -0
- package/src/utils/session-manager.ts +356 -0
- package/src/utils/session.test.ts +110 -0
- package/src/utils/session.ts +389 -0
- package/src/utils/subagent-depth.test.ts +170 -0
- package/src/utils/subagent-depth.ts +75 -0
- package/src/utils/system-collapse.test.ts +86 -0
- package/src/utils/system-collapse.ts +24 -0
- package/src/utils/task.test.ts +24 -0
- package/src/utils/task.ts +20 -0
- package/src/utils/zip-extractor.ts +102 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface NpmDistTags {
|
|
2
|
+
latest: string;
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}
|
|
5
|
+
export interface OpencodeConfig {
|
|
6
|
+
plugin?: unknown[];
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface PackageJson {
|
|
10
|
+
version: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface AutoUpdateCheckerOptions {
|
|
15
|
+
autoUpdate?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface PluginEntryInfo {
|
|
18
|
+
entry: string;
|
|
19
|
+
isPinned: boolean;
|
|
20
|
+
pinnedVersion: string | null;
|
|
21
|
+
configPath: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PluginInput, ProviderContext } from '@opencode-ai/plugin';
|
|
2
|
+
import type { Model, UserMessage } from '@opencode-ai/sdk';
|
|
3
|
+
interface ChatHeadersInput {
|
|
4
|
+
sessionID: string;
|
|
5
|
+
model: Model;
|
|
6
|
+
provider: ProviderContext;
|
|
7
|
+
message: UserMessage;
|
|
8
|
+
}
|
|
9
|
+
interface ChatHeadersOutput {
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export declare function __resetInternalMarkerCacheForTesting(): void;
|
|
13
|
+
export declare function createChatHeadersHook(ctx: PluginInput): {
|
|
14
|
+
'chat.headers': (input: ChatHeadersInput, output: ChatHeadersOutput) => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injects a /compact heads-up into the orchestrator's latest user turn when
|
|
3
|
+
* sidebar-style context telemetry shows the session is near the model window.
|
|
4
|
+
*/
|
|
5
|
+
import { type TuiSnapshot } from '../../tui-state';
|
|
6
|
+
/** Marker in the injected block; keep in sync with orchestrator prompt guidance. */
|
|
7
|
+
export declare const CONTEXT_PRESSURE_HEADING = "### Context budget (plugin telemetry)";
|
|
8
|
+
interface MessageInfo {
|
|
9
|
+
role: string;
|
|
10
|
+
agent?: string;
|
|
11
|
+
sessionID?: string;
|
|
12
|
+
}
|
|
13
|
+
interface MessagePart {
|
|
14
|
+
type: string;
|
|
15
|
+
text?: string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
interface MessageWithParts {
|
|
19
|
+
info: MessageInfo;
|
|
20
|
+
parts: MessagePart[];
|
|
21
|
+
}
|
|
22
|
+
export interface ContextPressureReminderOptions {
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
warnThresholdPct: number;
|
|
25
|
+
}
|
|
26
|
+
/** @internal Exported for tests */
|
|
27
|
+
export declare function applyContextPressureReminder(messages: MessageWithParts[], snapshot: TuiSnapshot, options: ContextPressureReminderOptions): void;
|
|
28
|
+
export declare function createContextPressureReminderHook(options: ContextPressureReminderOptions): {
|
|
29
|
+
'experimental.chat.messages.transform': (_input: Record<string, never>, output: {
|
|
30
|
+
messages: MessageWithParts[];
|
|
31
|
+
}) => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface DelegateTaskErrorPattern {
|
|
2
|
+
pattern: string;
|
|
3
|
+
errorType: string;
|
|
4
|
+
fixHint: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const DELEGATE_TASK_ERROR_PATTERNS: DelegateTaskErrorPattern[];
|
|
7
|
+
export interface DetectedError {
|
|
8
|
+
errorType: string;
|
|
9
|
+
originalOutput: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function detectDelegateTaskError(output: string): DetectedError | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter available_skills block based on the current agent's permission.skill rules.
|
|
3
|
+
* OpenCode core injects `<available_skills>` globally, so this hook rewrites that
|
|
4
|
+
* block before the prompt is sent.
|
|
5
|
+
*/
|
|
6
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
7
|
+
import { type PluginConfig } from '../../config';
|
|
8
|
+
interface MessageInfo {
|
|
9
|
+
role: string;
|
|
10
|
+
agent?: string;
|
|
11
|
+
}
|
|
12
|
+
interface MessagePart {
|
|
13
|
+
type: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
interface MessageWithParts {
|
|
18
|
+
info: MessageInfo;
|
|
19
|
+
parts: MessagePart[];
|
|
20
|
+
}
|
|
21
|
+
type SkillRule = 'allow' | 'ask' | 'deny';
|
|
22
|
+
declare function filterAvailableSkillsText(text: string, permissionRules: Record<string, SkillRule>): string;
|
|
23
|
+
/**
|
|
24
|
+
* Creates the experimental.chat.messages.transform hook for filtering available skills.
|
|
25
|
+
* This hook runs right before sending to API, so it doesn't affect UI display.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createFilterAvailableSkillsHook(ctx: PluginInput, config: PluginConfig): {
|
|
28
|
+
'experimental.chat.messages.transform': (_input: Record<string, never>, output: {
|
|
29
|
+
messages: MessageWithParts[];
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
export { filterAvailableSkillsText };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime model fallback for foreground (interactive) agent sessions.
|
|
3
|
+
*
|
|
4
|
+
* When OpenCode fires a session.error, message.updated, or session.status
|
|
5
|
+
* event containing a rate-limit signal, this manager:
|
|
6
|
+
* 1. Looks up the next untried model in the agent's configured chain
|
|
7
|
+
* 2. Aborts the rate-limited prompt via client.session.abort()
|
|
8
|
+
* 3. Re-queues the last user message via client.session.promptAsync()
|
|
9
|
+
* with the new model - promptAsync returns immediately so we never
|
|
10
|
+
* block the event handler waiting for a full LLM response.
|
|
11
|
+
*
|
|
12
|
+
* This mirrors the same fallback loop used for delegated sessions, but operates
|
|
13
|
+
* reactively through the event system instead of wrapping prompt() in a
|
|
14
|
+
* try/catch, which is not possible for interactive (foreground) sessions.
|
|
15
|
+
*/
|
|
16
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
17
|
+
type OpencodeClient = PluginInput['client'];
|
|
18
|
+
export declare function isRateLimitError(error: unknown): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Manages runtime model fallback for foreground agent sessions.
|
|
21
|
+
*
|
|
22
|
+
* Constructed at plugin init with the ordered fallback chains for each agent
|
|
23
|
+
* (built from _modelArray entries merged with fallback.chains config).
|
|
24
|
+
*/
|
|
25
|
+
export declare class ForegroundFallbackManager {
|
|
26
|
+
private readonly client;
|
|
27
|
+
/**
|
|
28
|
+
* Ordered fallback chains per agent.
|
|
29
|
+
* e.g. { orchestrator: ['anthropic/claude-opus-4-5', 'openai/gpt-4o'] }
|
|
30
|
+
* The first model that hasn't been tried yet is selected on each fallback.
|
|
31
|
+
*/
|
|
32
|
+
private readonly chains;
|
|
33
|
+
private readonly enabled;
|
|
34
|
+
/** sessionID → last observed model string ("providerID/modelID") */
|
|
35
|
+
private readonly sessionModel;
|
|
36
|
+
/** sessionID → agent name (populated from message.updated info.agent field) */
|
|
37
|
+
private readonly sessionAgent;
|
|
38
|
+
/** sessionID → set of models already attempted this session */
|
|
39
|
+
private readonly sessionTried;
|
|
40
|
+
/** Sessions with an active fallback switch in flight */
|
|
41
|
+
private readonly inProgress;
|
|
42
|
+
/** sessionID → timestamp of last trigger (for deduplication) */
|
|
43
|
+
private readonly lastTrigger;
|
|
44
|
+
constructor(client: OpencodeClient,
|
|
45
|
+
/**
|
|
46
|
+
* Ordered fallback chains per agent.
|
|
47
|
+
* e.g. { orchestrator: ['anthropic/claude-opus-4-5', 'openai/gpt-4o'] }
|
|
48
|
+
* The first model that hasn't been tried yet is selected on each fallback.
|
|
49
|
+
*/
|
|
50
|
+
chains: Record<string, string[]>, enabled: boolean);
|
|
51
|
+
/**
|
|
52
|
+
* Process an OpenCode plugin event.
|
|
53
|
+
* Call this from the plugin's `event` hook for every event received.
|
|
54
|
+
*/
|
|
55
|
+
handleEvent(rawEvent: unknown): Promise<void>;
|
|
56
|
+
private tryFallback;
|
|
57
|
+
/**
|
|
58
|
+
* Determine the fallback chain to use for a session.
|
|
59
|
+
*
|
|
60
|
+
* Priority:
|
|
61
|
+
* 1. Agent name known AND has a configured chain → return it directly
|
|
62
|
+
* 2. Agent name known but NO chain configured → return [] (no fallback;
|
|
63
|
+
* do NOT bleed into other agents' chains which would re-prompt the
|
|
64
|
+
* session with a model belonging to a completely different agent)
|
|
65
|
+
* 3. Agent name unknown, current model known → search all chains for
|
|
66
|
+
* the model to infer which chain to use
|
|
67
|
+
* 4. Nothing matches → flatten all chains as a last resort (only
|
|
68
|
+
* reached when both agent name and current model are unavailable)
|
|
69
|
+
*/
|
|
70
|
+
private resolveChain;
|
|
71
|
+
}
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createApplyPatchHook } from './apply-patch';
|
|
2
|
+
export type { AutoUpdateCheckerOptions } from './auto-update-checker';
|
|
3
|
+
export { createAutoUpdateCheckerHook } from './auto-update-checker';
|
|
4
|
+
export { createChatHeadersHook } from './chat-headers';
|
|
5
|
+
export { createContextPressureReminderHook } from './context-pressure-reminder';
|
|
6
|
+
export { createDelegateTaskRetryHook } from './delegate-task-retry';
|
|
7
|
+
export { createFilterAvailableSkillsHook } from './filter-available-skills';
|
|
8
|
+
export { ForegroundFallbackManager, isRateLimitError, } from './foreground-fallback';
|
|
9
|
+
export { processImageAttachments } from './image-hook';
|
|
10
|
+
export { createJsonErrorRecoveryHook } from './json-error-recovery';
|
|
11
|
+
export { createPhaseReminderHook } from './phase-reminder';
|
|
12
|
+
export { createPostFileToolNudgeHook } from './post-file-tool-nudge';
|
|
13
|
+
export { createTaskSessionManagerHook } from './task-session-manager';
|
|
14
|
+
export { createTodoContinuationHook } from './todo-continuation';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
2
|
+
export declare const JSON_ERROR_TOOL_EXCLUDE_LIST: readonly ["bash", "read", "glob", "webfetch", "grep_app_searchgithub", "websearch_web_search_exa"];
|
|
3
|
+
export declare const JSON_ERROR_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp];
|
|
4
|
+
export declare const JSON_ERROR_REMINDER = "\n[JSON PARSE ERROR - IMMEDIATE ACTION REQUIRED]\n\nYou sent invalid JSON arguments. The system could not parse your tool call.\nSTOP and do this NOW:\n\n1. LOOK at the error message above to see what was expected vs what you sent.\n2. CORRECT your JSON syntax (missing braces, unescaped quotes, trailing commas, etc).\n3. RETRY the tool call with valid JSON.\n\nDO NOT repeat the exact same invalid call.\n";
|
|
5
|
+
interface ToolExecuteAfterInput {
|
|
6
|
+
tool: string;
|
|
7
|
+
sessionID: string;
|
|
8
|
+
callID: string;
|
|
9
|
+
}
|
|
10
|
+
interface ToolExecuteAfterOutput {
|
|
11
|
+
title: string;
|
|
12
|
+
output: unknown;
|
|
13
|
+
metadata: unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare function createJsonErrorRecoveryHook(_ctx: PluginInput): {
|
|
16
|
+
'tool.execute.after': (input: ToolExecuteAfterInput, output: ToolExecuteAfterOutput) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createJsonErrorRecoveryHook, JSON_ERROR_PATTERNS, JSON_ERROR_REMINDER, JSON_ERROR_TOOL_EXCLUDE_LIST, } from './hook';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const PHASE_REMINDER = "<internal_reminder>!IMPORTANT! Follow <first_gate> order in system prompt; delegate_subagent in the same turn you name the agent. !END!</internal_reminder>";
|
|
2
|
+
interface MessageInfo {
|
|
3
|
+
role: string;
|
|
4
|
+
agent?: string;
|
|
5
|
+
sessionID?: string;
|
|
6
|
+
}
|
|
7
|
+
interface MessagePart {
|
|
8
|
+
type: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
interface MessageWithParts {
|
|
13
|
+
info: MessageInfo;
|
|
14
|
+
parts: MessagePart[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates the experimental.chat.messages.transform hook for phase reminder injection.
|
|
18
|
+
* This hook runs right before sending to API, so it doesn't affect UI display.
|
|
19
|
+
* Only injects for the orchestrator agent.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createPhaseReminderHook(): {
|
|
22
|
+
'experimental.chat.messages.transform': (_input: Record<string, never>, output: {
|
|
23
|
+
messages: MessageWithParts[];
|
|
24
|
+
}) => Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-tool nudge - queues a delegation reminder after file reads/writes.
|
|
3
|
+
* Catches the "inspect/edit files → implement myself" anti-pattern.
|
|
4
|
+
*/
|
|
5
|
+
interface ToolExecuteAfterInput {
|
|
6
|
+
tool: string;
|
|
7
|
+
sessionID?: string;
|
|
8
|
+
callID?: string;
|
|
9
|
+
}
|
|
10
|
+
interface ToolExecuteAfterOutput {
|
|
11
|
+
output?: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface PostFileToolNudgeOptions {
|
|
14
|
+
shouldInject?: (sessionID: string) => boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function createPostFileToolNudgeHook(options?: PostFileToolNudgeOptions): {
|
|
17
|
+
'tool.execute.after': (input: ToolExecuteAfterInput, output: ToolExecuteAfterOutput) => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
2
|
+
interface ChatMessagePart {
|
|
3
|
+
type: string;
|
|
4
|
+
text?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
interface ChatMessage {
|
|
8
|
+
info: {
|
|
9
|
+
role: string;
|
|
10
|
+
agent?: string;
|
|
11
|
+
sessionID?: string;
|
|
12
|
+
};
|
|
13
|
+
parts: ChatMessagePart[];
|
|
14
|
+
}
|
|
15
|
+
export declare function createTaskSessionManagerHook(_ctx: PluginInput, options: {
|
|
16
|
+
maxSessionsPerAgent: number;
|
|
17
|
+
readContextMinLines?: number;
|
|
18
|
+
readContextMaxFiles?: number;
|
|
19
|
+
shouldManageSession: (sessionID: string) => boolean;
|
|
20
|
+
}): {
|
|
21
|
+
'tool.execute.before': (input: {
|
|
22
|
+
tool: string;
|
|
23
|
+
sessionID?: string;
|
|
24
|
+
callID?: string;
|
|
25
|
+
}, output: {
|
|
26
|
+
args?: unknown;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
'tool.execute.after': (input: {
|
|
29
|
+
tool: string;
|
|
30
|
+
sessionID?: string;
|
|
31
|
+
callID?: string;
|
|
32
|
+
}, output: {
|
|
33
|
+
output: unknown;
|
|
34
|
+
metadata?: unknown;
|
|
35
|
+
}) => Promise<void>;
|
|
36
|
+
'experimental.chat.messages.transform': (_input: Record<string, never>, output: {
|
|
37
|
+
messages: ChatMessage[];
|
|
38
|
+
}) => Promise<void>;
|
|
39
|
+
event: (input: {
|
|
40
|
+
event: {
|
|
41
|
+
type: string;
|
|
42
|
+
properties?: {
|
|
43
|
+
info?: {
|
|
44
|
+
id?: string;
|
|
45
|
+
parentID?: string;
|
|
46
|
+
};
|
|
47
|
+
sessionID?: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}) => Promise<void>;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
2
|
+
interface MessagePart {
|
|
3
|
+
type?: string;
|
|
4
|
+
text?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
interface ChatTransformMessage {
|
|
8
|
+
info: {
|
|
9
|
+
id?: string;
|
|
10
|
+
role?: string;
|
|
11
|
+
agent?: string;
|
|
12
|
+
sessionID?: string;
|
|
13
|
+
};
|
|
14
|
+
parts: MessagePart[];
|
|
15
|
+
}
|
|
16
|
+
export declare function createTodoContinuationHook(ctx: PluginInput, config?: {
|
|
17
|
+
maxContinuations?: number;
|
|
18
|
+
cooldownMs?: number;
|
|
19
|
+
autoEnable?: boolean;
|
|
20
|
+
autoEnableThreshold?: number;
|
|
21
|
+
}): {
|
|
22
|
+
tool: Record<string, unknown>;
|
|
23
|
+
handleToolExecuteAfter: (input: {
|
|
24
|
+
tool: string;
|
|
25
|
+
sessionID?: string;
|
|
26
|
+
}, output?: {
|
|
27
|
+
output?: unknown;
|
|
28
|
+
}) => Promise<void>;
|
|
29
|
+
handleMessagesTransform: (output: {
|
|
30
|
+
messages: ChatTransformMessage[];
|
|
31
|
+
}) => Promise<void>;
|
|
32
|
+
handleEvent: (input: {
|
|
33
|
+
event: {
|
|
34
|
+
type: string;
|
|
35
|
+
properties?: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
}) => Promise<void>;
|
|
38
|
+
handleChatMessage: (input: {
|
|
39
|
+
sessionID: string;
|
|
40
|
+
agent?: string;
|
|
41
|
+
}) => void;
|
|
42
|
+
handleCommandExecuteBefore: (input: {
|
|
43
|
+
command: string;
|
|
44
|
+
sessionID: string;
|
|
45
|
+
arguments: string;
|
|
46
|
+
}, output: {
|
|
47
|
+
parts: Array<{
|
|
48
|
+
type: string;
|
|
49
|
+
text?: string;
|
|
50
|
+
}>;
|
|
51
|
+
}) => Promise<void>;
|
|
52
|
+
};
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare const TODO_HYGIENE_REMINDER = "If the active task changed or finished, update the todo list to match the current work state.";
|
|
2
|
+
export declare const TODO_FINAL_ACTIVE_REMINDER = "If you are finishing now, do not leave the active todo in_progress. Mark it completed, or move unfinished work back to pending.";
|
|
3
|
+
interface ToolInput {
|
|
4
|
+
tool: string;
|
|
5
|
+
sessionID?: string;
|
|
6
|
+
}
|
|
7
|
+
interface EventInput {
|
|
8
|
+
type: string;
|
|
9
|
+
properties?: {
|
|
10
|
+
info?: {
|
|
11
|
+
id?: string;
|
|
12
|
+
};
|
|
13
|
+
sessionID?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface RequestStartInput {
|
|
17
|
+
sessionID: string;
|
|
18
|
+
}
|
|
19
|
+
interface Options {
|
|
20
|
+
getTodoState: (sessionID: string) => Promise<{
|
|
21
|
+
hasOpenTodos: boolean;
|
|
22
|
+
openCount: number;
|
|
23
|
+
inProgressCount: number;
|
|
24
|
+
pendingCount: number;
|
|
25
|
+
}>;
|
|
26
|
+
shouldInject?: (sessionID: string) => boolean;
|
|
27
|
+
log?: (message: string, meta?: Record<string, unknown>) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare function createTodoHygiene(options: Options): {
|
|
30
|
+
handleRequestStart(input: RequestStartInput): void;
|
|
31
|
+
handleToolExecuteAfter(input: ToolInput, _output?: unknown): Promise<void>;
|
|
32
|
+
getPendingReminder(sessionID: string): string | null;
|
|
33
|
+
handleEvent(event: EventInput): void;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
package/dist/index.d.ts
ADDED