skillwiki 0.10.110 → 0.10.111

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.
Files changed (36) hide show
  1. package/dist/{chunk-5MV5SSRM.js → chunk-5IBLXGLY.js} +5 -3
  2. package/dist/chunk-6OQLBNKR.js +250 -0
  3. package/dist/chunk-GQWCTJTU.js +55 -0
  4. package/dist/{chunk-QU2CKXM4.js → chunk-HBJLFPQP.js} +91 -199
  5. package/dist/chunk-I2J3IJB7.js +54 -0
  6. package/dist/{chunk-WPJHDRTP.js → chunk-I6IRJCUJ.js} +12 -57
  7. package/dist/{chunk-NA3TZ4JN.js → chunk-JQV5KNPT.js} +8 -6
  8. package/dist/chunk-KWEYA3OE.js +60 -0
  9. package/dist/{chunk-KX5Y3GSX.js → chunk-MRPJ7X7W.js} +5 -3
  10. package/dist/{chunk-6X6PPQNI.js → chunk-OJJBZDPR.js} +162 -296
  11. package/dist/chunk-OSL4J7GF.js +32 -0
  12. package/dist/chunk-PYPPG7RF.js +126 -0
  13. package/dist/chunk-QESNTTVY.js +50 -0
  14. package/dist/chunk-TDBUJUYH.js +109 -0
  15. package/dist/{chunk-R2DJ7IJ5.js → chunk-UIEQIJXP.js} +5 -336
  16. package/dist/chunk-X5GL2FCU.js +344 -0
  17. package/dist/chunk-ZRGZBAVS.js +98 -0
  18. package/dist/cli.js +308 -298
  19. package/dist/{index-projection-6XGESSHV.js → index-projection-2K672CBO.js} +5 -3
  20. package/dist/journal-QU5IDXQF.js +13 -0
  21. package/dist/{managed-write-preflight-JPOBVVSU.js → managed-write-preflight-GRSHQYKC.js} +7 -4
  22. package/dist/migrate-PIB4QA54.js +21 -0
  23. package/dist/ready-S7F53Q2D.js +9 -0
  24. package/dist/runtime-GLMI5OCT.js +15 -0
  25. package/dist/skillwiki-mcp.js +12 -7
  26. package/dist/sources-D2MGP246.js +10 -0
  27. package/dist/upload-HTE62TOV.js +14 -0
  28. package/dist/watcher-MHG46J3R.js +616 -0
  29. package/docs/clip-outbox.md +119 -0
  30. package/package.json +5 -1
  31. package/skills/.claude-plugin/plugin.json +1 -1
  32. package/skills/.codex-plugin/plugin.json +1 -1
  33. package/skills/.cursor-plugin/plugin.json +1 -1
  34. package/skills/package.json +1 -1
  35. package/templates/launchd/com.karlchow.skillwiki-clip-outbox.plist +12 -13
  36. package/dist/sources-CLOF5VAT.js +0 -9
