opencode-dev-framework 0.1.16 → 0.1.18
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/README.md +5 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +24 -14
- package/dist/messenger.d.ts +9 -0
- package/dist/messenger.js +28 -0
- package/dist/registry.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,10 +30,12 @@ reimplemented as an OpenCode-native plugin.
|
|
|
30
30
|
- **CLI installer.** `df init` auto-detects your language and writes a config
|
|
31
31
|
with sensible commands; `df profile <name>` changes the profile from the
|
|
32
32
|
shell; `df status` / `df version` report template state and the version.
|
|
33
|
-
- **Slash commands.** `/df-status`, `/df-verify`, and `/df-
|
|
34
|
-
registered directly by the plugin so they work without template files.
|
|
33
|
+
- **Slash commands.** `/df-status`, `/df-verify`, `/df-profile`, and `/df-help`
|
|
34
|
+
are registered directly by the plugin so they work without template files.
|
|
35
35
|
`/df-status` and `/df-verify` read live in-memory state; `/df-profile`
|
|
36
|
-
updates the config and applies the change immediately
|
|
36
|
+
updates the config and applies the change immediately; `/df-help` lists
|
|
37
|
+
the commands. Responses are posted as ignored messages so they do not get
|
|
38
|
+
re-processed as user input.
|
|
37
39
|
|
|
38
40
|
## Profiles
|
|
39
41
|
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { Hooks, Plugin, PluginInput } from "@opencode-ai/plugin";
|
|
|
14
14
|
import { type ChangedFileTracker } from "./gate.js";
|
|
15
15
|
import { type RunCommand } from "./host.js";
|
|
16
16
|
import { type LogFn } from "./logger.js";
|
|
17
|
+
import { type SendMessageFn } from "./messenger.js";
|
|
17
18
|
import type { ResolvedConfig } from "./types.js";
|
|
18
19
|
/**
|
|
19
20
|
* The `experimental.session.stopping` hook was added in OpenCode PR #41811
|
|
@@ -32,6 +33,6 @@ export interface HooksWithStopping extends Hooks {
|
|
|
32
33
|
* Build the plugin's hooks and custom tools. Exported (rather than inlined in
|
|
33
34
|
* the plugin) so tests can inject a stubbed command runner and tracker.
|
|
34
35
|
*/
|
|
35
|
-
export declare function buildHooks(ctx: PluginInput, config: ResolvedConfig, log: LogFn, run?: RunCommand, tracker?: ChangedFileTracker, constitution?: string | null): HooksWithStopping;
|
|
36
|
+
export declare function buildHooks(ctx: PluginInput, config: ResolvedConfig, log: LogFn, run?: RunCommand, tracker?: ChangedFileTracker, constitution?: string | null, sendMessage?: SendMessageFn | null): HooksWithStopping;
|
|
36
37
|
export declare const devFramework: Plugin;
|
|
37
38
|
export default devFramework;
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import { renderStatus } from "./format-status.js";
|
|
|
17
17
|
import { runCommand } from "./host.js";
|
|
18
18
|
import { detectPreCommitAvailability, isLintFailure, lintFile, summarizeLint } from "./lint.js";
|
|
19
19
|
import { createLogger } from "./logger.js";
|
|
20
|
+
import { createMessenger } from "./messenger.js";
|
|
20
21
|
import { checkToolCall } from "./protect.js";
|
|
21
22
|
import { clearSessionDirectory, getHookState, getStateForSession, setBaseDirectory, setHookState, setSessionDirectory, updateHookState, } from "./registry.js";
|
|
22
23
|
import { injectConstitution, loadConstitution } from "./rules.js";
|
|
@@ -26,7 +27,7 @@ import { buildTools } from "./tools.js";
|
|
|
26
27
|
* Build the plugin's hooks and custom tools. Exported (rather than inlined in
|
|
27
28
|
* the plugin) so tests can inject a stubbed command runner and tracker.
|
|
28
29
|
*/
|
|
29
|
-
export function buildHooks(ctx, config, log, run = runCommand, tracker = createChangedFileTracker(), constitution = null) {
|
|
30
|
+
export function buildHooks(ctx, config, log, run = runCommand, tracker = createChangedFileTracker(), constitution = null, sendMessage = createMessenger(ctx.client)) {
|
|
30
31
|
// All hook state — including the project directory — lives in the registry
|
|
31
32
|
// and is looked up at call time. OpenCode's Effect runtime stripped closure
|
|
32
33
|
// captures in production (config/log/run came back undefined), so hooks must
|
|
@@ -39,6 +40,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
39
40
|
tracker,
|
|
40
41
|
constitution,
|
|
41
42
|
blockCounts: new Map(),
|
|
43
|
+
sendMessage,
|
|
42
44
|
});
|
|
43
45
|
return {
|
|
44
46
|
tool: buildTools(ctx),
|
|
@@ -63,24 +65,32 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
63
65
|
template: "",
|
|
64
66
|
description: "Run the dev-framework completion gate manually",
|
|
65
67
|
};
|
|
68
|
+
typedConfig.command["df-help"] = {
|
|
69
|
+
template: "",
|
|
70
|
+
description: "List the available dev-framework slash commands",
|
|
71
|
+
};
|
|
66
72
|
},
|
|
67
73
|
"command.execute.before": async (input, output) => {
|
|
68
74
|
const state = getStateForSession(input.sessionID);
|
|
69
75
|
if (!state) {
|
|
76
|
+
const fallback = "[opencode-dev-framework] plugin state is not available for this session.";
|
|
70
77
|
output.parts.length = 0;
|
|
71
|
-
output.parts.push({
|
|
72
|
-
type: "text",
|
|
73
|
-
text: "[opencode-dev-framework] plugin state is not available for this session.",
|
|
74
|
-
});
|
|
78
|
+
output.parts.push({ type: "text", text: fallback });
|
|
75
79
|
return;
|
|
76
80
|
}
|
|
77
81
|
const directory = state.directory;
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
const reply = async (text) => {
|
|
83
|
+
if (state.sendMessage) {
|
|
84
|
+
output.parts.length = 0;
|
|
85
|
+
await state.sendMessage(input.sessionID, text);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
output.parts.length = 0;
|
|
89
|
+
output.parts.push({ type: "text", text });
|
|
90
|
+
}
|
|
81
91
|
};
|
|
82
92
|
if (input.command === "df-help" || input.command === "df") {
|
|
83
|
-
|
|
93
|
+
await reply(`df — opencode-dev-framework commands
|
|
84
94
|
|
|
85
95
|
/df-status Show the current dev-framework state
|
|
86
96
|
/df-profile Change the profile to off, advisory, standard, or strict
|
|
@@ -90,7 +100,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
90
100
|
return;
|
|
91
101
|
}
|
|
92
102
|
if (input.command === "df-status") {
|
|
93
|
-
|
|
103
|
+
await reply(renderStatus(state.config, state));
|
|
94
104
|
await state.log("info", "df-status command executed", { directory });
|
|
95
105
|
return;
|
|
96
106
|
}
|
|
@@ -98,7 +108,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
98
108
|
const profile = input.arguments.trim().toLowerCase();
|
|
99
109
|
const validProfiles = ["off", "advisory", "standard", "strict"];
|
|
100
110
|
if (!validProfiles.includes(profile)) {
|
|
101
|
-
|
|
111
|
+
await reply(`Invalid profile "${profile}". Valid values: ${validProfiles.join(", ")}.`);
|
|
102
112
|
return;
|
|
103
113
|
}
|
|
104
114
|
const configPath = join(state.directory, ".opencode-dev-framework.yml");
|
|
@@ -107,7 +117,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
107
117
|
const nextConfig = loadConfig(state.directory);
|
|
108
118
|
const { constitution } = await loadConstitution(nextConfig, state.directory);
|
|
109
119
|
updateHookState(state.directory, { config: nextConfig, constitution });
|
|
110
|
-
|
|
120
|
+
await reply(`opencode-dev-framework profile set to "${profile}". Change applied immediately.`);
|
|
111
121
|
await state.log("info", "df-profile command executed", { directory, profile });
|
|
112
122
|
return;
|
|
113
123
|
}
|
|
@@ -117,7 +127,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
117
127
|
cwd: state.directory,
|
|
118
128
|
});
|
|
119
129
|
const summary = summarizeGate(report);
|
|
120
|
-
|
|
130
|
+
await reply(summary);
|
|
121
131
|
const level = report.ok ? "info" : "error";
|
|
122
132
|
await state.log(level, "df-verify command executed", {
|
|
123
133
|
directory,
|
|
@@ -128,7 +138,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
128
138
|
}
|
|
129
139
|
// Unknown /df-* command — give a helpful response.
|
|
130
140
|
if (input.command.startsWith("df-")) {
|
|
131
|
-
|
|
141
|
+
await reply(`Unknown command /${input.command}. Try /df-help.`);
|
|
132
142
|
await state.log("warn", "unknown df command", { directory, command: input.command });
|
|
133
143
|
}
|
|
134
144
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
+
export type SendMessageFn = (sessionID: string, text: string) => Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* Create a messenger that posts a chat message without it being treated as a
|
|
5
|
+
* user turn. OpenCode's `client.session.prompt` with `noReply: true` and an
|
|
6
|
+
* `ignored: true` text part shows the message in the conversation UI but does
|
|
7
|
+
* not feed it back to the model as input.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createMessenger(client: PluginInput["client"]): SendMessageFn;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a messenger that posts a chat message without it being treated as a
|
|
3
|
+
* user turn. OpenCode's `client.session.prompt` with `noReply: true` and an
|
|
4
|
+
* `ignored: true` text part shows the message in the conversation UI but does
|
|
5
|
+
* not feed it back to the model as input.
|
|
6
|
+
*/
|
|
7
|
+
export function createMessenger(client) {
|
|
8
|
+
const typedClient = client;
|
|
9
|
+
const prompt = typedClient?.session?.prompt;
|
|
10
|
+
if (!prompt) {
|
|
11
|
+
return async () => { };
|
|
12
|
+
}
|
|
13
|
+
return async (sessionID, text) => {
|
|
14
|
+
await prompt({
|
|
15
|
+
path: { id: sessionID },
|
|
16
|
+
body: {
|
|
17
|
+
noReply: true,
|
|
18
|
+
parts: [
|
|
19
|
+
{
|
|
20
|
+
type: "text",
|
|
21
|
+
text,
|
|
22
|
+
ignored: true,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
}
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ChangedFileTracker } from "./gate.js";
|
|
2
2
|
import type { RunCommand } from "./host.js";
|
|
3
3
|
import type { LogFn } from "./logger.js";
|
|
4
|
+
import type { SendMessageFn } from "./messenger.js";
|
|
4
5
|
import type { ResolvedConfig } from "./types.js";
|
|
5
6
|
export interface HostPermission {
|
|
6
7
|
permission?: string;
|
|
@@ -22,6 +23,8 @@ export interface HookState {
|
|
|
22
23
|
precommitAvailable?: boolean;
|
|
23
24
|
/** Snapshot of host permissions from OpenCode's effective config. */
|
|
24
25
|
hostPermissions?: HostPermission[];
|
|
26
|
+
/** Messenger for posting ignored chat messages from slash commands. */
|
|
27
|
+
sendMessage?: SendMessageFn | null;
|
|
25
28
|
}
|
|
26
29
|
export declare function setBaseDirectory(directory: string): void;
|
|
27
30
|
export declare function getBaseDirectory(): string | null;
|