@sirenodeck/sirenodeck 0.2.10 → 0.4.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/dist/main.mjs +1089 -626
- package/dist/{windows-CRWdUgCn.mjs → windows-BCvfQ3PA.mjs} +4 -4
- package/frontend/src/App.tsx +3 -0
- package/frontend/src/components/Deck.tsx +13 -2
- package/package.json +10 -1
- package/src/addon/api.ts +24 -1
- package/src/addon/data-directory.ts +52 -0
- package/src/api/protocol-internal.ts +1 -0
- package/src/builtin-addons/index.ts +0 -1
- package/src/builtin-addons/internal-settings/backend.ts +1 -1
- package/src/builtin-addons/internal-settings/buttons/brightness/common/frontend.tsx +14 -3
- package/src/builtin-addons/internal-settings/buttons/brightness-compact/frontend.tsx +6 -0
- package/src/builtin-addons/internal-settings/index.ts +15 -0
- package/src/builtin-addons/register-builtins.ts +0 -3
- package/src/cli/commands/addon-decks.ts +1 -0
- package/src/cli/commands/addon-setup-config.ts +85 -0
- package/src/cli/commands/addon-setup.ts +134 -0
- package/src/cli/commands/run.ts +53 -11
- package/src/cli/commands/service-manager.ts +3 -5
- package/src/cli/commands/start.ts +14 -81
- package/src/cli/commands/stop.ts +4 -0
- package/src/cli/index.ts +2 -0
- package/src/config/environment.ts +44 -0
- package/src/config/loader.ts +17 -1
- package/src/config/schemas.ts +2 -1
- package/src/config/validation.ts +5 -1
- package/src/deck/addon-handler-bridge.ts +105 -6
- package/src/deck/addon-settings.ts +94 -0
- package/src/deck/deck-config.ts +1 -0
- package/src/deck/inject-config-ui-button.ts +25 -14
- package/src/deck/runtime/runtime.ts +175 -3
- package/src/deck/system-back-injection.ts +2 -0
- package/src/deck/system-buttons/registry.tsx +1 -0
- package/src/deck/system-buttons/types.ts +1 -0
- package/src/system/credentials/native.ts +74 -0
- package/src/system/credentials/store.ts +77 -0
- package/src/system/providers/notification/windows.ts +4 -4
- package/src/themes/default/sirenodeck.json +1 -0
- package/src/themes/light/sirenodeck.json +1 -0
- package/src/themes/manifest.ts +1 -0
- package/src/ui/primitives/Chip.tsx +1 -0
- package/src/ui/primitives/StatusIndicator.tsx +36 -0
- package/src/ui/primitives/index.ts +1 -0
- package/src/ui/surfaces/BinaryToggleSurface.tsx +52 -0
- package/src/ui/surfaces/LoadingSurface.tsx +34 -0
- package/src/ui/surfaces/index.ts +2 -0
- package/src/builtin-addons/brightness/README.md +0 -51
- package/src/builtin-addons/brightness/buttons/brightness/backend.ts +0 -13
- package/src/builtin-addons/brightness/buttons/brightness/config.ts +0 -20
- package/src/builtin-addons/brightness/buttons/brightness/frontend.tsx +0 -50
- package/src/builtin-addons/brightness/domain/macos.ts +0 -46
- package/src/builtin-addons/brightness/index.d.ts +0 -5
- package/src/builtin-addons/brightness/index.ts +0 -20
- package/src/builtin-addons/brightness/poller.ts +0 -27
- package/src/builtin-addons/brightness/sirenodeck.json +0 -6
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/darwin.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/index.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/linux.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/windows.ts +0 -0
package/src/cli/commands/run.ts
CHANGED
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
} from "@/deck"
|
|
47
47
|
import { paginateDeck } from "@/deck/paginate-deck"
|
|
48
48
|
import { injectConfigUiButton } from "@/deck/inject-config-ui-button"
|
|
49
|
-
import {
|
|
49
|
+
import { buildAddonSettingsDecks } from "@/deck/addon-settings"
|
|
50
50
|
import { positionButtons } from "@/deck/position-buttons"
|
|
51
51
|
import { subscribeNavigateDeck } from "@/deck/runtime-subscriptions"
|
|
52
52
|
import {
|
|
@@ -207,6 +207,7 @@ export interface SetupAddonServicesOptions {
|
|
|
207
207
|
readonly resolverOptions: ReturnType<typeof buildResolverOptions>
|
|
208
208
|
/** Optional host callback that re-materializes addon decks (dynamic decks). */
|
|
209
209
|
readonly requestDeckRebuild?: () => void
|
|
210
|
+
readonly addonServiceConfigs?: ReadonlyMap<string, unknown>
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
export interface SetupAddonServicesResult {
|
|
@@ -245,6 +246,7 @@ export const setupAddonServices = (
|
|
|
245
246
|
methods,
|
|
246
247
|
logger,
|
|
247
248
|
requestDeckRebuild,
|
|
249
|
+
addonServiceConfigs,
|
|
248
250
|
} = options
|
|
249
251
|
|
|
250
252
|
const addonBridge = bridgeAddonServices({
|
|
@@ -260,6 +262,7 @@ export const setupAddonServices = (
|
|
|
260
262
|
bridge,
|
|
261
263
|
store,
|
|
262
264
|
methods,
|
|
265
|
+
...(addonServiceConfigs !== undefined ? { addonServiceConfigs } : {}),
|
|
263
266
|
...(requestDeckRebuild !== undefined ? { requestDeckRebuild } : {}),
|
|
264
267
|
})
|
|
265
268
|
|
|
@@ -699,6 +702,7 @@ export const buildAddonConfigOverrides = (
|
|
|
699
702
|
const {
|
|
700
703
|
decks: perDeckRaw,
|
|
701
704
|
defaults,
|
|
705
|
+
service: _service,
|
|
702
706
|
...rest
|
|
703
707
|
} = cfg as {
|
|
704
708
|
decks?: Record<
|
|
@@ -706,6 +710,7 @@ export const buildAddonConfigOverrides = (
|
|
|
706
710
|
import("@/cli/commands/addon-decks").AddonDeckOverride
|
|
707
711
|
>
|
|
708
712
|
defaults?: { autoShow?: boolean }
|
|
713
|
+
service?: unknown
|
|
709
714
|
} & Record<string, unknown>
|
|
710
715
|
// ponytail: key on the loaded addon's manifest name — that's what
|
|
711
716
|
// materializeAddonDecks looks up. The user wrote `src:` (path or npm
|
|
@@ -728,6 +733,21 @@ export const buildAddonConfigOverrides = (
|
|
|
728
733
|
return overrides
|
|
729
734
|
}
|
|
730
735
|
|
|
736
|
+
export const buildAddonServiceConfigs = (
|
|
737
|
+
addonEntries: ReadonlyArray<import("@/config/schemas").RawAddonEntry>,
|
|
738
|
+
addonSpecToName: ReadonlyMap<string, string>,
|
|
739
|
+
): Map<string, unknown> => {
|
|
740
|
+
const configs = new Map<string, unknown>()
|
|
741
|
+
for (const entry of addonEntries) {
|
|
742
|
+
if (typeof entry === "string" || entry.enabled === false) continue
|
|
743
|
+
const name = addonSpecToName.get(entry.src)
|
|
744
|
+
if (name !== undefined && entry.config?.service !== undefined) {
|
|
745
|
+
configs.set(name, entry.config.service)
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
return configs
|
|
749
|
+
}
|
|
750
|
+
|
|
731
751
|
const buildRuntime = (
|
|
732
752
|
options: RunOptions,
|
|
733
753
|
loaded: LoadConfigResult,
|
|
@@ -897,7 +917,11 @@ const buildRuntime = (
|
|
|
897
917
|
config.lock?.buttons,
|
|
898
918
|
addonConfigOverrides,
|
|
899
919
|
)
|
|
900
|
-
const sourceDecks =
|
|
920
|
+
const sourceDecks = buildAddonSettingsDecks(
|
|
921
|
+
materializedDecks,
|
|
922
|
+
registry.listAddons(),
|
|
923
|
+
keyCount,
|
|
924
|
+
)
|
|
901
925
|
const allDecsWithSystemButtons = injectSystemButtons(sourceDecks, keyCount, {
|
|
902
926
|
lockActive,
|
|
903
927
|
})
|
|
@@ -913,7 +937,11 @@ const buildRuntime = (
|
|
|
913
937
|
)
|
|
914
938
|
if (token.length > 0) configUiUrl.searchParams.set("token", token)
|
|
915
939
|
configUiUrl.hash = "/config"
|
|
916
|
-
const runtimeDecks = injectConfigUiButton(
|
|
940
|
+
const runtimeDecks = injectConfigUiButton(
|
|
941
|
+
allDecks,
|
|
942
|
+
configUiUrl.toString(),
|
|
943
|
+
keyCount,
|
|
944
|
+
)
|
|
917
945
|
const { runtime, methods, pubSub, store } = createDeckRuntime({
|
|
918
946
|
decks: runtimeDecks,
|
|
919
947
|
logger,
|
|
@@ -990,6 +1018,8 @@ export const applyConfigErrorReplacements = (
|
|
|
990
1018
|
path,
|
|
991
1019
|
deck.id,
|
|
992
1020
|
position,
|
|
1021
|
+
deck.addonOwner !== undefined &&
|
|
1022
|
+
btn.type.startsWith(`${deck.addonOwner.addonName}:`),
|
|
993
1023
|
)
|
|
994
1024
|
if (issues.length === 0) continue
|
|
995
1025
|
|
|
@@ -1159,12 +1189,16 @@ interface AddonRegistryBundle {
|
|
|
1159
1189
|
// full core kit (any @sirenodeck/sirenodeck/ui component). Falls back to the
|
|
1160
1190
|
// dist entry when src/index.ts doesn't exist (npm-cached third-party
|
|
1161
1191
|
// addons ship compiled output only).
|
|
1162
|
-
const browserFrontendMain = (entry: string): string => {
|
|
1192
|
+
const browserFrontendMain = (entry: string, dedicated = false): string => {
|
|
1163
1193
|
const dir = dirname(entry)
|
|
1164
1194
|
// Entry lives in <pkg>/dist (JSON-manifest addons, compiled) or directly
|
|
1165
1195
|
// in <pkg> (regex-scanned builtins' index.ts). Normalize to pkg root.
|
|
1166
1196
|
const pkgRoot = basename(dir) === "dist" ? dirname(dir) : dir
|
|
1167
|
-
const src = resolvePath(
|
|
1197
|
+
const src = resolvePath(
|
|
1198
|
+
pkgRoot,
|
|
1199
|
+
"src",
|
|
1200
|
+
dedicated ? "frontend-entry.ts" : "index.ts",
|
|
1201
|
+
)
|
|
1168
1202
|
return existsSync(src) ? src : entry
|
|
1169
1203
|
}
|
|
1170
1204
|
|
|
@@ -1172,7 +1206,12 @@ export const addonSpecFromScanned = (s: ScannedAddon) => ({
|
|
|
1172
1206
|
name: s.name,
|
|
1173
1207
|
frontend:
|
|
1174
1208
|
s.browserEntry != null
|
|
1175
|
-
? {
|
|
1209
|
+
? {
|
|
1210
|
+
main: browserFrontendMain(
|
|
1211
|
+
s.browserEntry,
|
|
1212
|
+
s.browserEntry !== s.frontendEntry,
|
|
1213
|
+
),
|
|
1214
|
+
}
|
|
1176
1215
|
: s.frontendEntry !== null
|
|
1177
1216
|
? { main: browserFrontendMain(s.frontendEntry) }
|
|
1178
1217
|
: undefined,
|
|
@@ -1615,10 +1654,10 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1615
1654
|
// session provider existed; if the OS is locked at boot, re-inject
|
|
1616
1655
|
// without the n-1 so the deck structure is honest. Re-inject on every
|
|
1617
1656
|
// subsequent lock transition so the source stays correct.
|
|
1657
|
+
let currentLoadedConfig = loadedConfig
|
|
1618
1658
|
const reInjectedDecks = (isLocked: boolean): ReadonlyArray<RuntimeDeck> =>
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
})
|
|
1659
|
+
buildRuntime(options, currentLoadedConfig, descriptor!.keyCount, isLocked)
|
|
1660
|
+
.decks
|
|
1622
1661
|
if (providers.session.getState() === "locked") {
|
|
1623
1662
|
const reInjected = reInjectedDecks(true)
|
|
1624
1663
|
runtime.setDecks(reInjected)
|
|
@@ -1718,7 +1757,6 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1718
1757
|
})
|
|
1719
1758
|
|
|
1720
1759
|
const serviceDecks: RuntimeDeck[] = [...decks]
|
|
1721
|
-
let currentLoadedConfig = loadedConfig
|
|
1722
1760
|
const nextMainDeckId = (
|
|
1723
1761
|
config: typeof currentLoadedConfig.config,
|
|
1724
1762
|
): string =>
|
|
@@ -1739,7 +1777,7 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1739
1777
|
}
|
|
1740
1778
|
const rebuilt = buildRuntime(
|
|
1741
1779
|
options,
|
|
1742
|
-
|
|
1780
|
+
currentLoadedConfig,
|
|
1743
1781
|
descriptor.keyCount,
|
|
1744
1782
|
providers.session.getState() === "locked",
|
|
1745
1783
|
).decks
|
|
@@ -1788,6 +1826,10 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1788
1826
|
keyCount: descriptor.keyCount,
|
|
1789
1827
|
resolverOptions,
|
|
1790
1828
|
requestDeckRebuild,
|
|
1829
|
+
addonServiceConfigs: buildAddonServiceConfigs(
|
|
1830
|
+
loadedConfig.config.addons ?? [],
|
|
1831
|
+
loadedConfig.addonSpecToName,
|
|
1832
|
+
),
|
|
1791
1833
|
...(mainDeck !== undefined ? { initialDeck: mainDeck } : {}),
|
|
1792
1834
|
signal: bridgeSignal.signal,
|
|
1793
1835
|
store,
|
|
@@ -37,10 +37,6 @@ export const refreshStaleUnit = (
|
|
|
37
37
|
!exists(currentScript)
|
|
38
38
|
)
|
|
39
39
|
return content
|
|
40
|
-
const brewUpgrade =
|
|
41
|
-
oldScript.includes("/Cellar/sirenodeck/") &&
|
|
42
|
-
currentScript.includes("/Cellar/sirenodeck/")
|
|
43
|
-
if (exists(oldScript) && !brewUpgrade) return content
|
|
44
40
|
return content.replace(
|
|
45
41
|
match[0],
|
|
46
42
|
`ExecStart="${nodePath}" "${currentScript}" start`,
|
|
@@ -210,7 +206,9 @@ export const invokeManager = async (
|
|
|
210
206
|
// still holding throws, so go through the retry.
|
|
211
207
|
await bootstrapWithRetry(uid, plist, DAEMON_NAME)
|
|
212
208
|
} else if (action === "stop") {
|
|
213
|
-
|
|
209
|
+
if (isJobLoaded(uid, DAEMON_NAME)) {
|
|
210
|
+
launchctl("bootout", [`gui/${uid}/${DAEMON_NAME}`])
|
|
211
|
+
}
|
|
214
212
|
} else if (action === "restart") {
|
|
215
213
|
try {
|
|
216
214
|
launchctl("bootout", [`gui/${uid}/${DAEMON_NAME}`])
|
|
@@ -3,7 +3,7 @@ import { execFileSync } from "node:child_process"
|
|
|
3
3
|
import { dirname, join, resolve as resolvePath } from "node:path"
|
|
4
4
|
import { fileURLToPath } from "node:url"
|
|
5
5
|
|
|
6
|
-
import { confirm
|
|
6
|
+
import { confirm } from "@/cli/prompt"
|
|
7
7
|
import type pino from "pino"
|
|
8
8
|
|
|
9
9
|
import {
|
|
@@ -409,34 +409,6 @@ const killPortListeners = async (
|
|
|
409
409
|
await new Promise((r) => setTimeout(r, 500))
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
-
const promptConflict = async (
|
|
413
|
-
pid: number | null,
|
|
414
|
-
): Promise<"restart" | "cancel"> => {
|
|
415
|
-
const who = pid === null ? "" : ` with pid ${pid}`
|
|
416
|
-
if (!process.stdin.isTTY) {
|
|
417
|
-
throw new Error(
|
|
418
|
-
`Daemon already running${who} (non-interactive: not stopping)`,
|
|
419
|
-
)
|
|
420
|
-
}
|
|
421
|
-
const answer = await select<"restart" | "cancel">({
|
|
422
|
-
message: `Daemon already running${who}.`,
|
|
423
|
-
options: [
|
|
424
|
-
{
|
|
425
|
-
value: "restart",
|
|
426
|
-
label: "restart",
|
|
427
|
-
hint: "Stop the existing daemon and start a new one",
|
|
428
|
-
},
|
|
429
|
-
{
|
|
430
|
-
value: "cancel",
|
|
431
|
-
label: "cancel",
|
|
432
|
-
hint: "Exit without changes",
|
|
433
|
-
},
|
|
434
|
-
],
|
|
435
|
-
})
|
|
436
|
-
if (isCancel(answer)) return "cancel"
|
|
437
|
-
return answer
|
|
438
|
-
}
|
|
439
|
-
|
|
440
412
|
const stopExisting = async (
|
|
441
413
|
pid: number,
|
|
442
414
|
logger: pino.Logger,
|
|
@@ -449,23 +421,20 @@ const stopExisting = async (
|
|
|
449
421
|
removeStartLock()
|
|
450
422
|
return
|
|
451
423
|
}
|
|
424
|
+
if (!isOurDaemon(pid))
|
|
425
|
+
throw new Error(`Refusing to stop unverified daemon PID ${pid}`)
|
|
452
426
|
logger.info({ pid }, "stopping existing daemon")
|
|
453
427
|
try {
|
|
454
428
|
process.kill(pid, "SIGTERM")
|
|
455
429
|
} catch (err) {
|
|
456
|
-
|
|
430
|
+
throw new Error(`Failed to stop existing daemon ${pid}`, { cause: err })
|
|
457
431
|
}
|
|
458
|
-
const deadline = Date.now() +
|
|
432
|
+
const deadline = Date.now() + 20_000
|
|
459
433
|
while (Date.now() < deadline && isRunning(pid)) {
|
|
460
434
|
await new Promise((r) => setTimeout(r, 100))
|
|
461
435
|
}
|
|
462
436
|
if (isRunning(pid)) {
|
|
463
|
-
|
|
464
|
-
try {
|
|
465
|
-
process.kill(pid, "SIGKILL")
|
|
466
|
-
} catch (err) {
|
|
467
|
-
logger.warn({ err, pid }, "failed to send SIGKILL to existing daemon")
|
|
468
|
-
}
|
|
437
|
+
throw new Error(`Existing daemon ${pid} did not exit after SIGTERM`)
|
|
469
438
|
}
|
|
470
439
|
await terminateChildren({ logger, timeoutMs: 2_000 })
|
|
471
440
|
removePidFile()
|
|
@@ -982,57 +951,21 @@ const start = async (options: StartOptions): Promise<StartLaunchResult> => {
|
|
|
982
951
|
// children as strangers. Asking first also means the answer can come from
|
|
983
952
|
// the instance lock, which is the one source that cannot be stale: a daemon
|
|
984
953
|
// holds it for exactly as long as it is alive.
|
|
954
|
+
if (isUnitInstalled()) await invokeManager({ action: "stop", logger })
|
|
985
955
|
const existing = readPid()
|
|
986
956
|
const lockHeld = await isSocketLive(instanceLockPath(resolveDaemonPaths()))
|
|
987
957
|
if (lockHeld || (existing !== null && isRunning(existing))) {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
return "cancelled"
|
|
992
|
-
}
|
|
993
|
-
// ponytail: a supervised daemon cannot be restarted by killing it. launchd
|
|
994
|
-
// with KeepAlive brings it back in about two seconds — measured — and the
|
|
995
|
-
// daemon we would spawn here loses the race for the instance lock and dies
|
|
996
|
-
// with "another sirenodeck daemon is already running". Before the lock
|
|
997
|
-
// existed the same race simply produced TWO daemons, which is how this
|
|
998
|
-
// machine ended up with one from 09:39 and another from 16:54 fighting
|
|
999
|
-
// over the same ports. The manager owns the process, so the manager is
|
|
1000
|
-
// what restarts it; the config and flags go through the state files, the
|
|
1001
|
-
// same way `startProduction` hands them over.
|
|
1002
|
-
if (isUnitInstalled()) {
|
|
1003
|
-
const resolvedRestart = resolveConfigPath(options)
|
|
1004
|
-
writeConfigPath(resolvedRestart.path)
|
|
1005
|
-
writeFlags(buildRuntimeFlags(options))
|
|
1006
|
-
logger.info(
|
|
1007
|
-
{ configPath: resolvedRestart.path },
|
|
1008
|
-
"start: daemon is service-managed — restarting through the service manager",
|
|
1009
|
-
)
|
|
1010
|
-
await invokeManager({ action: "restart", logger })
|
|
1011
|
-
const deadline = Date.now() + 10_000
|
|
1012
|
-
let restarted: number | null = null
|
|
1013
|
-
while (Date.now() < deadline) {
|
|
1014
|
-
await new Promise((r) => setTimeout(r, 200))
|
|
1015
|
-
const pid = readPid()
|
|
1016
|
-
if (pid !== null && pid !== existing && isRunning(pid)) {
|
|
1017
|
-
restarted = pid
|
|
1018
|
-
break
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
logger.info(
|
|
1022
|
-
{ pid: restarted },
|
|
1023
|
-
restarted === null
|
|
1024
|
-
? "start: service manager restarted the daemon (pid not yet visible)"
|
|
1025
|
-
: "start: daemon restarted by the service manager",
|
|
958
|
+
if (lockHeld && (existing === null || !isRunning(existing)))
|
|
959
|
+
throw new Error(
|
|
960
|
+
"A daemon holds the instance lock but has no live PID; refusing to stop an unidentified process",
|
|
1026
961
|
)
|
|
1027
|
-
return "started"
|
|
1028
|
-
}
|
|
1029
962
|
if (existing !== null) await stopExisting(existing, logger)
|
|
1030
963
|
else
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
logger.warn(
|
|
1034
|
-
"start: a daemon holds the instance lock but left no pid file — falling back to the port reap",
|
|
964
|
+
throw new Error(
|
|
965
|
+
"A daemon holds the instance lock but has no PID; refusing to stop an unidentified process",
|
|
1035
966
|
)
|
|
967
|
+
if (await isSocketLive(instanceLockPath(resolveDaemonPaths())))
|
|
968
|
+
throw new Error("The previous daemon still holds the instance lock")
|
|
1036
969
|
removePidFile()
|
|
1037
970
|
removeDaemonControl(resolveDaemonPaths())
|
|
1038
971
|
removeRuntimeStateFile()
|
package/src/cli/commands/stop.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
resolveDaemonPaths,
|
|
14
14
|
} from "@/util/daemon"
|
|
15
15
|
import { removeDaemonControl } from "@/util/daemon-control"
|
|
16
|
+
import { invokeManager, isUnitInstalled } from "./service-manager"
|
|
16
17
|
import {
|
|
17
18
|
readDaemonEventsFromSnapshot,
|
|
18
19
|
snapshotDaemonLog,
|
|
@@ -61,6 +62,9 @@ const killGracefully = async (
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
export const stop = async ({ logger }: StopOptions): Promise<void> => {
|
|
65
|
+
if (isUnitInstalled()) {
|
|
66
|
+
await invokeManager({ action: "stop", logger })
|
|
67
|
+
}
|
|
64
68
|
const pid = readPid()
|
|
65
69
|
if (pid === null) {
|
|
66
70
|
logger.info("stop: no running daemon found")
|
package/src/cli/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
} from "@/util/daemon"
|
|
37
37
|
import { cancel, intro, log } from "./prompt"
|
|
38
38
|
import { skillsCommand } from "./commands/skills"
|
|
39
|
+
import { addonSetupCommand } from "./commands/addon-setup"
|
|
39
40
|
|
|
40
41
|
export interface GlobalOptions {
|
|
41
42
|
verbose?: boolean
|
|
@@ -360,6 +361,7 @@ export const buildCli = async (): Promise<{
|
|
|
360
361
|
logsCommand as CommandModule<object, GlobalOptions>,
|
|
361
362
|
systemRequirementsCommand as CommandModule<object, GlobalOptions>,
|
|
362
363
|
installCommand as CommandModule<object, GlobalOptions>,
|
|
364
|
+
addonSetupCommand as CommandModule<object, GlobalOptions>,
|
|
363
365
|
skillsCommand as CommandModule<object, GlobalOptions>,
|
|
364
366
|
],
|
|
365
367
|
packageName: PACKAGE_NAME,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export class MissingEnvironmentVariableError extends Error {
|
|
2
|
+
constructor(
|
|
3
|
+
readonly variable: string,
|
|
4
|
+
readonly configPath: string,
|
|
5
|
+
) {
|
|
6
|
+
super(
|
|
7
|
+
`Environment variable ${variable} is not set (at ${configPath || "<root>"})`,
|
|
8
|
+
)
|
|
9
|
+
this.name = "MissingEnvironmentVariableError"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Resolve placeholders in values, never mapping keys or YAML source text. */
|
|
14
|
+
export const resolveEnvironmentVariables = (
|
|
15
|
+
value: unknown,
|
|
16
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
17
|
+
path = "",
|
|
18
|
+
): unknown => {
|
|
19
|
+
if (typeof value === "string") {
|
|
20
|
+
return value.replace(
|
|
21
|
+
/\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g,
|
|
22
|
+
(_match, name: string) => {
|
|
23
|
+
const resolved = Object.hasOwn(env, name) ? env[name] : undefined
|
|
24
|
+
if (resolved === undefined)
|
|
25
|
+
throw new MissingEnvironmentVariableError(name, path)
|
|
26
|
+
return resolved
|
|
27
|
+
},
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return value.map((item, index) =>
|
|
32
|
+
resolveEnvironmentVariables(item, env, `${path}[${index}]`),
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === "object" && value !== null) {
|
|
36
|
+
return Object.fromEntries(
|
|
37
|
+
Object.entries(value).map(([key, item]) => [
|
|
38
|
+
key,
|
|
39
|
+
resolveEnvironmentVariables(item, env, path ? `${path}.${key}` : key),
|
|
40
|
+
]),
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
return value
|
|
44
|
+
}
|
package/src/config/loader.ts
CHANGED
|
@@ -8,6 +8,10 @@ import { getOriginalCwd } from "@/cli/cwd"
|
|
|
8
8
|
import { IncludeResolutionError, resolveIncludes } from "./include-resolver"
|
|
9
9
|
import { RawConfigSchema, type RawConfig } from "./schemas"
|
|
10
10
|
import { expandButtonReferences } from "./reference-expander"
|
|
11
|
+
import {
|
|
12
|
+
MissingEnvironmentVariableError,
|
|
13
|
+
resolveEnvironmentVariables,
|
|
14
|
+
} from "./environment"
|
|
11
15
|
|
|
12
16
|
export interface LoadConfigOptions {
|
|
13
17
|
configPath: string
|
|
@@ -169,7 +173,19 @@ export const loadConfig = ({
|
|
|
169
173
|
}: LoadConfigOptions): LoadConfigResult => {
|
|
170
174
|
const configDir = dirname(configPath)
|
|
171
175
|
const raw = loadConfigFile(configPath)
|
|
172
|
-
|
|
176
|
+
let expanded: unknown
|
|
177
|
+
try {
|
|
178
|
+
expanded = resolveEnvironmentVariables(
|
|
179
|
+
expandButtonReferences(raw, configDir),
|
|
180
|
+
)
|
|
181
|
+
} catch (err) {
|
|
182
|
+
if (err instanceof MissingEnvironmentVariableError) {
|
|
183
|
+
throw new ConfigLoadError(err.message, [
|
|
184
|
+
{ message: err.message, path: err.configPath },
|
|
185
|
+
])
|
|
186
|
+
}
|
|
187
|
+
throw err
|
|
188
|
+
}
|
|
173
189
|
const result = RawConfigSchema.safeParse(expanded)
|
|
174
190
|
if (!result.success) {
|
|
175
191
|
// ponytail: recurse into unionErrors so the user sees the actual
|
package/src/config/schemas.ts
CHANGED
|
@@ -159,12 +159,13 @@ export const AddonDeckDefaultsSchema = z
|
|
|
159
159
|
* Phase 11: addon-config block under `addons[i]`. Hosts three shape variants:
|
|
160
160
|
* - `defaults:` addon-wide deck defaults (applied before per-deck overrides)
|
|
161
161
|
* - `decks:` record keyed by addon deck id, with per-deck overrides
|
|
162
|
-
* - addon-
|
|
162
|
+
* - `service:` addon-global backend settings (never merged into deck config)
|
|
163
163
|
*/
|
|
164
164
|
export const AddonConfigSchema = z
|
|
165
165
|
.object({
|
|
166
166
|
defaults: AddonDeckDefaultsSchema.optional(),
|
|
167
167
|
decks: z.record(z.string(), AddonDeckOverrideSchema).optional(),
|
|
168
|
+
service: z.record(z.string(), z.unknown()).optional(),
|
|
168
169
|
})
|
|
169
170
|
.strict()
|
|
170
171
|
|
package/src/config/validation.ts
CHANGED
|
@@ -99,6 +99,7 @@ export const validateButton = (
|
|
|
99
99
|
path: string,
|
|
100
100
|
deckId?: string,
|
|
101
101
|
position?: number,
|
|
102
|
+
allowInternal = false,
|
|
102
103
|
): ButtonValidationResult => {
|
|
103
104
|
const base = { deckId, position }
|
|
104
105
|
const issues: FullValidationIssue[] = []
|
|
@@ -119,7 +120,10 @@ export const validateButton = (
|
|
|
119
120
|
return { issues, schemaIssues: [] }
|
|
120
121
|
}
|
|
121
122
|
const def = registry.getButtonType(btn.type)!
|
|
122
|
-
if (
|
|
123
|
+
if (
|
|
124
|
+
isSystemButtonType(btn.type) ||
|
|
125
|
+
(!allowInternal && def.def.service.internal === true)
|
|
126
|
+
) {
|
|
123
127
|
issues.push({
|
|
124
128
|
level: "error",
|
|
125
129
|
path: `${path}.type`,
|