skillar 0.2.1 → 0.3.1
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/NOTICE +280 -0
- package/README.md +37 -5
- package/dist/analysis/finding.js +8 -190
- package/dist/analysis/kernel.js +896 -0
- package/dist/analysis/tree.js +7 -154
- package/dist/analysis/usage.js +9 -394
- package/dist/api/flows.js +42 -212
- package/dist/api/report-kernel.js +1063 -0
- package/dist/api/routes.js +12 -2
- package/dist/catalog/fields.js +138 -146
- package/dist/catalog/watcher.js +7 -2
- package/dist/cli/init.js +45 -0
- package/dist/cli/main.js +76 -3
- package/dist/cli/private-skills.js +122 -0
- package/dist/cli/serve.js +15 -1
- package/dist/cli/sync.js +124 -0
- package/dist/dashboard/NOTICE +280 -0
- package/dist/dashboard/assets/app.js +737 -275
- package/dist/dashboard/assets/astryx-reset.css +407 -0
- package/dist/dashboard/assets/astryx.css +1077 -0
- package/dist/dashboard/assets/charts.css +54 -0
- package/dist/dashboard/assets/chunk-TPGDA2J4.js +1 -0
- package/dist/dashboard/assets/chunk-YLWHVDMP.js +36 -0
- package/dist/dashboard/assets/controls.css +207 -0
- package/dist/dashboard/assets/overlays.css +132 -0
- package/dist/dashboard/assets/p1.css +135 -0
- package/dist/dashboard/assets/shell.css +71 -0
- package/dist/dashboard/assets/skillar-theme.css +692 -0
- package/dist/dashboard/assets/styles.css +224 -121
- package/dist/dashboard/assets/tokens.css +278 -0
- package/dist/dashboard/assets/widgets.css +83 -0
- package/dist/dashboard/index.html +11 -2
- package/dist/dashboard/viewers/viewers.css +61 -0
- package/dist/ingest/attribution.js +5 -1
- package/dist/ingest/pipeline.js +2 -0
- package/dist/ingest/request-recorder.js +39 -0
- package/dist/mcp/dispatch.js +2 -2
- package/dist/mcp/http.js +43 -3
- package/dist/mcp/skills-extension.js +42 -15
- package/dist/mcp/stdio-proxy.js +24 -3
- package/dist/mcp/tools.js +38 -24
- package/dist/packs/claude-code.js +22 -11
- package/dist/packs/cursor.js +9 -4
- package/dist/packs/gemini.js +9 -4
- package/dist/packs/json-config.js +41 -0
- package/dist/packs/omo.js +15 -6
- package/dist/request-status.js +81 -0
- package/dist/search/fts.js +93 -58
- package/dist/search/fusion.js +49 -47
- package/dist/search/guidance.js +18 -6
- package/dist/search/index.js +291 -70
- package/dist/search/lexical.js +71 -63
- package/dist/server.js +12 -0
- package/dist/skills/apply.js +130 -0
- package/dist/skills/capture.js +54 -0
- package/dist/skills/cloud-plan.js +57 -0
- package/dist/skills/cloud.js +81 -0
- package/dist/skills/fs.js +133 -0
- package/dist/skills/package.js +734 -0
- package/dist/skills/plan.js +83 -0
- package/dist/skills/receipt.js +44 -0
- package/dist/skills/rollback.js +119 -0
- package/dist/skills/transfer.js +51 -0
- package/dist/store/db.js +7 -1
- package/dist/store/execution.js +2 -34
- package/dist/store/export.js +25 -4
- package/dist/store/migrations/007_sync.sql +49 -0
- package/dist/store/migrations/008_connector_commands.sql +12 -0
- package/dist/store/queries.js +33 -7
- package/dist/store/writes.js +38 -5
- package/dist/sync/cloud-blobs.js +175 -0
- package/dist/sync/cloud-commands.js +101 -0
- package/dist/sync/cloud-connection.js +105 -0
- package/dist/sync/cloud-delivery.js +114 -0
- package/dist/sync/cloud-documents.js +103 -0
- package/dist/sync/cloud-export.js +67 -0
- package/dist/sync/cloud-http.js +150 -0
- package/dist/sync/cloud-jobs.js +94 -0
- package/dist/sync/cloud-pending.js +143 -0
- package/dist/sync/cloud-prepare.js +101 -0
- package/dist/sync/cloud-restore.js +136 -0
- package/dist/sync/cloud-rollback.js +24 -0
- package/dist/sync/cloud-runner.js +86 -0
- package/dist/sync/cloud-runtime.js +293 -0
- package/dist/sync/cloud-schema.js +32 -0
- package/dist/sync/cloud-stage.js +112 -0
- package/dist/sync/cloud-wire.js +693 -0
- package/dist/sync/cloud-worker.js +57 -0
- package/dist/sync/cloud.js +157 -0
- package/dist/sync/command-apply.js +140 -0
- package/dist/sync/command-control.js +25 -0
- package/dist/sync/command-wire.js +437 -0
- package/dist/sync/consent.js +130 -0
- package/dist/sync/journal.js +43 -0
- package/dist/sync/outbox.js +134 -0
- package/dist/sync/restore-rows.js +125 -0
- package/dist/sync/restore.js +174 -0
- package/dist/sync/snapshot.js +78 -0
- package/dist/sync/spool-request.js +103 -0
- package/dist/sync/tables.js +27 -0
- package/dist/sync/triggers.js +34 -0
- package/dist/workflow/compare.js +3 -43
- package/docs/cloud-sync.md +94 -0
- package/docs/private-skills.md +75 -0
- package/docs/sync-p4.md +102 -0
- package/docs/sync-restore.md +167 -0
- package/package.json +18 -5
- package/src/store/migrations/007_sync.sql +49 -0
- package/src/store/migrations/008_connector_commands.sql +12 -0
- package/dist/dashboard/assets/chunk-5DFWNJC2.js +0 -1
- package/dist/dashboard/assets/chunk-S6B2HJQA.js +0 -17
package/dist/api/routes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { REQUEST_STATUSES } from "../request-status.js";
|
|
1
2
|
import { ingestOtlpTraces } from "../ingest/otlp-traces.js";
|
|
2
3
|
import { ingestHook, ingestOtlp } from "../ingest/pipeline.js";
|
|
3
4
|
import { isRuntimeId, RUNTIME_IDS } from "../ingest/runtimes.js";
|
|
@@ -46,6 +47,9 @@ export function parseFilter(q) {
|
|
|
46
47
|
const to = intParam(q, "to");
|
|
47
48
|
const runtime = listParam(q, "runtime", RUNTIME_IDS);
|
|
48
49
|
const skill = listParam(q, "skill");
|
|
50
|
+
const searchStatus = listParam(q, "searchStatus", REQUEST_STATUSES);
|
|
51
|
+
const loadStatus = listParam(q, "loadStatus", REQUEST_STATUSES);
|
|
52
|
+
const searchResult = listParam(q, "searchResult", ["candidates_found", "no_candidates"]);
|
|
49
53
|
const state = listParam(q, "state", STATES);
|
|
50
54
|
const dow = intParam(q, "dow", [0, 6]);
|
|
51
55
|
const hour = intParam(q, "hour", [0, 23]);
|
|
@@ -65,6 +69,12 @@ export function parseFilter(q) {
|
|
|
65
69
|
f.skill = skill;
|
|
66
70
|
if (state)
|
|
67
71
|
f.state = state;
|
|
72
|
+
if (searchStatus)
|
|
73
|
+
f.searchStatus = searchStatus;
|
|
74
|
+
if (loadStatus)
|
|
75
|
+
f.loadStatus = loadStatus;
|
|
76
|
+
if (searchResult)
|
|
77
|
+
f.searchResult = searchResult;
|
|
68
78
|
if (dow !== undefined)
|
|
69
79
|
f.dow = dow;
|
|
70
80
|
if (hour !== undefined)
|
|
@@ -147,8 +157,8 @@ export function registerRoutes(app, deps) {
|
|
|
147
157
|
}));
|
|
148
158
|
app.get("/api/flow", handle(log, (req, res) => {
|
|
149
159
|
const unit = one(req.query.unit) ?? "first_load";
|
|
150
|
-
if (unit !== "first_load" && unit !== "all_loads")
|
|
151
|
-
throw new BadRequest("bad_request", "unit must be first_load or
|
|
160
|
+
if (unit !== "first_load" && unit !== "all_loads" && unit !== "search_requests" && unit !== "load_requests")
|
|
161
|
+
throw new BadRequest("bad_request", "unit must be first_load, all_loads, search_requests or load_requests");
|
|
152
162
|
const top = Math.min(15, intParam(req.query, "top", [1, 1000]) ?? 7);
|
|
153
163
|
res.json(store.flow(parseFilter(req.query), unit, top));
|
|
154
164
|
}));
|
package/dist/catalog/fields.js
CHANGED
|
@@ -1,159 +1,151 @@
|
|
|
1
|
-
//
|
|
1
|
+
// ../shared/dist/skill-fields.js
|
|
2
2
|
import { parse as parseYaml } from "yaml";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
var BODY_HEAD_MAX = 600;
|
|
5
|
+
var recordSchema = z.record(z.string(), z.unknown());
|
|
6
|
+
function splitSkillMarkdown(input, options = {}) {
|
|
7
|
+
const markdown = input.replace(/\r\n/g, "\n");
|
|
8
|
+
if (!markdown.startsWith("---\n"))
|
|
9
|
+
return { frontmatter: null, body: markdown };
|
|
10
|
+
const end = markdown.indexOf("\n---", 4);
|
|
11
|
+
if (end === -1)
|
|
12
|
+
return { frontmatter: null, body: markdown };
|
|
13
|
+
const afterDelimiter = markdown.slice(end + 4, end + 5);
|
|
14
|
+
if (afterDelimiter !== "" && afterDelimiter !== "\n")
|
|
15
|
+
return { frontmatter: null, body: markdown };
|
|
16
|
+
const body = markdown.slice(end + 5);
|
|
17
|
+
let parsed;
|
|
18
|
+
try {
|
|
19
|
+
parsed = parseYaml(markdown.slice(4, end), options.rejectAliases ? { maxAliasCount: 0 } : {});
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (error instanceof Error)
|
|
22
|
+
return { frontmatter: null, body };
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
const result = recordSchema.safeParse(parsed);
|
|
26
|
+
return { frontmatter: result.success ? result.data : null, body };
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return [];
|
|
28
|
+
function stringList(value) {
|
|
29
|
+
if (Array.isArray(value))
|
|
30
|
+
return value.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean);
|
|
31
|
+
if (typeof value === "string")
|
|
32
|
+
return value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
33
|
+
return [];
|
|
34
34
|
}
|
|
35
35
|
function explicitGroup(value) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
if (typeof value === "string" && value.trim())
|
|
37
|
+
return { id: value.trim() };
|
|
38
|
+
const parsed = recordSchema.safeParse(value);
|
|
39
|
+
if (!parsed.success)
|
|
40
|
+
return void 0;
|
|
41
|
+
const record = parsed.data;
|
|
42
|
+
if (typeof record.id !== "string" || !record.id.trim())
|
|
43
|
+
return void 0;
|
|
44
|
+
const stage = typeof record.stage === "string" && record.stage.trim() ? record.stage.trim() : typeof record.stage === "number" ? String(record.stage) : void 0;
|
|
45
|
+
return stage === void 0 ? { id: record.id.trim() } : { id: record.id.trim(), stage };
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (inFence)
|
|
61
|
-
continue;
|
|
62
|
-
if (!line.trim()) {
|
|
63
|
-
if (current.length) {
|
|
64
|
-
paragraphs.push(current.join(" "));
|
|
65
|
-
current = [];
|
|
66
|
-
}
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (/^\s{0,3}#/.test(line)) {
|
|
70
|
-
if (current.length) {
|
|
71
|
-
paragraphs.push(current.join(" "));
|
|
72
|
-
current = [];
|
|
73
|
-
}
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
current.push(line.trim());
|
|
77
|
-
if (current.join(" ").length > BODY_HEAD_MAX)
|
|
78
|
-
break;
|
|
47
|
+
function bodyHead(body) {
|
|
48
|
+
let inFence = false;
|
|
49
|
+
const paragraphs = [];
|
|
50
|
+
let current = [];
|
|
51
|
+
for (const line of body.split("\n")) {
|
|
52
|
+
if (/^\s*(```|~~~)/.test(line)) {
|
|
53
|
+
inFence = !inFence;
|
|
54
|
+
if (current.length) {
|
|
55
|
+
paragraphs.push(current.join(" "));
|
|
56
|
+
current = [];
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
79
59
|
}
|
|
80
|
-
if (
|
|
60
|
+
if (inFence)
|
|
61
|
+
continue;
|
|
62
|
+
if (!line.trim()) {
|
|
63
|
+
if (current.length) {
|
|
81
64
|
paragraphs.push(current.join(" "));
|
|
82
|
-
|
|
83
|
-
|
|
65
|
+
current = [];
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (/^\s{0,3}#/.test(line)) {
|
|
70
|
+
if (current.length) {
|
|
71
|
+
paragraphs.push(current.join(" "));
|
|
72
|
+
current = [];
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
current.push(line.trim());
|
|
77
|
+
if (current.join(" ").length > BODY_HEAD_MAX)
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
if (current.length)
|
|
81
|
+
paragraphs.push(current.join(" "));
|
|
82
|
+
return (paragraphs.find((paragraph) => paragraph.trim()) ?? "").replace(/\s+/g, " ").trim().slice(0, BODY_HEAD_MAX);
|
|
84
83
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
};
|
|
113
|
-
if (typeof whenRaw === "string" && whenRaw.trim())
|
|
114
|
-
fields.whenToUse = whenRaw.trim();
|
|
115
|
-
const group = explicitGroup(frontmatter.group);
|
|
116
|
-
if (group)
|
|
117
|
-
fields.group = group;
|
|
118
|
-
return fields;
|
|
84
|
+
function extractFields(frontmatter, body) {
|
|
85
|
+
const { name, description, compatibility, metadata, license } = frontmatter;
|
|
86
|
+
if (typeof name !== "string" || [...name].length < 1 || [...name].length > 64 || name !== name.toLowerCase() || !/^[\p{L}\p{N}]+(?:-[\p{L}\p{N}]+)*$/u.test(name))
|
|
87
|
+
return null;
|
|
88
|
+
if (typeof description !== "string" || !description.trim() || [...description].length > 1024)
|
|
89
|
+
return null;
|
|
90
|
+
if (compatibility !== void 0 && (typeof compatibility !== "string" || !compatibility.trim() || [...compatibility].length > 500))
|
|
91
|
+
return null;
|
|
92
|
+
if (license !== void 0 && typeof license !== "string")
|
|
93
|
+
return null;
|
|
94
|
+
if (frontmatter["allowed-tools"] !== void 0 && typeof frontmatter["allowed-tools"] !== "string")
|
|
95
|
+
return null;
|
|
96
|
+
if (metadata !== void 0 && (!metadata || typeof metadata !== "object" || Array.isArray(metadata) || Object.values(metadata).some((value) => typeof value !== "string")))
|
|
97
|
+
return null;
|
|
98
|
+
const whenRaw = frontmatter.when_to_use ?? frontmatter["when-to-use"];
|
|
99
|
+
const group = explicitGroup(frontmatter.group);
|
|
100
|
+
return {
|
|
101
|
+
name,
|
|
102
|
+
description,
|
|
103
|
+
tags: stringList(frontmatter.tags),
|
|
104
|
+
examples: stringList(frontmatter.examples),
|
|
105
|
+
aliasesKo: stringList(frontmatter.aliases_ko),
|
|
106
|
+
invocation: frontmatter["disable-model-invocation"] === true || frontmatter["disable-model-invocation"] === "true" ? "explicit" : "automatic",
|
|
107
|
+
bodyHead: bodyHead(body),
|
|
108
|
+
...typeof whenRaw === "string" && whenRaw.trim() ? { whenToUse: whenRaw.trim() } : {},
|
|
109
|
+
...group === void 0 ? {} : { group }
|
|
110
|
+
};
|
|
119
111
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return index === -1 ? name : name.slice(0, index);
|
|
112
|
+
function familyPrefix(name) {
|
|
113
|
+
const index = name.indexOf("-");
|
|
114
|
+
return index === -1 ? name : name.slice(0, index);
|
|
124
115
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
116
|
+
|
|
117
|
+
// src/catalog/fields.ts
|
|
118
|
+
function applyFamilies(entries, explicit) {
|
|
119
|
+
const namesByPrefix = /* @__PURE__ */ new Map();
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
if (explicit.get(entry.uri)) continue;
|
|
122
|
+
const prefix = familyPrefix(entry.name);
|
|
123
|
+
if (!namesByPrefix.has(prefix)) namesByPrefix.set(prefix, /* @__PURE__ */ new Set());
|
|
124
|
+
namesByPrefix.get(prefix).add(entry.name);
|
|
125
|
+
}
|
|
126
|
+
const families = /* @__PURE__ */ new Map();
|
|
127
|
+
for (const entry of entries) {
|
|
128
|
+
const group = explicit.get(entry.uri);
|
|
129
|
+
if (group) {
|
|
130
|
+
entry.group = group;
|
|
131
|
+
} else {
|
|
132
|
+
const prefix = familyPrefix(entry.name);
|
|
133
|
+
if ((namesByPrefix.get(prefix)?.size ?? 0) >= 2) entry.group = { id: prefix };
|
|
134
|
+
else delete entry.group;
|
|
138
135
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (group) {
|
|
143
|
-
entry.group = group;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
const prefix = familyPrefix(entry.name);
|
|
147
|
-
if ((namesByPrefix.get(prefix)?.size ?? 0) >= 2)
|
|
148
|
-
entry.group = { id: prefix };
|
|
149
|
-
else
|
|
150
|
-
delete entry.group;
|
|
151
|
-
}
|
|
152
|
-
if (entry.group) {
|
|
153
|
-
if (!families.has(entry.group.id))
|
|
154
|
-
families.set(entry.group.id, []);
|
|
155
|
-
families.get(entry.group.id).push(entry.uri);
|
|
156
|
-
}
|
|
136
|
+
if (entry.group) {
|
|
137
|
+
if (!families.has(entry.group.id)) families.set(entry.group.id, []);
|
|
138
|
+
families.get(entry.group.id).push(entry.uri);
|
|
157
139
|
}
|
|
158
|
-
|
|
140
|
+
}
|
|
141
|
+
return [...families.entries()].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([id, uris]) => ({ id, uris: uris.sort() }));
|
|
159
142
|
}
|
|
143
|
+
export {
|
|
144
|
+
BODY_HEAD_MAX,
|
|
145
|
+
applyFamilies,
|
|
146
|
+
bodyHead,
|
|
147
|
+
extractFields,
|
|
148
|
+
familyPrefix,
|
|
149
|
+
splitSkillMarkdown,
|
|
150
|
+
stringList
|
|
151
|
+
};
|
package/dist/catalog/watcher.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { watch } from "node:fs";
|
|
1
|
+
import { existsSync, watch } from "node:fs";
|
|
2
2
|
export const WATCH_DEBOUNCE_MS = 500;
|
|
3
3
|
const WATCH_FALLBACK_MS = 2000;
|
|
4
4
|
/**
|
|
@@ -8,6 +8,7 @@ const WATCH_FALLBACK_MS = 2000;
|
|
|
8
8
|
*/
|
|
9
9
|
export function watchRoots(roots, onChange, opts) {
|
|
10
10
|
const debounceMs = opts.debounceMs ?? WATCH_DEBOUNCE_MS;
|
|
11
|
+
const watchFn = opts.watchFn ?? watch;
|
|
11
12
|
const watchers = [];
|
|
12
13
|
let timer;
|
|
13
14
|
let closed = false;
|
|
@@ -23,8 +24,12 @@ export function watchRoots(roots, onChange, opts) {
|
|
|
23
24
|
}, debounceMs);
|
|
24
25
|
};
|
|
25
26
|
for (const root of roots) {
|
|
27
|
+
if (!existsSync(root.path)) {
|
|
28
|
+
opts.log(`catalog watcher cannot watch root ${root.id} (${root.path}): path does not exist`);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
26
31
|
try {
|
|
27
|
-
const watcher =
|
|
32
|
+
const watcher = watchFn(root.path, { recursive: true, persistent: false }, schedule);
|
|
28
33
|
let failed = false;
|
|
29
34
|
watcher.on("error", (error) => {
|
|
30
35
|
if (failed)
|
package/dist/cli/init.js
CHANGED
|
@@ -6,6 +6,8 @@ import { DEFAULT_PORT, defaultConfigFile, ensureSkillarHome, expandHome, loadCon
|
|
|
6
6
|
import { PACKS, getPack } from "../packs/registry.js";
|
|
7
7
|
import { assertPlatform } from "../version.js";
|
|
8
8
|
import { WriterError, applyFiles, changedFiles, maskSecrets, removeEmptyDirs, restoreFiles, unifiedDiff, unparseable } from "./config-writer.js";
|
|
9
|
+
import { readConnection } from "../sync/cloud-connection.js";
|
|
10
|
+
import { connectCloudDeviceFlow } from "../sync/cloud-pending.js";
|
|
9
11
|
import { currentServicePlatform, daemonLogPath, nodePath, packageRoot, planService, servicePath, serviceLabel } from "./serve.js";
|
|
10
12
|
// Planning never writes: a first run plans against default config and an in-memory token, and materialize() persists
|
|
11
13
|
// both only once the apply starts, so dry runs and aborted runs leave HOME byte-identical.
|
|
@@ -202,6 +204,49 @@ export async function runInit(opts, env, io, hooks = {}) {
|
|
|
202
204
|
if (applied.files.some((f) => f.path === serviceFile))
|
|
203
205
|
io.out(`service log: ${daemonLogPath(skillarHome)}\n`);
|
|
204
206
|
io.out(`applied ${applied.files.length} file(s) and ${manifest.commands.length} command(s); backup set ${backupDir}\n`);
|
|
207
|
+
if (opts.connect === true) {
|
|
208
|
+
if (readConnection(skillarHome) !== null) {
|
|
209
|
+
io.out("cloud: already connected; skipping browser approval\n");
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
try {
|
|
213
|
+
const connected = await connectCloudDeviceFlow(skillarHome, {
|
|
214
|
+
origin: "https://skillar.sh", uploadIntent: opts.upload ?? false, env, io,
|
|
215
|
+
fetcher: hooks.fetcher, wait: hooks.wait,
|
|
216
|
+
});
|
|
217
|
+
io.out(`cloud: connected device ${connected.deviceId}\n`);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
io.err(`cloud connect failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
221
|
+
return 1;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else if (opts.serviceOnly !== true && opts.connect !== false &&
|
|
226
|
+
readConnection(skillarHome) === null && io.ask !== undefined) {
|
|
227
|
+
// Interactive TTY offer with default yes: --connect runs without asking,
|
|
228
|
+
// --no-connect skips, non-TTY skips without --connect, connected skips.
|
|
229
|
+
// The offer never implies upload consent (browser-side, default off).
|
|
230
|
+
const answer = (await io.ask("skillar.sh 계정에 이 기기를 연결할까요? 업로드 동의는 브라우저에서 직접 선택하며 기본은 로컬 전용입니다. [Y/n] ")).trim().toLowerCase();
|
|
231
|
+
if (answer === "" || answer === "y" || answer === "yes") {
|
|
232
|
+
try {
|
|
233
|
+
const connected = await connectCloudDeviceFlow(skillarHome, {
|
|
234
|
+
origin: "https://skillar.sh", uploadIntent: opts.upload ?? false, env, io,
|
|
235
|
+
fetcher: hooks.fetcher, wait: hooks.wait,
|
|
236
|
+
});
|
|
237
|
+
io.out(`cloud: connected device ${connected.deviceId}\n`);
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
// The offer is optional: a failed connect must not fail the completed
|
|
241
|
+
// install. Explicit --connect above still returns 1 on failure.
|
|
242
|
+
io.err(`cloud connect failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
243
|
+
io.out("설치는 완료됐습니다. 나중에 `skillar sync connect`로 다시 연결할 수 있습니다.\n");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
io.out("나중에 `skillar sync connect`로 연결할 수 있습니다.\n");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
205
250
|
return 0;
|
|
206
251
|
}
|
|
207
252
|
function undoRun(manifest, dir, env, io) {
|
package/dist/cli/main.js
CHANGED
|
@@ -5,6 +5,7 @@ import { ensureToken, loadConfig, resolveSkillarHome } from "../config.js";
|
|
|
5
5
|
import { runDoctor } from "./doctor.js";
|
|
6
6
|
import { runInit, serviceInstall, serviceRemove } from "./init.js";
|
|
7
7
|
import { runOpen } from "./open.js";
|
|
8
|
+
import { createInterface } from "node:readline";
|
|
8
9
|
import { makeCliDeps, packageVersion, processIo, runServe, serviceStatus } from "./serve.js";
|
|
9
10
|
const defaultLoaders = {
|
|
10
11
|
exportImport: () => import("./export-import.js"),
|
|
@@ -15,14 +16,27 @@ export const HELP = `skillar - local skill router
|
|
|
15
16
|
Usage:
|
|
16
17
|
skillar serve [--port <n>] [--foreground] run the daemon in the foreground (used by the service)
|
|
17
18
|
skillar open [--print] print and open the dashboard URL
|
|
18
|
-
skillar init [--dry-run] [--runtime <id>...] [--no-service] [--disable-remote]
|
|
19
|
+
skillar init [--dry-run] [--runtime <id>...] [--no-service] [--disable-remote] [--connect|--no-connect] [--upload]
|
|
19
20
|
skillar init --rollback [--all] undo the newest (or every) init run
|
|
20
21
|
skillar doctor [--json] check service, daemon, packs, index and backups
|
|
21
22
|
skillar service install|remove|status manage the LaunchAgent / systemd user unit
|
|
22
23
|
skillar mcp-stdio stdio MCP proxy to the local daemon
|
|
23
24
|
skillar export <dir> [--with-history]
|
|
24
25
|
skillar import <dir> [--dry-run]
|
|
26
|
+
skillar repair-loads --from <ms> --to <ms> [--limit <n>] [--session <id>...] [--after <event-id>] [--json]
|
|
25
27
|
skillar eval [--cases <file>] [--json]
|
|
28
|
+
skillar sync connect connect this device by one browser approval (no upload consent)
|
|
29
|
+
skillar sync connect --grant-file <path> advanced: connect with a downloaded grant file instead
|
|
30
|
+
skillar sync status|prepare|run|backfill|pause|rollback|disconnect
|
|
31
|
+
skillar sync restore --destination <db> --source-domain <id> --snapshot-id <id>
|
|
32
|
+
skillar skills preview --package <export.json> --destination-root <dir> --plan <file> [--allow-overwrite]
|
|
33
|
+
skillar skills push-preview --source-dir <dir> --plan <file> [--skill-id <uuid>]
|
|
34
|
+
skillar skills push --plan <file> --allow-private-upload
|
|
35
|
+
asks for one browser approval when skills scopes are missing
|
|
36
|
+
skillar skills pull --skill-id <uuid> --output <export.json> [--version <digest>]
|
|
37
|
+
same one-link approval when the read scope is missing
|
|
38
|
+
skillar skills apply --plan <file> apply locally; no cloud acknowledgement
|
|
39
|
+
skillar skills rollback --receipt <file> restore only matching installed files
|
|
26
40
|
skillar --help | --version
|
|
27
41
|
`;
|
|
28
42
|
class UsageError extends Error {
|
|
@@ -58,9 +72,21 @@ function oneDir(p, command) {
|
|
|
58
72
|
throw new UsageError(`${command} needs exactly one <dir>`);
|
|
59
73
|
return p.positional[0];
|
|
60
74
|
}
|
|
75
|
+
/** Interactive terminals get a prompt channel; piped/test runs stay non-interactive. */
|
|
76
|
+
function defaultIo() {
|
|
77
|
+
if (process.stdin.isTTY !== true)
|
|
78
|
+
return processIo;
|
|
79
|
+
return {
|
|
80
|
+
...processIo,
|
|
81
|
+
ask: (question) => new Promise(resolve => {
|
|
82
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
83
|
+
rl.question(question, answer => { rl.close(); resolve(answer); });
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
61
87
|
export async function runMain(argv, opts = {}) {
|
|
62
88
|
const env = opts.env ?? process.env;
|
|
63
|
-
const io = opts.io ??
|
|
89
|
+
const io = opts.io ?? defaultIo();
|
|
64
90
|
const loaders = opts.loaders ?? defaultLoaders;
|
|
65
91
|
const [command, ...rest] = argv;
|
|
66
92
|
try {
|
|
@@ -88,7 +114,9 @@ export async function runMain(argv, opts = {}) {
|
|
|
88
114
|
return await runOpen({ print: p.flags.has("--print") }, env, io);
|
|
89
115
|
}
|
|
90
116
|
case "init": {
|
|
91
|
-
const p = parseArgs(rest, { flags: ["--dry-run", "--rollback", "--all", "--no-service", "--disable-remote"], multi: ["--runtime"] });
|
|
117
|
+
const p = parseArgs(rest, { flags: ["--dry-run", "--rollback", "--all", "--no-service", "--disable-remote", "--connect", "--no-connect", "--upload"], multi: ["--runtime"] });
|
|
118
|
+
if (p.flags.has("--connect") && p.flags.has("--no-connect"))
|
|
119
|
+
throw new UsageError("--connect and --no-connect cannot be used together");
|
|
92
120
|
if (p.positional.length)
|
|
93
121
|
throw new UsageError(`unexpected argument ${p.positional[0]}`);
|
|
94
122
|
if (p.flags.has("--all") && !p.flags.has("--rollback"))
|
|
@@ -96,6 +124,8 @@ export async function runMain(argv, opts = {}) {
|
|
|
96
124
|
return await runInit({
|
|
97
125
|
dryRun: p.flags.has("--dry-run"), rollback: p.flags.has("--rollback"), all: p.flags.has("--all"),
|
|
98
126
|
noService: p.flags.has("--no-service"), disableRemote: p.flags.has("--disable-remote"), runtimes: p.values.get("--runtime") ?? [],
|
|
127
|
+
connect: p.flags.has("--connect") ? true : p.flags.has("--no-connect") ? false : undefined,
|
|
128
|
+
upload: p.flags.has("--upload"),
|
|
99
129
|
}, env, io);
|
|
100
130
|
}
|
|
101
131
|
case "doctor": {
|
|
@@ -130,11 +160,54 @@ export async function runMain(argv, opts = {}) {
|
|
|
130
160
|
const dir = oneDir(p, "import");
|
|
131
161
|
return await (await loaders.exportImport()).runImport(dir, { dryRun: p.flags.has("--dry-run") }, makeCliDeps(env));
|
|
132
162
|
}
|
|
163
|
+
case "repair-loads": {
|
|
164
|
+
const p = parseArgs(rest, { flags: ["--json"], values: ["--from", "--to", "--limit", "--after"], multi: ["--session"] });
|
|
165
|
+
if (p.positional.length)
|
|
166
|
+
throw new UsageError(`unexpected argument ${p.positional[0]}`);
|
|
167
|
+
const integer = (name, fallback) => {
|
|
168
|
+
const values = p.values.get(name);
|
|
169
|
+
if (values === undefined && fallback !== undefined)
|
|
170
|
+
return fallback;
|
|
171
|
+
if (values?.length !== 1 || !/^\d+$/.test(values[0]))
|
|
172
|
+
throw new UsageError(`${name} needs one nonnegative integer`);
|
|
173
|
+
const value = Number(values[0]);
|
|
174
|
+
if (!Number.isSafeInteger(value))
|
|
175
|
+
throw new UsageError(`${name} must be a safe integer`);
|
|
176
|
+
return value;
|
|
177
|
+
};
|
|
178
|
+
const from = integer("--from"), to = integer("--to"), limit = integer("--limit", 100);
|
|
179
|
+
if (from >= to)
|
|
180
|
+
throw new UsageError("--from must be less than --to");
|
|
181
|
+
if (limit < 1 || limit > 1000)
|
|
182
|
+
throw new UsageError("--limit must be between 1 and 1000");
|
|
183
|
+
const after = p.values.get("--after");
|
|
184
|
+
if (after !== undefined && after.length !== 1)
|
|
185
|
+
throw new UsageError("--after needs one event ID");
|
|
186
|
+
const sessionIds = p.values.get("--session");
|
|
187
|
+
if (sessionIds !== undefined && sessionIds.length === 0)
|
|
188
|
+
throw new UsageError("--session needs a session ID");
|
|
189
|
+
const store = makeCliDeps(env).openStore();
|
|
190
|
+
try {
|
|
191
|
+
const result = store.reconcileLoads({ from, to, limit,
|
|
192
|
+
...(after ? { after: after[0] } : {}), ...(sessionIds ? { sessionIds } : {}) });
|
|
193
|
+
const report = { examined: result.examined, repaired: result.repaired, pending: result.count, next: result.next };
|
|
194
|
+
io.out(p.flags.has("--json") ? JSON.stringify(report) + "\n"
|
|
195
|
+
: `examined: ${report.examined}; repaired: ${report.repaired}; pending in batch: ${report.pending}; next: ${report.next ?? "none"}\n`);
|
|
196
|
+
return 0;
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
store.close();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
133
202
|
case "eval": {
|
|
134
203
|
const p = parseArgs(rest, { flags: ["--json"], values: ["--cases"] });
|
|
135
204
|
const cases = p.values.get("--cases")?.[0];
|
|
136
205
|
return await (await loaders.evalApi()).runEval({ ...(cases ? { cases } : {}), json: p.flags.has("--json") }, makeCliDeps(env));
|
|
137
206
|
}
|
|
207
|
+
case "sync":
|
|
208
|
+
return await (await import("./sync.js")).runSync(rest, env, io);
|
|
209
|
+
case "skills":
|
|
210
|
+
return await (await import("./private-skills.js")).runPrivateSkills(rest, io, env);
|
|
138
211
|
default:
|
|
139
212
|
throw new UsageError(`unknown command ${command}`);
|
|
140
213
|
}
|