@sirenodeck/sirenodeck 0.1.1-alpha.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -21
- package/bin/dev.js +12 -2
- package/dist/main.mjs +3655 -1657
- package/package.json +18 -16
- package/src/api/protocol-internal.ts +16 -1
- package/src/assets/logo.png +0 -0
- package/src/assets/logo72x72.png +0 -0
- package/src/builtin-addons/brightness/buttons/brightness/config.ts +12 -2
- package/src/builtin-addons/coding-agents/buttons/agent/config.ts +5 -1
- package/src/builtin-addons/coding-agents/buttons/summary/config.ts +15 -3
- package/src/builtin-addons/coding-agents/buttons/summary/frontend.tsx +3 -3
- package/src/builtin-addons/coding-agents/global/backend.ts +56 -34
- package/src/builtin-addons/coding-agents/providers/opencode.ts +4 -5
- package/src/builtin-addons/core/buttons/action/config.ts +5 -2
- package/src/builtin-addons/core/buttons/change-deck/config.ts +6 -3
- package/src/builtin-addons/core/buttons/media-sample/config.ts +2 -2
- package/src/builtin-addons/core/buttons/toggle/config.ts +26 -9
- package/src/builtin-addons/date-time/buttons/custom/config.ts +5 -1
- package/src/builtin-addons/date-time/buttons/date/config.ts +2 -2
- package/src/builtin-addons/date-time/buttons/time/config.ts +5 -1
- package/src/builtin-addons/emoji-selector/buttons/category/config.ts +3 -3
- package/src/builtin-addons/emoji-selector/buttons/emoji/config.ts +5 -2
- package/src/builtin-addons/emoji-selector/support.ts +5 -2
- package/src/builtin-addons/global-services.ts +23 -0
- package/src/builtin-addons/internal-settings/buttons/app-info/config.ts +2 -1
- package/src/builtin-addons/internal-settings/buttons/brightness-down/config.ts +6 -1
- package/src/builtin-addons/internal-settings/buttons/brightness-up/config.ts +6 -1
- package/src/builtin-addons/media/backend.ts +54 -0
- package/src/builtin-addons/media/buttons/volume/volume-down/config.ts +1 -1
- package/src/builtin-addons/media/buttons/volume/volume-up/config.ts +1 -1
- package/src/builtin-addons/session/buttons/time/config.ts +1 -1
- package/src/builtin-addons/system-status/buttons/system-status/schemas.ts +32 -6
- package/src/builtin-addons/system-status/manifest.ts +49 -0
- package/src/builtin-addons/value-display/buttons/value-display/config.ts +23 -9
- package/src/builtin-addons/weather/buttons/weather/config.ts +11 -6
- package/src/cli/coding-agents-onboarding.ts +181 -34
- package/src/cli/commands/command-executor.ts +61 -0
- package/src/cli/commands/emulator-mode.ts +17 -2
- package/src/cli/commands/network-bind.ts +13 -9
- package/src/cli/commands/restart.ts +15 -5
- package/src/cli/commands/run.ts +174 -317
- package/src/cli/commands/service/render-template.ts +10 -0
- package/src/cli/commands/skills.ts +106 -0
- package/src/cli/commands/start.ts +39 -9
- package/src/cli/commands/stop.ts +3 -2
- package/src/cli/commands/system-requirements.ts +1 -0
- package/src/cli/index.ts +16 -3
- package/src/cli/main.ts +15 -2
- package/src/cli/package-manager.ts +6 -0
- package/src/cli/skills-first-run.ts +46 -0
- package/src/cli/startup-display.ts +35 -17
- package/src/config/mutation.ts +13 -1
- package/src/config/schemas.ts +3 -3
- package/src/config/validation.ts +7 -1
- package/src/core/icon-asset-registry.ts +11 -6
- package/src/deck/addon-handler-bridge.ts +246 -176
- package/src/deck/deck-config.ts +11 -2
- package/src/deck/deck-presentation-publisher.ts +116 -0
- package/src/deck/index.ts +13 -0
- package/src/deck/inject-config-ui-button.ts +23 -0
- package/src/deck/methods.ts +23 -0
- package/src/deck/position-settings-version-button.ts +20 -0
- package/src/deck/runtime/host-policy-coordinator.ts +186 -0
- package/src/deck/runtime/runtime.ts +123 -250
- package/src/deck/system-back-injection.ts +2 -1
- package/src/device/reconnecting.ts +8 -1
- package/src/index.ts +1 -2
- package/src/outputClient/emulator.ts +13 -0
- package/src/outputClient/index.ts +8 -0
- package/src/outputClient/real.ts +40 -45
- package/src/outputClient/remote-mirror.ts +77 -0
- package/src/outputClient/types.ts +2 -0
- package/src/render/editor-handler.ts +12 -1
- package/src/render/frontend-bridge-url.ts +10 -0
- package/src/render/push-startup-screen.ts +76 -0
- package/src/render/ws-bridge.ts +2 -0
- package/src/system/providers/active-app/capture-file.ts +61 -0
- package/src/system/providers/active-app/wayland-gnome.ts +26 -10
- package/src/system/providers/active-app.ts +6 -0
- package/src/system/providers/clipboard/darwin.ts +28 -4
- package/src/system/providers/url.ts +57 -0
- package/src/util/logger.ts +19 -3
- package/src/version.ts +3 -1
- package/src/vite/virtual-modules.ts +12 -6
|
@@ -24,6 +24,21 @@ const FALLBACK_STATE: MediaPlayerState = {
|
|
|
24
24
|
|
|
25
25
|
let provider: MediaStatusProvider | null = null
|
|
26
26
|
let ctxRef: AddonServiceContext | null = null
|
|
27
|
+
let captureMediaState: MediaPlayerState | null = null
|
|
28
|
+
let captureStage = "playing"
|
|
29
|
+
|
|
30
|
+
const captureMode = (): boolean =>
|
|
31
|
+
process.env["SIRENO_CAPTURE_FAKE_MEDIA"] === "1"
|
|
32
|
+
|
|
33
|
+
const setCapturePlayback = (playing: boolean): void => {
|
|
34
|
+
captureStage = playing ? "playing" : "paused"
|
|
35
|
+
if (captureMediaState === null) return
|
|
36
|
+
captureMediaState = {
|
|
37
|
+
...captureMediaState,
|
|
38
|
+
status: playing ? "play" : "pause",
|
|
39
|
+
isPlaying: playing,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
27
42
|
|
|
28
43
|
const mapStatus = (
|
|
29
44
|
playStatus: Awaited<
|
|
@@ -76,6 +91,21 @@ export const globalService: AddonGlobalService = {
|
|
|
76
91
|
channel: "media:state",
|
|
77
92
|
intervalMs: 1_000,
|
|
78
93
|
poll: async (_ctx: AddonServiceContext): Promise<MediaPlayerState> => {
|
|
94
|
+
if (captureMode() && captureMediaState !== null) {
|
|
95
|
+
const stagePath = process.env["SIRENO_CAPTURE_FAKE_MEDIA_FILE"]
|
|
96
|
+
if (stagePath !== undefined) {
|
|
97
|
+
try {
|
|
98
|
+
const stage = JSON.parse(
|
|
99
|
+
(await import("node:fs")).readFileSync(stagePath, "utf8"),
|
|
100
|
+
) as { stage?: unknown }
|
|
101
|
+
if (stage.stage === "paused" && captureStage !== "paused")
|
|
102
|
+
setCapturePlayback(false)
|
|
103
|
+
} catch {
|
|
104
|
+
// Keep the previous capture state while the stage file is being written.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { ...captureMediaState }
|
|
108
|
+
}
|
|
79
109
|
if (provider === null) return FALLBACK_STATE
|
|
80
110
|
try {
|
|
81
111
|
return buildState(await provider.getStatus())
|
|
@@ -88,12 +118,16 @@ export const globalService: AddonGlobalService = {
|
|
|
88
118
|
|
|
89
119
|
methods: {
|
|
90
120
|
play: wrap(async () => {
|
|
121
|
+
if (captureMode()) return setCapturePlayback(true)
|
|
91
122
|
await provider?.play()
|
|
92
123
|
}),
|
|
93
124
|
pause: wrap(async () => {
|
|
125
|
+
if (captureMode()) return setCapturePlayback(false)
|
|
94
126
|
await provider?.pause()
|
|
95
127
|
}),
|
|
96
128
|
toggle: wrap(async () => {
|
|
129
|
+
if (captureMode())
|
|
130
|
+
return setCapturePlayback(captureMediaState?.isPlaying !== true)
|
|
97
131
|
await provider?.toggle()
|
|
98
132
|
}),
|
|
99
133
|
next: wrap(async () => {
|
|
@@ -121,6 +155,25 @@ export const globalService: AddonGlobalService = {
|
|
|
121
155
|
|
|
122
156
|
onLoad: (ctx: AddonServiceContext) => {
|
|
123
157
|
ctxRef = ctx
|
|
158
|
+
if (captureMode()) {
|
|
159
|
+
captureMediaState = {
|
|
160
|
+
title: "Night Drive",
|
|
161
|
+
artist: "Sireno Studio",
|
|
162
|
+
source: "Demo session",
|
|
163
|
+
status: "play",
|
|
164
|
+
isPlaying: true,
|
|
165
|
+
volume: 68,
|
|
166
|
+
progress: 42,
|
|
167
|
+
currentTime: 84,
|
|
168
|
+
totalTime: 200,
|
|
169
|
+
muted: false,
|
|
170
|
+
}
|
|
171
|
+
captureStage = "playing"
|
|
172
|
+
provider = null
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
captureMediaState = null
|
|
176
|
+
captureStage = "playing"
|
|
124
177
|
provider = createMediaProvider(process.platform, {
|
|
125
178
|
async run(
|
|
126
179
|
command: string,
|
|
@@ -139,5 +192,6 @@ export const globalService: AddonGlobalService = {
|
|
|
139
192
|
onUnload: () => {
|
|
140
193
|
ctxRef = null
|
|
141
194
|
provider = null
|
|
195
|
+
captureMediaState = null
|
|
142
196
|
},
|
|
143
197
|
}
|
|
@@ -13,8 +13,13 @@ export const MetricEntrySchema = z
|
|
|
13
13
|
z
|
|
14
14
|
.object({
|
|
15
15
|
id: z.enum(SYSTEM_METRIC_IDS),
|
|
16
|
-
label: z.string().min(1).optional(),
|
|
17
|
-
shortLabel: z
|
|
16
|
+
label: z.string().min(1).optional().meta({ title: "Metric label" }),
|
|
17
|
+
shortLabel: z
|
|
18
|
+
.string()
|
|
19
|
+
.min(1)
|
|
20
|
+
.max(3)
|
|
21
|
+
.optional()
|
|
22
|
+
.meta({ title: "Short label" }),
|
|
18
23
|
})
|
|
19
24
|
.strict(),
|
|
20
25
|
])
|
|
@@ -34,24 +39,45 @@ export const MetricEntrySchema = z
|
|
|
34
39
|
export const BarPageSchema = z
|
|
35
40
|
.object({
|
|
36
41
|
type: z.literal("bars"),
|
|
37
|
-
metrics: z
|
|
42
|
+
metrics: z
|
|
43
|
+
.array(MetricEntrySchema)
|
|
44
|
+
.min(1)
|
|
45
|
+
.max(3)
|
|
46
|
+
.meta({ title: "Metrics" }),
|
|
38
47
|
})
|
|
39
48
|
.strict()
|
|
49
|
+
.meta({ title: "Bar gauges" })
|
|
40
50
|
|
|
41
51
|
export const KpiPageSchema = z
|
|
42
52
|
.object({
|
|
43
53
|
type: z.literal("kpis"),
|
|
44
|
-
metrics: z
|
|
54
|
+
metrics: z
|
|
55
|
+
.array(MetricEntrySchema)
|
|
56
|
+
.min(1)
|
|
57
|
+
.max(3)
|
|
58
|
+
.meta({ title: "Metrics" }),
|
|
45
59
|
})
|
|
46
60
|
.strict()
|
|
61
|
+
.meta({ title: "Key metrics" })
|
|
47
62
|
|
|
48
63
|
export const ChartPageSchema = z
|
|
49
64
|
.object({
|
|
50
65
|
type: z.literal("chart"),
|
|
51
|
-
metrics: z
|
|
52
|
-
|
|
66
|
+
metrics: z
|
|
67
|
+
.array(MetricEntrySchema)
|
|
68
|
+
.min(1)
|
|
69
|
+
.max(2)
|
|
70
|
+
.meta({ title: "Metrics" }),
|
|
71
|
+
windowSeconds: z
|
|
72
|
+
.number()
|
|
73
|
+
.int()
|
|
74
|
+
.positive()
|
|
75
|
+
.max(60)
|
|
76
|
+
.default(60)
|
|
77
|
+
.meta({ title: "History window (seconds)" }),
|
|
53
78
|
})
|
|
54
79
|
.strict()
|
|
80
|
+
.meta({ title: "History chart" })
|
|
55
81
|
|
|
56
82
|
export const PageSchema = z.discriminatedUnion("type", [
|
|
57
83
|
BarPageSchema,
|
|
@@ -9,9 +9,56 @@ import {
|
|
|
9
9
|
import { CHART_HISTORY_CHANNEL } from "./domain"
|
|
10
10
|
import {
|
|
11
11
|
SYSTEM_METRIC_IDS,
|
|
12
|
+
METRICS_CATALOG,
|
|
12
13
|
type SystemMetricId,
|
|
14
|
+
type SystemMetricSnapshot,
|
|
13
15
|
} from "./shared/metrics-catalog"
|
|
14
16
|
|
|
17
|
+
const CAPTURE_METRIC_VALUES: Readonly<Record<SystemMetricId, number>> = {
|
|
18
|
+
battery: 86,
|
|
19
|
+
cpu: 42,
|
|
20
|
+
"cpu-boost": 1,
|
|
21
|
+
"cpu-voltages": 1_180,
|
|
22
|
+
disk: 54,
|
|
23
|
+
"disk-io": 1_240_000,
|
|
24
|
+
"fan-rpm": 1_260,
|
|
25
|
+
frequency: 3_400,
|
|
26
|
+
"gpu-temp": 58,
|
|
27
|
+
"gpu-usage": 27,
|
|
28
|
+
load: 1.4,
|
|
29
|
+
network: 64,
|
|
30
|
+
"network-read": 840_000,
|
|
31
|
+
"network-write": 126_000,
|
|
32
|
+
processes: 184,
|
|
33
|
+
ram: 68,
|
|
34
|
+
swap: 24,
|
|
35
|
+
temperature: 54,
|
|
36
|
+
uptime: 92_400,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const captureMetric = (id: SystemMetricId): SystemMetricSnapshot => {
|
|
40
|
+
const definition = METRICS_CATALOG[id]
|
|
41
|
+
const value = CAPTURE_METRIC_VALUES[id]
|
|
42
|
+
const max = definition.maxValue
|
|
43
|
+
return {
|
|
44
|
+
id,
|
|
45
|
+
label: definition.defaultLabel,
|
|
46
|
+
available: true,
|
|
47
|
+
value,
|
|
48
|
+
...(definition.unit !== undefined ? { unit: definition.unit } : {}),
|
|
49
|
+
...(max !== undefined
|
|
50
|
+
? {
|
|
51
|
+
max,
|
|
52
|
+
percentage:
|
|
53
|
+
definition.formatter === "percent" ||
|
|
54
|
+
definition.formatter === "bool"
|
|
55
|
+
? value
|
|
56
|
+
: (value / max) * 100,
|
|
57
|
+
}
|
|
58
|
+
: {}),
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
15
62
|
// ponytail: pollers are server-only; lazy-import live-metrics so the manifest
|
|
16
63
|
// can be loaded by the frontend addon virtual module without dragging
|
|
17
64
|
// node:os / node:fs into the browser bundle.
|
|
@@ -25,6 +72,8 @@ function makePoller(metricId: SystemMetricId): AddonGlobalPoller {
|
|
|
25
72
|
// metric would race on one channel); not worth the refactor today.
|
|
26
73
|
intervalMs: POLL_INTERVAL_MS,
|
|
27
74
|
poll: async () => {
|
|
75
|
+
if (process.env["SIRENO_CAPTURE_FAKE_METRICS"] === "1")
|
|
76
|
+
return captureMetric(metricId)
|
|
28
77
|
const { probeMetric } = await import("./domain/live-metrics")
|
|
29
78
|
const result = await probeMetric(metricId)
|
|
30
79
|
if (result.value !== undefined && result.available) {
|
|
@@ -5,30 +5,44 @@ export const VALUE_DISPLAY_DEFAULT_TIMEOUT_MS = 5000
|
|
|
5
5
|
|
|
6
6
|
const ValueEntrySchema = z
|
|
7
7
|
.object({
|
|
8
|
-
label: z.string().min(1),
|
|
9
|
-
command: z
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
label: z.string().min(1).meta({ title: "Value label" }),
|
|
9
|
+
command: z
|
|
10
|
+
.string()
|
|
11
|
+
.min(1)
|
|
12
|
+
.meta({ title: "Shell command", "x-control": "shell" }),
|
|
13
|
+
formatter: z
|
|
14
|
+
.enum(["raw", "strip", "line"])
|
|
15
|
+
.optional()
|
|
16
|
+
.default("raw")
|
|
17
|
+
.meta({ title: "Output format" }),
|
|
18
|
+
units: z.string().optional().meta({ title: "Units" }),
|
|
19
|
+
timeout_ms: z
|
|
20
|
+
.number()
|
|
21
|
+
.int()
|
|
22
|
+
.positive()
|
|
23
|
+
.optional()
|
|
24
|
+
.meta({ title: "Timeout (ms)" }),
|
|
25
|
+
icon: z.string().optional().meta({ title: "Icon", "x-control": "icon" }),
|
|
14
26
|
})
|
|
15
27
|
.strict()
|
|
16
28
|
|
|
17
29
|
const ValueDisplayButtonSchema = z
|
|
18
30
|
.object({
|
|
19
|
-
values: z.array(ValueEntrySchema).min(1).max(4),
|
|
31
|
+
values: z.array(ValueEntrySchema).min(1).max(4).meta({ title: "Values" }),
|
|
20
32
|
poll_interval_ms: z
|
|
21
33
|
.number()
|
|
22
34
|
.int()
|
|
23
35
|
.positive()
|
|
24
36
|
.optional()
|
|
25
|
-
.default(VALUE_DISPLAY_DEFAULT_POLL_MS)
|
|
37
|
+
.default(VALUE_DISPLAY_DEFAULT_POLL_MS)
|
|
38
|
+
.meta({ title: "Refresh interval (ms)" }),
|
|
26
39
|
timeout_ms: z
|
|
27
40
|
.number()
|
|
28
41
|
.int()
|
|
29
42
|
.positive()
|
|
30
43
|
.optional()
|
|
31
|
-
.default(VALUE_DISPLAY_DEFAULT_TIMEOUT_MS)
|
|
44
|
+
.default(VALUE_DISPLAY_DEFAULT_TIMEOUT_MS)
|
|
45
|
+
.meta({ title: "Command timeout (ms)" }),
|
|
32
46
|
})
|
|
33
47
|
.strict()
|
|
34
48
|
|
|
@@ -4,22 +4,27 @@ export const WEATHER_DEFAULT_POLL_MS = 600_000
|
|
|
4
4
|
|
|
5
5
|
const WeatherLocationSchema = z
|
|
6
6
|
.object({
|
|
7
|
-
latitude: z.number().min(-90).max(90),
|
|
8
|
-
longitude: z.number().min(-180).max(180),
|
|
9
|
-
name: z.string().min(1).optional(),
|
|
7
|
+
latitude: z.number().min(-90).max(90).meta({ title: "Latitude" }),
|
|
8
|
+
longitude: z.number().min(-180).max(180).meta({ title: "Longitude" }),
|
|
9
|
+
name: z.string().min(1).optional().meta({ title: "Location name" }),
|
|
10
10
|
})
|
|
11
11
|
.strict()
|
|
12
12
|
|
|
13
13
|
const WeatherButtonSchema = z
|
|
14
14
|
.object({
|
|
15
|
-
location: WeatherLocationSchema.optional(),
|
|
15
|
+
location: WeatherLocationSchema.optional().meta({ title: "Location" }),
|
|
16
16
|
poll_interval_ms: z
|
|
17
17
|
.number()
|
|
18
18
|
.int()
|
|
19
19
|
.positive()
|
|
20
20
|
.optional()
|
|
21
|
-
.default(WEATHER_DEFAULT_POLL_MS)
|
|
22
|
-
|
|
21
|
+
.default(WEATHER_DEFAULT_POLL_MS)
|
|
22
|
+
.meta({ title: "Refresh interval (ms)" }),
|
|
23
|
+
units: z
|
|
24
|
+
.enum(["metric", "imperial"])
|
|
25
|
+
.optional()
|
|
26
|
+
.default("metric")
|
|
27
|
+
.meta({ title: "Units" }),
|
|
23
28
|
})
|
|
24
29
|
.strict()
|
|
25
30
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
unlinkSync,
|
|
8
8
|
writeFileSync,
|
|
9
9
|
} from "node:fs"
|
|
10
|
+
import { execFileSync } from "node:child_process"
|
|
10
11
|
import { homedir } from "node:os"
|
|
11
12
|
import { join } from "node:path"
|
|
12
13
|
|
|
@@ -24,6 +25,20 @@ import { applyEdits, modify, parse, type ParseError } from "jsonc-parser"
|
|
|
24
25
|
const PLUGIN_FILE = "sirenodeck-agent-state.js"
|
|
25
26
|
const PLUGIN_SPEC = `./plugins/${PLUGIN_FILE}`
|
|
26
27
|
const PLUGIN_MARKER = "SIRENODECK_INTEGRATION_ID=coding-agents-v2"
|
|
28
|
+
const PLUGIN_API_MARKER = "SIRENODECK_OPENCODE_PLUGIN_API="
|
|
29
|
+
|
|
30
|
+
export type OpenCodeMajorVersion = 1 | 2
|
|
31
|
+
|
|
32
|
+
export const parseOpenCodeMajorVersion = (
|
|
33
|
+
output: string,
|
|
34
|
+
): OpenCodeMajorVersion | null => {
|
|
35
|
+
const match = output.match(
|
|
36
|
+
/(?:^|\s|v)(\d+)\.\d+\.\d+(?:[-+][\w.-]+)?(?:\s|$)/i,
|
|
37
|
+
)
|
|
38
|
+
if (!match) return null
|
|
39
|
+
const major = Number(match[1])
|
|
40
|
+
return major === 1 || major === 2 ? major : null
|
|
41
|
+
}
|
|
27
42
|
|
|
28
43
|
const opencodeConfigDir = (): string =>
|
|
29
44
|
process.env["OPENCODE_CONFIG_DIR"] ??
|
|
@@ -47,14 +62,33 @@ export const isCodingAgentsConfigured = (configPath: string): boolean => {
|
|
|
47
62
|
}
|
|
48
63
|
}
|
|
49
64
|
|
|
50
|
-
export const isOpenCodePluginInstalled = (
|
|
65
|
+
export const isOpenCodePluginInstalled = (
|
|
66
|
+
majorVersion?: OpenCodeMajorVersion,
|
|
67
|
+
): boolean => {
|
|
51
68
|
try {
|
|
52
|
-
|
|
69
|
+
const source = readFileSync(opencodePluginPath(), "utf8")
|
|
70
|
+
return (
|
|
71
|
+
source.includes(PLUGIN_MARKER) &&
|
|
72
|
+
(majorVersion === undefined ||
|
|
73
|
+
source.includes(`${PLUGIN_API_MARKER}${majorVersion}`))
|
|
74
|
+
)
|
|
53
75
|
} catch {
|
|
54
76
|
return false
|
|
55
77
|
}
|
|
56
78
|
}
|
|
57
79
|
|
|
80
|
+
export const detectOpenCodeMajorVersion = (): OpenCodeMajorVersion | null => {
|
|
81
|
+
try {
|
|
82
|
+
const output = execFileSync("opencode", ["--version"], {
|
|
83
|
+
encoding: "utf8",
|
|
84
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
85
|
+
})
|
|
86
|
+
return parseOpenCodeMajorVersion(output)
|
|
87
|
+
} catch {
|
|
88
|
+
return null
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
58
92
|
const readOpenCodeConfig = (): {
|
|
59
93
|
config: Record<string, unknown>
|
|
60
94
|
text: string
|
|
@@ -77,40 +111,68 @@ const readOpenCodeConfig = (): {
|
|
|
77
111
|
const pluginSpec = (entry: unknown): unknown =>
|
|
78
112
|
Array.isArray(entry) ? entry[0] : entry
|
|
79
113
|
|
|
80
|
-
export const isOpenCodePluginEnabled = (
|
|
114
|
+
export const isOpenCodePluginEnabled = (
|
|
115
|
+
majorVersion?: OpenCodeMajorVersion,
|
|
116
|
+
): boolean => {
|
|
81
117
|
const config = readOpenCodeConfig()
|
|
82
|
-
const plugins =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
118
|
+
const plugins =
|
|
119
|
+
majorVersion === undefined
|
|
120
|
+
? [config?.config["plugin"], config?.config["plugins"]]
|
|
121
|
+
: [config?.config[majorVersion === 1 ? "plugin" : "plugins"]]
|
|
122
|
+
return plugins.some(
|
|
123
|
+
(entries) =>
|
|
124
|
+
Array.isArray(entries) &&
|
|
125
|
+
entries.some((entry) => pluginSpec(entry) === PLUGIN_SPEC),
|
|
86
126
|
)
|
|
87
127
|
}
|
|
88
128
|
|
|
89
|
-
export const enableOpenCodePlugin = (
|
|
129
|
+
export const enableOpenCodePlugin = (
|
|
130
|
+
majorVersion: OpenCodeMajorVersion,
|
|
131
|
+
): boolean => {
|
|
90
132
|
const config = readOpenCodeConfig()
|
|
91
133
|
if (config === null) return false
|
|
92
|
-
const
|
|
93
|
-
|
|
134
|
+
const key = majorVersion === 1 ? "plugin" : "plugins"
|
|
135
|
+
const otherKey = majorVersion === 1 ? "plugins" : "plugin"
|
|
136
|
+
const plugins = Array.isArray(config.config[key]) ? config.config[key] : []
|
|
137
|
+
const otherPlugins = Array.isArray(config.config[otherKey])
|
|
138
|
+
? config.config[otherKey]
|
|
94
139
|
: []
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
140
|
+
const hasPlugin = (entries: unknown[]): boolean =>
|
|
141
|
+
entries.some((entry) => pluginSpec(entry) === PLUGIN_SPEC)
|
|
142
|
+
const updatedKeyPlugins = hasPlugin(plugins)
|
|
143
|
+
? plugins
|
|
144
|
+
: [...plugins, PLUGIN_SPEC]
|
|
145
|
+
const updatedOtherPlugins = hasPlugin(otherPlugins)
|
|
146
|
+
? otherPlugins.filter((entry) => pluginSpec(entry) !== PLUGIN_SPEC)
|
|
147
|
+
: otherPlugins
|
|
148
|
+
|
|
149
|
+
let updated = config.text
|
|
150
|
+
if (!hasPlugin(plugins)) {
|
|
151
|
+
updated = applyEdits(
|
|
152
|
+
updated,
|
|
153
|
+
modify(updated, [key], updatedKeyPlugins, {
|
|
154
|
+
formattingOptions: { insertSpaces: true, tabSize: 2 },
|
|
155
|
+
}),
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
if (updatedOtherPlugins !== otherPlugins) {
|
|
159
|
+
updated = applyEdits(
|
|
160
|
+
updated,
|
|
161
|
+
modify(updated, [otherKey], updatedOtherPlugins, {
|
|
100
162
|
formattingOptions: { insertSpaces: true, tabSize: 2 },
|
|
101
163
|
}),
|
|
102
164
|
)
|
|
165
|
+
}
|
|
166
|
+
if (updated !== config.text) {
|
|
103
167
|
const path = opencodeConfigPath()
|
|
104
168
|
mkdirSync(opencodeConfigDir(), { recursive: true, mode: 0o700 })
|
|
105
|
-
writeFileSync(path, updated, {
|
|
106
|
-
encoding: "utf8",
|
|
107
|
-
mode: 0o600,
|
|
108
|
-
})
|
|
169
|
+
writeFileSync(path, updated, { encoding: "utf8", mode: 0o600 })
|
|
109
170
|
}
|
|
110
171
|
return true
|
|
111
172
|
}
|
|
112
173
|
|
|
113
|
-
export const
|
|
174
|
+
export const codingAgentsPluginSourceV1 = `// ${PLUGIN_MARKER}
|
|
175
|
+
// ${PLUGIN_API_MARKER}1
|
|
114
176
|
// Managed by Sireno Deck. Re-running setup replaces this file.
|
|
115
177
|
import { mkdirSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
116
178
|
import { homedir } from "node:os";
|
|
@@ -151,13 +213,82 @@ const heartbeat = setInterval(() => write(currentState, currentSessionID), 5000)
|
|
|
151
213
|
process.once("exit", () => clearInterval(heartbeat));
|
|
152
214
|
`
|
|
153
215
|
|
|
154
|
-
export const
|
|
216
|
+
export const codingAgentsPluginSourceV2 = `// ${PLUGIN_MARKER}
|
|
217
|
+
// ${PLUGIN_API_MARKER}2
|
|
218
|
+
// Managed by Sireno Deck. Re-running setup replaces this file.
|
|
219
|
+
import { Plugin } from "@opencode/plugin";
|
|
220
|
+
import { mkdirSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
221
|
+
import { homedir } from "node:os";
|
|
222
|
+
import { join } from "node:path";
|
|
223
|
+
|
|
224
|
+
const dir = join(process.env.XDG_STATE_HOME || join(homedir(), ".local", "state"), "sirenodeck", "coding-agents");
|
|
225
|
+
const file = join(dir, "opencode-" + process.pid + ".json");
|
|
226
|
+
|
|
227
|
+
export default Plugin.define({
|
|
228
|
+
id: "sirenodeck.agent-state",
|
|
229
|
+
setup(ctx) {
|
|
230
|
+
let currentState = "idle";
|
|
231
|
+
let currentSessionID;
|
|
232
|
+
const write = (state, sessionID) => {
|
|
233
|
+
currentState = state;
|
|
234
|
+
if (sessionID) currentSessionID = sessionID;
|
|
235
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
236
|
+
const tmp = file + ".tmp";
|
|
237
|
+
writeFileSync(tmp, JSON.stringify({ pid: process.pid, cwd: ctx.location.directory, state: currentState, sessionID: currentSessionID, updatedAt: Date.now() }), { mode: 0o600 });
|
|
238
|
+
renameSync(tmp, file);
|
|
239
|
+
};
|
|
240
|
+
const stateFromEvent = (event) => {
|
|
241
|
+
const properties = event?.properties || {};
|
|
242
|
+
const sessionID = properties.sessionID;
|
|
243
|
+
switch (event?.type) {
|
|
244
|
+
case "session.status":
|
|
245
|
+
write(properties.status?.type === "idle" ? "idle" : properties.status?.type === "retry" ? "waiting" : "running", sessionID);
|
|
246
|
+
break;
|
|
247
|
+
case "session.idle": write("idle", sessionID); break;
|
|
248
|
+
case "permission.asked":
|
|
249
|
+
case "question.asked": write("waiting_for_human", sessionID); break;
|
|
250
|
+
case "session.error": write("error", sessionID); break;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
write("idle");
|
|
255
|
+
const controller = new AbortController();
|
|
256
|
+
void (async () => {
|
|
257
|
+
try {
|
|
258
|
+
for await (const event of ctx.event.subscribe({ signal: controller.signal })) {
|
|
259
|
+
stateFromEvent(event);
|
|
260
|
+
}
|
|
261
|
+
} catch (error) {
|
|
262
|
+
if (!controller.signal.aborted) console.error("[sirenodeck] OpenCode event stream stopped", error);
|
|
263
|
+
}
|
|
264
|
+
})();
|
|
265
|
+
const heartbeat = setInterval(() => write(currentState, currentSessionID), 5000);
|
|
266
|
+
|
|
267
|
+
return () => {
|
|
268
|
+
controller.abort();
|
|
269
|
+
clearInterval(heartbeat);
|
|
270
|
+
try { unlinkSync(file); } catch {}
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
`
|
|
275
|
+
|
|
276
|
+
// Keep the original named export available to callers that used it directly.
|
|
277
|
+
export const codingAgentsPluginSource = codingAgentsPluginSourceV1
|
|
278
|
+
|
|
279
|
+
export const installOpenCodePlugin = (
|
|
280
|
+
majorVersion = detectOpenCodeMajorVersion(),
|
|
281
|
+
): string | null => {
|
|
282
|
+
if (majorVersion === null) return null
|
|
155
283
|
const path = opencodePluginPath()
|
|
156
284
|
mkdirSync(pluginDir(), { recursive: true, mode: 0o700 })
|
|
157
|
-
writeFileSync(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
285
|
+
writeFileSync(
|
|
286
|
+
path,
|
|
287
|
+
majorVersion === 1
|
|
288
|
+
? codingAgentsPluginSourceV1
|
|
289
|
+
: codingAgentsPluginSourceV2,
|
|
290
|
+
{ encoding: "utf8", mode: 0o600 },
|
|
291
|
+
)
|
|
161
292
|
return path
|
|
162
293
|
}
|
|
163
294
|
|
|
@@ -378,10 +509,14 @@ export const onboardCodingAgents = async (
|
|
|
378
509
|
options: { readonly nonInteractive?: boolean; readonly yes?: boolean } = {},
|
|
379
510
|
): Promise<boolean> => {
|
|
380
511
|
if (!isCodingAgentsConfigured(configPath)) return false
|
|
512
|
+
const openCodeMajorVersion = detectOpenCodeMajorVersion()
|
|
381
513
|
// ponytail: this used to bail as soon as OpenCode was set up, which meant a
|
|
382
514
|
// user who had already onboarded OpenCode was never offered the Claude Code
|
|
383
515
|
// hooks at all. The two harnesses are independent; each decides for itself.
|
|
384
|
-
const openCodeDone =
|
|
516
|
+
const openCodeDone =
|
|
517
|
+
openCodeMajorVersion !== null &&
|
|
518
|
+
isOpenCodePluginInstalled(openCodeMajorVersion) &&
|
|
519
|
+
isOpenCodePluginEnabled(openCodeMajorVersion)
|
|
385
520
|
const claudeDone = isClaudeHookInstalled() && isClaudeHookEnabled()
|
|
386
521
|
if (openCodeDone && claudeDone) return false
|
|
387
522
|
// ponytail: with no TTY nobody can answer — @clack's confirm() renders the
|
|
@@ -410,18 +545,30 @@ export const onboardCodingAgents = async (
|
|
|
410
545
|
initialValue: true,
|
|
411
546
|
})
|
|
412
547
|
if (!isCancel(answer) && answer) {
|
|
413
|
-
|
|
414
|
-
if (enableOpenCodePlugin()) {
|
|
548
|
+
if (openCodeMajorVersion === null) {
|
|
415
549
|
note(
|
|
416
|
-
`
|
|
550
|
+
"Could not detect a supported OpenCode version. Make sure `opencode --version` works, then run setup again. No plugin files were changed.",
|
|
417
551
|
"OpenCode integration",
|
|
418
552
|
)
|
|
419
|
-
changed = true
|
|
420
553
|
} else {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
554
|
+
const installedPath = installOpenCodePlugin(openCodeMajorVersion)
|
|
555
|
+
if (
|
|
556
|
+
installedPath !== null &&
|
|
557
|
+
enableOpenCodePlugin(openCodeMajorVersion)
|
|
558
|
+
) {
|
|
559
|
+
note(
|
|
560
|
+
`Installed the OpenCode ${openCodeMajorVersion} plugin at ${installedPath} and enabled it. Restart OpenCode to activate it.`,
|
|
561
|
+
"OpenCode integration",
|
|
562
|
+
)
|
|
563
|
+
changed = true
|
|
564
|
+
} else {
|
|
565
|
+
note(
|
|
566
|
+
installedPath === null
|
|
567
|
+
? "Could not detect a supported OpenCode version. No plugin files were changed."
|
|
568
|
+
: "Could not update OpenCode's opencode.json because it is invalid JSON.",
|
|
569
|
+
"OpenCode integration",
|
|
570
|
+
)
|
|
571
|
+
}
|
|
425
572
|
}
|
|
426
573
|
}
|
|
427
574
|
}
|