opencode-dev-framework 0.1.18 → 0.1.25
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 +49 -16
- package/dist/commands.d.ts +21 -0
- package/dist/commands.js +27 -0
- package/dist/format-status.d.ts +12 -1
- package/dist/format-status.js +30 -7
- package/dist/index.d.ts +3 -4
- package/dist/index.js +61 -101
- package/dist/registry.d.ts +5 -3
- package/dist/tools.js +4 -5
- package/package.json +20 -3
- package/tui.tsx +192 -0
- package/dist/messenger.d.ts +0 -9
- package/dist/messenger.js +0 -28
package/README.md
CHANGED
|
@@ -30,12 +30,16 @@ 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.**
|
|
34
|
-
|
|
35
|
-
`/df-status` and `/df-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
- **Slash commands.** The plugin registers four commands. None of them feed
|
|
34
|
+
anything to the LLM:
|
|
35
|
+
- `/df-status` and `/df-help` are TUI commands (bundled `./tui` companion module)
|
|
36
|
+
that open an instant modal dialog.
|
|
37
|
+
- `/df-profile <profile>` and `/df-verify` are server-side commands. They are
|
|
38
|
+
registered with an empty template so the argument (e.g. `standard`) is
|
|
39
|
+
captured by the plugin and the model never sees it; the result is shown as a
|
|
40
|
+
toast and the user turn is suppressed.
|
|
41
|
+
- The `dev_framework_init` and `dev_framework_set_profile` custom *tools* remain
|
|
42
|
+
available for in-agent use.
|
|
39
43
|
|
|
40
44
|
## Profiles
|
|
41
45
|
|
|
@@ -52,7 +56,7 @@ reimplemented as an OpenCode-native plugin.
|
|
|
52
56
|
npm install opencode-dev-framework
|
|
53
57
|
```
|
|
54
58
|
|
|
55
|
-
Then add
|
|
59
|
+
Then add the plugin to your project's `opencode.json`:
|
|
56
60
|
|
|
57
61
|
```json
|
|
58
62
|
{
|
|
@@ -60,6 +64,11 @@ Then add it to your project's `opencode.json`:
|
|
|
60
64
|
}
|
|
61
65
|
```
|
|
62
66
|
|
|
67
|
+
On OpenCode 1.18.18+ the `./tui` companion (the `/df-status` and `/df-help`
|
|
68
|
+
modals) is auto-discovered from the npm plugin entry above, so the server and
|
|
69
|
+
TUI parts load together. (On older builds, or if the modals do not appear, also
|
|
70
|
+
add the package to `tui.json` — see *Local development* below.)
|
|
71
|
+
|
|
63
72
|
Finally, scaffold the project-level files (agents, skills, local rules directory,
|
|
64
73
|
and default config) into your repo with the bundled `df` CLI:
|
|
65
74
|
|
|
@@ -79,7 +88,21 @@ profile from the shell; `df version` prints the plugin version.
|
|
|
79
88
|
## Local development and testing
|
|
80
89
|
|
|
81
90
|
To test the plugin from source without publishing to npm, point OpenCode at the
|
|
82
|
-
local repository path in your project's `opencode.json
|
|
91
|
+
local repository path in your project's `opencode.json` **and** in a `tui.json`.
|
|
92
|
+
The TUI module (`/df-status`, `/df-help` modals) is **not** auto-discovered for
|
|
93
|
+
local filesystem paths — it only loads when the package is listed in the TUI
|
|
94
|
+
config. OpenCode reads `tui.json` from the global config dir
|
|
95
|
+
(`~/.config/opencode/tui.json`) and the project dir (`.opencode/tui.json`).
|
|
96
|
+
|
|
97
|
+
`opencode.json` (server plugin):
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"plugin": ["/home/jerome/opencode-dev-framework"]
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`tui.json` (TUI plugin — same path):
|
|
83
106
|
|
|
84
107
|
```json
|
|
85
108
|
{
|
|
@@ -88,7 +111,8 @@ local repository path in your project's `opencode.json`:
|
|
|
88
111
|
```
|
|
89
112
|
|
|
90
113
|
The path must be the **repository root** (where `package.json` lives). OpenCode
|
|
91
|
-
loads `dist/index.js
|
|
114
|
+
loads the server plugin from `dist/index.js` and the TUI plugin from `tui.tsx`,
|
|
115
|
+
so rebuild after every source change:
|
|
92
116
|
|
|
93
117
|
```bash
|
|
94
118
|
npm run build
|
|
@@ -156,16 +180,25 @@ complete example.
|
|
|
156
180
|
|
|
157
181
|
## Slash commands
|
|
158
182
|
|
|
159
|
-
|
|
183
|
+
All four slash commands are **TUI commands** registered by the bundled `./tui`
|
|
184
|
+
companion module (see *Local development* above for the `tui.json` requirement).
|
|
185
|
+
They open instantly and **never** feed text back to the LLM:
|
|
160
186
|
|
|
161
|
-
- `/df-status` — shows the current profile, guardrails, completion gate,
|
|
162
|
-
configured commands
|
|
163
|
-
- `/df-
|
|
164
|
-
- `/df-profile
|
|
165
|
-
immediately
|
|
187
|
+
- `/df-status` — shows the current profile, guardrails, completion gate, and
|
|
188
|
+
configured commands in a modal dialog.
|
|
189
|
+
- `/df-help` — lists the available dev-framework commands in a modal dialog.
|
|
190
|
+
- `/df-profile` — opens a profile picker (off / advisory / standard / strict) in
|
|
191
|
+
a modal dialog; selecting one switches the active profile immediately (written
|
|
192
|
+
to the config file). Run it **bare** — the argument form
|
|
193
|
+
(`/df-profile standard`) is not wired up in this build.
|
|
194
|
+
- `/df-verify` — runs the configured verification suite (the completion gate)
|
|
195
|
+
manually and shows a pass/fail summary in a modal dialog.
|
|
166
196
|
|
|
167
197
|
You can still run `df init` to install the bundled agents, skills, and default
|
|
168
|
-
config; the commands themselves are provided by the plugin.
|
|
198
|
+
config; the commands themselves are provided by the plugin. The
|
|
199
|
+
`dev_framework_init` and `dev_framework_set_profile` custom *tools* remain
|
|
200
|
+
available for in-agent use (e.g. when the model wants to change the profile
|
|
201
|
+
itself).
|
|
169
202
|
|
|
170
203
|
## Limitations
|
|
171
204
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type GateReport } from "./gate.js";
|
|
2
|
+
import type { RunCommand } from "./host.js";
|
|
3
|
+
import type { Profile, ResolvedConfig } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Change the project profile by editing the config file on disk. The server
|
|
6
|
+
* plugin reloads the in-memory config on the next tool call / gate run (see
|
|
7
|
+
* `reloadConfigIfChanged` in index.ts), so the change does not require a
|
|
8
|
+
* restart. Used by both the `/df-profile` TUI command and the
|
|
9
|
+
* `dev_framework_set_profile` custom tool.
|
|
10
|
+
*/
|
|
11
|
+
export declare function changeProfile(directory: string, profile: Profile): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Run the completion gate manually for a project. When `config` is omitted the
|
|
14
|
+
* project config is loaded from disk. `changedFiles` is normally empty for a
|
|
15
|
+
* manual verify (the server's live tracker is not visible from the TUI), so a
|
|
16
|
+
* `scope: changed` gate will report "no changed files".
|
|
17
|
+
*/
|
|
18
|
+
export declare function verifyGate(run: RunCommand, directory: string, config?: ResolvedConfig, changedFiles?: string[]): Promise<{
|
|
19
|
+
report: GateReport;
|
|
20
|
+
summary: string;
|
|
21
|
+
}>;
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { loadConfig } from "./config.js";
|
|
3
|
+
import { runGate, summarizeGate } from "./gate.js";
|
|
4
|
+
import { setProfileInFile } from "./installer.js";
|
|
5
|
+
/**
|
|
6
|
+
* Change the project profile by editing the config file on disk. The server
|
|
7
|
+
* plugin reloads the in-memory config on the next tool call / gate run (see
|
|
8
|
+
* `reloadConfigIfChanged` in index.ts), so the change does not require a
|
|
9
|
+
* restart. Used by both the `/df-profile` TUI command and the
|
|
10
|
+
* `dev_framework_set_profile` custom tool.
|
|
11
|
+
*/
|
|
12
|
+
export async function changeProfile(directory, profile) {
|
|
13
|
+
const configPath = join(directory, ".opencode-dev-framework.yml");
|
|
14
|
+
await setProfileInFile(configPath, profile);
|
|
15
|
+
return `opencode-dev-framework profile set to "${profile}". Change applies on the next tool call / gate run.`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Run the completion gate manually for a project. When `config` is omitted the
|
|
19
|
+
* project config is loaded from disk. `changedFiles` is normally empty for a
|
|
20
|
+
* manual verify (the server's live tracker is not visible from the TUI), so a
|
|
21
|
+
* `scope: changed` gate will report "no changed files".
|
|
22
|
+
*/
|
|
23
|
+
export async function verifyGate(run, directory, config, changedFiles = []) {
|
|
24
|
+
const cfg = config ?? loadConfig(directory);
|
|
25
|
+
const report = await runGate(run, cfg, changedFiles, { cwd: directory });
|
|
26
|
+
return { report, summary: summarizeGate(report) };
|
|
27
|
+
}
|
package/dist/format-status.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import type { HookState } from "./registry.js";
|
|
2
2
|
import type { ResolvedConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Render the config-only portion of the status summary.
|
|
5
|
+
*
|
|
6
|
+
* This is shared between the server-side `/df-status` tool and the TUI plugin,
|
|
7
|
+
* which does not have access to live hook state.
|
|
8
|
+
*/
|
|
9
|
+
export declare function renderConfigStatus(config: ResolvedConfig): string;
|
|
10
|
+
/**
|
|
11
|
+
* Render a help message listing the available dev-framework slash commands.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderHelp(): string;
|
|
3
14
|
/**
|
|
4
15
|
* Render a human-readable summary of the current plugin state.
|
|
5
16
|
*
|
|
6
|
-
* Used by the `dev_framework_status` custom tool and by the
|
|
17
|
+
* Used by the `dev_framework_status` custom tool and by the server-side
|
|
7
18
|
* slash-command handler.
|
|
8
19
|
*/
|
|
9
20
|
export declare function renderStatus(config: ResolvedConfig, state?: HookState | null): string;
|
package/dist/format-status.js
CHANGED
|
@@ -28,12 +28,12 @@ function formatRules(rules) {
|
|
|
28
28
|
return lines.join("\n");
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Render
|
|
31
|
+
* Render the config-only portion of the status summary.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
33
|
+
* This is shared between the server-side `/df-status` tool and the TUI plugin,
|
|
34
|
+
* which does not have access to live hook state.
|
|
35
35
|
*/
|
|
36
|
-
export function
|
|
36
|
+
export function renderConfigStatus(config) {
|
|
37
37
|
const lines = [];
|
|
38
38
|
lines.push(`opencode-dev-framework status`);
|
|
39
39
|
lines.push("");
|
|
@@ -57,9 +57,6 @@ export function renderStatus(config, state) {
|
|
|
57
57
|
lines.push(` format: ${config.on_edit.format}`);
|
|
58
58
|
lines.push(` lint: ${config.on_edit.lint}`);
|
|
59
59
|
lines.push(` precommit: ${config.precommit}`);
|
|
60
|
-
if (state && config.precommit === "auto") {
|
|
61
|
-
lines.push(` pre-commit binary available: ${state.precommitAvailable === true ? "yes" : state.precommitAvailable === false ? "no" : "not checked yet"}`);
|
|
62
|
-
}
|
|
63
60
|
lines.push("");
|
|
64
61
|
lines.push("Completion gate:");
|
|
65
62
|
lines.push(` run_typecheck: ${config.gate.run_typecheck}`);
|
|
@@ -88,7 +85,33 @@ export function renderStatus(config, state) {
|
|
|
88
85
|
if (config.style_guide) {
|
|
89
86
|
lines.push(` style_guide: ${config.style_guide}`);
|
|
90
87
|
}
|
|
88
|
+
return lines.join("\n");
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Render a help message listing the available dev-framework slash commands.
|
|
92
|
+
*/
|
|
93
|
+
export function renderHelp() {
|
|
94
|
+
const lines = [];
|
|
95
|
+
lines.push("dev-framework commands");
|
|
96
|
+
lines.push("");
|
|
97
|
+
lines.push("/df-status Show the current dev-framework state");
|
|
98
|
+
lines.push("/df-profile Change the profile to off, advisory, standard, or strict");
|
|
99
|
+
lines.push("/df-verify Run the completion gate manually");
|
|
100
|
+
lines.push("/df-help Show this message");
|
|
101
|
+
return lines.join("\n");
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Render a human-readable summary of the current plugin state.
|
|
105
|
+
*
|
|
106
|
+
* Used by the `dev_framework_status` custom tool and by the server-side
|
|
107
|
+
* slash-command handler.
|
|
108
|
+
*/
|
|
109
|
+
export function renderStatus(config, state) {
|
|
110
|
+
const lines = [renderConfigStatus(config)];
|
|
91
111
|
if (state) {
|
|
112
|
+
if (config.precommit === "auto") {
|
|
113
|
+
lines.push(` pre-commit binary available: ${state.precommitAvailable === true ? "yes" : state.precommitAvailable === false ? "no" : "not checked yet"}`);
|
|
114
|
+
}
|
|
92
115
|
const changedFiles = state.tracker.getChangedFiles();
|
|
93
116
|
lines.push("");
|
|
94
117
|
lines.push(`Changed files tracked: ${changedFiles.length}`);
|
package/dist/index.d.ts
CHANGED
|
@@ -7,14 +7,13 @@
|
|
|
7
7
|
* - event (session.idle) -> completion gate fallback (advisory logging)
|
|
8
8
|
* - experimental.chat.system.transform -> constitution injection + session mapping
|
|
9
9
|
* - experimental.session.stopping -> blocking completion gate (OpenCode >= PR #41811)
|
|
10
|
-
* - config hook -> registers /df-
|
|
11
|
-
* - command.execute.before -> handles
|
|
10
|
+
* - config hook -> registers /df-profile and /df-verify prompt commands
|
|
11
|
+
* - command.execute.before -> handles /df-profile, /df-verify, and unknown /df-*
|
|
12
12
|
*/
|
|
13
13
|
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";
|
|
18
17
|
import type { ResolvedConfig } from "./types.js";
|
|
19
18
|
/**
|
|
20
19
|
* The `experimental.session.stopping` hook was added in OpenCode PR #41811
|
|
@@ -33,6 +32,6 @@ export interface HooksWithStopping extends Hooks {
|
|
|
33
32
|
* Build the plugin's hooks and custom tools. Exported (rather than inlined in
|
|
34
33
|
* the plugin) so tests can inject a stubbed command runner and tracker.
|
|
35
34
|
*/
|
|
36
|
-
export declare function buildHooks(ctx: PluginInput, config: ResolvedConfig, log: LogFn, run?: RunCommand, tracker?: ChangedFileTracker, constitution?: string | null,
|
|
35
|
+
export declare function buildHooks(ctx: PluginInput, config: ResolvedConfig, log: LogFn, run?: RunCommand, tracker?: ChangedFileTracker, constitution?: string | null, configMtime?: number): HooksWithStopping;
|
|
37
36
|
export declare const devFramework: Plugin;
|
|
38
37
|
export default devFramework;
|
package/dist/index.js
CHANGED
|
@@ -7,31 +7,62 @@
|
|
|
7
7
|
* - event (session.idle) -> completion gate fallback (advisory logging)
|
|
8
8
|
* - experimental.chat.system.transform -> constitution injection + session mapping
|
|
9
9
|
* - experimental.session.stopping -> blocking completion gate (OpenCode >= PR #41811)
|
|
10
|
-
* - config hook -> registers /df-
|
|
11
|
-
* - command.execute.before -> handles
|
|
10
|
+
* - config hook -> registers /df-profile and /df-verify prompt commands
|
|
11
|
+
* - command.execute.before -> handles /df-profile, /df-verify, and unknown /df-*
|
|
12
12
|
*/
|
|
13
|
+
import { stat } from "node:fs/promises";
|
|
13
14
|
import { join } from "node:path";
|
|
14
15
|
import { clearConfigCache, loadConfig } from "./config.js";
|
|
15
16
|
import { createChangedFileTracker, runGate, summarizeGate, } from "./gate.js";
|
|
16
|
-
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";
|
|
21
20
|
import { checkToolCall } from "./protect.js";
|
|
22
|
-
import { clearSessionDirectory, getHookState, getStateForSession, setBaseDirectory, setHookState, setSessionDirectory,
|
|
21
|
+
import { clearSessionDirectory, getHookState, getStateForSession, setBaseDirectory, setHookState, setSessionDirectory, } from "./registry.js";
|
|
23
22
|
import { injectConstitution, loadConstitution } from "./rules.js";
|
|
24
|
-
import { setProfileInFile } from "./installer.js";
|
|
25
23
|
import { buildTools } from "./tools.js";
|
|
24
|
+
/**
|
|
25
|
+
* Reload the in-memory config if the config file on disk changed since we last
|
|
26
|
+
* loaded it. This makes out-of-process edits (e.g. a `/df-profile` change made
|
|
27
|
+
* from the TUI module, which writes the file directly) take effect on the next
|
|
28
|
+
* enforcement hook without restarting OpenCode.
|
|
29
|
+
*/
|
|
30
|
+
async function reloadConfigIfChanged(state) {
|
|
31
|
+
const configPath = join(state.directory, ".opencode-dev-framework.yml");
|
|
32
|
+
try {
|
|
33
|
+
const stats = await stat(configPath);
|
|
34
|
+
if (state.configMtime !== undefined && state.configMtime === stats.mtimeMs) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
clearConfigCache();
|
|
38
|
+
const next = loadConfig(state.directory);
|
|
39
|
+
const { constitution } = await loadConstitution(next, state.directory);
|
|
40
|
+
state.config = next;
|
|
41
|
+
state.constitution = constitution;
|
|
42
|
+
state.configMtime = stats.mtimeMs;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Config file missing/unreadable — keep the current state.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
26
48
|
/**
|
|
27
49
|
* Build the plugin's hooks and custom tools. Exported (rather than inlined in
|
|
28
50
|
* the plugin) so tests can inject a stubbed command runner and tracker.
|
|
29
51
|
*/
|
|
30
|
-
export function buildHooks(ctx, config, log, run = runCommand, tracker = createChangedFileTracker(), constitution = null,
|
|
52
|
+
export function buildHooks(ctx, config, log, run = runCommand, tracker = createChangedFileTracker(), constitution = null, configMtime) {
|
|
31
53
|
// All hook state — including the project directory — lives in the registry
|
|
32
54
|
// and is looked up at call time. OpenCode's Effect runtime stripped closure
|
|
33
55
|
// captures in production (config/log/run came back undefined), so hooks must
|
|
34
56
|
// not rely on variables from this scope.
|
|
57
|
+
const showToast = (message, variant = "info") => {
|
|
58
|
+
try {
|
|
59
|
+
const tui = ctx.client.tui;
|
|
60
|
+
tui?.showToast?.({ title: "opencode-dev-framework", message, variant });
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// TUI may be unavailable; the log line is enough.
|
|
64
|
+
}
|
|
65
|
+
};
|
|
35
66
|
setHookState(ctx.directory, {
|
|
36
67
|
directory: ctx.directory,
|
|
37
68
|
config,
|
|
@@ -40,7 +71,8 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
40
71
|
tracker,
|
|
41
72
|
constitution,
|
|
42
73
|
blockCounts: new Map(),
|
|
43
|
-
|
|
74
|
+
showToast,
|
|
75
|
+
configMtime,
|
|
44
76
|
});
|
|
45
77
|
return {
|
|
46
78
|
tool: buildTools(ctx),
|
|
@@ -50,103 +82,18 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
50
82
|
if (state) {
|
|
51
83
|
state.hostPermissions = typedConfig.permission ?? [];
|
|
52
84
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
description: "Show the current dev-framework state",
|
|
59
|
-
};
|
|
60
|
-
typedConfig.command["df-profile"] = {
|
|
61
|
-
template: "",
|
|
62
|
-
description: "Change the dev-framework profile (off, advisory, standard, strict)",
|
|
63
|
-
};
|
|
64
|
-
typedConfig.command["df-verify"] = {
|
|
65
|
-
template: "",
|
|
66
|
-
description: "Run the dev-framework completion gate manually",
|
|
67
|
-
};
|
|
68
|
-
typedConfig.command["df-help"] = {
|
|
69
|
-
template: "",
|
|
70
|
-
description: "List the available dev-framework slash commands",
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
"command.execute.before": async (input, output) => {
|
|
74
|
-
const state = getStateForSession(input.sessionID);
|
|
75
|
-
if (!state) {
|
|
76
|
-
const fallback = "[opencode-dev-framework] plugin state is not available for this session.";
|
|
77
|
-
output.parts.length = 0;
|
|
78
|
-
output.parts.push({ type: "text", text: fallback });
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const directory = state.directory;
|
|
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
|
-
}
|
|
91
|
-
};
|
|
92
|
-
if (input.command === "df-help" || input.command === "df") {
|
|
93
|
-
await reply(`df — opencode-dev-framework commands
|
|
94
|
-
|
|
95
|
-
/df-status Show the current dev-framework state
|
|
96
|
-
/df-profile Change the profile to off, advisory, standard, or strict
|
|
97
|
-
/df-verify Run the completion gate manually
|
|
98
|
-
/df-help Show this message`);
|
|
99
|
-
await state.log("info", "df-help command executed", { directory });
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (input.command === "df-status") {
|
|
103
|
-
await reply(renderStatus(state.config, state));
|
|
104
|
-
await state.log("info", "df-status command executed", { directory });
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (input.command === "df-profile") {
|
|
108
|
-
const profile = input.arguments.trim().toLowerCase();
|
|
109
|
-
const validProfiles = ["off", "advisory", "standard", "strict"];
|
|
110
|
-
if (!validProfiles.includes(profile)) {
|
|
111
|
-
await reply(`Invalid profile "${profile}". Valid values: ${validProfiles.join(", ")}.`);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const configPath = join(state.directory, ".opencode-dev-framework.yml");
|
|
115
|
-
await setProfileInFile(configPath, profile);
|
|
116
|
-
clearConfigCache();
|
|
117
|
-
const nextConfig = loadConfig(state.directory);
|
|
118
|
-
const { constitution } = await loadConstitution(nextConfig, state.directory);
|
|
119
|
-
updateHookState(state.directory, { config: nextConfig, constitution });
|
|
120
|
-
await reply(`opencode-dev-framework profile set to "${profile}". Change applied immediately.`);
|
|
121
|
-
await state.log("info", "df-profile command executed", { directory, profile });
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (input.command === "df-verify") {
|
|
125
|
-
const changedFiles = state.tracker.getChangedFiles();
|
|
126
|
-
const report = await runGate(state.run, state.config, changedFiles, {
|
|
127
|
-
cwd: state.directory,
|
|
128
|
-
});
|
|
129
|
-
const summary = summarizeGate(report);
|
|
130
|
-
await reply(summary);
|
|
131
|
-
const level = report.ok ? "info" : "error";
|
|
132
|
-
await state.log(level, "df-verify command executed", {
|
|
133
|
-
directory,
|
|
134
|
-
ok: report.ok,
|
|
135
|
-
ran: report.ran,
|
|
136
|
-
});
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
// Unknown /df-* command — give a helpful response.
|
|
140
|
-
if (input.command.startsWith("df-")) {
|
|
141
|
-
await reply(`Unknown command /${input.command}. Try /df-help.`);
|
|
142
|
-
await state.log("warn", "unknown df command", { directory, command: input.command });
|
|
143
|
-
}
|
|
85
|
+
// `df-profile`, `df-verify`, `df-status`, and `df-help` are all registered
|
|
86
|
+
// as TUI commands (keymap layer with `slashName`) in `tui.tsx`. TUI
|
|
87
|
+
// commands never insert text into the chat stream, so they cannot leak
|
|
88
|
+
// into a model turn. No server prompt command is registered here — such
|
|
89
|
+
// commands always produce a model turn, which is exactly what we avoid.
|
|
144
90
|
},
|
|
145
91
|
"experimental.chat.system.transform": async (input, output) => {
|
|
146
92
|
const state = getStateForSession(input.sessionID);
|
|
147
93
|
if (!state) {
|
|
148
94
|
return;
|
|
149
95
|
}
|
|
96
|
+
await reloadConfigIfChanged(state);
|
|
150
97
|
if (input.sessionID) {
|
|
151
98
|
setSessionDirectory(input.sessionID, state.directory);
|
|
152
99
|
}
|
|
@@ -161,6 +108,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
161
108
|
if (!state) {
|
|
162
109
|
throw new Error("[opencode-dev-framework] plugin state is not available; guardrail cannot evaluate this tool call");
|
|
163
110
|
}
|
|
111
|
+
await reloadConfigIfChanged(state);
|
|
164
112
|
const result = checkToolCall(state.config, input.tool, output.args, state.directory, state.hostPermissions);
|
|
165
113
|
if (result.decision === "allow") {
|
|
166
114
|
return;
|
|
@@ -180,7 +128,11 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
180
128
|
},
|
|
181
129
|
"experimental.session.stopping": async (input, output) => {
|
|
182
130
|
const state = getStateForSession(input.sessionID);
|
|
183
|
-
if (!state
|
|
131
|
+
if (!state) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
await reloadConfigIfChanged(state);
|
|
135
|
+
if (!state.config.gate || state.config.profile === "off") {
|
|
184
136
|
return;
|
|
185
137
|
}
|
|
186
138
|
const changedFiles = state.tracker.getChangedFiles();
|
|
@@ -222,6 +174,7 @@ export function buildHooks(ctx, config, log, run = runCommand, tracker = createC
|
|
|
222
174
|
if (!state) {
|
|
223
175
|
return;
|
|
224
176
|
}
|
|
177
|
+
await reloadConfigIfChanged(state);
|
|
225
178
|
if (event.type === "file.edited") {
|
|
226
179
|
const filePath = event.properties.file;
|
|
227
180
|
state.tracker.add(filePath, state.directory);
|
|
@@ -327,6 +280,13 @@ export const devFramework = async (ctx) => {
|
|
|
327
280
|
if (warning) {
|
|
328
281
|
await log("warn", warning);
|
|
329
282
|
}
|
|
330
|
-
|
|
283
|
+
let configMtime;
|
|
284
|
+
try {
|
|
285
|
+
configMtime = (await stat(join(ctx.directory, ".opencode-dev-framework.yml"))).mtimeMs;
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
// Config file may not exist yet; reloadConfigIfChanged will pick it up.
|
|
289
|
+
}
|
|
290
|
+
return buildHooks(ctx, config, log, runCommand, createChangedFileTracker(), constitution, configMtime);
|
|
331
291
|
};
|
|
332
292
|
export default devFramework;
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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";
|
|
5
4
|
import type { ResolvedConfig } from "./types.js";
|
|
6
5
|
export interface HostPermission {
|
|
7
6
|
permission?: string;
|
|
@@ -23,8 +22,11 @@ export interface HookState {
|
|
|
23
22
|
precommitAvailable?: boolean;
|
|
24
23
|
/** Snapshot of host permissions from OpenCode's effective config. */
|
|
25
24
|
hostPermissions?: HostPermission[];
|
|
26
|
-
/**
|
|
27
|
-
|
|
25
|
+
/** Show a non-chat TUI toast (used for slash-command results). */
|
|
26
|
+
showToast?: (message: string, variant?: "info" | "success" | "warning" | "error") => void;
|
|
27
|
+
/** mtime (ms) of the config file at last load; used to detect out-of-process
|
|
28
|
+
* edits (e.g. a `/df-profile` change made from the TUI module). */
|
|
29
|
+
configMtime?: number;
|
|
28
30
|
}
|
|
29
31
|
export declare function setBaseDirectory(directory: string): void;
|
|
30
32
|
export declare function getBaseDirectory(): string | null;
|
package/dist/tools.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { tool } from "@opencode-ai/plugin";
|
|
3
2
|
import { loadConfig, clearConfigCache } from "./config.js";
|
|
4
|
-
import { installTemplates,
|
|
3
|
+
import { installTemplates, writeDetectedConfig } from "./installer.js";
|
|
5
4
|
import { getHookState, updateHookState } from "./registry.js";
|
|
6
5
|
import { loadConstitution } from "./rules.js";
|
|
7
6
|
import { renderStatus } from "./format-status.js";
|
|
7
|
+
import { changeProfile } from "./commands.js";
|
|
8
8
|
const PROFILES = ["off", "advisory", "standard", "strict"];
|
|
9
9
|
function isProfile(value) {
|
|
10
10
|
return PROFILES.includes(value);
|
|
@@ -64,8 +64,7 @@ export function buildTools(_ctx) {
|
|
|
64
64
|
if (!isProfile(profile)) {
|
|
65
65
|
return `Invalid profile "${args.profile}". Valid values: ${PROFILES.join(", ")}.`;
|
|
66
66
|
}
|
|
67
|
-
const
|
|
68
|
-
await setProfileInFile(configPath, profile);
|
|
67
|
+
const message = await changeProfile(targetDir, profile);
|
|
69
68
|
// Reload config and constitution so the change takes effect immediately.
|
|
70
69
|
clearConfigCache();
|
|
71
70
|
const config = loadConfig(targetDir);
|
|
@@ -74,7 +73,7 @@ export function buildTools(_ctx) {
|
|
|
74
73
|
if (state) {
|
|
75
74
|
updateHookState(targetDir, { config, constitution });
|
|
76
75
|
}
|
|
77
|
-
return
|
|
76
|
+
return `${message} Change applied immediately.`;
|
|
78
77
|
},
|
|
79
78
|
}),
|
|
80
79
|
dev_framework_status: tool({
|
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-dev-framework",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./tui": {
|
|
15
|
+
"types": "./dist/tui.d.ts",
|
|
16
|
+
"import": "./tui.tsx"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
9
19
|
"repository": {
|
|
10
20
|
"type": "git",
|
|
11
21
|
"url": "git+https://github.com/jwitmann/opencode-dev-framework.git"
|
|
@@ -14,15 +24,19 @@
|
|
|
14
24
|
"dist",
|
|
15
25
|
"bin",
|
|
16
26
|
"rules",
|
|
17
|
-
"templates"
|
|
27
|
+
"templates",
|
|
28
|
+
"tui.tsx"
|
|
18
29
|
],
|
|
19
30
|
"bin": {
|
|
20
31
|
"df": "bin/df"
|
|
21
32
|
},
|
|
22
33
|
"scripts": {
|
|
23
34
|
"build": "tsc -p tsconfig.json",
|
|
24
|
-
"
|
|
35
|
+
"pretypecheck": "npm run build",
|
|
36
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.tui.json",
|
|
37
|
+
"typecheck:tui": "tsc --noEmit -p tsconfig.tui.json",
|
|
25
38
|
"test": "vitest run",
|
|
39
|
+
"pretest": "npm run build",
|
|
26
40
|
"lint": "biome lint .",
|
|
27
41
|
"lint:fix": "biome lint --write .",
|
|
28
42
|
"format:check": "biome format .",
|
|
@@ -44,6 +58,9 @@
|
|
|
44
58
|
"devDependencies": {
|
|
45
59
|
"@biomejs/biome": "^2.5.8",
|
|
46
60
|
"@opencode-ai/plugin": "^1.18.18",
|
|
61
|
+
"@opentui/core": "^0.5.3",
|
|
62
|
+
"@opentui/keymap": "^0.5.3",
|
|
63
|
+
"@opentui/solid": "^0.5.3",
|
|
47
64
|
"@types/node": "^26.2.0",
|
|
48
65
|
"@types/picomatch": "^4.0.3",
|
|
49
66
|
"markdownlint-cli2": "^0.23.2",
|
package/tui.tsx
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
|
|
3
|
+
import type { TuiPluginModule } from "@opencode-ai/plugin/tui";
|
|
4
|
+
import { changeProfile, verifyGate } from "./dist/commands.js";
|
|
5
|
+
import { loadConfig } from "./dist/config.js";
|
|
6
|
+
import { runCommand } from "./dist/host.js";
|
|
7
|
+
import { renderConfigStatus, renderHelp } from "./dist/format-status.js";
|
|
8
|
+
import type { Profile } from "./dist/types.js";
|
|
9
|
+
|
|
10
|
+
type TuiApi = Parameters<TuiPluginModule["tui"]>[0];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* OpenCode invokes a slash command's `run` with a keymap `CommandContext`.
|
|
14
|
+
* The trailing slash text (e.g. `standard` in `/df-profile standard`) is
|
|
15
|
+
* available on `ctx.input`. TUI commands are UI-only: they never insert text
|
|
16
|
+
* into the chat stream, so they cannot leak into a model turn.
|
|
17
|
+
*/
|
|
18
|
+
type CommandCtx = { input?: string };
|
|
19
|
+
|
|
20
|
+
type DevFrameworkCommand = {
|
|
21
|
+
title: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
slashName: string;
|
|
25
|
+
run: (ctx?: CommandCtx) => void | Promise<void>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Register dev-framework slash commands.
|
|
30
|
+
*
|
|
31
|
+
* The current OpenCode API is `api.keymap.registerLayer` (a command-palette
|
|
32
|
+
* layer that also wires up `/slash` invocations). This mirrors how DCP
|
|
33
|
+
* registers its commands. The legacy `api.command` v1 API is kept as a
|
|
34
|
+
* fallback (also like DCP). `slashName` makes OpenCode recognize the command
|
|
35
|
+
* **with arguments** and pass the trailing text to `run` via `ctx.input`.
|
|
36
|
+
*
|
|
37
|
+
* All four commands are TUI commands (no server prompt command, which would
|
|
38
|
+
* produce a model turn). Each `run` reads `ctx.input` so both the bare form
|
|
39
|
+
* (e.g. `/df-profile` opens a picker) and the argument form (e.g.
|
|
40
|
+
* `/df-profile standard` applies directly) work without feeding text to the
|
|
41
|
+
* model.
|
|
42
|
+
*/
|
|
43
|
+
function registerCommands(api: TuiApi, commands: DevFrameworkCommand[]): void {
|
|
44
|
+
const keymap = (api as { keymap?: { registerLayer?: (layer: unknown) => void } }).keymap;
|
|
45
|
+
if (keymap?.registerLayer) {
|
|
46
|
+
keymap.registerLayer({
|
|
47
|
+
commands: commands.map((command) => ({
|
|
48
|
+
namespace: "palette",
|
|
49
|
+
name: command.name,
|
|
50
|
+
title: command.title,
|
|
51
|
+
desc: command.description,
|
|
52
|
+
category: "dev-framework",
|
|
53
|
+
slashName: command.slashName,
|
|
54
|
+
run: command.run,
|
|
55
|
+
})),
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Legacy v1 API fallback (used on runtimes where keymap.registerLayer is
|
|
61
|
+
// unavailable). Mirrors how DCP registers its commands.
|
|
62
|
+
const commandApi = (api as { command?: { register?: (fn: () => unknown) => void } }).command;
|
|
63
|
+
commandApi?.register?.(() =>
|
|
64
|
+
commands.map((command) => ({
|
|
65
|
+
title: command.title,
|
|
66
|
+
value: command.name,
|
|
67
|
+
description: command.description,
|
|
68
|
+
category: "dev-framework",
|
|
69
|
+
slash: { name: command.slashName },
|
|
70
|
+
onSelect: command.run,
|
|
71
|
+
})),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const PROFILES: Profile[] = ["off", "advisory", "standard", "strict"];
|
|
76
|
+
|
|
77
|
+
const tui: TuiPluginModule["tui"] = async (api) => {
|
|
78
|
+
const directory = api.state.path.directory;
|
|
79
|
+
|
|
80
|
+
registerCommands(api, [
|
|
81
|
+
{
|
|
82
|
+
title: "dev-framework status",
|
|
83
|
+
name: "df-status",
|
|
84
|
+
description: "Show the current dev-framework configuration",
|
|
85
|
+
slashName: "df-status",
|
|
86
|
+
run: () => showStatusDialog(api, directory),
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
title: "dev-framework help",
|
|
90
|
+
name: "df-help",
|
|
91
|
+
description: "List available dev-framework commands",
|
|
92
|
+
slashName: "df-help",
|
|
93
|
+
run: () => showHelpDialog(api),
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
title: "dev-framework profile",
|
|
97
|
+
name: "df-profile",
|
|
98
|
+
description: "Change the active dev-framework profile",
|
|
99
|
+
slashName: "df-profile",
|
|
100
|
+
run: (ctx) => handleProfile(api, directory, ctx?.input),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
title: "dev-framework verify",
|
|
104
|
+
name: "df-verify",
|
|
105
|
+
description: "Run the dev-framework completion gate",
|
|
106
|
+
slashName: "df-verify",
|
|
107
|
+
run: () => handleVerify(api, directory),
|
|
108
|
+
},
|
|
109
|
+
]);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
function showStatusDialog(api: TuiApi, directory: string): void {
|
|
113
|
+
const config = loadConfig(directory);
|
|
114
|
+
const DialogAlert = api.ui.DialogAlert;
|
|
115
|
+
api.ui.dialog.replace(() => (
|
|
116
|
+
<DialogAlert
|
|
117
|
+
title="opencode-dev-framework status"
|
|
118
|
+
message={renderConfigStatus(config)}
|
|
119
|
+
onConfirm={() => api.ui.dialog.clear()}
|
|
120
|
+
/>
|
|
121
|
+
));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function showHelpDialog(api: TuiApi): void {
|
|
125
|
+
const DialogAlert = api.ui.DialogAlert;
|
|
126
|
+
api.ui.dialog.replace(() => (
|
|
127
|
+
<DialogAlert
|
|
128
|
+
title="dev-framework commands"
|
|
129
|
+
message={renderHelp()}
|
|
130
|
+
onConfirm={() => api.ui.dialog.clear()}
|
|
131
|
+
/>
|
|
132
|
+
));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Bare `/df-profile` opens a picker; `/df-profile <name>` applies directly. */
|
|
136
|
+
function handleProfile(api: TuiApi, directory: string, input?: string): void {
|
|
137
|
+
// OpenCode passes the command name itself as `ctx.input` for a bare invocation
|
|
138
|
+
// (e.g. "df-profile"), not an empty string. Normalize that back to "bare".
|
|
139
|
+
const raw = (input ?? "").trim();
|
|
140
|
+
const arg = raw === "df-profile" ? "" : raw;
|
|
141
|
+
if (arg && PROFILES.includes(arg as Profile)) {
|
|
142
|
+
void changeProfile(directory, arg as Profile).then((message) => {
|
|
143
|
+
api.ui.toast?.({ message, variant: "success" });
|
|
144
|
+
});
|
|
145
|
+
api.ui.dialog.clear();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (arg) {
|
|
149
|
+
api.ui.toast?.({
|
|
150
|
+
message: `Usage: /df-profile <${PROFILES.join("|")}>`,
|
|
151
|
+
variant: "warning",
|
|
152
|
+
});
|
|
153
|
+
api.ui.dialog.clear();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
showProfileDialog(api, directory);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function showProfileDialog(api: TuiApi, directory: string): void {
|
|
160
|
+
const DialogSelect = api.ui.DialogSelect;
|
|
161
|
+
api.ui.dialog.replace(() => (
|
|
162
|
+
<DialogSelect
|
|
163
|
+
title="dev-framework profile"
|
|
164
|
+
options={PROFILES.map((p) => ({ title: p, value: p }))}
|
|
165
|
+
onSelect={(option) => {
|
|
166
|
+
api.ui.dialog.clear();
|
|
167
|
+
void changeProfile(directory, option.value as Profile).then((message) => {
|
|
168
|
+
api.ui.toast?.({ message, variant: "success" });
|
|
169
|
+
});
|
|
170
|
+
}}
|
|
171
|
+
/>
|
|
172
|
+
));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function handleVerify(api: TuiApi, directory: string): Promise<void> {
|
|
176
|
+
const config = loadConfig(directory);
|
|
177
|
+
const { summary, report } = await verifyGate(runCommand, directory, config);
|
|
178
|
+
const DialogAlert = api.ui.DialogAlert;
|
|
179
|
+
api.ui.dialog.replace(() => (
|
|
180
|
+
<DialogAlert
|
|
181
|
+
title={report.ok ? "dev-framework gate passed" : "dev-framework gate failed"}
|
|
182
|
+
message={summary}
|
|
183
|
+
onConfirm={() => api.ui.dialog.clear()}
|
|
184
|
+
/>
|
|
185
|
+
));
|
|
186
|
+
api.ui.toast?.({ message: summary, variant: report.ok ? "success" : "error" });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export default {
|
|
190
|
+
id: "opencode-dev-framework",
|
|
191
|
+
tui,
|
|
192
|
+
} satisfies TuiPluginModule;
|
package/dist/messenger.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
package/dist/messenger.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|