skillar 0.0.0-stage → 0.2.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/LICENSE +22 -0
- package/README.md +194 -2
- package/dist/analysis/finding.js +190 -0
- package/dist/analysis/tree.js +157 -0
- package/dist/analysis/usage.js +394 -0
- package/dist/api/flows.js +285 -0
- package/dist/api/routes.js +192 -0
- package/dist/api/security.js +86 -0
- package/dist/api/sse.js +55 -0
- package/dist/api/static.js +33 -0
- package/dist/catalog/fields.js +159 -0
- package/dist/catalog/index.js +133 -0
- package/dist/catalog/scanner.js +204 -0
- package/dist/catalog/uri.js +43 -0
- package/dist/catalog/watcher.js +59 -0
- package/dist/cli/config-writer.js +255 -0
- package/dist/cli/doctor.js +268 -0
- package/dist/cli/eval.js +64 -0
- package/dist/cli/export-import.js +68 -0
- package/dist/cli/init.js +272 -0
- package/dist/cli/main.js +165 -0
- package/dist/cli/open.js +24 -0
- package/dist/cli/serve.js +147 -0
- package/dist/config.js +92 -0
- package/dist/dashboard/assets/app.js +354 -0
- package/dist/dashboard/assets/chunk-5DFWNJC2.js +1 -0
- package/dist/dashboard/assets/chunk-S6B2HJQA.js +17 -0
- package/dist/dashboard/assets/styles.css +542 -0
- package/dist/dashboard/index.html +15 -0
- package/dist/fs-watchdog.js +35 -0
- package/dist/herdr/client.js +205 -0
- package/dist/herdr/sync.js +342 -0
- package/dist/ingest/attribution.js +80 -0
- package/dist/ingest/hooks.js +168 -0
- package/dist/ingest/identity.js +4 -0
- package/dist/ingest/mcp-recorder.js +41 -0
- package/dist/ingest/otlp-traces.js +106 -0
- package/dist/ingest/otlp.js +314 -0
- package/dist/ingest/pipeline.js +119 -0
- package/dist/ingest/redact.js +36 -0
- package/dist/ingest/runtimes.js +25 -0
- package/dist/mcp/dispatch.js +54 -0
- package/dist/mcp/http.js +112 -0
- package/dist/mcp/legacy.js +61 -0
- package/dist/mcp/pagination.js +17 -0
- package/dist/mcp/protocol.js +121 -0
- package/dist/mcp/skills-extension.js +77 -0
- package/dist/mcp/stdio-proxy.js +108 -0
- package/dist/mcp/tools.js +59 -0
- package/dist/packs/claude-code.js +176 -0
- package/dist/packs/codex.js +207 -0
- package/dist/packs/cursor.js +97 -0
- package/dist/packs/gajae.js +7 -0
- package/dist/packs/gemini.js +90 -0
- package/dist/packs/json-config.js +55 -0
- package/dist/packs/omo.js +154 -0
- package/dist/packs/openclaw.js +132 -0
- package/dist/packs/registry.js +13 -0
- package/dist/search/fts.js +61 -0
- package/dist/search/fusion.js +50 -0
- package/dist/search/guidance.js +7 -0
- package/dist/search/index.js +74 -0
- package/dist/search/lexical.js +69 -0
- package/dist/server.js +267 -0
- package/dist/store/automation.js +18 -0
- package/dist/store/db.js +134 -0
- package/dist/store/execution.js +157 -0
- package/dist/store/export.js +269 -0
- package/dist/store/index.js +14 -0
- package/dist/store/migrations/002_tracing.sql +94 -0
- package/dist/store/migrations/003_tracing_indexes.sql +11 -0
- package/dist/store/migrations/004_load_reconciliation.sql +50 -0
- package/dist/store/migrations/005_execution_boundaries.sql +6 -0
- package/dist/store/migrations/006_recording_order.sql +72 -0
- package/dist/store/queries.js +643 -0
- package/dist/store/schema.sql +96 -0
- package/dist/store/workflow.js +250 -0
- package/dist/store/writes.js +315 -0
- package/dist/types.js +1 -0
- package/dist/version.js +19 -0
- package/dist/workflow/compare.js +68 -0
- package/dist/workflow/routes.js +100 -0
- package/dist/workflow/spec.js +40 -0
- package/docs/execution-ownership.md +98 -0
- package/docs/mcp-conformance.md +156 -0
- package/docs/skill-tracing.md +294 -0
- package/package.json +48 -4
- package/packs/claude-code/README.md +5 -0
- package/packs/claude-code/settings.template.json +34 -0
- package/packs/codex/README.md +8 -0
- package/packs/codex/config.template.toml +12 -0
- package/packs/cursor/hooks.example.json +8 -0
- package/packs/cursor/mcp.example.json +8 -0
- package/packs/gajae/extension/discovery.md +5 -0
- package/packs/gajae/extension/index.js +52 -0
- package/packs/gemini/settings.example.json +16 -0
- package/packs/hook-post.mjs +37 -0
- package/packs/omo/extension/discovery.md +5 -0
- package/packs/omo/extension/index.js +52 -0
- package/packs/openclaw/.codex-plugin/plugin.json +11 -0
- package/packs/openclaw/.mcp.json +12 -0
- package/packs/openclaw/hooks/skillar-discovery/HOOK.md +8 -0
- package/packs/openclaw/hooks/skillar-discovery/handler.js +30 -0
- package/packs/openclaw/index.mjs +55 -0
- package/packs/openclaw/openclaw.plugin.json +22 -0
- package/packs/openclaw/package.json +11 -0
- package/packs/openclaw/skillar.json +1 -0
- package/src/store/migrations/002_tracing.sql +94 -0
- package/src/store/migrations/003_tracing_indexes.sql +11 -0
- package/src/store/migrations/004_load_reconciliation.sql +50 -0
- package/src/store/migrations/005_execution_boundaries.sql +6 -0
- package/src/store/migrations/006_recording_order.sql +72 -0
- package/src/store/schema.sql +96 -0
- package/src/store/task-types.json +15 -0
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { ensureToken, loadConfig, resolveSkillarHome } from "../config.js";
|
|
5
|
+
import { runDoctor } from "./doctor.js";
|
|
6
|
+
import { runInit, serviceInstall, serviceRemove } from "./init.js";
|
|
7
|
+
import { runOpen } from "./open.js";
|
|
8
|
+
import { makeCliDeps, packageVersion, processIo, runServe, serviceStatus } from "./serve.js";
|
|
9
|
+
const defaultLoaders = {
|
|
10
|
+
exportImport: () => import("./export-import.js"),
|
|
11
|
+
evalApi: () => import("./eval.js"),
|
|
12
|
+
};
|
|
13
|
+
export const HELP = `skillar - local skill router
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
skillar serve [--port <n>] [--foreground] run the daemon in the foreground (used by the service)
|
|
17
|
+
skillar open [--print] print and open the dashboard URL
|
|
18
|
+
skillar init [--dry-run] [--runtime <id>...] [--no-service] [--disable-remote]
|
|
19
|
+
skillar init --rollback [--all] undo the newest (or every) init run
|
|
20
|
+
skillar doctor [--json] check service, daemon, packs, index and backups
|
|
21
|
+
skillar service install|remove|status manage the LaunchAgent / systemd user unit
|
|
22
|
+
skillar mcp-stdio stdio MCP proxy to the local daemon
|
|
23
|
+
skillar export <dir> [--with-history]
|
|
24
|
+
skillar import <dir> [--dry-run]
|
|
25
|
+
skillar eval [--cases <file>] [--json]
|
|
26
|
+
skillar --help | --version
|
|
27
|
+
`;
|
|
28
|
+
class UsageError extends Error {
|
|
29
|
+
code = "usage";
|
|
30
|
+
}
|
|
31
|
+
function parseArgs(args, spec) {
|
|
32
|
+
const parsed = { flags: new Set(), values: new Map(), positional: [] };
|
|
33
|
+
for (let i = 0; i < args.length; i++) {
|
|
34
|
+
const arg = args[i];
|
|
35
|
+
if (spec.flags.includes(arg))
|
|
36
|
+
parsed.flags.add(arg);
|
|
37
|
+
else if (spec.values?.includes(arg) || spec.multi?.includes(arg)) {
|
|
38
|
+
const list = parsed.values.get(arg) ?? [];
|
|
39
|
+
const multi = spec.multi?.includes(arg);
|
|
40
|
+
let took = 0;
|
|
41
|
+
while (i + 1 < args.length && !args[i + 1].startsWith("--") && (multi || took === 0)) {
|
|
42
|
+
list.push(...args[++i].split(",").filter(Boolean));
|
|
43
|
+
took++;
|
|
44
|
+
}
|
|
45
|
+
if (took === 0)
|
|
46
|
+
throw new UsageError(`${arg} needs a value`);
|
|
47
|
+
parsed.values.set(arg, list);
|
|
48
|
+
}
|
|
49
|
+
else if (arg.startsWith("--"))
|
|
50
|
+
throw new UsageError(`unknown option ${arg}`);
|
|
51
|
+
else
|
|
52
|
+
parsed.positional.push(arg);
|
|
53
|
+
}
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
56
|
+
function oneDir(p, command) {
|
|
57
|
+
if (p.positional.length !== 1)
|
|
58
|
+
throw new UsageError(`${command} needs exactly one <dir>`);
|
|
59
|
+
return p.positional[0];
|
|
60
|
+
}
|
|
61
|
+
export async function runMain(argv, opts = {}) {
|
|
62
|
+
const env = opts.env ?? process.env;
|
|
63
|
+
const io = opts.io ?? processIo;
|
|
64
|
+
const loaders = opts.loaders ?? defaultLoaders;
|
|
65
|
+
const [command, ...rest] = argv;
|
|
66
|
+
try {
|
|
67
|
+
switch (command) {
|
|
68
|
+
case undefined:
|
|
69
|
+
case "--help":
|
|
70
|
+
case "-h":
|
|
71
|
+
case "help":
|
|
72
|
+
io.out(HELP);
|
|
73
|
+
return command === undefined ? 1 : 0;
|
|
74
|
+
case "--version":
|
|
75
|
+
case "-v":
|
|
76
|
+
io.out(packageVersion() + "\n");
|
|
77
|
+
return 0;
|
|
78
|
+
case "serve": {
|
|
79
|
+
const p = parseArgs(rest, { flags: ["--foreground"], values: ["--port"] });
|
|
80
|
+
const raw = p.values.get("--port")?.[0];
|
|
81
|
+
const port = raw === undefined ? undefined : Number(raw);
|
|
82
|
+
if (port !== undefined && !(Number.isInteger(port) && port > 0 && port < 65536))
|
|
83
|
+
throw new UsageError(`invalid --port ${raw}`);
|
|
84
|
+
return await runServe({ port }, env, io);
|
|
85
|
+
}
|
|
86
|
+
case "open": {
|
|
87
|
+
const p = parseArgs(rest, { flags: ["--print"] });
|
|
88
|
+
return await runOpen({ print: p.flags.has("--print") }, env, io);
|
|
89
|
+
}
|
|
90
|
+
case "init": {
|
|
91
|
+
const p = parseArgs(rest, { flags: ["--dry-run", "--rollback", "--all", "--no-service", "--disable-remote"], multi: ["--runtime"] });
|
|
92
|
+
if (p.positional.length)
|
|
93
|
+
throw new UsageError(`unexpected argument ${p.positional[0]}`);
|
|
94
|
+
if (p.flags.has("--all") && !p.flags.has("--rollback"))
|
|
95
|
+
throw new UsageError("--all is only valid with --rollback");
|
|
96
|
+
return await runInit({
|
|
97
|
+
dryRun: p.flags.has("--dry-run"), rollback: p.flags.has("--rollback"), all: p.flags.has("--all"),
|
|
98
|
+
noService: p.flags.has("--no-service"), disableRemote: p.flags.has("--disable-remote"), runtimes: p.values.get("--runtime") ?? [],
|
|
99
|
+
}, env, io);
|
|
100
|
+
}
|
|
101
|
+
case "doctor": {
|
|
102
|
+
const p = parseArgs(rest, { flags: ["--json"] });
|
|
103
|
+
return await runDoctor({ json: p.flags.has("--json") }, env, io);
|
|
104
|
+
}
|
|
105
|
+
case "service": {
|
|
106
|
+
const [sub, ...subRest] = rest;
|
|
107
|
+
const p = parseArgs(subRest, { flags: ["--dry-run"] });
|
|
108
|
+
if (sub === "install")
|
|
109
|
+
return await serviceInstall({ dryRun: p.flags.has("--dry-run") }, env, io);
|
|
110
|
+
if (sub === "remove")
|
|
111
|
+
return await serviceRemove(env, io);
|
|
112
|
+
if (sub === "status")
|
|
113
|
+
return serviceStatus(env, io);
|
|
114
|
+
throw new UsageError("service needs install, remove, or status");
|
|
115
|
+
}
|
|
116
|
+
case "mcp-stdio": {
|
|
117
|
+
parseArgs(rest, { flags: [] });
|
|
118
|
+
const config = loadConfig(env);
|
|
119
|
+
const { runStdioProxy } = await import("../mcp/stdio-proxy.js");
|
|
120
|
+
await runStdioProxy({ port: config.port, token: ensureToken(resolveSkillarHome(env)) });
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
case "export": {
|
|
124
|
+
const p = parseArgs(rest, { flags: ["--with-history"] });
|
|
125
|
+
const dir = oneDir(p, "export");
|
|
126
|
+
return await (await loaders.exportImport()).runExport(dir, { withHistory: p.flags.has("--with-history") }, makeCliDeps(env));
|
|
127
|
+
}
|
|
128
|
+
case "import": {
|
|
129
|
+
const p = parseArgs(rest, { flags: ["--dry-run"] });
|
|
130
|
+
const dir = oneDir(p, "import");
|
|
131
|
+
return await (await loaders.exportImport()).runImport(dir, { dryRun: p.flags.has("--dry-run") }, makeCliDeps(env));
|
|
132
|
+
}
|
|
133
|
+
case "eval": {
|
|
134
|
+
const p = parseArgs(rest, { flags: ["--json"], values: ["--cases"] });
|
|
135
|
+
const cases = p.values.get("--cases")?.[0];
|
|
136
|
+
return await (await loaders.evalApi()).runEval({ ...(cases ? { cases } : {}), json: p.flags.has("--json") }, makeCliDeps(env));
|
|
137
|
+
}
|
|
138
|
+
default:
|
|
139
|
+
throw new UsageError(`unknown command ${command}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (error instanceof UsageError) {
|
|
144
|
+
io.err(`usage: ${error.message}\n\n${HELP}`);
|
|
145
|
+
return 2;
|
|
146
|
+
}
|
|
147
|
+
const code = error.code;
|
|
148
|
+
const message = error.message ?? String(error);
|
|
149
|
+
io.err(`error: ${typeof code === "string" && !message.startsWith(code) ? `${code}: ` : ""}${message}\n`);
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function invokedDirectly() {
|
|
154
|
+
if (!process.argv[1])
|
|
155
|
+
return false;
|
|
156
|
+
try {
|
|
157
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (invokedDirectly()) {
|
|
164
|
+
process.exitCode = await runMain(process.argv.slice(2));
|
|
165
|
+
}
|
package/dist/cli/open.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { loadConfig, ensureToken, resolveSkillarHome } from "../config.js";
|
|
3
|
+
export function dashboardUrl(port, token) {
|
|
4
|
+
return `http://127.0.0.1:${port}/?token=${token}`;
|
|
5
|
+
}
|
|
6
|
+
export async function runOpen(opts, env, io) {
|
|
7
|
+
const config = loadConfig(env);
|
|
8
|
+
const url = dashboardUrl(config.port, ensureToken(resolveSkillarHome(env)));
|
|
9
|
+
io.out(url + "\n");
|
|
10
|
+
if (opts.print || (env.SKILLAR_NO_CLI ?? env.GISOOL_NO_CLI))
|
|
11
|
+
return 0;
|
|
12
|
+
const opener = process.platform === "darwin" ? "open" : "xdg-open";
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const child = spawn(opener, [url], { env, stdio: "ignore", detached: true });
|
|
15
|
+
child.once("error", (error) => {
|
|
16
|
+
io.err(`could not run ${opener}: ${error.message}; open the URL above manually\n`);
|
|
17
|
+
resolve(1);
|
|
18
|
+
});
|
|
19
|
+
child.once("spawn", () => {
|
|
20
|
+
child.unref();
|
|
21
|
+
resolve(0);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { dbPath, loadConfig, resolveSkillarHome, resolveHome } from "../config.js";
|
|
6
|
+
import { startServer } from "../server.js";
|
|
7
|
+
import { openDb } from "../store/db.js";
|
|
8
|
+
import { createStore } from "../store/index.js";
|
|
9
|
+
import { readTarget } from "./config-writer.js";
|
|
10
|
+
export const processIo = { out: (t) => process.stdout.write(t), err: (t) => process.stderr.write(t) };
|
|
11
|
+
export const SERVICE_LABEL = "dev.skillar.daemon";
|
|
12
|
+
export function packageRoot() {
|
|
13
|
+
return realpathSync(fileURLToPath(new URL("../../", import.meta.url)));
|
|
14
|
+
}
|
|
15
|
+
export function nodePath() {
|
|
16
|
+
return realpathSync(process.execPath);
|
|
17
|
+
}
|
|
18
|
+
export function packageVersion() {
|
|
19
|
+
const pkg = JSON.parse(readFileSync(join(packageRoot(), "package.json"), "utf8"));
|
|
20
|
+
return pkg.version;
|
|
21
|
+
}
|
|
22
|
+
export function makeCliDeps(env) {
|
|
23
|
+
const config = loadConfig(env);
|
|
24
|
+
const home = resolveHome(env);
|
|
25
|
+
const skillarHome = resolveSkillarHome(env);
|
|
26
|
+
return { config, home, skillarHome, env, openStore: () => createStore(openDb(dbPath(skillarHome)), { config, home, skillarHome }) };
|
|
27
|
+
}
|
|
28
|
+
export async function runServe(opts, env, io) {
|
|
29
|
+
const deps = makeCliDeps(env);
|
|
30
|
+
const config = opts.port === undefined ? deps.config : { ...deps.config, port: opts.port };
|
|
31
|
+
const server = await startServer(config, { skillarHome: deps.skillarHome, openStore: deps.openStore });
|
|
32
|
+
io.err(`skillar listening on http://127.0.0.1:${server.port}\n`);
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
const xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
36
|
+
const unitQuote = (s) => `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
37
|
+
export function serviceLabel(home, platform) {
|
|
38
|
+
const legacy = platform === "darwin" ? join(home, "Library", "LaunchAgents", "dev.gisool.daemon.plist") : join(home, ".config", "systemd", "user", "gisool.service");
|
|
39
|
+
return existsSync(legacy) ? (platform === "darwin" ? "dev.gisool.daemon" : "gisool") : (platform === "darwin" ? SERVICE_LABEL : "skillar");
|
|
40
|
+
}
|
|
41
|
+
export function servicePath(home, platform) {
|
|
42
|
+
const label = serviceLabel(home, platform);
|
|
43
|
+
return platform === "darwin"
|
|
44
|
+
? join(home, "Library", "LaunchAgents", `${label}.plist`)
|
|
45
|
+
: join(home, ".config", "systemd", "user", `${label}.service`);
|
|
46
|
+
}
|
|
47
|
+
export function daemonLogPath(skillarHome) {
|
|
48
|
+
return join(skillarHome, "logs", "daemon.log");
|
|
49
|
+
}
|
|
50
|
+
function plist(ctx) {
|
|
51
|
+
const log = xml(daemonLogPath(ctx.skillarHome));
|
|
52
|
+
const args = [ctx.nodePath, join(ctx.packageRoot, "dist", "cli", "main.js"), "serve"].map((a) => ` <string>${xml(a)}</string>`).join("\n");
|
|
53
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
54
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
55
|
+
<plist version="1.0">
|
|
56
|
+
<dict>
|
|
57
|
+
<key>Label</key>
|
|
58
|
+
<string>${serviceLabel(ctx.home, ctx.platform)}</string>
|
|
59
|
+
<key>ProgramArguments</key>
|
|
60
|
+
<array>
|
|
61
|
+
${args}
|
|
62
|
+
</array>
|
|
63
|
+
<key>EnvironmentVariables</key>
|
|
64
|
+
<dict>
|
|
65
|
+
<key>SKILLAR_HOME</key>
|
|
66
|
+
<string>${xml(ctx.skillarHome)}</string>
|
|
67
|
+
</dict>
|
|
68
|
+
<key>RunAtLoad</key>
|
|
69
|
+
<true/>
|
|
70
|
+
<key>KeepAlive</key>
|
|
71
|
+
<true/>
|
|
72
|
+
<key>StandardOutPath</key>
|
|
73
|
+
<string>${log}</string>
|
|
74
|
+
<key>StandardErrorPath</key>
|
|
75
|
+
<string>${log}</string>
|
|
76
|
+
</dict>
|
|
77
|
+
</plist>
|
|
78
|
+
`;
|
|
79
|
+
}
|
|
80
|
+
function unit(ctx) {
|
|
81
|
+
const log = daemonLogPath(ctx.skillarHome);
|
|
82
|
+
return `[Unit]
|
|
83
|
+
Description=skillar local skill router
|
|
84
|
+
|
|
85
|
+
[Service]
|
|
86
|
+
ExecStart=${unitQuote(ctx.nodePath)} ${unitQuote(join(ctx.packageRoot, "dist", "cli", "main.js"))} serve
|
|
87
|
+
Environment=${unitQuote(`SKILLAR_HOME=${ctx.skillarHome}`)}
|
|
88
|
+
Restart=always
|
|
89
|
+
StandardOutput=append:${log}
|
|
90
|
+
StandardError=append:${log}
|
|
91
|
+
|
|
92
|
+
[Install]
|
|
93
|
+
WantedBy=default.target
|
|
94
|
+
`;
|
|
95
|
+
}
|
|
96
|
+
export function planService(ctx) {
|
|
97
|
+
const path = servicePath(ctx.home, ctx.platform);
|
|
98
|
+
const before = readTarget(path);
|
|
99
|
+
const after = ctx.platform === "darwin" ? plist(ctx) : unit(ctx);
|
|
100
|
+
const file = { path, before, after, mode: 0o644 };
|
|
101
|
+
const commands = [];
|
|
102
|
+
const notes = [];
|
|
103
|
+
if (before === after)
|
|
104
|
+
return { file, commands, notes: ["service definition already up to date"] };
|
|
105
|
+
if (ctx.platform === "darwin") {
|
|
106
|
+
const domain = `gui/${ctx.uid}`;
|
|
107
|
+
if (before !== null)
|
|
108
|
+
commands.push({ argv: ["launchctl", "bootout", `${domain}/${serviceLabel(ctx.home, ctx.platform)}`], description: "Unload the previous skillar LaunchAgent", allowFailure: true });
|
|
109
|
+
commands.push({ argv: ["launchctl", "bootstrap", domain, path], description: "Load the skillar LaunchAgent",
|
|
110
|
+
undo: { argv: ["launchctl", "bootout", `${domain}/${serviceLabel(ctx.home, ctx.platform)}`], description: "Unload the skillar LaunchAgent" } });
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
commands.push({ argv: ["systemctl", "--user", "daemon-reload"], description: "Reload systemd user units" });
|
|
114
|
+
commands.push({ argv: ["systemctl", "--user", "enable", "--now", `${serviceLabel(ctx.home, ctx.platform)}.service`], description: "Enable and start the skillar user service",
|
|
115
|
+
undo: { argv: ["systemctl", "--user", "disable", "--now", `${serviceLabel(ctx.home, ctx.platform)}.service`], description: "Stop and disable the skillar user service" } });
|
|
116
|
+
if (before !== null)
|
|
117
|
+
commands.push({ argv: ["systemctl", "--user", "restart", `${serviceLabel(ctx.home, ctx.platform)}.service`], description: "Restart skillar with the new unit" });
|
|
118
|
+
}
|
|
119
|
+
if ((ctx.env.SKILLAR_NO_CLI ?? ctx.env.GISOOL_NO_CLI)) {
|
|
120
|
+
notes.push(`SKILLAR_NO_CLI set: service file written but not loaded; run manually: ${commands.map((c) => c.argv.join(" ")).join(" && ")}`);
|
|
121
|
+
return { file, commands: [], notes };
|
|
122
|
+
}
|
|
123
|
+
return { file, commands, notes };
|
|
124
|
+
}
|
|
125
|
+
export function serviceLoaded(platform, uid, env) {
|
|
126
|
+
const argv = platform === "darwin" ? ["launchctl", "print", `gui/${uid}/${serviceLabel(resolveHome(env), platform)}`] : ["systemctl", "--user", "is-active", serviceLabel(resolveHome(env), platform)];
|
|
127
|
+
const r = spawnSync(argv[0], argv.slice(1), { env, stdio: "ignore" });
|
|
128
|
+
return r.status === 0;
|
|
129
|
+
}
|
|
130
|
+
export function currentServicePlatform() {
|
|
131
|
+
return process.platform === "darwin" ? "darwin" : "linux";
|
|
132
|
+
}
|
|
133
|
+
export function serviceStatus(env, io) {
|
|
134
|
+
const home = resolveHome(env);
|
|
135
|
+
const platform = currentServicePlatform();
|
|
136
|
+
const path = servicePath(home, platform);
|
|
137
|
+
const installed = existsSync(path);
|
|
138
|
+
io.out(`service file: ${installed ? path : "not installed"}\n`);
|
|
139
|
+
if ((env.SKILLAR_NO_CLI ?? env.GISOOL_NO_CLI)) {
|
|
140
|
+
io.out("service loaded: skipped (SKILLAR_NO_CLI)\n");
|
|
141
|
+
return installed ? 0 : 1;
|
|
142
|
+
}
|
|
143
|
+
const loaded = serviceLoaded(platform, process.getuid?.() ?? 0, env);
|
|
144
|
+
io.out(`service loaded: ${loaded ? "yes" : "no"}\n`);
|
|
145
|
+
return installed && loaded ? 0 : 1;
|
|
146
|
+
}
|
|
147
|
+
export { dbPath } from "../config.js";
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { isAbsolute, join } from "node:path";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
export const DEFAULT_PORT = 8799;
|
|
7
|
+
export const DEFAULT_ROOTS = [
|
|
8
|
+
{ id: "agents", path: "~/.agents/skills" },
|
|
9
|
+
{ id: "claude", path: "~/.claude/skills" },
|
|
10
|
+
{ id: "codex", path: "~/.codex/skills" },
|
|
11
|
+
{ id: "gemini", path: "~/.gemini/skills" },
|
|
12
|
+
{ id: "omo", path: "~/.omo/agent/skills" },
|
|
13
|
+
{ id: "gajae", path: "~/.gjc/agent/skills" },
|
|
14
|
+
{ id: "openclaw", path: "~/.openclaw/skills" },
|
|
15
|
+
{ id: "iyen", path: "~/iyen-skills/skills" },
|
|
16
|
+
];
|
|
17
|
+
const runtimeIds = ["claude-code", "codex", "gemini", "cursor", "omo", "gajae", "openclaw", "unknown"];
|
|
18
|
+
const fileSchema = z.object({
|
|
19
|
+
port: z.number().int().min(1).max(65535).optional(),
|
|
20
|
+
captureLevel: z.enum(["metadata", "redacted", "full"]).optional(),
|
|
21
|
+
retentionDays: z.number().int().positive().nullable().optional(),
|
|
22
|
+
roots: z.array(z.object({ id: z.string().min(1), path: z.string().min(1) })).optional(),
|
|
23
|
+
runtimes: z.partialRecord(z.enum(runtimeIds), z.object({ enabled: z.boolean() })).optional(),
|
|
24
|
+
});
|
|
25
|
+
export function resolveHome(env) {
|
|
26
|
+
return env.HOME && env.HOME.length > 0 ? env.HOME : homedir();
|
|
27
|
+
}
|
|
28
|
+
export function resolveSkillarHome(env) {
|
|
29
|
+
const explicit = env.SKILLAR_HOME || env.GISOOL_HOME;
|
|
30
|
+
if (explicit)
|
|
31
|
+
return explicit;
|
|
32
|
+
// Reuse the complete legacy store in place: never split tokens, backups or history.
|
|
33
|
+
const preferred = join(resolveHome(env), ".skillar");
|
|
34
|
+
const legacy = join(resolveHome(env), ".gisool");
|
|
35
|
+
if (["config.json", "token", "skillar.db", "gisool.db"].some(file => existsSync(join(preferred, file))))
|
|
36
|
+
return preferred;
|
|
37
|
+
return existsSync(legacy) ? legacy : preferred;
|
|
38
|
+
}
|
|
39
|
+
export function expandHome(path, home) {
|
|
40
|
+
if (path === "~")
|
|
41
|
+
return home;
|
|
42
|
+
if (path.startsWith("~/"))
|
|
43
|
+
return join(home, path.slice(2));
|
|
44
|
+
return isAbsolute(path) ? path : join(home, path);
|
|
45
|
+
}
|
|
46
|
+
export function defaultConfigFile() {
|
|
47
|
+
return { port: DEFAULT_PORT, captureLevel: "full", retentionDays: null, roots: DEFAULT_ROOTS.map((r) => ({ ...r })), runtimes: {} };
|
|
48
|
+
}
|
|
49
|
+
export function ensureSkillarHome(env) {
|
|
50
|
+
const dir = resolveSkillarHome(env);
|
|
51
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
52
|
+
chmodSync(dir, 0o700);
|
|
53
|
+
return dir;
|
|
54
|
+
}
|
|
55
|
+
/** Returns the daemon bearer token, creating a 32-byte hex token (mode 0600) on first use. */
|
|
56
|
+
export function ensureToken(skillarHome) {
|
|
57
|
+
const path = join(skillarHome, "token");
|
|
58
|
+
if (existsSync(path)) {
|
|
59
|
+
const token = readFileSync(path, "utf8").trim();
|
|
60
|
+
if (/^[0-9a-f]{64}$/.test(token))
|
|
61
|
+
return token;
|
|
62
|
+
}
|
|
63
|
+
const token = randomBytes(32).toString("hex");
|
|
64
|
+
writeFileSync(path, token + "\n", { mode: 0o600 });
|
|
65
|
+
chmodSync(path, 0o600);
|
|
66
|
+
return token;
|
|
67
|
+
}
|
|
68
|
+
/** Loads (and on first run creates) SKILLAR_HOME, config.json and the token. No work happens at import time. */
|
|
69
|
+
export function loadConfig(env) {
|
|
70
|
+
const home = resolveHome(env);
|
|
71
|
+
const skillarHome = ensureSkillarHome(env);
|
|
72
|
+
const configPath = join(skillarHome, "config.json");
|
|
73
|
+
if (!existsSync(configPath)) {
|
|
74
|
+
writeFileSync(configPath, JSON.stringify(defaultConfigFile(), null, 2) + "\n", { mode: 0o600 });
|
|
75
|
+
}
|
|
76
|
+
const parsed = fileSchema.parse(JSON.parse(readFileSync(configPath, "utf8")));
|
|
77
|
+
ensureToken(skillarHome);
|
|
78
|
+
const defaults = defaultConfigFile();
|
|
79
|
+
return {
|
|
80
|
+
port: parsed.port ?? defaults.port,
|
|
81
|
+
captureLevel: parsed.captureLevel ?? defaults.captureLevel,
|
|
82
|
+
retentionDays: parsed.retentionDays ?? null,
|
|
83
|
+
roots: (parsed.roots ?? defaults.roots).map((r) => ({ id: r.id, path: expandHome(r.path, home) })),
|
|
84
|
+
runtimes: parsed.runtimes ?? {},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export function dbPath(skillarHome) {
|
|
88
|
+
const current = join(skillarHome, "skillar.db"), legacy = join(skillarHome, "gisool.db");
|
|
89
|
+
if (existsSync(current) && existsSync(legacy))
|
|
90
|
+
throw new Error("Both skillar.db and gisool.db exist in the selected home; preserve both and choose one store before starting Skillar");
|
|
91
|
+
return existsSync(legacy) ? legacy : current;
|
|
92
|
+
}
|