@thehumanpatternlab/hpl 1.0.2 → 1.0.3
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/src/commands/capabilities.js +3 -3
- package/dist/src/commands/version.js +2 -2
- package/dist/src/contract/capabilities.js +2 -2
- package/dist/src/contract/envelope.js +1 -1
- package/dist/src/http/client.js +1 -1
- package/dist/src/render/text.js +1 -1
- package/package.json +72 -72
- package/dist/__tests__/config.test.js +0 -22
- package/dist/__tests__/outputContract.test.js +0 -58
- package/dist/cli/output.js +0 -21
- package/dist/cli/outputContract.js +0 -32
- package/dist/commands/notesSync.js +0 -191
- package/dist/commands/publish.js +0 -36
- package/dist/index.js +0 -36
- package/dist/lab.js +0 -10
- package/dist/lib/config.js +0 -52
- package/dist/lib/http.js +0 -18
- package/dist/lib/notes.js +0 -62
- package/dist/lib/output.js +0 -21
- package/dist/sdk/LabClient.js +0 -94
- package/dist/src/__tests__/config.test.js +0 -22
- package/dist/src/__tests__/outputContract.test.js +0 -58
- package/dist/src/commands/notesSync.js +0 -191
- package/dist/sync/summary.js +0 -25
- package/dist/sync/types.js +0 -2
- package/dist/utils/loadMarkdown.js +0 -10
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import { writeHuman, writeJson } from "../io.js";
|
|
6
6
|
import { EXIT } from "../contract/exitCodes.js";
|
|
7
|
-
import { getAlphaIntent } from "../contract/intents";
|
|
8
|
-
import { ok } from "../contract/envelope";
|
|
9
|
-
import { getCapabilitiesAlpha } from "../contract/capabilities";
|
|
7
|
+
import { getAlphaIntent } from "../contract/intents.js";
|
|
8
|
+
import { ok } from "../contract/envelope.js";
|
|
9
|
+
import { getCapabilitiesAlpha } from "../contract/capabilities.js";
|
|
10
10
|
export function capabilitiesCommand() {
|
|
11
11
|
return new Command("capabilities")
|
|
12
12
|
.description("Show CLI capabilities for agents (contract: show_capabilities)")
|
|
@@ -5,8 +5,8 @@ import { Command } from "commander";
|
|
|
5
5
|
import { writeHuman, writeJson } from "../io.js";
|
|
6
6
|
import { EXIT } from "../contract/exitCodes.js";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
|
-
import { getAlphaIntent } from "../contract/intents";
|
|
9
|
-
import { ok } from "../contract/envelope";
|
|
8
|
+
import { getAlphaIntent } from "../contract/intents.js";
|
|
9
|
+
import { ok } from "../contract/envelope.js";
|
|
10
10
|
const require = createRequire(import.meta.url);
|
|
11
11
|
const pkg = require("../../package.json");
|
|
12
12
|
export function versionCommand() {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
Purpose: Capability disclosure for AI agents (no assumptions).
|
|
5
5
|
Contract: show_capabilities MUST emit tier, intents, schema versions.
|
|
6
6
|
=========================================================== */
|
|
7
|
-
import { CLI_SCHEMA_VERSION } from "./schema";
|
|
8
|
-
import { listAlphaIntents } from "./intents";
|
|
7
|
+
import { CLI_SCHEMA_VERSION } from "./schema.js";
|
|
8
|
+
import { listAlphaIntents } from "./intents.js";
|
|
9
9
|
export function getCapabilitiesAlpha() {
|
|
10
10
|
return {
|
|
11
11
|
intentTier: "alpha",
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
Purpose: Single source of truth for contract-compliant JSON output.
|
|
5
5
|
Guarantee: When --json, stdout emits JSON only (no logs).
|
|
6
6
|
=========================================================== */
|
|
7
|
-
import { CLI_SCHEMA_VERSION } from "./schema";
|
|
7
|
+
import { CLI_SCHEMA_VERSION } from "./schema.js";
|
|
8
8
|
export function ok(command, intent, data) {
|
|
9
9
|
return { schemaVersion: CLI_SCHEMA_VERSION, command, status: "ok", intent, data };
|
|
10
10
|
}
|
package/dist/src/http/client.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
Notes:
|
|
6
6
|
- Supports both raw API payloads and envelope form { ok: true, data: ... }.
|
|
7
7
|
=========================================================== */
|
|
8
|
-
import { getConfig } from "../config";
|
|
8
|
+
import { getConfig } from "../config.js";
|
|
9
9
|
export class HttpError extends Error {
|
|
10
10
|
status;
|
|
11
11
|
body;
|
package/dist/src/render/text.js
CHANGED
package/package.json
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@thehumanpatternlab/hpl",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "AI-forward, automation-safe SDK and CLI for the Human Pattern Lab",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/AdaInTheLab/the-human-pattern-lab-cli.git"
|
|
10
|
-
},
|
|
11
|
-
"homepage": "https://github.com/AdaInTheLab/the-human-pattern-lab-cli#readme",
|
|
12
|
-
"bugs": {
|
|
13
|
-
"url": "https://github.com/AdaInTheLab/the-human-pattern-lab-cli/issues"
|
|
14
|
-
},
|
|
15
|
-
"publishConfig": {
|
|
16
|
-
"access": "public"
|
|
17
|
-
},
|
|
18
|
-
"files": [
|
|
19
|
-
"dist",
|
|
20
|
-
"README.md",
|
|
21
|
-
"LICENSE"
|
|
22
|
-
],
|
|
23
|
-
"bin": {
|
|
24
|
-
"hpl": "./dist/bin/hpl.js"
|
|
25
|
-
},
|
|
26
|
-
"main": "./dist/index.js",
|
|
27
|
-
"types": "./dist/index.d.ts",
|
|
28
|
-
"exports": {
|
|
29
|
-
".": {
|
|
30
|
-
"types": "./dist/index.d.ts",
|
|
31
|
-
"import": "./dist/index.js"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"dev": "tsx ./bin/hpl.ts",
|
|
36
|
-
"build": "tsc -p tsconfig.json",
|
|
37
|
-
"start": "node ./dist/bin/hpl.js",
|
|
38
|
-
"test": "vitest run",
|
|
39
|
-
"test:watch": "vitest",
|
|
40
|
-
"json:check": "tsx ./bin/hpl.ts --json version | node -e \"JSON.parse(require('fs').readFileSync(0,'utf8'))\"",
|
|
41
|
-
"lint": "node -e \"console.log('lint: add eslint when ready')\""
|
|
42
|
-
},
|
|
43
|
-
"dependencies": {
|
|
44
|
-
"commander": "^12.1.0",
|
|
45
|
-
"execa": "^9.6.1",
|
|
46
|
-
"gray-matter": "^4.0.3",
|
|
47
|
-
"zod": "^3.24.1"
|
|
48
|
-
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@types/node": "^22.19.3",
|
|
51
|
-
"tsx": "^4.19.2",
|
|
52
|
-
"typescript": "^5.7.2",
|
|
53
|
-
"vitest": "^4.0.16"
|
|
54
|
-
},
|
|
55
|
-
"engines": {
|
|
56
|
-
"node": ">=18"
|
|
57
|
-
},
|
|
58
|
-
"keywords": [
|
|
59
|
-
"human-pattern-lab",
|
|
60
|
-
"hpl",
|
|
61
|
-
"ai",
|
|
62
|
-
"ai-forward",
|
|
63
|
-
"automation",
|
|
64
|
-
"automation-safe",
|
|
65
|
-
"cli",
|
|
66
|
-
"sdk",
|
|
67
|
-
"developer-tools",
|
|
68
|
-
"observability",
|
|
69
|
-
"notes",
|
|
70
|
-
"knowledge-systems"
|
|
71
|
-
]
|
|
72
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@thehumanpatternlab/hpl",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "AI-forward, automation-safe SDK and CLI for the Human Pattern Lab",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/AdaInTheLab/the-human-pattern-lab-cli.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/AdaInTheLab/the-human-pattern-lab-cli#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/AdaInTheLab/the-human-pattern-lab-cli/issues"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"bin": {
|
|
24
|
+
"hpl": "./dist/bin/hpl.js"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"dev": "tsx ./bin/hpl.ts",
|
|
36
|
+
"build": "tsc -p tsconfig.json",
|
|
37
|
+
"start": "node ./dist/bin/hpl.js",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"test:watch": "vitest",
|
|
40
|
+
"json:check": "tsx ./bin/hpl.ts --json version | node -e \"JSON.parse(require('fs').readFileSync(0,'utf8'))\"",
|
|
41
|
+
"lint": "node -e \"console.log('lint: add eslint when ready')\""
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"commander": "^12.1.0",
|
|
45
|
+
"execa": "^9.6.1",
|
|
46
|
+
"gray-matter": "^4.0.3",
|
|
47
|
+
"zod": "^3.24.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^22.19.3",
|
|
51
|
+
"tsx": "^4.19.2",
|
|
52
|
+
"typescript": "^5.7.2",
|
|
53
|
+
"vitest": "^4.0.16"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18"
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"human-pattern-lab",
|
|
60
|
+
"hpl",
|
|
61
|
+
"ai",
|
|
62
|
+
"ai-forward",
|
|
63
|
+
"automation",
|
|
64
|
+
"automation-safe",
|
|
65
|
+
"cli",
|
|
66
|
+
"sdk",
|
|
67
|
+
"developer-tools",
|
|
68
|
+
"observability",
|
|
69
|
+
"notes",
|
|
70
|
+
"knowledge-systems"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, beforeEach } from 'vitest';
|
|
2
|
-
import { SKULK_BASE_URL, SKULK_TOKEN } from '../lib/config.js';
|
|
3
|
-
describe('env config', () => {
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
delete process.env.SKULK_BASE_URL;
|
|
6
|
-
delete process.env.SKULK_TOKEN;
|
|
7
|
-
delete process.env.HPL_API_BASE_URL;
|
|
8
|
-
delete process.env.HPL_TOKEN;
|
|
9
|
-
});
|
|
10
|
-
it('uses SKULK_TOKEN when set', () => {
|
|
11
|
-
process.env.SKULK_TOKEN = 'abc123';
|
|
12
|
-
expect(SKULK_TOKEN()).toBe('abc123');
|
|
13
|
-
});
|
|
14
|
-
it('uses SKULK_BASE_URL when set', () => {
|
|
15
|
-
process.env.SKULK_BASE_URL = 'https://example.com/api';
|
|
16
|
-
expect(SKULK_BASE_URL()).toBe('https://example.com/api');
|
|
17
|
-
});
|
|
18
|
-
it('override beats SKULK_BASE_URL', () => {
|
|
19
|
-
process.env.SKULK_BASE_URL = 'https://example.com/api';
|
|
20
|
-
expect(SKULK_BASE_URL('https://override.com/api')).toBe('https://override.com/api');
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { buildSyncReport } from '../cli/outputContract.js';
|
|
3
|
-
describe('buildSyncReport (JSON contract)', () => {
|
|
4
|
-
it('counts synced in live mode (dryRun=false)', () => {
|
|
5
|
-
const report = buildSyncReport({
|
|
6
|
-
dryRun: false,
|
|
7
|
-
locale: 'en',
|
|
8
|
-
baseUrl: 'https://example.com/api',
|
|
9
|
-
results: [
|
|
10
|
-
{ file: 'a.md', slug: 'a', status: 'ok', action: 'updated' },
|
|
11
|
-
{ file: 'b.md', slug: 'b', status: 'ok', action: 'created' },
|
|
12
|
-
],
|
|
13
|
-
});
|
|
14
|
-
expect(report.ok).toBe(true);
|
|
15
|
-
expect(report.summary).toEqual({
|
|
16
|
-
synced: 2,
|
|
17
|
-
dryRun: 0,
|
|
18
|
-
failed: 0,
|
|
19
|
-
total: 2,
|
|
20
|
-
});
|
|
21
|
-
expect(report.results.every((r) => r.written === true)).toBe(true);
|
|
22
|
-
});
|
|
23
|
-
it('counts dryRun in dry-run mode (dryRun=true)', () => {
|
|
24
|
-
const report = buildSyncReport({
|
|
25
|
-
dryRun: true,
|
|
26
|
-
results: [
|
|
27
|
-
{ file: 'a.md', slug: 'a', status: 'dry-run' },
|
|
28
|
-
{ file: 'b.md', slug: 'b', status: 'dry-run' },
|
|
29
|
-
],
|
|
30
|
-
});
|
|
31
|
-
expect(report.ok).toBe(true);
|
|
32
|
-
expect(report.dryRun).toBe(true);
|
|
33
|
-
expect(report.summary).toEqual({
|
|
34
|
-
synced: 0,
|
|
35
|
-
dryRun: 2,
|
|
36
|
-
failed: 0,
|
|
37
|
-
total: 2,
|
|
38
|
-
});
|
|
39
|
-
expect(report.results.every((r) => r.written === false)).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
it('normalizes legacy fail -> failed and keeps totals balanced', () => {
|
|
42
|
-
const report = buildSyncReport({
|
|
43
|
-
dryRun: false,
|
|
44
|
-
results: [
|
|
45
|
-
{ file: 'a.md', slug: 'a', status: 'ok' },
|
|
46
|
-
{ file: 'b.md', status: 'fail', error: 'boom' },
|
|
47
|
-
],
|
|
48
|
-
});
|
|
49
|
-
expect(report.ok).toBe(false);
|
|
50
|
-
expect(report.summary).toEqual({
|
|
51
|
-
synced: 1,
|
|
52
|
-
dryRun: 0,
|
|
53
|
-
failed: 1,
|
|
54
|
-
total: 2,
|
|
55
|
-
});
|
|
56
|
-
expect(report.results[1].status).toBe('failed');
|
|
57
|
-
});
|
|
58
|
-
});
|
package/dist/cli/output.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Output is a contract. If it breaks, it should break loudly.
|
|
2
|
-
function getRootCommand(cmd) {
|
|
3
|
-
let cur = cmd;
|
|
4
|
-
while (cur.parent)
|
|
5
|
-
cur = cur.parent;
|
|
6
|
-
return cur;
|
|
7
|
-
}
|
|
8
|
-
export function getOutputMode(cmd) {
|
|
9
|
-
const root = getRootCommand(cmd);
|
|
10
|
-
const opts = root.opts?.() ?? {};
|
|
11
|
-
return opts.json ? "json" : "human";
|
|
12
|
-
}
|
|
13
|
-
export function printJson(data) {
|
|
14
|
-
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
15
|
-
}
|
|
16
|
-
export function printError(message) {
|
|
17
|
-
process.stderr.write(message + "\n");
|
|
18
|
-
}
|
|
19
|
-
export function printJsonError(message, extra) {
|
|
20
|
-
process.stderr.write(JSON.stringify({ ok: false, error: { message, extra } }, null, 2) + "\n");
|
|
21
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// src/cli/outputContract.ts
|
|
2
|
-
import { buildSyncSummary } from "../sync/summary.js";
|
|
3
|
-
function normalizeResult(r, dryRunFlag) {
|
|
4
|
-
const status = r.status === "fail" ? "failed" : "ok"; // "dry-run" is not a failure
|
|
5
|
-
// If any result claims "dry-run", treat it as dry-run even if flag is off (safety)
|
|
6
|
-
const effectiveDryRun = dryRunFlag || r.status === "dry-run";
|
|
7
|
-
return {
|
|
8
|
-
file: r.file,
|
|
9
|
-
slug: r.slug,
|
|
10
|
-
status,
|
|
11
|
-
action: r.action,
|
|
12
|
-
error: r.error,
|
|
13
|
-
// written only when not dry-run and ok
|
|
14
|
-
written: !effectiveDryRun && status === "ok",
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export function buildSyncReport(args) {
|
|
18
|
-
const { results, dryRun, locale, baseUrl } = args;
|
|
19
|
-
const normalized = results.map((r) => normalizeResult(r, dryRun));
|
|
20
|
-
// IMPORTANT: pass the effective dryRun mode you used for written calc
|
|
21
|
-
// If you want to be ultra strict, you could compute effectiveDryRun = dryRun || any(r.status==="dry-run")
|
|
22
|
-
const effectiveDryRun = dryRun || results.some((r) => r.status === "dry-run");
|
|
23
|
-
const summary = buildSyncSummary(normalized, effectiveDryRun);
|
|
24
|
-
return {
|
|
25
|
-
ok: summary.failed === 0,
|
|
26
|
-
summary,
|
|
27
|
-
results: normalized,
|
|
28
|
-
dryRun: effectiveDryRun,
|
|
29
|
-
locale,
|
|
30
|
-
baseUrl,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/* ===========================================================
|
|
2
|
-
🦊 THE HUMAN PATTERN LAB — SKULK CLI
|
|
3
|
-
-----------------------------------------------------------
|
|
4
|
-
Author: Ada (Founder, The Human Pattern Lab)
|
|
5
|
-
Assistant: Lyric (AI Lab Companion)
|
|
6
|
-
File: notesSync.ts
|
|
7
|
-
Module: Notes Command Suite
|
|
8
|
-
Lab Unit: SCMS — Systems & Code Management Suite
|
|
9
|
-
Status: Active
|
|
10
|
-
-----------------------------------------------------------
|
|
11
|
-
Purpose:
|
|
12
|
-
Implements `skulk notes sync` — syncing local markdown Lab Notes
|
|
13
|
-
to the Lab API with predictable behavior in both human and
|
|
14
|
-
automation contexts.
|
|
15
|
-
-----------------------------------------------------------
|
|
16
|
-
Key Behaviors:
|
|
17
|
-
- Human mode: readable progress + summaries
|
|
18
|
-
- JSON mode (--json): stdout emits ONLY valid JSON (contract)
|
|
19
|
-
- Errors: stderr only
|
|
20
|
-
- Exit codes: deterministic (non-zero only on failure)
|
|
21
|
-
-----------------------------------------------------------
|
|
22
|
-
Notes:
|
|
23
|
-
JSON output is a contract. If it breaks, it should break loudly.
|
|
24
|
-
=========================================================== */
|
|
25
|
-
/**
|
|
26
|
-
* @file notesSync.ts
|
|
27
|
-
* @author Ada
|
|
28
|
-
* @assistant Lyric
|
|
29
|
-
* @lab-unit SCMS — Systems & Code Management Suite
|
|
30
|
-
* @since 2025-12-28
|
|
31
|
-
* @description Syncs markdown Lab Notes to the API via `skulk notes sync`.
|
|
32
|
-
* Supports human + JSON output modes; JSON mode is stdout-pure.
|
|
33
|
-
*/
|
|
34
|
-
import { Command } from 'commander';
|
|
35
|
-
import { SKULK_BASE_URL, SKULK_TOKEN } from '../lib/config.js';
|
|
36
|
-
import { httpJson } from '../lib/http.js';
|
|
37
|
-
import { listMarkdownFiles, readNote } from '../lib/notes.js';
|
|
38
|
-
import { getOutputMode, printJson } from '../cli/output.js';
|
|
39
|
-
import { buildSyncReport } from '../cli/outputContract.js';
|
|
40
|
-
import fs from 'node:fs';
|
|
41
|
-
async function upsertNote(baseUrl, token, note, locale) {
|
|
42
|
-
const payload = {
|
|
43
|
-
slug: note.slug,
|
|
44
|
-
title: note.attributes.title,
|
|
45
|
-
markdown: note.markdown,
|
|
46
|
-
locale,
|
|
47
|
-
};
|
|
48
|
-
if (!payload.slug || !payload.title || !payload.markdown) {
|
|
49
|
-
throw new Error(`Invalid note payload: slug/title/markdown missing for ${payload.slug ?? 'unknown'}`);
|
|
50
|
-
}
|
|
51
|
-
return httpJson({ baseUrl, token }, 'POST', '/lab-notes/upsert', payload);
|
|
52
|
-
}
|
|
53
|
-
export function notesSyncCommand() {
|
|
54
|
-
const notes = new Command('notes').description('Lab Notes commands');
|
|
55
|
-
notes
|
|
56
|
-
.command('sync')
|
|
57
|
-
.description('Sync local markdown notes to the API')
|
|
58
|
-
.option('--dir <path>', 'Directory containing markdown notes', './src/labnotes/en')
|
|
59
|
-
//.option("--dir <path>", "Directory containing markdown notes", "./labnotes/en")
|
|
60
|
-
.option('--locale <code>', 'Locale code', 'en')
|
|
61
|
-
.option('--base-url <url>', 'Override API base URL (ex: https://thehumanpatternlab.com/api)')
|
|
62
|
-
.option('--dry-run', 'Print what would be sent, but do not call the API', false)
|
|
63
|
-
.option('--only <slug>', 'Sync only a single note by slug')
|
|
64
|
-
.option('--limit <n>', 'Sync only the first N notes', (v) => parseInt(v, 10))
|
|
65
|
-
.action(async (opts, cmd) => {
|
|
66
|
-
const mode = getOutputMode(cmd); // "json" | "human"
|
|
67
|
-
const jsonError = (message, extra) => {
|
|
68
|
-
if (mode === 'json') {
|
|
69
|
-
process.stderr.write(JSON.stringify({ ok: false, error: { message, extra } }, null, 2) +
|
|
70
|
-
'\n');
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
console.error(message);
|
|
74
|
-
if (extra)
|
|
75
|
-
console.error(extra);
|
|
76
|
-
}
|
|
77
|
-
process.exitCode = 1;
|
|
78
|
-
};
|
|
79
|
-
if (!fs.existsSync(opts.dir)) {
|
|
80
|
-
jsonError(`Notes directory not found: ${opts.dir}`, {
|
|
81
|
-
hint: `Try: skulk notes sync --dir "..\\\\the-human-pattern-lab\\\\src\\\\labnotes\\\\en"`,
|
|
82
|
-
});
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const baseUrl = SKULK_BASE_URL(opts.baseUrl);
|
|
86
|
-
const token = SKULK_TOKEN();
|
|
87
|
-
const files = listMarkdownFiles(opts.dir);
|
|
88
|
-
let selectedFiles = files;
|
|
89
|
-
if (opts.only) {
|
|
90
|
-
selectedFiles = files.filter((f) => f.toLowerCase().includes(opts.only.toLowerCase()));
|
|
91
|
-
}
|
|
92
|
-
if (opts.limit && Number.isFinite(opts.limit)) {
|
|
93
|
-
selectedFiles = selectedFiles.slice(0, opts.limit);
|
|
94
|
-
}
|
|
95
|
-
if (selectedFiles.length === 0) {
|
|
96
|
-
if (mode === 'json') {
|
|
97
|
-
printJson({
|
|
98
|
-
ok: true,
|
|
99
|
-
action: 'noop',
|
|
100
|
-
message: 'No matching notes found.',
|
|
101
|
-
matched: 0,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
console.log('No matching notes found.');
|
|
106
|
-
}
|
|
107
|
-
process.exitCode = 0;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
// Human-mode header chatter
|
|
111
|
-
if (mode === 'human') {
|
|
112
|
-
console.log(`Skulk syncing ${selectedFiles.length} note(s) from ${opts.dir}`);
|
|
113
|
-
console.log(`API: ${baseUrl}`);
|
|
114
|
-
console.log(`Locale: ${opts.locale}`);
|
|
115
|
-
console.log(opts.dryRun ? 'Mode: DRY RUN (no writes)' : 'Mode: LIVE (writing)');
|
|
116
|
-
}
|
|
117
|
-
let ok = 0;
|
|
118
|
-
let fail = 0;
|
|
119
|
-
const results = [];
|
|
120
|
-
for (const file of selectedFiles) {
|
|
121
|
-
try {
|
|
122
|
-
const note = readNote(file, opts.locale);
|
|
123
|
-
if (opts.dryRun) {
|
|
124
|
-
ok++;
|
|
125
|
-
results.push({
|
|
126
|
-
file,
|
|
127
|
-
slug: note.slug,
|
|
128
|
-
status: 'dry-run',
|
|
129
|
-
});
|
|
130
|
-
if (mode === 'human') {
|
|
131
|
-
console.log(`\n---\n${note.slug}\n${file}\nfrontmatter keys: ${Object.keys(note.attributes).join(', ')}`);
|
|
132
|
-
}
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
const res = await upsertNote(baseUrl, token, note, opts.locale);
|
|
136
|
-
ok++;
|
|
137
|
-
results.push({
|
|
138
|
-
file,
|
|
139
|
-
slug: note.slug,
|
|
140
|
-
status: 'ok',
|
|
141
|
-
action: res.action,
|
|
142
|
-
});
|
|
143
|
-
if (mode === 'human') {
|
|
144
|
-
console.log(`✅ ${note.slug} (${res.action ?? 'ok'})`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
fail++;
|
|
149
|
-
const msg = String(e);
|
|
150
|
-
results.push({
|
|
151
|
-
file,
|
|
152
|
-
status: 'fail',
|
|
153
|
-
error: msg,
|
|
154
|
-
});
|
|
155
|
-
if (mode === 'human') {
|
|
156
|
-
console.error(`❌ ${file}`);
|
|
157
|
-
console.error(msg);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (mode === 'json') {
|
|
162
|
-
const report = buildSyncReport({
|
|
163
|
-
results,
|
|
164
|
-
dryRun: Boolean(opts.dryRun),
|
|
165
|
-
locale: opts.locale,
|
|
166
|
-
baseUrl,
|
|
167
|
-
});
|
|
168
|
-
printJson(report);
|
|
169
|
-
if (!report.ok)
|
|
170
|
-
process.exitCode = 1;
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
const report = buildSyncReport({
|
|
174
|
-
results,
|
|
175
|
-
dryRun: Boolean(opts.dryRun),
|
|
176
|
-
locale: opts.locale,
|
|
177
|
-
baseUrl,
|
|
178
|
-
});
|
|
179
|
-
const { synced, dryRun, failed } = report.summary;
|
|
180
|
-
if (report.dryRun) {
|
|
181
|
-
console.log(`\nDone. ${dryRun} note(s) would be synced (dry-run). Failures: ${failed}`);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
console.log(`\nDone. ${synced} note(s) synced successfully. Failures: ${failed}`);
|
|
185
|
-
}
|
|
186
|
-
if (!report.ok)
|
|
187
|
-
process.exitCode = 1;
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
return notes;
|
|
191
|
-
}
|
package/dist/commands/publish.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { loadMarkdown } from '../utils/loadMarkdown.js';
|
|
3
|
-
import { LabClient } from '../sdk/LabClient.js';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
const publish = new Command('publish')
|
|
6
|
-
.description('Publish a Lab Note from a Markdown file')
|
|
7
|
-
.argument('<file>', 'Markdown file to publish')
|
|
8
|
-
.option('-u, --url <url>', 'API base URL', 'https://thehumanpatternlab.com/api')
|
|
9
|
-
.option('-t, --token <token>', 'Auth token (if required)')
|
|
10
|
-
.action(async (file, options) => {
|
|
11
|
-
try {
|
|
12
|
-
const filePath = path.resolve(process.cwd(), file);
|
|
13
|
-
const { content, metadata } = loadMarkdown(filePath);
|
|
14
|
-
if (!metadata.title || !metadata.slug) {
|
|
15
|
-
console.error('Error: frontmatter must include at least: title, slug');
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
const client = new LabClient(options.url, options.token);
|
|
19
|
-
const payload = {
|
|
20
|
-
title: metadata.title,
|
|
21
|
-
slug: metadata.slug,
|
|
22
|
-
content,
|
|
23
|
-
tags: metadata.tags || [],
|
|
24
|
-
artifacts: metadata.artifacts || []
|
|
25
|
-
};
|
|
26
|
-
const result = await client.createOrUpdateNote(payload);
|
|
27
|
-
console.log(`✔ Published: ${metadata.title}`);
|
|
28
|
-
console.log(`→ slug: ${metadata.slug}`);
|
|
29
|
-
console.log(result.message);
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
console.error('Publish failed:', err.message);
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
export default publish;
|
package/dist/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* ===========================================================
|
|
3
|
-
🦊 THE HUMAN PATTERN LAB — SKULK CLI
|
|
4
|
-
-----------------------------------------------------------
|
|
5
|
-
File: notesSync.ts
|
|
6
|
-
Role: Command Implementation
|
|
7
|
-
Author: Ada (The Human Pattern Lab)
|
|
8
|
-
Assistant: Lyric
|
|
9
|
-
Status: Active
|
|
10
|
-
Description:
|
|
11
|
-
Implements the `skulk notes sync` command.
|
|
12
|
-
Handles human-readable and machine-readable output modes
|
|
13
|
-
with enforced JSON purity for automation safety.
|
|
14
|
-
-----------------------------------------------------------
|
|
15
|
-
Design Notes:
|
|
16
|
-
- Output format is a contract
|
|
17
|
-
- JSON mode emits stdout-only structured data
|
|
18
|
-
- Errors are written to stderr
|
|
19
|
-
- Exit codes are deterministic
|
|
20
|
-
=========================================================== */
|
|
21
|
-
import { Command } from "commander";
|
|
22
|
-
import { notesSyncCommand } from "./commands/notesSync.js";
|
|
23
|
-
const program = new Command();
|
|
24
|
-
program
|
|
25
|
-
.name("skulk")
|
|
26
|
-
.description("Skulk CLI for The Human Pattern Lab")
|
|
27
|
-
.version("0.1.0")
|
|
28
|
-
.option("--json", "Output machine-readable JSON")
|
|
29
|
-
.configureHelp({ helpWidth: 100 });
|
|
30
|
-
const argv = process.argv.slice(2);
|
|
31
|
-
if (argv.length === 0) {
|
|
32
|
-
program.outputHelp();
|
|
33
|
-
process.exit(0);
|
|
34
|
-
}
|
|
35
|
-
program.addCommand(notesSyncCommand());
|
|
36
|
-
program.parse(process.argv);
|
package/dist/lab.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
import publishCommand from './commands/publish.js';
|
|
4
|
-
const program = new Command();
|
|
5
|
-
program
|
|
6
|
-
.name('lab')
|
|
7
|
-
.description('CLI tools for The Human Pattern Lab')
|
|
8
|
-
.version('0.1.0');
|
|
9
|
-
program.addCommand(publishCommand);
|
|
10
|
-
program.parse();
|
package/dist/lib/config.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
/**
|
|
6
|
-
* Skulk CLI configuration schema
|
|
7
|
-
* Stored in ~/.humanpatternlab/skulk.json
|
|
8
|
-
*/
|
|
9
|
-
const ConfigSchema = z.object({
|
|
10
|
-
apiBaseUrl: z.string().url().default('https://thehumanpatternlab.com/api'),
|
|
11
|
-
token: z.string().optional(),
|
|
12
|
-
});
|
|
13
|
-
function getConfigPath() {
|
|
14
|
-
return path.join(os.homedir(), '.humanpatternlab', 'skulk.json');
|
|
15
|
-
}
|
|
16
|
-
export function loadConfig() {
|
|
17
|
-
const p = getConfigPath();
|
|
18
|
-
if (!fs.existsSync(p)) {
|
|
19
|
-
return ConfigSchema.parse({});
|
|
20
|
-
}
|
|
21
|
-
const raw = fs.readFileSync(p, 'utf-8');
|
|
22
|
-
return ConfigSchema.parse(JSON.parse(raw));
|
|
23
|
-
}
|
|
24
|
-
export function saveConfig(partial) {
|
|
25
|
-
const p = getConfigPath();
|
|
26
|
-
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
27
|
-
const current = loadConfig();
|
|
28
|
-
const next = ConfigSchema.parse({ ...current, ...partial });
|
|
29
|
-
fs.writeFileSync(p, JSON.stringify(next, null, 2), 'utf-8');
|
|
30
|
-
}
|
|
31
|
-
export function SKULK_BASE_URL(override) {
|
|
32
|
-
if (override?.trim())
|
|
33
|
-
return override.trim();
|
|
34
|
-
// NEW official env var
|
|
35
|
-
const env = process.env.SKULK_BASE_URL?.trim();
|
|
36
|
-
if (env)
|
|
37
|
-
return env;
|
|
38
|
-
// optional legacy support (remove later if you want)
|
|
39
|
-
const legacy = process.env.HPL_API_BASE_URL?.trim();
|
|
40
|
-
if (legacy)
|
|
41
|
-
return legacy;
|
|
42
|
-
return loadConfig().apiBaseUrl;
|
|
43
|
-
}
|
|
44
|
-
export function SKULK_TOKEN() {
|
|
45
|
-
const env = process.env.SKULK_TOKEN?.trim();
|
|
46
|
-
if (env)
|
|
47
|
-
return env;
|
|
48
|
-
const legacy = process.env.HPL_TOKEN?.trim();
|
|
49
|
-
if (legacy)
|
|
50
|
-
return legacy;
|
|
51
|
-
return loadConfig().token;
|
|
52
|
-
}
|
package/dist/lib/http.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export async function httpJson(opts, method, path, body) {
|
|
2
|
-
const url = `${opts.baseUrl.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
|
|
3
|
-
const headers = {
|
|
4
|
-
"Content-Type": "application/json"
|
|
5
|
-
};
|
|
6
|
-
if (opts.token)
|
|
7
|
-
headers["Authorization"] = `Bearer ${opts.token}`;
|
|
8
|
-
const res = await fetch(url, {
|
|
9
|
-
method,
|
|
10
|
-
headers,
|
|
11
|
-
body: body ? JSON.stringify(body) : undefined
|
|
12
|
-
});
|
|
13
|
-
const text = await res.text();
|
|
14
|
-
if (!res.ok) {
|
|
15
|
-
throw new Error(`HTTP ${res.status} ${res.statusText} @ ${url}\n${text}`);
|
|
16
|
-
}
|
|
17
|
-
return text ? JSON.parse(text) : {};
|
|
18
|
-
}
|
package/dist/lib/notes.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import matter from "gray-matter";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
const FrontmatterSchema = z.object({
|
|
6
|
-
id: z.string().optional(),
|
|
7
|
-
type: z.string().optional(),
|
|
8
|
-
title: z.string(),
|
|
9
|
-
subtitle: z.string().optional(),
|
|
10
|
-
published: z.string().optional(),
|
|
11
|
-
tags: z.array(z.string()).optional(),
|
|
12
|
-
summary: z.string().optional(),
|
|
13
|
-
readingTime: z.number().optional(),
|
|
14
|
-
status: z.enum(["published", "draft", "archived"]).optional(),
|
|
15
|
-
dept: z.string().optional(),
|
|
16
|
-
department_id: z.string().optional(),
|
|
17
|
-
shadow_density: z.number().optional(),
|
|
18
|
-
safer_landing: z.boolean().optional(),
|
|
19
|
-
slug: z.string().optional()
|
|
20
|
-
});
|
|
21
|
-
function slugFromFilename(filePath) {
|
|
22
|
-
const base = path.basename(filePath);
|
|
23
|
-
return base.replace(/\.mdx?$/i, "");
|
|
24
|
-
}
|
|
25
|
-
export function readNote(filePath, locale) {
|
|
26
|
-
const raw = fs.readFileSync(filePath, "utf-8");
|
|
27
|
-
const parsed = matter(raw);
|
|
28
|
-
const fm = FrontmatterSchema.parse(parsed.data ?? {});
|
|
29
|
-
const slug = (fm.slug && String(fm.slug).trim()) || slugFromFilename(filePath);
|
|
30
|
-
const body = parsed.content.trim();
|
|
31
|
-
const markdown = body.length > 0 ? body : raw.trim();
|
|
32
|
-
// Keep full attributes, but ensure key stuff exists
|
|
33
|
-
const title = (fm.title && String(fm.title).trim()) || "";
|
|
34
|
-
if (!title) {
|
|
35
|
-
throw new Error(`Missing required frontmatter: title (${filePath})`);
|
|
36
|
-
}
|
|
37
|
-
if (!markdown) {
|
|
38
|
-
throw new Error(`Missing required markdown content (${filePath})`);
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
slug,
|
|
42
|
-
locale,
|
|
43
|
-
attributes: { ...fm, slug },
|
|
44
|
-
markdown
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
export function listMarkdownFiles(dir) {
|
|
48
|
-
const out = [];
|
|
49
|
-
const stack = [dir];
|
|
50
|
-
while (stack.length) {
|
|
51
|
-
const d = stack.pop();
|
|
52
|
-
const entries = fs.readdirSync(d, { withFileTypes: true });
|
|
53
|
-
for (const e of entries) {
|
|
54
|
-
const p = path.join(d, e.name);
|
|
55
|
-
if (e.isDirectory())
|
|
56
|
-
stack.push(p);
|
|
57
|
-
else if (e.isFile() && /\.mdx?$/i.test(e.name))
|
|
58
|
-
out.push(p);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return out.sort();
|
|
62
|
-
}
|
package/dist/lib/output.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Output is a contract. If it breaks, it should break loudly.
|
|
2
|
-
function getRootCommand(cmd) {
|
|
3
|
-
let cur = cmd;
|
|
4
|
-
while (cur.parent)
|
|
5
|
-
cur = cur.parent;
|
|
6
|
-
return cur;
|
|
7
|
-
}
|
|
8
|
-
export function getOutputMode(cmd) {
|
|
9
|
-
const root = getRootCommand(cmd);
|
|
10
|
-
const opts = root.opts?.() ?? {};
|
|
11
|
-
return opts.json ? "json" : "human";
|
|
12
|
-
}
|
|
13
|
-
export function printJson(data) {
|
|
14
|
-
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
15
|
-
}
|
|
16
|
-
export function printError(message) {
|
|
17
|
-
process.stderr.write(message + "\n");
|
|
18
|
-
}
|
|
19
|
-
export function printJsonError(message, extra) {
|
|
20
|
-
process.stderr.write(JSON.stringify({ ok: false, error: { message, extra } }, null, 2) + "\n");
|
|
21
|
-
}
|
package/dist/sdk/LabClient.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// src/sdk/LabClient.ts
|
|
2
|
-
export class LabClient {
|
|
3
|
-
baseUrl;
|
|
4
|
-
token;
|
|
5
|
-
constructor(baseUrl, token) {
|
|
6
|
-
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
7
|
-
this.token = token;
|
|
8
|
-
}
|
|
9
|
-
setToken(token) {
|
|
10
|
-
this.token = token;
|
|
11
|
-
}
|
|
12
|
-
headers() {
|
|
13
|
-
const h = {
|
|
14
|
-
'Content-Type': 'application/json'
|
|
15
|
-
};
|
|
16
|
-
if (this.token) {
|
|
17
|
-
h['Authorization'] = `Bearer ${this.token}`;
|
|
18
|
-
}
|
|
19
|
-
return h;
|
|
20
|
-
}
|
|
21
|
-
//
|
|
22
|
-
// ────────────────────────────────────────────────
|
|
23
|
-
// PUBLIC ROUTES
|
|
24
|
-
// ────────────────────────────────────────────────
|
|
25
|
-
//
|
|
26
|
-
async getAllNotes() {
|
|
27
|
-
const res = await fetch(`${this.baseUrl}/`, {
|
|
28
|
-
method: 'GET',
|
|
29
|
-
headers: this.headers()
|
|
30
|
-
});
|
|
31
|
-
if (!res.ok)
|
|
32
|
-
throw new Error('Failed to fetch notes');
|
|
33
|
-
return res.json();
|
|
34
|
-
}
|
|
35
|
-
async getNoteBySlug(slug) {
|
|
36
|
-
const res = await fetch(`${this.baseUrl}/notes/${slug}`, {
|
|
37
|
-
method: 'GET',
|
|
38
|
-
headers: this.headers()
|
|
39
|
-
});
|
|
40
|
-
if (!res.ok)
|
|
41
|
-
throw new Error('Note not found');
|
|
42
|
-
return res.json();
|
|
43
|
-
}
|
|
44
|
-
//
|
|
45
|
-
// ────────────────────────────────────────────────
|
|
46
|
-
// ADMIN ROUTES
|
|
47
|
-
// ────────────────────────────────────────────────
|
|
48
|
-
//
|
|
49
|
-
async getAdminNotes() {
|
|
50
|
-
const res = await fetch(`${this.baseUrl}/api/admin/notes`, {
|
|
51
|
-
method: 'GET',
|
|
52
|
-
credentials: 'include',
|
|
53
|
-
headers: this.headers()
|
|
54
|
-
});
|
|
55
|
-
if (!res.ok)
|
|
56
|
-
throw new Error('Failed to fetch admin notes');
|
|
57
|
-
return res.json();
|
|
58
|
-
}
|
|
59
|
-
async createOrUpdateNote(input) {
|
|
60
|
-
const res = await fetch(`${this.baseUrl}/api/admin/notes`, {
|
|
61
|
-
method: 'POST',
|
|
62
|
-
credentials: 'include',
|
|
63
|
-
headers: this.headers(),
|
|
64
|
-
body: JSON.stringify(input)
|
|
65
|
-
});
|
|
66
|
-
if (!res.ok) {
|
|
67
|
-
const err = await res.json().catch(() => ({}));
|
|
68
|
-
throw new Error(err.error || 'Failed to save note');
|
|
69
|
-
}
|
|
70
|
-
return res.json();
|
|
71
|
-
}
|
|
72
|
-
async deleteNote(id) {
|
|
73
|
-
const res = await fetch(`${this.baseUrl}/api/admin/notes/${id}`, {
|
|
74
|
-
method: 'DELETE',
|
|
75
|
-
credentials: 'include',
|
|
76
|
-
headers: this.headers()
|
|
77
|
-
});
|
|
78
|
-
if (!res.ok)
|
|
79
|
-
throw new Error('Failed to delete note');
|
|
80
|
-
return res.json();
|
|
81
|
-
}
|
|
82
|
-
//
|
|
83
|
-
// ────────────────────────────────────────────────
|
|
84
|
-
// HEALTH
|
|
85
|
-
// ────────────────────────────────────────────────
|
|
86
|
-
//
|
|
87
|
-
async health() {
|
|
88
|
-
const res = await fetch(`${this.baseUrl}/api/health`, {
|
|
89
|
-
method: 'GET',
|
|
90
|
-
headers: this.headers()
|
|
91
|
-
});
|
|
92
|
-
return res.json();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, beforeEach } from 'vitest';
|
|
2
|
-
import { SKULK_BASE_URL, SKULK_TOKEN } from '../lib/config.js';
|
|
3
|
-
describe('env config', () => {
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
delete process.env.SKULK_BASE_URL;
|
|
6
|
-
delete process.env.SKULK_TOKEN;
|
|
7
|
-
delete process.env.HPL_API_BASE_URL;
|
|
8
|
-
delete process.env.HPL_TOKEN;
|
|
9
|
-
});
|
|
10
|
-
it('uses SKULK_TOKEN when set', () => {
|
|
11
|
-
process.env.SKULK_TOKEN = 'abc123';
|
|
12
|
-
expect(SKULK_TOKEN()).toBe('abc123');
|
|
13
|
-
});
|
|
14
|
-
it('uses SKULK_BASE_URL when set', () => {
|
|
15
|
-
process.env.SKULK_BASE_URL = 'https://example.com/api';
|
|
16
|
-
expect(SKULK_BASE_URL()).toBe('https://example.com/api');
|
|
17
|
-
});
|
|
18
|
-
it('override beats SKULK_BASE_URL', () => {
|
|
19
|
-
process.env.SKULK_BASE_URL = 'https://example.com/api';
|
|
20
|
-
expect(SKULK_BASE_URL('https://override.com/api')).toBe('https://override.com/api');
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { buildSyncReport } from '../cli/outputContract.js';
|
|
3
|
-
describe('buildSyncReport (JSON contract)', () => {
|
|
4
|
-
it('counts synced in live mode (dryRun=false)', () => {
|
|
5
|
-
const report = buildSyncReport({
|
|
6
|
-
dryRun: false,
|
|
7
|
-
locale: 'en',
|
|
8
|
-
baseUrl: 'https://example.com/api',
|
|
9
|
-
results: [
|
|
10
|
-
{ file: 'a.md', slug: 'a', status: 'ok', action: 'updated' },
|
|
11
|
-
{ file: 'b.md', slug: 'b', status: 'ok', action: 'created' },
|
|
12
|
-
],
|
|
13
|
-
});
|
|
14
|
-
expect(report.ok).toBe(true);
|
|
15
|
-
expect(report.summary).toEqual({
|
|
16
|
-
synced: 2,
|
|
17
|
-
dryRun: 0,
|
|
18
|
-
failed: 0,
|
|
19
|
-
total: 2,
|
|
20
|
-
});
|
|
21
|
-
expect(report.results.every((r) => r.written === true)).toBe(true);
|
|
22
|
-
});
|
|
23
|
-
it('counts dryRun in dry-run mode (dryRun=true)', () => {
|
|
24
|
-
const report = buildSyncReport({
|
|
25
|
-
dryRun: true,
|
|
26
|
-
results: [
|
|
27
|
-
{ file: 'a.md', slug: 'a', status: 'dry-run' },
|
|
28
|
-
{ file: 'b.md', slug: 'b', status: 'dry-run' },
|
|
29
|
-
],
|
|
30
|
-
});
|
|
31
|
-
expect(report.ok).toBe(true);
|
|
32
|
-
expect(report.dryRun).toBe(true);
|
|
33
|
-
expect(report.summary).toEqual({
|
|
34
|
-
synced: 0,
|
|
35
|
-
dryRun: 2,
|
|
36
|
-
failed: 0,
|
|
37
|
-
total: 2,
|
|
38
|
-
});
|
|
39
|
-
expect(report.results.every((r) => r.written === false)).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
it('normalizes legacy fail -> failed and keeps totals balanced', () => {
|
|
42
|
-
const report = buildSyncReport({
|
|
43
|
-
dryRun: false,
|
|
44
|
-
results: [
|
|
45
|
-
{ file: 'a.md', slug: 'a', status: 'ok' },
|
|
46
|
-
{ file: 'b.md', status: 'fail', error: 'boom' },
|
|
47
|
-
],
|
|
48
|
-
});
|
|
49
|
-
expect(report.ok).toBe(false);
|
|
50
|
-
expect(report.summary).toEqual({
|
|
51
|
-
synced: 1,
|
|
52
|
-
dryRun: 0,
|
|
53
|
-
failed: 1,
|
|
54
|
-
total: 2,
|
|
55
|
-
});
|
|
56
|
-
expect(report.results[1].status).toBe('failed');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/* ===========================================================
|
|
2
|
-
🦊 THE HUMAN PATTERN LAB — SKULK CLI
|
|
3
|
-
-----------------------------------------------------------
|
|
4
|
-
Author: Ada (Founder, The Human Pattern Lab)
|
|
5
|
-
Assistant: Lyric (AI Lab Companion)
|
|
6
|
-
File: notesSync.ts
|
|
7
|
-
Module: Notes Command Suite
|
|
8
|
-
Lab Unit: SCMS — Systems & Code Management Suite
|
|
9
|
-
Status: Active
|
|
10
|
-
-----------------------------------------------------------
|
|
11
|
-
Purpose:
|
|
12
|
-
Implements `skulk notes sync` — syncing local markdown Lab Notes
|
|
13
|
-
to the Lab API with predictable behavior in both human and
|
|
14
|
-
automation contexts.
|
|
15
|
-
-----------------------------------------------------------
|
|
16
|
-
Key Behaviors:
|
|
17
|
-
- Human mode: readable progress + summaries
|
|
18
|
-
- JSON mode (--json): stdout emits ONLY valid JSON (contract)
|
|
19
|
-
- Errors: stderr only
|
|
20
|
-
- Exit codes: deterministic (non-zero only on failure)
|
|
21
|
-
-----------------------------------------------------------
|
|
22
|
-
Notes:
|
|
23
|
-
JSON output is a contract. If it breaks, it should break loudly.
|
|
24
|
-
=========================================================== */
|
|
25
|
-
/**
|
|
26
|
-
* @file notesSync.ts
|
|
27
|
-
* @author Ada
|
|
28
|
-
* @assistant Lyric
|
|
29
|
-
* @lab-unit SCMS — Systems & Code Management Suite
|
|
30
|
-
* @since 2025-12-28
|
|
31
|
-
* @description Syncs markdown Lab Notes to the API via `skulk notes sync`.
|
|
32
|
-
* Supports human + JSON output modes; JSON mode is stdout-pure.
|
|
33
|
-
*/
|
|
34
|
-
import { Command } from 'commander';
|
|
35
|
-
import { SKULK_BASE_URL, SKULK_TOKEN } from '../lib/config.js';
|
|
36
|
-
import { httpJson } from '../lib/http.js';
|
|
37
|
-
import { listMarkdownFiles, readNote } from '../lib/notes.js';
|
|
38
|
-
import { getOutputMode, printJson } from '../cli/output.js';
|
|
39
|
-
import { buildSyncReport } from '../cli/outputContract.js';
|
|
40
|
-
import fs from 'node:fs';
|
|
41
|
-
async function upsertNote(baseUrl, token, note, locale) {
|
|
42
|
-
const payload = {
|
|
43
|
-
slug: note.slug,
|
|
44
|
-
title: note.attributes.title,
|
|
45
|
-
markdown: note.markdown,
|
|
46
|
-
locale,
|
|
47
|
-
};
|
|
48
|
-
if (!payload.slug || !payload.title || !payload.markdown) {
|
|
49
|
-
throw new Error(`Invalid note payload: slug/title/markdown missing for ${payload.slug ?? 'unknown'}`);
|
|
50
|
-
}
|
|
51
|
-
return httpJson({ baseUrl, token }, 'POST', '/lab-notes/upsert', payload);
|
|
52
|
-
}
|
|
53
|
-
export function notesSyncCommand() {
|
|
54
|
-
const notes = new Command('notes').description('Lab Notes commands');
|
|
55
|
-
notes
|
|
56
|
-
.command('sync')
|
|
57
|
-
.description('Sync local markdown notes to the API')
|
|
58
|
-
.option('--dir <path>', 'Directory containing markdown notes', './src/labnotes/en')
|
|
59
|
-
//.option("--dir <path>", "Directory containing markdown notes", "./labnotes/en")
|
|
60
|
-
.option('--locale <code>', 'Locale code', 'en')
|
|
61
|
-
.option('--base-url <url>', 'Override API base URL (ex: https://api.thehumanpatternlab.com)')
|
|
62
|
-
.option('--dry-run', 'Print what would be sent, but do not call the API', false)
|
|
63
|
-
.option('--only <slug>', 'Sync only a single note by slug')
|
|
64
|
-
.option('--limit <n>', 'Sync only the first N notes', (v) => parseInt(v, 10))
|
|
65
|
-
.action(async (opts, cmd) => {
|
|
66
|
-
const mode = getOutputMode(cmd); // "json" | "human"
|
|
67
|
-
const jsonError = (message, extra) => {
|
|
68
|
-
if (mode === 'json') {
|
|
69
|
-
process.stderr.write(JSON.stringify({ ok: false, error: { message, extra } }, null, 2) +
|
|
70
|
-
'\n');
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
console.error(message);
|
|
74
|
-
if (extra)
|
|
75
|
-
console.error(extra);
|
|
76
|
-
}
|
|
77
|
-
process.exitCode = 1;
|
|
78
|
-
};
|
|
79
|
-
if (!fs.existsSync(opts.dir)) {
|
|
80
|
-
jsonError(`Notes directory not found: ${opts.dir}`, {
|
|
81
|
-
hint: `Try: skulk notes sync --dir "..\\\\the-human-pattern-lab\\\\src\\\\labnotes\\\\en"`,
|
|
82
|
-
});
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const baseUrl = SKULK_BASE_URL(opts.baseUrl);
|
|
86
|
-
const token = SKULK_TOKEN();
|
|
87
|
-
const files = listMarkdownFiles(opts.dir);
|
|
88
|
-
let selectedFiles = files;
|
|
89
|
-
if (opts.only) {
|
|
90
|
-
selectedFiles = files.filter((f) => f.toLowerCase().includes(opts.only.toLowerCase()));
|
|
91
|
-
}
|
|
92
|
-
if (opts.limit && Number.isFinite(opts.limit)) {
|
|
93
|
-
selectedFiles = selectedFiles.slice(0, opts.limit);
|
|
94
|
-
}
|
|
95
|
-
if (selectedFiles.length === 0) {
|
|
96
|
-
if (mode === 'json') {
|
|
97
|
-
printJson({
|
|
98
|
-
ok: true,
|
|
99
|
-
action: 'noop',
|
|
100
|
-
message: 'No matching notes found.',
|
|
101
|
-
matched: 0,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
console.log('No matching notes found.');
|
|
106
|
-
}
|
|
107
|
-
process.exitCode = 0;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
// Human-mode header chatter
|
|
111
|
-
if (mode === 'human') {
|
|
112
|
-
console.log(`Skulk syncing ${selectedFiles.length} note(s) from ${opts.dir}`);
|
|
113
|
-
console.log(`API: ${baseUrl}`);
|
|
114
|
-
console.log(`Locale: ${opts.locale}`);
|
|
115
|
-
console.log(opts.dryRun ? 'Mode: DRY RUN (no writes)' : 'Mode: LIVE (writing)');
|
|
116
|
-
}
|
|
117
|
-
let ok = 0;
|
|
118
|
-
let fail = 0;
|
|
119
|
-
const results = [];
|
|
120
|
-
for (const file of selectedFiles) {
|
|
121
|
-
try {
|
|
122
|
-
const note = readNote(file, opts.locale);
|
|
123
|
-
if (opts.dryRun) {
|
|
124
|
-
ok++;
|
|
125
|
-
results.push({
|
|
126
|
-
file,
|
|
127
|
-
slug: note.slug,
|
|
128
|
-
status: 'dry-run',
|
|
129
|
-
});
|
|
130
|
-
if (mode === 'human') {
|
|
131
|
-
console.log(`\n---\n${note.slug}\n${file}\nfrontmatter keys: ${Object.keys(note.attributes).join(', ')}`);
|
|
132
|
-
}
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
const res = await upsertNote(baseUrl, token, note, opts.locale);
|
|
136
|
-
ok++;
|
|
137
|
-
results.push({
|
|
138
|
-
file,
|
|
139
|
-
slug: note.slug,
|
|
140
|
-
status: 'ok',
|
|
141
|
-
action: res.action,
|
|
142
|
-
});
|
|
143
|
-
if (mode === 'human') {
|
|
144
|
-
console.log(`✅ ${note.slug} (${res.action ?? 'ok'})`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
fail++;
|
|
149
|
-
const msg = String(e);
|
|
150
|
-
results.push({
|
|
151
|
-
file,
|
|
152
|
-
status: 'fail',
|
|
153
|
-
error: msg,
|
|
154
|
-
});
|
|
155
|
-
if (mode === 'human') {
|
|
156
|
-
console.error(`❌ ${file}`);
|
|
157
|
-
console.error(msg);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (mode === 'json') {
|
|
162
|
-
const report = buildSyncReport({
|
|
163
|
-
results,
|
|
164
|
-
dryRun: Boolean(opts.dryRun),
|
|
165
|
-
locale: opts.locale,
|
|
166
|
-
baseUrl,
|
|
167
|
-
});
|
|
168
|
-
printJson(report);
|
|
169
|
-
if (!report.ok)
|
|
170
|
-
process.exitCode = 1;
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
const report = buildSyncReport({
|
|
174
|
-
results,
|
|
175
|
-
dryRun: Boolean(opts.dryRun),
|
|
176
|
-
locale: opts.locale,
|
|
177
|
-
baseUrl,
|
|
178
|
-
});
|
|
179
|
-
const { synced, dryRun, failed } = report.summary;
|
|
180
|
-
if (report.dryRun) {
|
|
181
|
-
console.log(`\nDone. ${dryRun} note(s) would be synced (dry-run). Failures: ${failed}`);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
console.log(`\nDone. ${synced} note(s) synced successfully. Failures: ${failed}`);
|
|
185
|
-
}
|
|
186
|
-
if (!report.ok)
|
|
187
|
-
process.exitCode = 1;
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
return notes;
|
|
191
|
-
}
|
package/dist/sync/summary.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export function buildSyncSummary(results, dryRunMode) {
|
|
2
|
-
let synced = 0;
|
|
3
|
-
let dryRun = 0;
|
|
4
|
-
let failed = 0;
|
|
5
|
-
for (const r of results) {
|
|
6
|
-
if (r.status === "failed") {
|
|
7
|
-
failed++;
|
|
8
|
-
continue;
|
|
9
|
-
}
|
|
10
|
-
if (dryRunMode)
|
|
11
|
-
dryRun++;
|
|
12
|
-
else
|
|
13
|
-
synced++;
|
|
14
|
-
}
|
|
15
|
-
const total = results.length;
|
|
16
|
-
// Invariant: dry-run must never report synced writes
|
|
17
|
-
if (dryRunMode && synced > 0) {
|
|
18
|
-
throw new Error("Invariant violation: dry-run mode cannot produce synced > 0");
|
|
19
|
-
}
|
|
20
|
-
// Invariant: accounting must balance
|
|
21
|
-
if (synced + dryRun + failed !== total) {
|
|
22
|
-
throw new Error("SyncSummary invariant failed: counts do not add up to total");
|
|
23
|
-
}
|
|
24
|
-
return { synced, dryRun, failed, total };
|
|
25
|
-
}
|
package/dist/sync/types.js
DELETED