@cfbender/cesium 0.7.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -1
- package/plugin.lua +197 -0
- package/plugin.toml +4 -0
- package/src/hygge/bridge.ts +133 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfbender/cesium",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Beautiful self-contained HTML artifacts from your opencode agent.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"src",
|
|
27
|
+
"plugin.lua",
|
|
28
|
+
"plugin.toml",
|
|
27
29
|
"assets/styleguide.html",
|
|
28
30
|
"agents",
|
|
29
31
|
"ARCHITECTURE.md",
|
package/plugin.lua
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
-- Hygge Lua plugin entrypoint. Core Cesium behavior remains in TypeScript;
|
|
2
|
+
-- this file only adapts Hygge's Lua plugin API to src/hygge/bridge.ts.
|
|
3
|
+
|
|
4
|
+
local source = debug.getinfo(1, "S").source
|
|
5
|
+
local plugin_dir = source:sub(1, 1) == "@" and source:sub(2):match("(.+)/[^/]+$") or "."
|
|
6
|
+
local bridge = "src/hygge/bridge.ts"
|
|
7
|
+
|
|
8
|
+
local function json_escape(value)
|
|
9
|
+
return value:gsub('\\', '\\\\'):gsub('"', '\\"'):gsub('\n', '\\n'):gsub('\r', '\\r'):gsub('\t', '\\t')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
local function json_encode(value)
|
|
13
|
+
local value_type = type(value)
|
|
14
|
+
if value_type == "nil" then
|
|
15
|
+
return "null"
|
|
16
|
+
end
|
|
17
|
+
if value_type == "boolean" or value_type == "number" then
|
|
18
|
+
return tostring(value)
|
|
19
|
+
end
|
|
20
|
+
if value_type == "string" then
|
|
21
|
+
return '"' .. json_escape(value) .. '"'
|
|
22
|
+
end
|
|
23
|
+
if value_type ~= "table" then
|
|
24
|
+
error("cannot JSON-encode " .. value_type)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
local max_index = 0
|
|
28
|
+
local count = 0
|
|
29
|
+
for key, _ in pairs(value) do
|
|
30
|
+
count = count + 1
|
|
31
|
+
if type(key) == "number" and key > max_index and key % 1 == 0 then
|
|
32
|
+
max_index = key
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
if max_index == count then
|
|
37
|
+
local items = {}
|
|
38
|
+
for index = 1, max_index do
|
|
39
|
+
items[index] = json_encode(value[index])
|
|
40
|
+
end
|
|
41
|
+
return "[" .. table.concat(items, ",") .. "]"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
local fields = {}
|
|
45
|
+
for key, field_value in pairs(value) do
|
|
46
|
+
fields[#fields + 1] = json_encode(tostring(key)) .. ":" .. json_encode(field_value)
|
|
47
|
+
end
|
|
48
|
+
return "{" .. table.concat(fields, ",") .. "}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
local function run_bridge(ctx, name, input)
|
|
52
|
+
local session_id = (hygge.session and hygge.session.id) or "hygge"
|
|
53
|
+
local pwd = (ctx and ctx.pwd) or plugin_dir
|
|
54
|
+
local result = hygge.exec("bun", { "run", bridge, "tool", name, pwd, session_id, "", json_encode(input or {}) }, {
|
|
55
|
+
dir = plugin_dir,
|
|
56
|
+
timeout = "10m",
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
if result.code ~= 0 then
|
|
60
|
+
return { content = result.stderr ~= "" and result.stderr or result.stdout, is_error = true }
|
|
61
|
+
end
|
|
62
|
+
return { content = result.stdout }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
local string_array = { type = "array", items = { type = "string" } }
|
|
66
|
+
local block_array = { type = "array", items = { type = "object", additionalProperties = true } }
|
|
67
|
+
local question_array = { type = "array", items = { type = "object", additionalProperties = true } }
|
|
68
|
+
|
|
69
|
+
local tools = {
|
|
70
|
+
{
|
|
71
|
+
name = "cesium_publish",
|
|
72
|
+
description = "Publish a beautiful self-contained HTML document to the cesium artifacts directory.",
|
|
73
|
+
input_schema = {
|
|
74
|
+
type = "object",
|
|
75
|
+
properties = {
|
|
76
|
+
title = { type = "string" },
|
|
77
|
+
kind = { type = "string", enum = { "plan", "review", "comparison", "report", "explainer", "design", "audit", "rfc", "other", "ask", "annotate" } },
|
|
78
|
+
blocks = block_array,
|
|
79
|
+
summary = { type = "string" },
|
|
80
|
+
tags = string_array,
|
|
81
|
+
supersedes = { type = "string" },
|
|
82
|
+
},
|
|
83
|
+
required = { "title", "kind", "blocks" },
|
|
84
|
+
additionalProperties = false,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name = "cesium_ask",
|
|
89
|
+
description = "Publish an interactive Q&A artifact and return its URL.",
|
|
90
|
+
input_schema = {
|
|
91
|
+
type = "object",
|
|
92
|
+
properties = {
|
|
93
|
+
title = { type = "string" },
|
|
94
|
+
body = { type = "string" },
|
|
95
|
+
questions = question_array,
|
|
96
|
+
summary = { type = "string" },
|
|
97
|
+
tags = string_array,
|
|
98
|
+
expiresAt = { type = "string" },
|
|
99
|
+
requireAll = { type = "boolean" },
|
|
100
|
+
},
|
|
101
|
+
required = { "title", "body", "questions" },
|
|
102
|
+
additionalProperties = false,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name = "cesium_annotate",
|
|
107
|
+
description = "Publish an interactive review artifact with comments and verdict.",
|
|
108
|
+
input_schema = {
|
|
109
|
+
type = "object",
|
|
110
|
+
properties = {
|
|
111
|
+
title = { type = "string" },
|
|
112
|
+
blocks = block_array,
|
|
113
|
+
verdictMode = { type = "string", enum = { "approve", "approve-or-reject", "full" } },
|
|
114
|
+
perLineFor = string_array,
|
|
115
|
+
requireVerdict = { type = "boolean" },
|
|
116
|
+
summary = { type = "string" },
|
|
117
|
+
tags = string_array,
|
|
118
|
+
expiresAt = { type = "string" },
|
|
119
|
+
},
|
|
120
|
+
required = { "title", "blocks" },
|
|
121
|
+
additionalProperties = false,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name = "cesium_wait",
|
|
126
|
+
description = "Block until the user completes a cesium_ask or cesium_annotate artifact.",
|
|
127
|
+
input_schema = {
|
|
128
|
+
type = "object",
|
|
129
|
+
properties = {
|
|
130
|
+
id = { type = "string" },
|
|
131
|
+
timeoutMs = { type = "number" },
|
|
132
|
+
pollIntervalMs = { type = "number" },
|
|
133
|
+
},
|
|
134
|
+
required = { "id" },
|
|
135
|
+
additionalProperties = false,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name = "cesium_styleguide",
|
|
140
|
+
description = "Return the Cesium HTML design system reference page.",
|
|
141
|
+
input_schema = { type = "object", properties = {}, required = {} },
|
|
142
|
+
parallelizable = true,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name = "cesium_critique",
|
|
146
|
+
description = "Analyze a draft Cesium blocks array for design-system adherence.",
|
|
147
|
+
input_schema = {
|
|
148
|
+
type = "object",
|
|
149
|
+
properties = { blocks = block_array },
|
|
150
|
+
required = { "blocks" },
|
|
151
|
+
additionalProperties = false,
|
|
152
|
+
},
|
|
153
|
+
parallelizable = true,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name = "cesium_stop",
|
|
157
|
+
description = "Stop the running Cesium HTTP server.",
|
|
158
|
+
input_schema = {
|
|
159
|
+
type = "object",
|
|
160
|
+
properties = {
|
|
161
|
+
force = { type = "boolean" },
|
|
162
|
+
timeoutMs = { type = "number" },
|
|
163
|
+
},
|
|
164
|
+
required = { "force", "timeoutMs" },
|
|
165
|
+
additionalProperties = false,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for _, spec in ipairs(tools) do
|
|
171
|
+
hygge.register_tool {
|
|
172
|
+
name = spec.name,
|
|
173
|
+
description = spec.description,
|
|
174
|
+
input_schema = spec.input_schema,
|
|
175
|
+
parallelizable = spec.parallelizable,
|
|
176
|
+
execute = function(ctx, input)
|
|
177
|
+
return run_bridge(ctx, spec.name, input)
|
|
178
|
+
end,
|
|
179
|
+
}
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
local system_fragment = nil
|
|
183
|
+
|
|
184
|
+
hygge.register_hook("pre_message", { name = "cesium_system_guidance", timeout = "10s" }, function(event)
|
|
185
|
+
if system_fragment == nil then
|
|
186
|
+
local result = hygge.exec("bun", { "run", bridge, "system-fragment" }, { dir = plugin_dir, timeout = "10s" })
|
|
187
|
+
if result.code ~= 0 or result.stdout == "" then
|
|
188
|
+
return nil
|
|
189
|
+
end
|
|
190
|
+
system_fragment = result.stdout
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
decision = "allow",
|
|
195
|
+
system_prompt_append = system_fragment,
|
|
196
|
+
}
|
|
197
|
+
end)
|
package/plugin.toml
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
// Hygge adapter boundary: execute Cesium's existing TypeScript tool handlers from Lua.
|
|
4
|
+
|
|
5
|
+
import { $ } from "bun";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { readFile } from "node:fs/promises";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
10
|
+
import { createPublishTool } from "../tools/publish.ts";
|
|
11
|
+
import { createAskTool } from "../tools/ask.ts";
|
|
12
|
+
import { createAnnotateTool } from "../tools/annotate.ts";
|
|
13
|
+
import { createWaitTool } from "../tools/wait.ts";
|
|
14
|
+
import { createStyleguideTool } from "../tools/styleguide.ts";
|
|
15
|
+
import { createCritiqueTool } from "../tools/critique.ts";
|
|
16
|
+
import { createStopTool } from "../tools/stop.ts";
|
|
17
|
+
import { generateBlockFieldReference } from "../prompt/field-reference.ts";
|
|
18
|
+
import { recordSessionModel } from "../session-model.ts";
|
|
19
|
+
|
|
20
|
+
type ToolName =
|
|
21
|
+
| "cesium_publish"
|
|
22
|
+
| "cesium_ask"
|
|
23
|
+
| "cesium_annotate"
|
|
24
|
+
| "cesium_wait"
|
|
25
|
+
| "cesium_styleguide"
|
|
26
|
+
| "cesium_critique"
|
|
27
|
+
| "cesium_stop";
|
|
28
|
+
|
|
29
|
+
interface ExecutableTool {
|
|
30
|
+
execute: (args: Record<string, unknown>, context: unknown) => unknown | Promise<unknown>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const toolNames = new Set<ToolName>([
|
|
34
|
+
"cesium_publish",
|
|
35
|
+
"cesium_ask",
|
|
36
|
+
"cesium_annotate",
|
|
37
|
+
"cesium_wait",
|
|
38
|
+
"cesium_styleguide",
|
|
39
|
+
"cesium_critique",
|
|
40
|
+
"cesium_stop",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
function isToolName(value: string): value is ToolName {
|
|
44
|
+
return toolNames.has(value as ToolName);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function readStdin(): Promise<string> {
|
|
48
|
+
return await Bun.stdin.text();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function makeContext(directory: string): PluginInput {
|
|
52
|
+
const ctx = {
|
|
53
|
+
directory,
|
|
54
|
+
worktree: "",
|
|
55
|
+
$,
|
|
56
|
+
client: {},
|
|
57
|
+
project: {},
|
|
58
|
+
experimental_workspace: {},
|
|
59
|
+
serverUrl: "",
|
|
60
|
+
};
|
|
61
|
+
return ctx as unknown as PluginInput;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function createTool(name: ToolName, ctx: PluginInput): ExecutableTool {
|
|
65
|
+
const tool = (() => {
|
|
66
|
+
switch (name) {
|
|
67
|
+
case "cesium_publish":
|
|
68
|
+
return createPublishTool(ctx);
|
|
69
|
+
case "cesium_ask":
|
|
70
|
+
return createAskTool(ctx);
|
|
71
|
+
case "cesium_annotate":
|
|
72
|
+
return createAnnotateTool(ctx);
|
|
73
|
+
case "cesium_wait":
|
|
74
|
+
return createWaitTool(ctx);
|
|
75
|
+
case "cesium_styleguide":
|
|
76
|
+
return createStyleguideTool(ctx);
|
|
77
|
+
case "cesium_critique":
|
|
78
|
+
return createCritiqueTool(ctx);
|
|
79
|
+
case "cesium_stop":
|
|
80
|
+
return createStopTool(ctx);
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
|
|
84
|
+
return tool as unknown as ExecutableTool;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function systemFragment(): Promise<string> {
|
|
88
|
+
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
89
|
+
const raw = await readFile(join(root, "prompt/system-fragment.md"), "utf8");
|
|
90
|
+
return raw.replace("{{BLOCK_FIELD_REFERENCE}}", generateBlockFieldReference());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function main(): Promise<void> {
|
|
94
|
+
const command = process.argv[2];
|
|
95
|
+
if (command === "system-fragment") {
|
|
96
|
+
process.stdout.write(await systemFragment());
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (command !== "tool") {
|
|
101
|
+
throw new Error("usage: bridge.ts system-fragment | tool <name> [cwd] [sessionID] [model] [json]");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const name = process.argv[3];
|
|
105
|
+
if (name === undefined || !isToolName(name)) {
|
|
106
|
+
throw new Error(`unknown Cesium tool: ${name ?? "<missing>"}`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const directory = process.argv[4] ?? process.cwd();
|
|
110
|
+
const sessionID = process.argv[5] ?? "hygge";
|
|
111
|
+
const model = process.argv[6];
|
|
112
|
+
if (model !== undefined && model.length > 0) {
|
|
113
|
+
recordSessionModel(sessionID, "hygge", model);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const rawInput = process.argv[7] ?? (await readStdin());
|
|
117
|
+
const parsedInput: unknown = rawInput.trim().length === 0 ? {} : JSON.parse(rawInput);
|
|
118
|
+
if (typeof parsedInput !== "object" || parsedInput === null || Array.isArray(parsedInput)) {
|
|
119
|
+
throw new Error("tool input must be a JSON object");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const args = parsedInput as Record<string, unknown>;
|
|
123
|
+
const result = await createTool(name, makeContext(directory)).execute(args, { sessionID });
|
|
124
|
+
process.stdout.write(typeof result === "string" ? result : JSON.stringify(result, null, 2));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
await main();
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
131
|
+
process.stderr.write(`${message}\n`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|