@@ -0,0 +1,344 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ err,
4
+ getErrorMessage,
5
+ ok
6
+ } from "./chunk-UIEQIJXP.js";
7
+
8
+ // src/parsers/frontmatter.ts
9
+ import yaml from "js-yaml";
10
+ var FM_OPEN = /^---\r?\n/;
11
+ function splitFrontmatter(text) {
12
+ if (!FM_OPEN.test(text)) return ok({ rawFrontmatter: "", body: text, bodyStart: 0 });
13
+ const afterOpen = text.replace(FM_OPEN, "");
14
+ const closeIdx = afterOpen.search(/\r?\n---\r?\n/);
15
+ if (closeIdx === -1) return err("MISSING_CLOSING_DELIMITER");
16
+ const rawFrontmatter = afterOpen.slice(0, closeIdx);
17
+ const closeMatch = afterOpen.slice(closeIdx).match(/\r?\n---\r?\n/);
18
+ const bodyStart = text.length - (afterOpen.length - closeIdx - closeMatch[0].length);
19
+ const body = text.slice(bodyStart);
20
+ return ok({ rawFrontmatter, body, bodyStart });
21
+ }
22
+ function extractFrontmatter(text) {
23
+ const split = splitFrontmatter(text);
24
+ if (!split.ok) return split;
25
+ if (!split.data.rawFrontmatter) return ok({});
26
+ try {
27
+ const parsed = yaml.load(split.data.rawFrontmatter, { schema: yaml.JSON_SCHEMA });
28
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return ok({});
29
+ return ok(parsed);
30
+ } catch (e) {
31
+ return err("INVALID_FRONTMATTER", { message: getErrorMessage(e) });
32
+ }
33
+ }
34
+
35
+ // src/utils/sensitive-content.ts
36
+ import { createHash } from "crypto";
37
+ var REDACTED_RE = /\[REDACTED:[^\]]+\]/i;
38
+ var SYNTHETIC_RE = /^(?:<[^>]+>|\$\{[^}]+\}|REPLACE_WITH_[A-Z0-9_]+|YOUR_[A-Z0-9_]+|EXAMPLE_[A-Z0-9_]+)$/i;
39
+ var MATCHERS = [
40
+ {
41
+ kind: "private_key",
42
+ re: /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g
43
+ },
44
+ {
45
+ kind: "authorization_header",
46
+ re: /\bAuthorization["']?\s*:\s*["']?(Bearer\s+[A-Za-z0-9._~+/-]{20,})["']?/gi,
47
+ valueGroup: 1
48
+ },
49
+ {
50
+ kind: "cookie",
51
+ re: /\b(?:Cookie|Set-Cookie)\s*:\s*([^\n]{20,})/gi,
52
+ valueGroup: 1
53
+ },
54
+ {
55
+ kind: "jwt",
56
+ re: /\b([A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{12,}\.[A-Za-z0-9_-]{12,})\b/g,
57
+ valueGroup: 1
58
+ },
59
+ {
60
+ kind: "provider_key",
61
+ re: /\b(sk-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{20,}|gh[pousr]_[A-Za-z0-9_=-]{20,})\b/g,
62
+ valueGroup: 1
63
+ },
64
+ {
65
+ kind: "access_key",
66
+ re: /\b((?:AKIA|ASIA)[A-Z0-9]{16})\b/g,
67
+ valueGroup: 1
68
+ },
69
+ {
70
+ kind: "access_key",
71
+ re: /\b(?:access[-_ ]?key|credential)["']?\s*[:=]\s*["']?([A-Za-z0-9._~+/-]{20,})["']?/gi,
72
+ valueGroup: 1
73
+ },
74
+ {
75
+ kind: "api_key",
76
+ re: /\b(?:api[-_ ]?key)["']?\s*[:=]\s*["']?([A-Za-z0-9._~+/-]{20,})["']?/gi,
77
+ valueGroup: 1
78
+ },
79
+ {
80
+ kind: "password",
81
+ re: /\b(?:password|passwd)["']?\s*[:=]\s*[`"']?([^\s`"']{8,})[`"']?/gi,
82
+ valueGroup: 1
83
+ },
84
+ {
85
+ kind: "secret",
86
+ re: /\b(?:secret|client[-_ ]?secret)["']?\s*[:=]\s*["']?([A-Za-z0-9._~+/-]{16,})["']?/gi,
87
+ valueGroup: 1
88
+ },
89
+ {
90
+ kind: "token",
91
+ re: /\b(?:token|session)["']?\s*[:=]\s*["']?([A-Za-z0-9._~+/-]{16,})["']?/gi,
92
+ valueGroup: 1
93
+ }
94
+ ];
95
+ function fingerprint(value) {
96
+ return createHash("sha256").update(value).digest("hex").slice(0, 12);
97
+ }
98
+ function lineFor(text, offset) {
99
+ return text.slice(0, offset).split(/\r?\n/).length;
100
+ }
101
+ function redactMarker(kind, value) {
102
+ return `[REDACTED:${kind}:${fingerprint(value)}]`;
103
+ }
104
+ function isSyntheticPlaceholder(value) {
105
+ return REDACTED_RE.test(value) || SYNTHETIC_RE.test(value.trim());
106
+ }
107
+ function isInsideRedactedMarker(text, start, end) {
108
+ for (const marker of text.matchAll(new RegExp(REDACTED_RE.source, "gi"))) {
109
+ const markerStart = marker.index ?? 0;
110
+ const markerEnd = markerStart + marker[0].length;
111
+ if (start >= markerStart && end <= markerEnd) return true;
112
+ }
113
+ return false;
114
+ }
115
+ function isNonSecretTokenCapture(value) {
116
+ if (value.startsWith("//")) return true;
117
+ if (value.includes("/")) return true;
118
+ if (/^[a-z0-9.]+(?:-[a-z0-9.]+)+$/.test(value) && !/^[0-9a-f]+(?:-[0-9a-f]+)+$/.test(value)) return true;
119
+ return false;
120
+ }
121
+ var PASSWORD_PROSE_SENTINELS = /* @__PURE__ */ new Set([
122
+ "generated",
123
+ "configured",
124
+ "required",
125
+ "optional",
126
+ "provided",
127
+ "disabled",
128
+ "enabled",
129
+ "undefined",
130
+ "unspecified",
131
+ "unknown"
132
+ ]);
133
+ function isNonSecretPasswordCapture(value) {
134
+ return PASSWORD_PROSE_SENTINELS.has(value.toLowerCase());
135
+ }
136
+ function collectMatches(text) {
137
+ const matches = [];
138
+ for (const matcher of MATCHERS) {
139
+ matcher.re.lastIndex = 0;
140
+ for (const m of text.matchAll(matcher.re)) {
141
+ const whole = m[0];
142
+ const start = m.index ?? 0;
143
+ if (REDACTED_RE.test(whole) || isInsideRedactedMarker(text, start, start + whole.length)) continue;
144
+ const value = matcher.valueGroup ? m[matcher.valueGroup] : whole;
145
+ if (isSyntheticPlaceholder(value)) continue;
146
+ if (matcher.kind === "token" && isNonSecretTokenCapture(value)) continue;
147
+ if (matcher.kind === "password" && isNonSecretPasswordCapture(value)) continue;
148
+ const valueOffset = whole.lastIndexOf(value);
149
+ const valueStart = start + Math.max(0, valueOffset);
150
+ matches.push({
151
+ start,
152
+ end: start + whole.length,
153
+ valueStart,
154
+ valueEnd: valueStart + value.length,
155
+ kind: matcher.kind
156
+ });
157
+ }
158
+ }
159
+ return matches.sort((a, b) => {
160
+ if (a.valueStart !== b.valueStart) return a.valueStart - b.valueStart;
161
+ return b.valueEnd - b.valueStart - (a.valueEnd - a.valueStart);
162
+ });
163
+ }
164
+ function collapseOverlaps(matches) {
165
+ const kept = [];
166
+ for (const match of matches) {
167
+ const overlaps = kept.some((k) => match.valueStart < k.valueEnd && match.valueEnd > k.valueStart);
168
+ if (!overlaps) kept.push(match);
169
+ }
170
+ return kept;
171
+ }
172
+ function scanSensitiveContent(text, opts = {}) {
173
+ return collapseOverlaps(collectMatches(text)).map((match) => {
174
+ const value = text.slice(match.valueStart, match.valueEnd);
175
+ const marker = redactMarker(match.kind, value);
176
+ const rawPreview = text.slice(Math.max(0, match.start - 24), Math.min(text.length, match.end + 24));
177
+ const preview = rawPreview.replace(value, marker);
178
+ return {
179
+ file: opts.file,
180
+ line: lineFor(text, match.valueStart),
181
+ kind: match.kind,
182
+ preview,
183
+ fingerprint: fingerprint(value)
184
+ };
185
+ });
186
+ }
187
+ function redactSensitiveContent(text, opts = {}) {
188
+ const matches = collapseOverlaps(collectMatches(text));
189
+ if (matches.length === 0) return { text, changed: false, findings: [] };
190
+ let out = "";
191
+ let cursor = 0;
192
+ for (const match of matches) {
193
+ const value = text.slice(match.valueStart, match.valueEnd);
194
+ out += text.slice(cursor, match.valueStart);
195
+ out += redactMarker(match.kind, value);
196
+ cursor = match.valueEnd;
197
+ }
198
+ out += text.slice(cursor);
199
+ return {
200
+ text: out,
201
+ changed: out !== text,
202
+ findings: scanSensitiveContent(text, opts)
203
+ };
204
+ }
205
+
206
+ // src/utils/vault.ts
207
+ import { existsSync, readFileSync } from "fs";
208
+ import { readFile, readdir, stat } from "fs/promises";
209
+ import { join, relative, sep } from "path";
210
+ import { execFileSync } from "child_process";
211
+ var TYPED_DIRS = ["entities", "concepts", "comparisons", "queries", "meta"];
212
+ var SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
213
+ var DEFAULT_IO_CONCURRENCY = 1;
214
+ function vaultIoConcurrency() {
215
+ const raw = Number.parseInt(process.env.SKILLWIKI_VAULT_IO_CONCURRENCY ?? "", 10);
216
+ return Number.isFinite(raw) && raw > 0 ? Math.min(raw, 64) : DEFAULT_IO_CONCURRENCY;
217
+ }
218
+ function decodeProcMountPath(value) {
219
+ return value.replace(/\\040/g, " ");
220
+ }
221
+ function isRcloneFuseVaultFromMounts(root, mounts) {
222
+ return mounts.split(/\r?\n/).some((line) => {
223
+ const parts = line.split(" ");
224
+ if (parts.length < 3) return false;
225
+ const mountPoint = decodeProcMountPath(parts[1]);
226
+ const fsType = parts[2];
227
+ return fsType === "fuse.rclone" && (root === mountPoint || root.startsWith(`${mountPoint}/`));
228
+ });
229
+ }
230
+ function resolveReadOnlyVaultRootWithMounts(root, mounts) {
231
+ if (/^(1|true|yes)$/i.test(process.env.SKILLWIKI_DISABLE_VAULT_READ_MIRROR ?? "")) {
232
+ return { root, mirrored: false };
233
+ }
234
+ const explicitMirror = process.env.SKILLWIKI_VAULT_READ_MIRROR;
235
+ if (explicitMirror && existsSync(join(explicitMirror, "SCHEMA.md"))) {
236
+ return { root: explicitMirror, mirrored: explicitMirror !== root };
237
+ }
238
+ const siblingMirror = `${root}-git`;
239
+ if (isRcloneFuseVaultFromMounts(root, mounts) && existsSync(join(siblingMirror, "SCHEMA.md"))) {
240
+ return { root: siblingMirror, mirrored: true };
241
+ }
242
+ return { root, mirrored: false };
243
+ }
244
+ function resolveReadOnlyVaultRoot(root) {
245
+ let mounts = "";
246
+ try {
247
+ mounts = readFileSync("/proc/mounts", "utf8");
248
+ } catch {
249
+ }
250
+ return resolveReadOnlyVaultRootWithMounts(root, mounts);
251
+ }
252
+ async function mapWithConcurrency(items, limit, mapper) {
253
+ const out = new Array(items.length);
254
+ let next = 0;
255
+ const workers = Array.from({ length: Math.min(Math.max(1, limit), items.length) }, async () => {
256
+ for (; ; ) {
257
+ const index = next++;
258
+ if (index >= items.length) return;
259
+ out[index] = await mapper(items[index], index);
260
+ }
261
+ });
262
+ await Promise.all(workers);
263
+ return out;
264
+ }
265
+ function filterGitIgnoredRelativePaths(root, relPaths) {
266
+ if (relPaths.length === 0 || !existsSync(join(root, ".git"))) {
267
+ return /* @__PURE__ */ new Set();
268
+ }
269
+ try {
270
+ const input = relPaths.join("\0") + "\0";
271
+ const stdout = execFileSync("git", ["check-ignore", "-z", "--stdin"], {
272
+ cwd: root,
273
+ input,
274
+ encoding: "utf8",
275
+ stdio: ["pipe", "pipe", "pipe"]
276
+ });
277
+ const ignored = stdout.split("\0").filter(Boolean);
278
+ return new Set(ignored);
279
+ } catch (error) {
280
+ if (error && typeof error === "object" && error.status === 1) {
281
+ return /* @__PURE__ */ new Set();
282
+ }
283
+ return /* @__PURE__ */ new Set();
284
+ }
285
+ }
286
+ async function scanVault(root) {
287
+ try {
288
+ await stat(join(root, "SCHEMA.md"));
289
+ } catch {
290
+ return err("VAULT_PATH_INVALID", { root, reason: "SCHEMA.md missing" });
291
+ }
292
+ const all = await walk(root);
293
+ const rawRels = all.map((p) => ({ absPath: p, relPath: relative(root, p).split(sep).join("/") }));
294
+ const ignored = filterGitIgnoredRelativePaths(root, rawRels.map((p) => p.relPath));
295
+ const rels = ignored.size > 0 ? rawRels.filter((p) => !ignored.has(p.relPath)) : rawRels;
296
+ return ok({
297
+ root,
298
+ allMarkdown: rels,
299
+ typedKnowledge: rels.filter((p) => TYPED_DIRS.some((d) => p.relPath.startsWith(d + "/"))),
300
+ raw: rels.filter((p) => p.relPath.startsWith("raw/")),
301
+ workItems: rels.filter((p) => /^projects\/[^/]+\/work\/[^/]+\/(spec|plan|log)\.md$/.test(p.relPath)),
302
+ compound: rels.filter((p) => /^projects\/[^/]+\/compound\//.test(p.relPath))
303
+ });
304
+ }
305
+ async function walk(dir) {
306
+ const entries = await readdir(dir, { withFileTypes: true });
307
+ const out = [];
308
+ const subdirs = [];
309
+ for (const e of entries) {
310
+ const p = join(dir, e.name);
311
+ if (e.isDirectory()) {
312
+ if (SKIP_DIRS.has(e.name)) continue;
313
+ subdirs.push(p);
314
+ } else if (e.isFile() && e.name.endsWith(".md")) out.push(p);
315
+ }
316
+ const nested = await mapWithConcurrency(subdirs, Math.min(8, vaultIoConcurrency()), walk);
317
+ for (const files of nested) out.push(...files);
318
+ return out;
319
+ }
320
+ async function readPage(p) {
321
+ return readFile(p.absPath, "utf8");
322
+ }
323
+ async function readPageCached(p, cache) {
324
+ if (!cache) return readPage(p);
325
+ const existing = cache.get(p.absPath);
326
+ if (existing) return existing;
327
+ const pending = readPage(p);
328
+ cache.set(p.absPath, pending);
329
+ return pending;
330
+ }
331
+
332
+ export {
333
+ splitFrontmatter,
334
+ extractFrontmatter,
335
+ scanSensitiveContent,
336
+ redactSensitiveContent,
337
+ vaultIoConcurrency,
338
+ resolveReadOnlyVaultRoot,
339
+ mapWithConcurrency,
340
+ filterGitIgnoredRelativePaths,
341
+ scanVault,
342
+ readPage,
343
+ readPageCached
344
+ };
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ DELETE_INTENT_DIR,
4
+ DELETE_INTENT_SCHEMA,
5
+ pathToIntentFilename
6
+ } from "./chunk-QESNTTVY.js";
7
+
8
+ // src/clip-outbox/upload.ts
9
+ import { createHash } from "crypto";
10
+ import { PutObjectCommand, GetObjectCommand, S3ServiceException } from "@aws-sdk/client-s3";
11
+ function sha256Hex(body) {
12
+ return createHash("sha256").update(body).digest("hex");
13
+ }
14
+ function parseDestination(destination) {
15
+ const colon = destination.indexOf(":");
16
+ if (colon <= 0) throw new Error("invalid destination");
17
+ const remote = destination.slice(0, colon);
18
+ const rest = destination.slice(colon + 1);
19
+ const slash = rest.indexOf("/");
20
+ if (slash <= 0) return { remote, bucket: rest, prefix: "" };
21
+ return { remote, bucket: rest.slice(0, slash), prefix: rest.slice(slash + 1) };
22
+ }
23
+ function createS3CreateOnlyPut(opts) {
24
+ const prefix = opts.prefix ?? "";
25
+ const resolveKey = (rel) => [prefix, rel].filter(Boolean).join("/");
26
+ return async (key, body) => {
27
+ if (!/^raw\/(articles|assets)\/[A-Za-z0-9._/-]+$/.test(key) || key.split("/").some((s) => s === ".." || s === "." || !s)) throw new Error("unsafe upload key");
28
+ const objectKey = resolveKey(key);
29
+ const parts = key.split("/");
30
+ for (let count = 1; count <= parts.length; count++) {
31
+ const target = parts.slice(0, count).join("/");
32
+ let intentBody;
33
+ try {
34
+ const intent2 = await opts.client.send(new GetObjectCommand({ Bucket: opts.bucket, Key: resolveKey(`${DELETE_INTENT_DIR}/${pathToIntentFilename(target)}`) }));
35
+ if (!intent2.Body) throw new Error("DELETE_INTENT_UNAVAILABLE");
36
+ intentBody = Buffer.from(await intent2.Body.transformToByteArray());
37
+ } catch (error) {
38
+ if (error.$metadata?.httpStatusCode === 404 || error.name === "NoSuchKey") continue;
39
+ throw error;
40
+ }
41
+ const intent = JSON.parse(intentBody.toString("utf8"));
42
+ if (intent.schema !== DELETE_INTENT_SCHEMA || intent.path !== target || !["remove", "archive"].includes(intent.action ?? "")) throw new Error("DELETE_INTENT_UNAVAILABLE");
43
+ if (!intent.expires || !Number.isFinite(Date.parse(intent.expires)) || Date.parse(intent.expires) > Date.now()) throw new Error("TOMBSTONE_HOLD");
44
+ }
45
+ const inspect = async () => {
46
+ try {
47
+ const existing = await opts.client.send(new GetObjectCommand({ Bucket: opts.bucket, Key: objectKey }));
48
+ if (!existing.Body) throw new Error("missing S3 response body");
49
+ const bytes = Buffer.from(await existing.Body.transformToByteArray());
50
+ return bytes.length === body.length && sha256Hex(bytes) === sha256Hex(body) ? "idempotent" : "conflict";
51
+ } catch (error) {
52
+ if (error.$metadata?.httpStatusCode === 404 || error.name === "NoSuchKey") return "absent";
53
+ throw error;
54
+ }
55
+ };
56
+ const prior = await inspect();
57
+ if (prior !== "absent") return { status: prior };
58
+ try {
59
+ await opts.client.send(new PutObjectCommand({
60
+ Bucket: opts.bucket,
61
+ Key: objectKey,
62
+ Body: body,
63
+ IfNoneMatch: "*"
64
+ }));
65
+ } catch (error) {
66
+ const name = error instanceof S3ServiceException ? error.name : error.name;
67
+ const status = error.$metadata?.httpStatusCode;
68
+ if (name === "PreconditionFailed" || status === 412) {
69
+ const outcome = await inspect();
70
+ if (outcome !== "absent") return { status: outcome };
71
+ }
72
+ throw error;
73
+ }
74
+ const verified = await inspect();
75
+ if (verified === "absent") throw new Error("S3 verification pending");
76
+ return { status: verified === "conflict" ? "conflict" : "created" };
77
+ };
78
+ }
79
+ async function uploadBundle(opts) {
80
+ for (const asset of opts.assets) {
81
+ const result = await opts.put(asset.key, asset.body);
82
+ if (result.status === "conflict") {
83
+ return { ok: false, reason: `asset conflict: ${asset.key}`, articlePut: false };
84
+ }
85
+ }
86
+ const article = await opts.put(opts.articleKey, opts.article);
87
+ if (article.status === "conflict") {
88
+ return { ok: false, reason: `article conflict: ${opts.articleKey}`, articlePut: false };
89
+ }
90
+ return { ok: true };
91
+ }
92
+
93
+ export {
94
+ sha256Hex,
95
+ parseDestination,
96
+ createS3CreateOnlyPut,
97
+ uploadBundle
98
+ };