@osovv/vv-opencode 2.0.1 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/README.md +88 -87
- package/dist/commands/completion.js +0 -1
- package/dist/commands/completion.js.map +1 -1
- package/dist/commands/doctor.js +6 -9
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts +2 -1
- package/dist/commands/init.js +7 -12
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/install.d.ts +4 -0
- package/dist/commands/install.js +40 -37
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/launch.d.ts +2 -1
- package/dist/commands/launch.js +18 -14
- package/dist/commands/launch.js.map +1 -1
- package/dist/commands/patch-provider.d.ts +225 -307
- package/dist/commands/patch-provider.js +92 -296
- package/dist/commands/patch-provider.js.map +1 -1
- package/dist/commands/status.js +7 -10
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/sync.d.ts +4 -0
- package/dist/commands/sync.js +38 -35
- package/dist/commands/sync.js.map +1 -1
- package/dist/index.d.ts +25 -5
- package/dist/index.js +73 -34
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-tool-catalog.d.ts +1 -1
- package/dist/lib/agent-tool-catalog.js +3 -6
- package/dist/lib/agent-tool-catalog.js.map +1 -1
- package/dist/lib/agent-tool-contract.d.ts +22 -13
- package/dist/lib/agent-tool-contract.js +20 -20
- package/dist/lib/agent-tool-contract.js.map +1 -1
- package/dist/lib/analytics/types.d.ts +7 -1
- package/dist/lib/analytics/types.js +2 -2
- package/dist/lib/analytics/types.js.map +1 -1
- package/dist/lib/config-layers.d.ts +28 -6
- package/dist/lib/config-layers.js +268 -73
- package/dist/lib/config-layers.js.map +1 -1
- package/dist/lib/managed-agents.d.ts +24 -2
- package/dist/lib/managed-agents.js +45 -15
- package/dist/lib/managed-agents.js.map +1 -1
- package/dist/lib/model-roles.d.ts +5 -0
- package/dist/lib/model-roles.js +22 -1
- package/dist/lib/model-roles.js.map +1 -1
- package/dist/lib/opencode/agent-registrations.d.ts +4 -4
- package/dist/lib/opencode/agent-registrations.js +386 -197
- package/dist/lib/opencode/agent-registrations.js.map +1 -1
- package/dist/lib/opencode/inspection.d.ts +13 -13
- package/dist/lib/opencode/inspection.js +69 -106
- package/dist/lib/opencode/inspection.js.map +1 -1
- package/dist/lib/opencode/model-overrides.d.ts +2 -2
- package/dist/lib/opencode/model-overrides.js +192 -47
- package/dist/lib/opencode/model-overrides.js.map +1 -1
- package/dist/lib/opencode/paths.d.ts +6 -2
- package/dist/lib/opencode/paths.js +12 -11
- package/dist/lib/opencode/paths.js.map +1 -1
- package/dist/lib/opencode/plugin-registration.d.ts +10 -11
- package/dist/lib/opencode/plugin-registration.js +76 -138
- package/dist/lib/opencode/plugin-registration.js.map +1 -1
- package/dist/lib/opencode/shared-utils.d.ts +47 -3
- package/dist/lib/opencode/shared-utils.js +346 -15
- package/dist/lib/opencode/shared-utils.js.map +1 -1
- package/dist/lib/opencode.d.ts +5 -6
- package/dist/lib/opencode.js +10 -10
- package/dist/lib/opencode.js.map +1 -1
- package/dist/lib/vvoc-config.js +4 -4
- package/dist/lib/vvoc-config.js.map +1 -1
- package/dist/lib/vvoc-paths.d.ts +7 -0
- package/dist/lib/vvoc-paths.js +15 -1
- package/dist/lib/vvoc-paths.js.map +1 -1
- package/dist/lib/vvoc-preset-registry.d.ts +38 -50
- package/dist/lib/vvoc-preset-registry.js +38 -48
- package/dist/lib/vvoc-preset-registry.js.map +1 -1
- package/dist/plugins/analytics/index.d.ts +20 -14
- package/dist/plugins/analytics/index.js +281 -133
- package/dist/plugins/analytics/index.js.map +1 -1
- package/dist/plugins/guardian/index.d.ts +63 -42
- package/dist/plugins/guardian/index.js +217 -759
- package/dist/plugins/guardian/index.js.map +1 -1
- package/dist/plugins/hashline-edit/index.d.ts +145 -31
- package/dist/plugins/hashline-edit/index.js +679 -244
- package/dist/plugins/hashline-edit/index.js.map +1 -1
- package/dist/plugins/hashline-edit/schemas.d.ts +1 -1
- package/dist/plugins/hashline-edit/schemas.js +3 -3
- package/dist/plugins/hashline-edit/schemas.js.map +1 -1
- package/dist/plugins/model-roles/index.d.ts +18 -4
- package/dist/plugins/model-roles/index.js +44 -181
- package/dist/plugins/model-roles/index.js.map +1 -1
- package/dist/plugins/peak-hours/index.d.ts +23 -23
- package/dist/plugins/peak-hours/index.js +211 -180
- package/dist/plugins/peak-hours/index.js.map +1 -1
- package/dist/plugins/secrets-redaction/deep.js +35 -51
- package/dist/plugins/secrets-redaction/deep.js.map +1 -1
- package/dist/plugins/secrets-redaction/index.d.ts +96 -8
- package/dist/plugins/secrets-redaction/index.js +290 -102
- package/dist/plugins/secrets-redaction/index.js.map +1 -1
- package/dist/plugins/secrets-redaction/session.d.ts +9 -0
- package/dist/plugins/secrets-redaction/session.js +21 -4
- package/dist/plugins/secrets-redaction/session.js.map +1 -1
- package/dist/plugins/secrets-redaction/stream.d.ts +92 -0
- package/dist/plugins/secrets-redaction/stream.js +772 -0
- package/dist/plugins/secrets-redaction/stream.js.map +1 -0
- package/dist/plugins/spec-guard/index.d.ts +49 -18
- package/dist/plugins/spec-guard/index.js +231 -129
- package/dist/plugins/spec-guard/index.js.map +1 -1
- package/dist/plugins/system-context-injection/index.d.ts +10 -4
- package/dist/plugins/system-context-injection/index.js +271 -78
- package/dist/plugins/system-context-injection/index.js.map +1 -1
- package/dist/plugins/tool-history-compaction/index.d.ts +26 -4
- package/dist/plugins/tool-history-compaction/index.js +170 -32
- package/dist/plugins/tool-history-compaction/index.js.map +1 -1
- package/dist/plugins/tool-history-compaction/transform.d.ts +47 -16
- package/dist/plugins/tool-history-compaction/transform.js +173 -55
- package/dist/plugins/tool-history-compaction/transform.js.map +1 -1
- package/dist/plugins/web-tools/fetch-service.d.ts +51 -13
- package/dist/plugins/web-tools/fetch-service.js +106 -75
- package/dist/plugins/web-tools/fetch-service.js.map +1 -1
- package/dist/plugins/web-tools/index.d.ts +58 -16
- package/dist/plugins/web-tools/index.js +202 -91
- package/dist/plugins/web-tools/index.js.map +1 -1
- package/dist/plugins/web-tools/media-loader.d.ts +3 -3
- package/dist/plugins/web-tools/media-loader.js +3 -3
- package/dist/plugins/web-tools/media-loader.js.map +1 -1
- package/dist/plugins/web-tools/providers/native-fetch.d.ts +2 -2
- package/dist/plugins/web-tools/providers/native-fetch.js +1 -1
- package/dist/plugins/web-tools/providers/native-fetch.js.map +1 -1
- package/dist/plugins/web-tools/providers/spider.d.ts +2 -2
- package/dist/plugins/web-tools/providers/spider.js +1 -1
- package/dist/plugins/web-tools/providers/spider.js.map +1 -1
- package/dist/plugins/web-tools/providers/zai.d.ts +2 -2
- package/dist/plugins/web-tools/providers/zai.js +1 -1
- package/dist/plugins/web-tools/providers/zai.js.map +1 -1
- package/dist/plugins/web-tools/schemas.d.ts +1 -1
- package/dist/plugins/web-tools/schemas.js +3 -3
- package/dist/plugins/web-tools/schemas.js.map +1 -1
- package/dist/plugins/web-tools/search-service.d.ts +81 -12
- package/dist/plugins/web-tools/search-service.js +104 -57
- package/dist/plugins/web-tools/search-service.js.map +1 -1
- package/dist/plugins/workflow/authorization.d.ts +44 -10
- package/dist/plugins/workflow/authorization.js +113 -73
- package/dist/plugins/workflow/authorization.js.map +1 -1
- package/dist/plugins/workflow/cancellation.d.ts +86 -0
- package/dist/plugins/workflow/cancellation.js +202 -0
- package/dist/plugins/workflow/cancellation.js.map +1 -0
- package/dist/plugins/workflow/checkpoints.d.ts +7 -1
- package/dist/plugins/workflow/checkpoints.js +141 -21
- package/dist/plugins/workflow/checkpoints.js.map +1 -1
- package/dist/plugins/workflow/delegated.d.ts +14 -0
- package/dist/plugins/workflow/delegated.js +6 -5
- package/dist/plugins/workflow/delegated.js.map +1 -1
- package/dist/plugins/workflow/host.d.ts +81 -0
- package/dist/plugins/workflow/host.js +189 -0
- package/dist/plugins/workflow/host.js.map +1 -0
- package/dist/plugins/workflow/index.d.ts +69 -4
- package/dist/plugins/workflow/index.js +1391 -1026
- package/dist/plugins/workflow/index.js.map +1 -1
- package/dist/plugins/workflow/recovery.d.ts +3 -5
- package/dist/plugins/workflow/recovery.js +18 -33
- package/dist/plugins/workflow/recovery.js.map +1 -1
- package/dist/plugins/workflow/repair.d.ts +31 -5
- package/dist/plugins/workflow/repair.js +116 -48
- package/dist/plugins/workflow/repair.js.map +1 -1
- package/dist/plugins/workflow/results.d.ts +31 -31
- package/dist/plugins/workflow/results.js +4 -4
- package/dist/plugins/workflow/results.js.map +1 -1
- package/dist/plugins/workflow/schemas.d.ts +3 -3
- package/dist/plugins/workflow/schemas.js +5 -5
- package/dist/plugins/workflow/schemas.js.map +1 -1
- package/dist/plugins/workflow/system-instruction.md +4 -0
- package/dist/plugins/workflow/tooling.d.ts +6 -0
- package/dist/plugins/workflow/tooling.js +3 -1
- package/dist/plugins/workflow/tooling.js.map +1 -1
- package/dist/runtime/auxiliary.d.ts +13 -0
- package/dist/runtime/auxiliary.js +108 -0
- package/dist/runtime/auxiliary.js.map +1 -0
- package/dist/runtime/client.d.ts +88 -0
- package/dist/runtime/client.js +174 -0
- package/dist/runtime/client.js.map +1 -0
- package/dist/runtime/context-inspection-contract.d.ts +397 -0
- package/dist/runtime/context-inspection-contract.js +622 -0
- package/dist/runtime/context-inspection-contract.js.map +1 -0
- package/dist/runtime/context-inspection.d.ts +52 -0
- package/dist/runtime/context-inspection.js +324 -0
- package/dist/runtime/context-inspection.js.map +1 -0
- package/dist/runtime/context.d.ts +192 -0
- package/dist/runtime/context.js +1246 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/coordination.d.ts +40 -0
- package/dist/runtime/coordination.js +87 -0
- package/dist/runtime/coordination.js.map +1 -0
- package/dist/runtime/model-registry.d.ts +34 -0
- package/dist/runtime/model-registry.js +227 -0
- package/dist/runtime/model-registry.js.map +1 -0
- package/dist/runtime/permissions.d.ts +20 -0
- package/dist/runtime/permissions.js +250 -0
- package/dist/runtime/permissions.js.map +1 -0
- package/dist/runtime/snapshot-config.d.ts +80 -0
- package/dist/runtime/snapshot-config.js +268 -0
- package/dist/runtime/snapshot-config.js.map +1 -0
- package/dist/runtime/snapshot-store.d.ts +25 -0
- package/dist/runtime/snapshot-store.js +519 -0
- package/dist/runtime/snapshot-store.js.map +1 -0
- package/dist/runtime/snapshots.d.ts +59 -0
- package/dist/runtime/snapshots.js +721 -0
- package/dist/runtime/snapshots.js.map +1 -0
- package/dist/runtime/types.d.ts +713 -0
- package/dist/runtime/types.js +190 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/tui/analytics/indicator.d.ts +25 -26
- package/dist/tui/analytics/indicator.js +66 -74
- package/dist/tui/analytics/indicator.js.map +1 -1
- package/dist/tui/branding/footer.d.ts +7 -12
- package/dist/tui/branding/footer.js +16 -24
- package/dist/tui/branding/footer.js.map +1 -1
- package/dist/tui/context/analyze.d.ts +20 -9
- package/dist/tui/context/analyze.js +295 -257
- package/dist/tui/context/analyze.js.map +1 -1
- package/dist/tui/context/collect.d.ts +29 -3
- package/dist/tui/context/collect.js +450 -66
- package/dist/tui/context/collect.js.map +1 -1
- package/dist/tui/context/plugin.d.ts +21 -7
- package/dist/tui/context/plugin.js +65 -70
- package/dist/tui/context/plugin.js.map +1 -1
- package/dist/tui/context/types.d.ts +174 -43
- package/dist/tui/context/types.js +25 -19
- package/dist/tui/context/types.js.map +1 -1
- package/dist/tui/context/view.d.ts +33 -7
- package/dist/tui/context/view.js +136 -81
- package/dist/tui/context/view.js.map +1 -1
- package/dist/tui/peak-hours/banner.d.ts +13 -11
- package/dist/tui/peak-hours/banner.js +48 -80
- package/dist/tui/peak-hours/banner.js.map +1 -1
- package/dist/tui/policy.d.ts +69 -0
- package/dist/tui/policy.js +169 -0
- package/dist/tui/policy.js.map +1 -0
- package/dist/tui.d.ts +3 -8
- package/dist/tui.js +72 -68
- package/dist/tui.js.map +1 -1
- package/package.json +18 -14
- package/schemas/vvoc/v3.json +1 -1
- package/server.js +3 -5
- package/templates/agents/enhancer.md +10 -5
- package/templates/agents/guardian.md +10 -4
- package/templates/agents/investigator.md +4 -2
- package/templates/agents/vv-code-reviewer.md +4 -2
- package/templates/agents/vv-spec-reviewer.md +4 -2
- package/templates/skills/vv-execute/references/tool-contracts.md +1 -1
- package/tui.js +3 -5
- package/dist/plugins/analytics/v2.d.ts +0 -21
- package/dist/plugins/analytics/v2.js +0 -133
- package/dist/plugins/analytics/v2.js.map +0 -1
- package/dist/plugins/guardian/v2.d.ts +0 -13
- package/dist/plugins/guardian/v2.js +0 -204
- package/dist/plugins/guardian/v2.js.map +0 -1
- package/dist/plugins/hashline-edit/v2.d.ts +0 -12
- package/dist/plugins/hashline-edit/v2.js +0 -145
- package/dist/plugins/hashline-edit/v2.js.map +0 -1
- package/dist/plugins/model-roles/v2.d.ts +0 -24
- package/dist/plugins/model-roles/v2.js +0 -274
- package/dist/plugins/model-roles/v2.js.map +0 -1
- package/dist/plugins/peak-hours/v2.d.ts +0 -12
- package/dist/plugins/peak-hours/v2.js +0 -99
- package/dist/plugins/peak-hours/v2.js.map +0 -1
- package/dist/plugins/secrets-redaction/v2.d.ts +0 -19
- package/dist/plugins/secrets-redaction/v2.js +0 -138
- package/dist/plugins/secrets-redaction/v2.js.map +0 -1
- package/dist/plugins/spec-guard/v2.d.ts +0 -12
- package/dist/plugins/spec-guard/v2.js +0 -139
- package/dist/plugins/spec-guard/v2.js.map +0 -1
- package/dist/plugins/system-context-injection/agent-contexts.d.ts +0 -5
- package/dist/plugins/system-context-injection/agent-contexts.js +0 -164
- package/dist/plugins/system-context-injection/agent-contexts.js.map +0 -1
- package/dist/plugins/system-context-injection/v2.d.ts +0 -13
- package/dist/plugins/system-context-injection/v2.js +0 -60
- package/dist/plugins/system-context-injection/v2.js.map +0 -1
- package/dist/plugins/tool-history-compaction/v2.d.ts +0 -11
- package/dist/plugins/tool-history-compaction/v2.js +0 -56
- package/dist/plugins/tool-history-compaction/v2.js.map +0 -1
- package/dist/plugins/v2-runtime/config-watcher.d.ts +0 -26
- package/dist/plugins/v2-runtime/config-watcher.js +0 -111
- package/dist/plugins/v2-runtime/config-watcher.js.map +0 -1
- package/dist/plugins/v2-runtime/index.d.ts +0 -50
- package/dist/plugins/v2-runtime/index.js +0 -114
- package/dist/plugins/v2-runtime/index.js.map +0 -1
- package/dist/plugins/v2-runtime/location-config.d.ts +0 -51
- package/dist/plugins/v2-runtime/location-config.js +0 -91
- package/dist/plugins/v2-runtime/location-config.js.map +0 -1
- package/dist/plugins/v2-runtime/setup.d.ts +0 -48
- package/dist/plugins/v2-runtime/setup.js +0 -174
- package/dist/plugins/v2-runtime/setup.js.map +0 -1
- package/dist/plugins/web-tools/v2.d.ts +0 -11
- package/dist/plugins/web-tools/v2.js +0 -99
- package/dist/plugins/web-tools/v2.js.map +0 -1
- package/dist/plugins/workflow/v2.d.ts +0 -76
- package/dist/plugins/workflow/v2.js +0 -283
- package/dist/plugins/workflow/v2.js.map +0 -1
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Plugin as V2Plugin } from "@opencode/plugin";
|
|
2
|
-
import type { V2AdapterContext } from "../v2-runtime/setup.js";
|
|
3
|
-
/**
|
|
4
|
-
* Register the edit routing on the v2 runtime.
|
|
5
|
-
*
|
|
6
|
-
* The v1 chat.message visibility mutation becomes deletion of non-visible
|
|
7
|
-
* edit tools from the context hook's request tools, model tracking moves to
|
|
8
|
-
* the same hook's model reference, and the owned tools publish through the
|
|
9
|
-
* tool transform with their strict JSON Schema inputs. Routing resolves per
|
|
10
|
-
* session location through the shared adapter.
|
|
11
|
-
*/
|
|
12
|
-
export declare function setupHashlineEditV2(adapter: V2AdapterContext): Promise<V2Plugin.Cleanup | void>;
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
// FILE: src/plugins/hashline-edit/v2.ts
|
|
2
|
-
// VERSION: 1.0.0
|
|
3
|
-
// START_MODULE_CONTRACT
|
|
4
|
-
// PURPOSE: Route per-model edit tooling on the OpenCode v2 runtime: expose exactly one edit tool per model, validate owned arguments, and transform read output for hashline sessions.
|
|
5
|
-
// SCOPE: v2 setup only: track the session model from the context hook, enforce edit-tool visibility by deleting non-visible tools from the request, register hashline_edit and str_replace_editor with their strict JSON Schema inputs through the tool transform, run the shared visibility and argument guards on execute.before, apply the routed read transformation on execute.after, and resolve routing per session location.
|
|
6
|
-
// DEPENDS: [@opencode/plugin, src/lib/config-layers.ts, src/plugins/hashline-edit/index.ts, src/plugins/hashline-edit/routing.ts, src/plugins/hashline-edit/schemas.ts, src/plugins/hashline-edit/session-state.ts, src/plugins/v2-runtime/setup.ts]
|
|
7
|
-
// LINKS: [M-PLUGIN-HASHLINE-EDIT, V-M-PLUGIN-HASHLINE-EDIT, M-PLUGIN-V2-RUNTIME]
|
|
8
|
-
// ROLE: RUNTIME
|
|
9
|
-
// MAP_MODE: EXPORTS
|
|
10
|
-
// END_MODULE_CONTRACT
|
|
11
|
-
//
|
|
12
|
-
// START_MODULE_MAP
|
|
13
|
-
// setupHashlineEditV2 - Register edit routing, owned tools, and the read transformer for one OpenCode v2 plugin context.
|
|
14
|
-
// END_MODULE_MAP
|
|
15
|
-
//
|
|
16
|
-
// START_CHANGE_SUMMARY
|
|
17
|
-
// LAST_CHANGE: [C-OPENCODE-V2-MIGRATION T-004 - Ported edit routing onto v2 context and tool hooks.]
|
|
18
|
-
// END_CHANGE_SUMMARY
|
|
19
|
-
import { loadVvocConfigForRead } from "../../lib/config-layers.js";
|
|
20
|
-
import { assertEditToolVisible, EDIT_VISIBILITY_TOOLS, executeHashlineEdit, executeStrReplaceEditor, isEditTypeTool, isHashlineEligibleReadOutput, isReadTool, readArgFilePath, readSourceLines, statSnapshot, transformReadOutput, visibleToolsForMode, } from "./index.js";
|
|
21
|
-
import { hashlineEditContract, strReplaceEditorContract } from "./schemas.js";
|
|
22
|
-
import { parseHashlineEditPluginEntry, resolveEditMode } from "./routing.js";
|
|
23
|
-
import { SessionFileCache, SessionModelCache } from "./session-state.js";
|
|
24
|
-
// START_BLOCK_SETUP_HASHLINE_EDIT_V2
|
|
25
|
-
/**
|
|
26
|
-
* Register the edit routing on the v2 runtime.
|
|
27
|
-
*
|
|
28
|
-
* The v1 chat.message visibility mutation becomes deletion of non-visible
|
|
29
|
-
* edit tools from the context hook's request tools, model tracking moves to
|
|
30
|
-
* the same hook's model reference, and the owned tools publish through the
|
|
31
|
-
* tool transform with their strict JSON Schema inputs. Routing resolves per
|
|
32
|
-
* session location through the shared adapter.
|
|
33
|
-
*/
|
|
34
|
-
export async function setupHashlineEditV2(adapter) {
|
|
35
|
-
const directory = adapter.ctx.location.directory;
|
|
36
|
-
const read = await loadVvocConfigForRead({
|
|
37
|
-
cwd: directory,
|
|
38
|
-
scope: "effective",
|
|
39
|
-
allowDefault: true,
|
|
40
|
-
});
|
|
41
|
-
const settings = parseHashlineEditPluginEntry(read.config.plugins?.["hashline-edit"]);
|
|
42
|
-
if (!settings.enabled)
|
|
43
|
-
return undefined;
|
|
44
|
-
const routing = settings.routing;
|
|
45
|
-
const modelCache = new SessionModelCache();
|
|
46
|
-
const fileCache = new SessionFileCache();
|
|
47
|
-
const resolveSessionMode = (sessionID) => resolveEditMode(routing, modelCache.get(sessionID));
|
|
48
|
-
const contextHook = await adapter.ctx.session.hook("context", (event) => {
|
|
49
|
-
const model = event.model;
|
|
50
|
-
if (model?.providerID && model?.id) {
|
|
51
|
-
modelCache.set(String(event.sessionID), { providerID: model.providerID, modelID: model.id });
|
|
52
|
-
}
|
|
53
|
-
const mode = resolveEditMode(routing, {
|
|
54
|
-
providerID: model?.providerID,
|
|
55
|
-
modelID: model?.id,
|
|
56
|
-
});
|
|
57
|
-
const visible = new Set(visibleToolsForMode(mode));
|
|
58
|
-
for (const toolName of EDIT_VISIBILITY_TOOLS) {
|
|
59
|
-
if (toolName === "edit" && mode === "edit")
|
|
60
|
-
continue;
|
|
61
|
-
if (!visible.has(toolName)) {
|
|
62
|
-
delete event.tools[toolName];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
const beforeHook = await adapter.ctx.tool.hook("execute.before", (event) => {
|
|
67
|
-
const tool = String(event.tool);
|
|
68
|
-
if (!isEditTypeTool(tool))
|
|
69
|
-
return;
|
|
70
|
-
assertEditToolVisible(tool, String(event.sessionID), resolveSessionMode);
|
|
71
|
-
});
|
|
72
|
-
const afterHook = await adapter.ctx.tool.hook("execute.after", async (event) => {
|
|
73
|
-
if (!isReadTool(String(event.tool)))
|
|
74
|
-
return;
|
|
75
|
-
if (event.status !== "completed")
|
|
76
|
-
return;
|
|
77
|
-
const sessionID = String(event.sessionID);
|
|
78
|
-
const filePath = readArgFilePath(event.input);
|
|
79
|
-
if (filePath) {
|
|
80
|
-
const snapshot = await statSnapshot(filePath);
|
|
81
|
-
if (snapshot) {
|
|
82
|
-
fileCache.record(sessionID, filePath, snapshot);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (resolveSessionMode(sessionID) !== "hashline_edit")
|
|
86
|
-
return;
|
|
87
|
-
const result = event.result;
|
|
88
|
-
const current = typeof result.content === "string"
|
|
89
|
-
? result.content
|
|
90
|
-
: Array.isArray(result.content) && result.content.every((part) => part.type === "text")
|
|
91
|
-
? result.content.map((part) => part.text ?? "").join("\n")
|
|
92
|
-
: undefined;
|
|
93
|
-
if (typeof current !== "string" || !isHashlineEligibleReadOutput(current))
|
|
94
|
-
return;
|
|
95
|
-
const transformed = transformReadOutput(current, await readSourceLines(event.input));
|
|
96
|
-
result.content = transformed;
|
|
97
|
-
});
|
|
98
|
-
const toolRegistration = await adapter.ctx.tool.transform((editor) => {
|
|
99
|
-
editor.add({
|
|
100
|
-
name: "hashline_edit",
|
|
101
|
-
description: hashlineEditContract.description,
|
|
102
|
-
input: hashlineEditContract.inputJsonSchema,
|
|
103
|
-
execute: (async (input, context) => {
|
|
104
|
-
const sessionID = String(context.sessionID ?? "");
|
|
105
|
-
assertEditToolVisible("hashline_edit", sessionID, resolveSessionMode);
|
|
106
|
-
const model = modelCache.get(sessionID);
|
|
107
|
-
return {
|
|
108
|
-
content: await executeHashlineEdit(input, {
|
|
109
|
-
sessionID,
|
|
110
|
-
abort: context.signal,
|
|
111
|
-
}, {
|
|
112
|
-
editMode: resolveSessionMode(sessionID),
|
|
113
|
-
providerID: model?.providerID,
|
|
114
|
-
modelID: model?.modelID,
|
|
115
|
-
}),
|
|
116
|
-
};
|
|
117
|
-
}),
|
|
118
|
-
});
|
|
119
|
-
editor.add({
|
|
120
|
-
name: "str_replace_editor",
|
|
121
|
-
description: strReplaceEditorContract.description,
|
|
122
|
-
input: strReplaceEditorContract.inputJsonSchema,
|
|
123
|
-
execute: (async (input, context) => {
|
|
124
|
-
const sessionID = String(context.sessionID ?? "");
|
|
125
|
-
assertEditToolVisible("str_replace_editor", sessionID, resolveSessionMode);
|
|
126
|
-
const model = modelCache.get(sessionID);
|
|
127
|
-
return {
|
|
128
|
-
content: await executeStrReplaceEditor(input, { sessionID, abort: context.signal }, sessionID, fileCache, {
|
|
129
|
-
editMode: resolveSessionMode(sessionID),
|
|
130
|
-
providerID: model?.providerID,
|
|
131
|
-
modelID: model?.modelID,
|
|
132
|
-
}),
|
|
133
|
-
};
|
|
134
|
-
}),
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
return async () => {
|
|
138
|
-
await contextHook.dispose();
|
|
139
|
-
await beforeHook.dispose();
|
|
140
|
-
await afterHook.dispose();
|
|
141
|
-
await toolRegistration.dispose();
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
// END_BLOCK_SETUP_HASHLINE_EDIT_V2
|
|
145
|
-
//# sourceMappingURL=v2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"v2.js","sourceRoot":"","sources":["../../../src/plugins/hashline-edit/v2.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,iBAAiB;AACjB,wBAAwB;AACxB,yLAAyL;AACzL,uaAAua;AACva,uPAAuP;AACvP,mFAAmF;AACnF,kBAAkB;AAClB,sBAAsB;AACtB,sBAAs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AwB,CAAC,WAAW;YACjD,KAAK,EAAE,wBAAwB,CAAC,eAAwB;YACxD,OAAO,EAAE,CAAC,KAAK,EAAE,KAAY,EAAE,OAAqD,EAAE,EAAE;gBACtF,MAAM,SAAS,GAAG,MAAM,CAAE,OAAmC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;gBAC/E,qBAAqB,CAAC,oBAAoB,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAC;gBAC3E,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBACxC,OAAO;oBACL,OAAO,EAAE,MAAM,uBAAuB,CACpC,KAAK,EACL,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAW,EAC7C,SAAS,EACT,SAAS,EACT;wBACE,QAAQ,EAAE,kBAAkB,CAAC,SAAS,CAAC;wBACvC,UAAU,EAAE,KAAK,EAAE,UAAU;wBAC7B,OAAO,EAAE,KAAK,EAAE,OAAO;qBACxB,CACF;iBACF,CAAC;YACJ,CAAC,CAAU;SACZ,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;QAC5B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;QAC3B,MAAM,SAAS,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,gBAAgB,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC;AACD,mCAAmC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Plugin as V2Plugin } from "@opencode/plugin";
|
|
2
|
-
import type { V2AdapterContext } from "../v2-runtime/setup.js";
|
|
3
|
-
/**
|
|
4
|
-
* Captured transform inputs. Transforms must stay synchronous and replayable,
|
|
5
|
-
* so every external read happens before registration and is refreshed by the
|
|
6
|
-
* config watcher through domain reload().
|
|
7
|
-
*/
|
|
8
|
-
export interface RoleResolutionState {
|
|
9
|
-
roleMap: Record<string, string>;
|
|
10
|
-
defaultModelReference: string | undefined;
|
|
11
|
-
titleModelReference: string | undefined;
|
|
12
|
-
/** Raw-config agent model references that v2 normalization strips from the registry. */
|
|
13
|
-
agentRoleReferences: Record<string, string>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Register the role-resolving transforms on the v2 runtime.
|
|
17
|
-
*
|
|
18
|
-
* The v1 startup config hook becomes two replayable transforms plus a config
|
|
19
|
-
* watcher: agent transforms rewrite every role-referenced agent model, the
|
|
20
|
-
* model transform applies role-referenced default and title selections read
|
|
21
|
-
* from the raw project config, and vvoc.json changes reload both domains so
|
|
22
|
-
* preset switching takes effect without restarting the shared server.
|
|
23
|
-
*/
|
|
24
|
-
export declare function setupModelRolesV2(adapter: V2AdapterContext): Promise<V2Plugin.Cleanup | void>;
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
// FILE: src/plugins/model-roles/v2.ts
|
|
2
|
-
// VERSION: 1.0.0
|
|
3
|
-
// START_MODULE_CONTRACT
|
|
4
|
-
// PURPOSE: Resolve vv-role model references through OpenCode v2 replayable agent and model transforms with config-file-driven hot reload.
|
|
5
|
-
// SCOPE: v2 setup only: load the canonical role map for the plugin-load location, rewrite role-referenced agent models inside the agent transform, apply role-referenced top-level model and small_model selections through the model transform default and the built-in title agent, pin each session's model to its role-resolved selection on the first prompt (probe-verified v2 mechanism), watch the project vvoc config and reload both domains on change, and fail closed per reference with a logged error instead of breaking the server.
|
|
6
|
-
// DEPENDS: [@opencode/plugin, src/lib/config-layers.ts, src/lib/model-roles.ts, src/lib/plugin-toggle-config.ts, src/plugins/v2-runtime/setup.ts]
|
|
7
|
-
// LINKS: [M-PLUGIN-MODEL-ROLES, V-M-PLUGIN-MODEL-ROLES, M-MODEL-ROLES, M-PLUGIN-V2-RUNTIME]
|
|
8
|
-
// ROLE: RUNTIME
|
|
9
|
-
// MAP_MODE: EXPORTS
|
|
10
|
-
// END_MODULE_CONTRACT
|
|
11
|
-
//
|
|
12
|
-
// START_MODULE_MAP
|
|
13
|
-
// setupModelRolesV2 - Register the role-resolving agent and model transforms with hot reload for one OpenCode v2 plugin context.
|
|
14
|
-
// RoleResolutionState - Captured, replayable inputs for the transforms: role map, default-model reference, and title-model reference.
|
|
15
|
-
// END_MODULE_MAP
|
|
16
|
-
//
|
|
17
|
-
// START_CHANGE_SUMMARY
|
|
18
|
-
// LAST_CHANGE: [C-OPENCODE-V2-MIGRATION T-006 - Ported role resolution onto v2 transforms with restart-free preset switching.]
|
|
19
|
-
// END_CHANGE_SUMMARY
|
|
20
|
-
import { loadVvocConfigForRead } from "../../lib/config-layers.js";
|
|
21
|
-
import { isRoleReference, parseModelSelection, resolveRoleReference, } from "../../lib/model-roles.js";
|
|
22
|
-
import { isVvocPluginEnabled } from "../../lib/plugin-toggle-config.js";
|
|
23
|
-
import { readFile } from "node:fs/promises";
|
|
24
|
-
import { join } from "node:path";
|
|
25
|
-
// END_BLOCK_ROLE_RESOLUTION_STATE
|
|
26
|
-
// START_BLOCK_LOAD_ROLE_RESOLUTION_STATE
|
|
27
|
-
/**
|
|
28
|
-
* Load the role map and the raw OpenCode config model references for one
|
|
29
|
-
* location. Unknown roles or unreadable files degrade to an empty state with
|
|
30
|
-
* a logged warning so the transforms stay registered and inert.
|
|
31
|
-
*/
|
|
32
|
-
async function loadRoleResolutionState(directory) {
|
|
33
|
-
try {
|
|
34
|
-
const read = await loadVvocConfigForRead({
|
|
35
|
-
cwd: directory,
|
|
36
|
-
scope: "effective",
|
|
37
|
-
allowDefault: true,
|
|
38
|
-
});
|
|
39
|
-
if (!isVvocPluginEnabled(read.config, "model-roles")) {
|
|
40
|
-
return {
|
|
41
|
-
roleMap: {},
|
|
42
|
-
defaultModelReference: undefined,
|
|
43
|
-
titleModelReference: undefined,
|
|
44
|
-
agentRoleReferences: {},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const roleMap = {};
|
|
48
|
-
const roles = read.config.roles;
|
|
49
|
-
if (roles && typeof roles === "object" && !Array.isArray(roles)) {
|
|
50
|
-
for (const [role, selection] of Object.entries(roles)) {
|
|
51
|
-
if (typeof selection === "string" && selection.trim()) {
|
|
52
|
-
roleMap[role] = selection.trim();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
let defaultModelReference;
|
|
57
|
-
let titleModelReference;
|
|
58
|
-
const agentRoleReferences = {};
|
|
59
|
-
const projectRoot = read.source.rootDir ?? directory;
|
|
60
|
-
for (const name of ["opencode.json", "opencode.jsonc"]) {
|
|
61
|
-
let text;
|
|
62
|
-
try {
|
|
63
|
-
text = await readFile(join(projectRoot, name), "utf8");
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
const parsed = JSON.parse(text.replace(/^\s*\/\/.*$/gm, ""));
|
|
70
|
-
if (typeof parsed.model === "string" && isRoleReference(parsed.model)) {
|
|
71
|
-
defaultModelReference = parsed.model;
|
|
72
|
-
}
|
|
73
|
-
if (typeof parsed.small_model === "string" && isRoleReference(parsed.small_model)) {
|
|
74
|
-
titleModelReference = parsed.small_model;
|
|
75
|
-
}
|
|
76
|
-
const agentMaps = [parsed.agent, parsed.agents];
|
|
77
|
-
for (const agentMap of agentMaps) {
|
|
78
|
-
if (!agentMap || typeof agentMap !== "object" || Array.isArray(agentMap))
|
|
79
|
-
continue;
|
|
80
|
-
for (const [agentName, entry] of Object.entries(agentMap)) {
|
|
81
|
-
const model = entry?.model;
|
|
82
|
-
if (typeof model === "string" && isRoleReference(model)) {
|
|
83
|
-
agentRoleReferences[agentName] = model;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
// Unreadable project config leaves the references unset.
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return { roleMap, defaultModelReference, titleModelReference, agentRoleReferences };
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
console.warn(`[vvoc][model-roles] state load failed for ${directory}: ${String(error)}`);
|
|
97
|
-
return {
|
|
98
|
-
roleMap: {},
|
|
99
|
-
defaultModelReference: undefined,
|
|
100
|
-
titleModelReference: undefined,
|
|
101
|
-
agentRoleReferences: {},
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// END_BLOCK_LOAD_ROLE_RESOLUTION_STATE
|
|
106
|
-
// START_BLOCK_RESOLVE_REFERENCE
|
|
107
|
-
/**
|
|
108
|
-
* Resolve one role reference against the captured role map, failing closed
|
|
109
|
-
* with a logged error that leaves the caller's field untouched.
|
|
110
|
-
*/
|
|
111
|
-
function resolveReferenceOrLog(reference, roleMap, fieldPath) {
|
|
112
|
-
try {
|
|
113
|
-
return resolveRoleReference(reference, roleMap).normalized;
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
console.error(`[vvoc][model-roles] ${fieldPath} references an invalid role (${reference}): ${String(error)}`);
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// END_BLOCK_RESOLVE_REFERENCE
|
|
121
|
-
// START_BLOCK_APPLY_AGENT_MODEL
|
|
122
|
-
/**
|
|
123
|
-
* Apply one resolved provider/model selection to an agent draft in the v2
|
|
124
|
-
* Agent.Info object shape. The editor schema rejects plain string models, so
|
|
125
|
-
* the selection is parsed and assigned as { providerID, id } with an optional
|
|
126
|
-
* variant suffix split from the model id.
|
|
127
|
-
*/
|
|
128
|
-
function applyAgentModel(draft, selection, fieldPath) {
|
|
129
|
-
try {
|
|
130
|
-
const parsed = parseModelSelection(selection);
|
|
131
|
-
const variantMatch = /^(.+)#(.+)$/.exec(parsed.model);
|
|
132
|
-
draft.model = variantMatch
|
|
133
|
-
? { providerID: parsed.provider, id: variantMatch[1], variant: variantMatch[2] }
|
|
134
|
-
: { providerID: parsed.provider, id: parsed.model };
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
console.error(`[vvoc][model-roles] ${fieldPath} resolved an unparseable model (${selection}): ${String(error)}`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// END_BLOCK_APPLY_AGENT_MODEL
|
|
141
|
-
// START_BLOCK_SETUP_MODEL_ROLES_V2
|
|
142
|
-
/**
|
|
143
|
-
* Register the role-resolving transforms on the v2 runtime.
|
|
144
|
-
*
|
|
145
|
-
* The v1 startup config hook becomes two replayable transforms plus a config
|
|
146
|
-
* watcher: agent transforms rewrite every role-referenced agent model, the
|
|
147
|
-
* model transform applies role-referenced default and title selections read
|
|
148
|
-
* from the raw project config, and vvoc.json changes reload both domains so
|
|
149
|
-
* preset switching takes effect without restarting the shared server.
|
|
150
|
-
*/
|
|
151
|
-
export async function setupModelRolesV2(adapter) {
|
|
152
|
-
const directory = adapter.ctx.location.directory;
|
|
153
|
-
const state = await loadRoleResolutionState(directory);
|
|
154
|
-
const agentRegistration = await adapter.ctx.agent.transform((editor) => {
|
|
155
|
-
for (const agent of editor.list()) {
|
|
156
|
-
const agentId = String(agent.id);
|
|
157
|
-
const rawReference = state.agentRoleReferences[agentId];
|
|
158
|
-
if (rawReference) {
|
|
159
|
-
const resolved = resolveReferenceOrLog(rawReference, state.roleMap, `agent.${agentId}.model`);
|
|
160
|
-
if (resolved) {
|
|
161
|
-
editor.update(agentId, (draft) => {
|
|
162
|
-
applyAgentModel(draft, resolved, `agent.${agentId}.model`);
|
|
163
|
-
});
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
const model = agent.model;
|
|
168
|
-
if (typeof model !== "string" || !isRoleReference(model))
|
|
169
|
-
continue;
|
|
170
|
-
const resolved = resolveReferenceOrLog(model, state.roleMap, `agent.${agentId}.model`);
|
|
171
|
-
if (!resolved)
|
|
172
|
-
continue;
|
|
173
|
-
editor.update(agentId, (draft) => {
|
|
174
|
-
applyAgentModel(draft, resolved, `agent.${agentId}.model`);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
if (state.titleModelReference) {
|
|
178
|
-
const title = editor.list().find((agent) => String(agent.id) === "title");
|
|
179
|
-
if (title) {
|
|
180
|
-
const resolved = resolveReferenceOrLog(state.titleModelReference, state.roleMap, "small_model");
|
|
181
|
-
if (resolved) {
|
|
182
|
-
editor.update(String(title.id), (draft) => {
|
|
183
|
-
applyAgentModel(draft, resolved, "small_model");
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
const modelRegistration = await adapter.ctx.model.transform((editor) => {
|
|
190
|
-
if (!state.defaultModelReference)
|
|
191
|
-
return;
|
|
192
|
-
const resolved = resolveReferenceOrLog(state.defaultModelReference, state.roleMap, "model");
|
|
193
|
-
if (!resolved)
|
|
194
|
-
return;
|
|
195
|
-
const [providerID, modelID] = resolved.split("/");
|
|
196
|
-
if (!providerID || !modelID) {
|
|
197
|
-
console.error(`[vvoc][model-roles] resolved model is not provider/model shaped: ${resolved}`);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
editor.default.set(providerID, modelID);
|
|
201
|
-
});
|
|
202
|
-
// START_BLOCK_PROMPT_MODEL_APPLICATION
|
|
203
|
-
// Probe-verified on OpenCode v2.0.18: external plugin agent transforms write
|
|
204
|
-
// a plugin-host registry that config-defined agents and session model
|
|
205
|
-
// selection do not read, so role references also apply through the prompt
|
|
206
|
-
// hook: the first prompt of a session pins that session's model to the
|
|
207
|
-
// role-resolved selection, which both restores the v1 behavior and anchors
|
|
208
|
-
// long-running sessions to the preset they started with. Later prompts keep
|
|
209
|
-
// the pinned selection; new sessions resolve against the current role map,
|
|
210
|
-
// which the config watcher refreshes without a server restart.
|
|
211
|
-
const appliedSessions = new Set();
|
|
212
|
-
const promptRegistration = await adapter.ctx.session.hook("prompt", (event) => {
|
|
213
|
-
// Fire-and-forget: awaiting the switch inside admission races the first
|
|
214
|
-
// model dispatch (probe-verified — the awaited form interrupts the
|
|
215
|
-
// request), while the unawaited form lands before dispatch in practice.
|
|
216
|
-
void (async () => {
|
|
217
|
-
try {
|
|
218
|
-
const sessionID = String(event.sessionID);
|
|
219
|
-
if (appliedSessions.has(sessionID))
|
|
220
|
-
return;
|
|
221
|
-
const session = await adapter.ctx.session.get({ sessionID });
|
|
222
|
-
const agent = session?.agent;
|
|
223
|
-
if (typeof agent !== "string" || !agent)
|
|
224
|
-
return;
|
|
225
|
-
const reference = state.agentRoleReferences[agent];
|
|
226
|
-
if (!reference)
|
|
227
|
-
return;
|
|
228
|
-
const resolved = resolveReferenceOrLog(reference, state.roleMap, `agent.${agent}.model`);
|
|
229
|
-
if (!resolved)
|
|
230
|
-
return;
|
|
231
|
-
const parsed = parseModelSelection(resolved);
|
|
232
|
-
const variantMatch = /^(.+)#(.+)$/.exec(parsed.model);
|
|
233
|
-
await adapter.ctx.session.switchModel({
|
|
234
|
-
sessionID: event.sessionID,
|
|
235
|
-
model: {
|
|
236
|
-
providerID: parsed.provider,
|
|
237
|
-
id: variantMatch ? variantMatch[1] : parsed.model,
|
|
238
|
-
...(variantMatch ? { variant: variantMatch[2] } : {}),
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
appliedSessions.add(sessionID);
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
console.warn(`[vvoc][model-roles] prompt model application failed: ${String(error)}`);
|
|
245
|
-
}
|
|
246
|
-
})();
|
|
247
|
-
});
|
|
248
|
-
// END_BLOCK_PROMPT_MODEL_APPLICATION
|
|
249
|
-
const stopWatch = await adapter.watchConfig(directory, () => {
|
|
250
|
-
void (async () => {
|
|
251
|
-
const fresh = await loadRoleResolutionState(directory);
|
|
252
|
-
state.roleMap = fresh.roleMap;
|
|
253
|
-
state.defaultModelReference = fresh.defaultModelReference;
|
|
254
|
-
state.titleModelReference = fresh.titleModelReference;
|
|
255
|
-
state.agentRoleReferences = fresh.agentRoleReferences;
|
|
256
|
-
try {
|
|
257
|
-
await adapter.ctx.agent.reload();
|
|
258
|
-
await adapter.ctx.model.reload();
|
|
259
|
-
}
|
|
260
|
-
catch (error) {
|
|
261
|
-
console.warn(`[vvoc][model-roles] reload after config change failed: ${String(error)}`);
|
|
262
|
-
}
|
|
263
|
-
})();
|
|
264
|
-
});
|
|
265
|
-
return async () => {
|
|
266
|
-
stopWatch();
|
|
267
|
-
await promptRegistration.dispose();
|
|
268
|
-
await agentRegistration.dispose();
|
|
269
|
-
await modelRegistration.dispose();
|
|
270
|
-
await modelRegistration.dispose();
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
// END_BLOCK_SETUP_MODEL_ROLES_V2
|
|
274
|
-
//# sourceMappingURL=v2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"v2.js","sourceRoot":"","sources":["../../../src/plugins/model-roles/v2.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iBAAiB;AACjB,wBAAwB;AACxB,4IAA4I;AAC5I,shBAAshB;AACthB,oJAAoJ;AACpJ,8FAA8F;AAC9F,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,mIAAmI;AACnI,wIAAwI;AACxI,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,iIAAiI;AACjI,qBAAqB;AAIrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAsBjC,kCAAkC;AAElC,yCAAyC;AACzC;;;;GAIG;AACH,KAAK,UAAU,uBAAuB,CAAC,SAAiB;IACtD,IAAI,CAAC;QACH,MAAM,IA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;YACtD,KAAK,CAAC,mBAAmB,GAAG,KAAK,CAAC,mBAAmB,CAAC;YACtD,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;gBACjC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACnC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,0DAA0D,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1F,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,IAAI,EAAE;QAChB,SAAS,EAAE,CAAC;QACZ,MAAM,kBAAkB,CAAC,OAAO,EAAE,CAAC;QACnC,MAAM,iBAAiB,CAAC,OAAO,EAAE,CAAC;QAClC,MAAM,iBAAiB,CAAC,OAAO,EAAE,CAAC;QAClC,MAAM,iBAAiB,CAAC,OAAO,EAAE,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;AACD,iCAAiC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Plugin as V2Plugin } from "@opencode/plugin";
|
|
2
|
-
import type { V2AdapterContext } from "../v2-runtime/setup.js";
|
|
3
|
-
/**
|
|
4
|
-
* Register the peak-hours hook on the v2 runtime.
|
|
5
|
-
*
|
|
6
|
-
* The v1 chat.params post-persist throw becomes the v2 session context hook:
|
|
7
|
-
* the prompt is already admitted, so throwing fails the outgoing model call
|
|
8
|
-
* and surfaces the block as the request error, preserving the v1 semantics.
|
|
9
|
-
* The peak decision reuses the shared pure schedule library with the same
|
|
10
|
-
* internal-agent, subagent, parent-session, and session-age grace rules.
|
|
11
|
-
*/
|
|
12
|
-
export declare function setupPeakHoursV2(adapter: V2AdapterContext): Promise<V2Plugin.Cleanup | void>;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// FILE: src/plugins/peak-hours/v2.ts
|
|
2
|
-
// VERSION: 1.0.0
|
|
3
|
-
// START_MODULE_CONTRACT
|
|
4
|
-
// PURPOSE: Block peak-priced provider requests on the OpenCode v2 runtime with dynamic off-peak suggestions and session-age plus subagent grace.
|
|
5
|
-
// SCOPE: v2 setup only: gate the session context hook on the per-location peak-hours entry, apply internal-agent and known-subagent exemptions plus persisted-session grace, compose the identical hard-block message from the shared pure schedule library, enumerate connected providers through the v2 provider domain, and degrade fail-open on any resolution error.
|
|
6
|
-
// DEPENDS: [@opencode/plugin, src/lib/peak-hours.ts, src/plugins/peak-hours/index.ts, src/plugins/v2-runtime/setup.ts]
|
|
7
|
-
// LINKS: [M-PLUGIN-PEAK-HOURS, V-M-PLUGIN-PEAK-HOURS, M-PEAK-HOURS-SCHEDULES, M-PLUGIN-V2-RUNTIME]
|
|
8
|
-
// ROLE: RUNTIME
|
|
9
|
-
// MAP_MODE: EXPORTS
|
|
10
|
-
// END_MODULE_CONTRACT
|
|
11
|
-
//
|
|
12
|
-
// START_MODULE_MAP
|
|
13
|
-
// setupPeakHoursV2 - Register the peak-hours hard-block context hook for one OpenCode v2 plugin context.
|
|
14
|
-
// END_MODULE_MAP
|
|
15
|
-
//
|
|
16
|
-
// START_CHANGE_SUMMARY
|
|
17
|
-
// LAST_CHANGE: [C-OPENCODE-V2-MIGRATION T-003 - Ported peak-hours hard blocking onto the v2 session context hook.]
|
|
18
|
-
// END_CHANGE_SUMMARY
|
|
19
|
-
import { findActivePeak, formatPeakEndTime, normalizeProviderId, parsePeakHoursEntry, suggestOffPeakProviders, } from "../../lib/peak-hours.js";
|
|
20
|
-
import { buildHardBlockMessage, createKnownSubagentSet } from "./index.js";
|
|
21
|
-
// START_BLOCK_SETUP_PEAK_HOURS_V2
|
|
22
|
-
/**
|
|
23
|
-
* Register the peak-hours hook on the v2 runtime.
|
|
24
|
-
*
|
|
25
|
-
* The v1 chat.params post-persist throw becomes the v2 session context hook:
|
|
26
|
-
* the prompt is already admitted, so throwing fails the outgoing model call
|
|
27
|
-
* and surfaces the block as the request error, preserving the v1 semantics.
|
|
28
|
-
* The peak decision reuses the shared pure schedule library with the same
|
|
29
|
-
* internal-agent, subagent, parent-session, and session-age grace rules.
|
|
30
|
-
*/
|
|
31
|
-
export async function setupPeakHoursV2(adapter) {
|
|
32
|
-
// Static managed-subagent set: these agents are continuation of already
|
|
33
|
-
// admitted work and always soften. Config-defined subagents cannot be
|
|
34
|
-
// discovered through the v2 plugin-host registry (probe-verified split),
|
|
35
|
-
// so the managed names plus built-ins carry the exemption.
|
|
36
|
-
const knownSubagents = createKnownSubagentSet();
|
|
37
|
-
const registration = await adapter.ctx.session.hook("context", async (event) => {
|
|
38
|
-
try {
|
|
39
|
-
const providerID = event.model?.providerID;
|
|
40
|
-
if (!providerID)
|
|
41
|
-
return;
|
|
42
|
-
const agent = event.agent;
|
|
43
|
-
if (agent === "compaction" || agent === "title" || agent === "summary")
|
|
44
|
-
return;
|
|
45
|
-
const snapshot = await adapter.resolver.forSession(event.sessionID, (input) => adapter.ctx.session.get(input));
|
|
46
|
-
if (!snapshot)
|
|
47
|
-
return;
|
|
48
|
-
const { entry } = parsePeakHoursEntry(snapshot.config.plugins?.["peak-hours"]);
|
|
49
|
-
if (!entry.enabled)
|
|
50
|
-
return;
|
|
51
|
-
const now = new Date();
|
|
52
|
-
const peak = findActivePeak(now, entry.schedules, providerID);
|
|
53
|
-
if (!peak)
|
|
54
|
-
return;
|
|
55
|
-
const override = entry.schedules[peak.providerKey]?.mode;
|
|
56
|
-
let mode = override ?? entry.mode;
|
|
57
|
-
if (agent && knownSubagents.has(agent))
|
|
58
|
-
mode = "soft";
|
|
59
|
-
if (mode === "hard") {
|
|
60
|
-
const session = (await adapter.ctx.session
|
|
61
|
-
.get({ sessionID: event.sessionID })
|
|
62
|
-
.catch(() => undefined));
|
|
63
|
-
if (!session) {
|
|
64
|
-
mode = "soft";
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const parentID = session.parentID;
|
|
68
|
-
if (typeof parentID === "string" && parentID)
|
|
69
|
-
mode = "soft";
|
|
70
|
-
const created = session.time?.created;
|
|
71
|
-
if (entry.graceActiveSessions &&
|
|
72
|
-
(typeof created === "number" || typeof created === "string") &&
|
|
73
|
-
new Date(created).getTime() < peak.startedAt.getTime()) {
|
|
74
|
-
mode = "soft";
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (mode !== "hard")
|
|
79
|
-
return;
|
|
80
|
-
const providersResponse = (await adapter.ctx.provider.list().catch(() => undefined));
|
|
81
|
-
const connected = (providersResponse?.data ?? [])
|
|
82
|
-
.map((provider) => (typeof provider.id === "string" ? provider.id : ""))
|
|
83
|
-
.filter(Boolean);
|
|
84
|
-
const suggestions = suggestOffPeakProviders(now, entry.schedules, connected).filter((candidate) => normalizeProviderId(candidate) !== normalizeProviderId(providerID));
|
|
85
|
-
const message = buildHardBlockMessage(providerID, peak, suggestions);
|
|
86
|
-
console.log(`[peak-hours] hard block applied: provider=${providerID} until=${formatPeakEndTime(peak.endsAt)} session=${String(event.sessionID)}`);
|
|
87
|
-
throw new Error(message);
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
if (error instanceof Error && error.message.includes("peak")) {
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
console.warn(`[vvoc][peak-hours] context hook failed open: ${String(error)}`);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
return () => registration.dispose();
|
|
97
|
-
}
|
|
98
|
-
// END_BLOCK_SETUP_PEAK_HOURS_V2
|
|
99
|
-
//# sourceMappingURL=v2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"v2.js","sourceRoot":"","sources":["../../../src/plugins/peak-hours/v2.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,iBAAiB;AACjB,wBAAwB;AACxB,mJAAmJ;AACnJ,4WAA4W;AAC5W,yHAAyH;AACzH,qGAAqG;AACrG,kBAAkB;AAClB,s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,CAAC,EAAE,CAAC,CAAC;QAChF,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;AACtC,CAAC;AACD,gCAAgC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Plugin as V2Plugin } from "@opencode/plugin";
|
|
2
|
-
import type { V2AdapterContext } from "../v2-runtime/setup.js";
|
|
3
|
-
/**
|
|
4
|
-
* Register the secrets-redaction hooks on the v2 runtime.
|
|
5
|
-
*
|
|
6
|
-
* The v1 experimental.chat.messages.transform becomes the v2 session context
|
|
7
|
-
* hook redacting the mutable request messages (including tool-part state),
|
|
8
|
-
* and the v1 tool.execute.before restore keeps the identical role on the v2
|
|
9
|
-
* tool hook.
|
|
10
|
-
*
|
|
11
|
-
* The v1 experimental.text.complete output restore has NO v2 equivalent: v2
|
|
12
|
-
* exposes no completion-output hook for transient title or generate calls.
|
|
13
|
-
* The v2-native protection is input-side instead — the title, generate, and
|
|
14
|
-
* compaction hooks redact their request messages so those models never see
|
|
15
|
-
* placeholders and cannot echo them into persisted titles or summaries.
|
|
16
|
-
* Pattern configuration resolves per session location, and every handler
|
|
17
|
-
* failure degrades fail-open with a logged warning.
|
|
18
|
-
*/
|
|
19
|
-
export declare function setupSecretsRedactionV2(adapter: V2AdapterContext): Promise<V2Plugin.Cleanup | void>;
|