@wastedcode/memex 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +291 -0
  3. package/dist/cli/client.d.ts +35 -0
  4. package/dist/cli/client.js +183 -0
  5. package/dist/cli/client.js.map +1 -0
  6. package/dist/cli/commands/chown.d.ts +2 -0
  7. package/dist/cli/commands/chown.js +22 -0
  8. package/dist/cli/commands/chown.js.map +1 -0
  9. package/dist/cli/commands/config.d.ts +2 -0
  10. package/dist/cli/commands/config.js +132 -0
  11. package/dist/cli/commands/config.js.map +1 -0
  12. package/dist/cli/commands/create.d.ts +2 -0
  13. package/dist/cli/commands/create.js +21 -0
  14. package/dist/cli/commands/create.js.map +1 -0
  15. package/dist/cli/commands/destroy.d.ts +2 -0
  16. package/dist/cli/commands/destroy.js +34 -0
  17. package/dist/cli/commands/destroy.js.map +1 -0
  18. package/dist/cli/commands/ingest.d.ts +2 -0
  19. package/dist/cli/commands/ingest.js +74 -0
  20. package/dist/cli/commands/ingest.js.map +1 -0
  21. package/dist/cli/commands/lint.d.ts +2 -0
  22. package/dist/cli/commands/lint.js +46 -0
  23. package/dist/cli/commands/lint.js.map +1 -0
  24. package/dist/cli/commands/list.d.ts +2 -0
  25. package/dist/cli/commands/list.js +28 -0
  26. package/dist/cli/commands/list.js.map +1 -0
  27. package/dist/cli/commands/login.d.ts +2 -0
  28. package/dist/cli/commands/login.js +51 -0
  29. package/dist/cli/commands/login.js.map +1 -0
  30. package/dist/cli/commands/logs.d.ts +2 -0
  31. package/dist/cli/commands/logs.js +26 -0
  32. package/dist/cli/commands/logs.js.map +1 -0
  33. package/dist/cli/commands/query.d.ts +2 -0
  34. package/dist/cli/commands/query.js +48 -0
  35. package/dist/cli/commands/query.js.map +1 -0
  36. package/dist/cli/commands/serve.d.ts +2 -0
  37. package/dist/cli/commands/serve.js +14 -0
  38. package/dist/cli/commands/serve.js.map +1 -0
  39. package/dist/cli/commands/status.d.ts +2 -0
  40. package/dist/cli/commands/status.js +66 -0
  41. package/dist/cli/commands/status.js.map +1 -0
  42. package/dist/daemon/auth.d.ts +31 -0
  43. package/dist/daemon/auth.js +84 -0
  44. package/dist/daemon/auth.js.map +1 -0
  45. package/dist/daemon/db.d.ts +36 -0
  46. package/dist/daemon/db.js +181 -0
  47. package/dist/daemon/db.js.map +1 -0
  48. package/dist/daemon/namespace.d.ts +34 -0
  49. package/dist/daemon/namespace.js +74 -0
  50. package/dist/daemon/namespace.js.map +1 -0
  51. package/dist/daemon/peercred.d.ts +15 -0
  52. package/dist/daemon/peercred.js +19 -0
  53. package/dist/daemon/peercred.js.map +1 -0
  54. package/dist/daemon/queue.d.ts +26 -0
  55. package/dist/daemon/queue.js +126 -0
  56. package/dist/daemon/queue.js.map +1 -0
  57. package/dist/daemon/routes.d.ts +38 -0
  58. package/dist/daemon/routes.js +258 -0
  59. package/dist/daemon/routes.js.map +1 -0
  60. package/dist/daemon/runner.d.ts +25 -0
  61. package/dist/daemon/runner.js +195 -0
  62. package/dist/daemon/runner.js.map +1 -0
  63. package/dist/daemon/scaffold.d.ts +38 -0
  64. package/dist/daemon/scaffold.js +141 -0
  65. package/dist/daemon/scaffold.js.map +1 -0
  66. package/dist/daemon/server.d.ts +11 -0
  67. package/dist/daemon/server.js +145 -0
  68. package/dist/daemon/server.js.map +1 -0
  69. package/dist/daemon.d.ts +1 -0
  70. package/dist/daemon.js +55 -0
  71. package/dist/daemon.js.map +1 -0
  72. package/dist/index.d.ts +2 -0
  73. package/dist/index.js +36 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/lib/constants.d.ts +17 -0
  76. package/dist/lib/constants.js +30 -0
  77. package/dist/lib/constants.js.map +1 -0
  78. package/dist/lib/errors.d.ts +32 -0
  79. package/dist/lib/errors.js +64 -0
  80. package/dist/lib/errors.js.map +1 -0
  81. package/dist/lib/prompts/ingest.d.ts +9 -0
  82. package/dist/lib/prompts/ingest.js +48 -0
  83. package/dist/lib/prompts/ingest.js.map +1 -0
  84. package/dist/lib/prompts/lint.d.ts +8 -0
  85. package/dist/lib/prompts/lint.js +62 -0
  86. package/dist/lib/prompts/lint.js.map +1 -0
  87. package/dist/lib/prompts/query.d.ts +8 -0
  88. package/dist/lib/prompts/query.js +37 -0
  89. package/dist/lib/prompts/query.js.map +1 -0
  90. package/dist/lib/prompts/wiki.d.ts +11 -0
  91. package/dist/lib/prompts/wiki.js +112 -0
  92. package/dist/lib/prompts/wiki.js.map +1 -0
  93. package/dist/lib/types.d.ts +76 -0
  94. package/dist/lib/types.js +3 -0
  95. package/dist/lib/types.js.map +1 -0
  96. package/dist/standalone/memex.mjs +2313 -0
  97. package/dist/standalone/memex.mjs.map +7 -0
  98. package/package.json +54 -0
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { serveCommand } from './cli/commands/serve.js';
4
+ import { createCommand } from './cli/commands/create.js';
5
+ import { destroyCommand } from './cli/commands/destroy.js';
6
+ import { configCommand } from './cli/commands/config.js';
7
+ import { loginCommand } from './cli/commands/login.js';
8
+ import { ingestCommand } from './cli/commands/ingest.js';
9
+ import { queryCommand } from './cli/commands/query.js';
10
+ import { lintCommand } from './cli/commands/lint.js';
11
+ import { logsCommand } from './cli/commands/logs.js';
12
+ import { listCommand } from './cli/commands/list.js';
13
+ import { chownCommand } from './cli/commands/chown.js';
14
+ import { statusCommand } from './cli/commands/status.js';
15
+ const program = new Command();
16
+ program
17
+ .name('memex')
18
+ .description('Isolated, queued claude -p runtime for persistent knowledge bases')
19
+ .version('0.1.0');
20
+ program.addCommand(serveCommand);
21
+ program.addCommand(createCommand);
22
+ program.addCommand(destroyCommand);
23
+ program.addCommand(configCommand);
24
+ program.addCommand(loginCommand);
25
+ program.addCommand(ingestCommand);
26
+ program.addCommand(queryCommand);
27
+ program.addCommand(lintCommand);
28
+ program.addCommand(logsCommand);
29
+ program.addCommand(listCommand);
30
+ program.addCommand(chownCommand);
31
+ program.addCommand(statusCommand);
32
+ program.parseAsync().catch((err) => {
33
+ console.error(err.message ?? err);
34
+ process.exit(1);
35
+ });
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,OAAO,CAAC;KACb,WAAW,CAAC,mEAAmE,CAAC;KAChF,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAClC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AACnC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAClC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAClC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAChC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAChC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAChC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAElC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACjC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC;IAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { JobType, JobLimits } from './types.js';
2
+ export declare const DATA_DIR: string;
3
+ export declare const RUN_DIR: string;
4
+ export declare const SOCKET_PATH: string;
5
+ export declare const DB_PATH: string;
6
+ export declare const WIKIS_DIR: string;
7
+ export declare const NS_DIR: string;
8
+ export declare const WORKSPACE_MOUNT = "/workspace";
9
+ export declare const JOB_LIMITS: Record<JobType, JobLimits>;
10
+ export declare const SIGTERM_GRACE_MS = 5000;
11
+ export declare const AUTO_LINT_INTERVAL = 10;
12
+ export declare const JOB_POLL_INTERVAL_MS = 500;
13
+ export declare const DEFAULT_MODEL = "sonnet";
14
+ export declare const BASE_ALLOWED_TOOLS: string[];
15
+ /** Tools that may be added via .tools/allowed-tools.txt. Bash and other shell/code tools are excluded. */
16
+ export declare const ALLOWED_TOOLS_WHITELIST: Set<string>;
17
+ export declare const WIKI_ID_PATTERN: RegExp;
@@ -0,0 +1,30 @@
1
+ // ── Paths (overridable via env) ──────────────────────────────────────────────
2
+ export const DATA_DIR = process.env['MEMEX_DATA_DIR'] ?? '/var/lib/memex';
3
+ export const RUN_DIR = process.env['MEMEX_RUN_DIR'] ?? '/run/memex';
4
+ export const SOCKET_PATH = process.env['MEMEX_SOCKET_PATH'] ?? `${RUN_DIR}/memex.sock`;
5
+ export const DB_PATH = `${DATA_DIR}/memex.db`;
6
+ export const WIKIS_DIR = `${DATA_DIR}/wikis`;
7
+ export const NS_DIR = `${RUN_DIR}/ns`;
8
+ // Mount target inside namespaces — must exist on host as empty directory
9
+ export const WORKSPACE_MOUNT = '/workspace';
10
+ // ── Job limits ───────────────────────────────────────────────────────────────
11
+ export const JOB_LIMITS = {
12
+ ingest: { timeout_ms: 5 * 60_000, max_turns: 25 },
13
+ query: { timeout_ms: 2 * 60_000, max_turns: 15 },
14
+ lint: { timeout_ms: 10 * 60_000, max_turns: 30 },
15
+ };
16
+ // ── Process management ───────────────────────────────────────────────────────
17
+ export const SIGTERM_GRACE_MS = 5_000;
18
+ export const AUTO_LINT_INTERVAL = 10;
19
+ export const JOB_POLL_INTERVAL_MS = 500;
20
+ // ── Claude defaults ──────────────────────────────────────────────────────────
21
+ export const DEFAULT_MODEL = 'sonnet';
22
+ export const BASE_ALLOWED_TOOLS = ['Read', 'Write', 'Edit', 'Glob', 'Grep'];
23
+ /** Tools that may be added via .tools/allowed-tools.txt. Bash and other shell/code tools are excluded. */
24
+ export const ALLOWED_TOOLS_WHITELIST = new Set([
25
+ 'Read', 'Write', 'Edit', 'Glob', 'Grep',
26
+ 'NotebookEdit', 'WebFetch', 'WebSearch',
27
+ ]);
28
+ // ── Validation ───────────────────────────────────────────────────────────────
29
+ export const WIKI_ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,62}[a-z0-9]$/;
30
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAEhF,MAAM,CAAC,MAAM,QAAQ,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I,GAAG,CAAC;IAC7C,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IACvC,cAAc,EAAE,UAAU,EAAE,WAAW;CACxC,CAAC,CAAC;AAEH,gFAAgF;AAEhF,MAAM,CAAC,MAAM,eAAe,GAAG,mCAAmC,CAAC"}
@@ -0,0 +1,32 @@
1
+ export declare class MemexError extends Error {
2
+ code: string;
3
+ statusCode: number;
4
+ constructor(message: string, code: string, statusCode?: number);
5
+ }
6
+ export declare class WikiNotFoundError extends MemexError {
7
+ constructor(wikiId: string);
8
+ }
9
+ export declare class WikiExistsError extends MemexError {
10
+ constructor(wikiId: string);
11
+ }
12
+ export declare class JobNotFoundError extends MemexError {
13
+ constructor(jobId: number);
14
+ }
15
+ export declare class NamespaceError extends MemexError {
16
+ constructor(message: string);
17
+ }
18
+ export declare class CapabilityError extends MemexError {
19
+ constructor();
20
+ }
21
+ export declare class NoCredentialsError extends MemexError {
22
+ constructor(wikiId: string);
23
+ }
24
+ export declare class ForbiddenError extends MemexError {
25
+ constructor(wikiId: string);
26
+ }
27
+ export declare class ValidationError extends MemexError {
28
+ constructor(message: string);
29
+ }
30
+ export declare class DaemonNotRunningError extends MemexError {
31
+ constructor();
32
+ }
@@ -0,0 +1,64 @@
1
+ export class MemexError extends Error {
2
+ code;
3
+ statusCode;
4
+ constructor(message, code, statusCode = 500) {
5
+ super(message);
6
+ this.code = code;
7
+ this.statusCode = statusCode;
8
+ this.name = 'MemexError';
9
+ }
10
+ }
11
+ export class WikiNotFoundError extends MemexError {
12
+ constructor(wikiId) {
13
+ super(`Wiki '${wikiId}' not found`, 'WIKI_NOT_FOUND', 404);
14
+ }
15
+ }
16
+ export class WikiExistsError extends MemexError {
17
+ constructor(wikiId) {
18
+ super(`Wiki '${wikiId}' already exists`, 'WIKI_EXISTS', 409);
19
+ }
20
+ }
21
+ export class JobNotFoundError extends MemexError {
22
+ constructor(jobId) {
23
+ super(`Job #${jobId} not found`, 'JOB_NOT_FOUND', 404);
24
+ }
25
+ }
26
+ export class NamespaceError extends MemexError {
27
+ constructor(message) {
28
+ super(message, 'NAMESPACE_ERROR', 500);
29
+ }
30
+ }
31
+ export class CapabilityError extends MemexError {
32
+ constructor() {
33
+ super('CAP_SYS_ADMIN is required for mount namespace isolation.\n' +
34
+ 'Options:\n' +
35
+ ' 1. Run the daemon as root: sudo memex serve\n' +
36
+ ' 2. Use systemd with AmbientCapabilities=CAP_SYS_ADMIN\n' +
37
+ ' 3. Grant capability: sudo setcap cap_sys_admin+ep $(which node)', 'NO_CAP_SYS_ADMIN', 500);
38
+ }
39
+ }
40
+ export class NoCredentialsError extends MemexError {
41
+ constructor(wikiId) {
42
+ super(`No credentials configured for wiki '${wikiId}'.\n` +
43
+ 'Set credentials with:\n' +
44
+ ` memex login ${wikiId} (OAuth)\n` +
45
+ ` memex config ${wikiId} --set-key (API key)`, 'NO_CREDENTIALS', 400);
46
+ }
47
+ }
48
+ export class ForbiddenError extends MemexError {
49
+ constructor(wikiId) {
50
+ super(`Access denied to wiki '${wikiId}'`, 'FORBIDDEN', 403);
51
+ }
52
+ }
53
+ export class ValidationError extends MemexError {
54
+ constructor(message) {
55
+ super(message, 'VALIDATION_ERROR', 400);
56
+ }
57
+ }
58
+ export class DaemonNotRunningError extends MemexError {
59
+ constructor() {
60
+ super('Cannot connect to memex daemon.\n' +
61
+ 'Start it with: memex serve', 'DAEMON_NOT_RUNNING', 502);
62
+ }
63
+ }
64
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAG1B;IACA;IAHT,YACE,OAAe,EACR,IAAY,EACZ,aAAqB,GAAG;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAJ,IAAI,CAAQ;QACZ,eAAU,GAAV,UAAU,CAAc;QAG/B,IAAI,CAAC,IAA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ACzB,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,CAAC,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,UAAU;IACnD;QACE,KAAK,CACH,mCAAmC;YACnC,4BAA4B,EAC5B,oBAAoB,EACpB,GAAG,CACJ,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import type { IngestPayload } from '../types.js';
2
+ /**
3
+ * Build the prompt for an ingest job.
4
+ *
5
+ * Claude reads the raw source files and integrates them into the wiki.
6
+ * This is not just filing — it's building understanding. The wiki should
7
+ * get richer with every ingest, not just wider.
8
+ */
9
+ export declare function buildIngestPrompt(payload: IngestPayload): string;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Build the prompt for an ingest job.
3
+ *
4
+ * Claude reads the raw source files and integrates them into the wiki.
5
+ * This is not just filing — it's building understanding. The wiki should
6
+ * get richer with every ingest, not just wider.
7
+ */
8
+ export function buildIngestPrompt(payload) {
9
+ const fileList = payload.files
10
+ .map(f => `- raw/${f}`)
11
+ .join('\n');
12
+ return `New source documents have been added to the knowledge base.
13
+
14
+ Source files to process:
15
+ ${fileList}
16
+
17
+ Integrate these into the wiki:
18
+
19
+ 1. Read each source file listed above.
20
+ 2. Read _schema.md for current conventions (create it if it doesn't exist — this is a new knowledge base).
21
+ 3. Read _index.md to see what's already filed.
22
+ 4. Search existing wiki pages for related content (grep for names, topics, themes).
23
+ 5. For each source document:
24
+ a. Extract key facts, concepts, entities, and relationships.
25
+ b. Determine which existing pages should be updated and which new pages should be created.
26
+ c. Create or update wiki pages with the extracted information.
27
+ d. Maintain bidirectional links — if you link A→B, update B→A too.
28
+ e. Update _index.md with current summaries for all affected pages.
29
+ 6. Append a dated ingest entry to _log.md summarizing what was ingested and what pages were affected.
30
+
31
+ Rules:
32
+ - NEVER modify files in raw/ — they are immutable sources
33
+ - Prefer updating existing pages over creating duplicates
34
+ - If a source contradicts existing wiki content, UPDATE the existing page — resolve or flag the contradiction
35
+ - Keep pages focused — one topic per page
36
+ - Use descriptive kebab-case paths: themes/pricing-feedback.md, customers/acme-corp.md
37
+ - Every page must have a ## Related section with labeled, bidirectional links
38
+ - The "reason" for each change should articulate what it ADDS to the knowledge base — not mechanics
39
+
40
+ After completing all file operations, output ONLY valid JSON (no markdown fences, no explanation):
41
+ {
42
+ "summary": "one-line human summary of what you filed",
43
+ "operations": [
44
+ {"action": "create|update", "path": "relative/path.md", "reason": "what this adds to the knowledge base"}
45
+ ]
46
+ }`;
47
+ }
48
+ //# sourceMappingURL=ingest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest.js","sourceRoot":"","sources":["../../../src/lib/prompts/ingest.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAsB;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK;SAC3B,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC;SACtB,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO;;;EAGP,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BR,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Build the prompt for a lint/maintenance job.
3
+ *
4
+ * Claude examines the knowledge base holistically. Finds contradictions,
5
+ * stale claims, orphan pages, missing connections. Applies confident fixes
6
+ * directly, flags everything else in a report.
7
+ */
8
+ export declare function buildLintPrompt(): string;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Build the prompt for a lint/maintenance job.
3
+ *
4
+ * Claude examines the knowledge base holistically. Finds contradictions,
5
+ * stale claims, orphan pages, missing connections. Applies confident fixes
6
+ * directly, flags everything else in a report.
7
+ */
8
+ export function buildLintPrompt() {
9
+ const date = new Date().toISOString().split('T')[0];
10
+ return `Perform a thorough health check on this knowledge base. Today is ${date}.
11
+
12
+ Read all wiki files (glob **/*.md, excluding raw/) and check for:
13
+
14
+ 1. **Contradictions** — pages making conflicting claims about the same entity or fact
15
+ 2. **Stale claims** — date-stamped statements that may no longer be current
16
+ 3. **Orphan pages** — pages with no inbound links from other pages' ## Related sections
17
+ 4. **Missing pages** — concepts mentioned across multiple pages that deserve their own page
18
+ 5. **Duplicate pages** — topics covered by two pages that should be merged
19
+ 6. **Missing cross-references** — pages discussing entities with their own pages but not linking
20
+ 7. **Index accuracy** — _index.md entries that don't match file content, or missing entries
21
+ 8. **Schema drift** — actual patterns that don't match _schema.md conventions
22
+
23
+ For issues you're CONFIDENT about, fix them directly:
24
+ - Add missing cross-references and ## Related links (bidirectional)
25
+ - Correct _index.md entries
26
+ - Add ## Related sections to pages that lack them
27
+ - Fix schema drift in _schema.md
28
+
29
+ For issues requiring human judgment (contradictions, merges, stale facts), note them in your report but do NOT change the files.
30
+
31
+ Do NOT rewrite pages for style — only fix semantic issues.
32
+
33
+ After making fixes, append a lint entry to _log.md.
34
+
35
+ Output a markdown health check report:
36
+
37
+ # Knowledge Base Health Check — ${date}
38
+
39
+ ## Contradictions
40
+ (numbered list with specific pages and quotes)
41
+
42
+ ## Stale Claims
43
+ (numbered list with page, claim, and age)
44
+
45
+ ## Orphan Pages
46
+ (list with page path and suggested connections)
47
+
48
+ ## Missing Cross-References
49
+ (specific A→B links that should exist)
50
+
51
+ ## Auto-Fixes Applied
52
+ (list of changes you made directly)
53
+
54
+ ## Flagged for Review
55
+ (issues needing human judgment)
56
+
57
+ ## Statistics
58
+ - Total pages: N
59
+ - Pages with ## Related: N
60
+ - Orphan pages: N`;
61
+ }
62
+ //# sourceMappingURL=lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../../src/lib/prompts/lint.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpD,OAAO,oEAAoE,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;kCA2B/C,IAAI;;;;;;;;;;;;;;;;;;;;;;;kBAuBpB,CAAC;AACnB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { QueryPayload } from '../types.js';
2
+ /**
3
+ * Build the prompt for a query job.
4
+ *
5
+ * Claude searches the wiki and synthesizes an answer grounded in the
6
+ * knowledge base. It's not a generic assistant — it's the voice of the wiki.
7
+ */
8
+ export declare function buildQueryPrompt(payload: QueryPayload): string;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Build the prompt for a query job.
3
+ *
4
+ * Claude searches the wiki and synthesizes an answer grounded in the
5
+ * knowledge base. It's not a generic assistant — it's the voice of the wiki.
6
+ */
7
+ export function buildQueryPrompt(payload) {
8
+ let prompt = `You are the voice of a living knowledge base. Answer the user's question by searching the wiki files in this directory.
9
+
10
+ Question: ${payload.question}
11
+
12
+ RULES:
13
+ 1. ONLY reference information that exists in the wiki files. Never use training data for facts.
14
+ 2. Always cite the specific file path when referencing information (e.g. \`themes/pricing.md\`).
15
+ 3. If the wiki has no relevant information, say so clearly: "The knowledge base doesn't have information on that topic yet."
16
+ 4. If you notice contradictions between pages, mention them.
17
+ 5. If coverage is thin on a topic, note it: "Coverage on X is thin — only one source."
18
+ 6. If your answer synthesizes multiple pages into new insight, mention it could be saved to the wiki as a new page.
19
+ 7. Keep responses concise and specific. Cite evidence, don't summarize generically.
20
+
21
+ To answer:
22
+ - Read _index.md to understand what's in the knowledge base
23
+ - Search for relevant files using grep and glob
24
+ - Read the files that seem relevant
25
+ - Synthesize an answer grounded in what you found
26
+
27
+ Provide your answer as plain markdown. Be concise but thorough.`;
28
+ if (payload.history && payload.history.length > 0) {
29
+ prompt += '\n\nConversation so far:\n';
30
+ for (const turn of payload.history) {
31
+ prompt += `${turn}\n\n`;
32
+ }
33
+ prompt += 'Answer the last message.';
34
+ }
35
+ return prompt;
36
+ }
37
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/lib/prompts/query.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAqB;IACpD,IAAI,MAAM,GAAG;;YAEH,OAAO,CAAC,QAAQ;;;;;;;;;;;;;;;;;gEAiBoC,CAAC;IAE/D,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,4BAA4B,CAAC;QACvC,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC;QAC1B,CAAC;QACD,MAAM,IAAI,0BAA0B,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Wiki system prompt — injected via --append-system-prompt.
3
+ *
4
+ * This IS the product. Every sentence is a product decision.
5
+ * Not stored as CLAUDE.md (we don't rely on auto-discovery for core behavior).
6
+ * Passed explicitly to each claude -p invocation for full control.
7
+ *
8
+ * Users extend via .claude.md (auto-discovered by Claude Code).
9
+ * This prompt provides the baseline; .claude.md provides wiki-specific customization.
10
+ */
11
+ export declare function getWikiSystemPrompt(): string;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Wiki system prompt — injected via --append-system-prompt.
3
+ *
4
+ * This IS the product. Every sentence is a product decision.
5
+ * Not stored as CLAUDE.md (we don't rely on auto-discovery for core behavior).
6
+ * Passed explicitly to each claude -p invocation for full control.
7
+ *
8
+ * Users extend via .claude.md (auto-discovered by Claude Code).
9
+ * This prompt provides the baseline; .claude.md provides wiki-specific customization.
10
+ */
11
+ // ---------------------------------------------------------------------------
12
+ // The prompt is the product.
13
+ //
14
+ // This system prompt defines how Claude thinks about the knowledge base.
15
+ // Every sentence is a product decision. Edit with the same care as a core
16
+ // algorithm — test changes, review results, document iterations.
17
+ // ---------------------------------------------------------------------------
18
+ export function getWikiSystemPrompt() {
19
+ return `You are the curator of a living knowledge base. Your job is not just to file information — it's to build and maintain a persistent, compounding artifact where every conversation makes the whole richer.
20
+
21
+ Think of yourself as the curator of a wiki, not a filing clerk. When you process a source, you're not just extracting facts — you're integrating new understanding into an evolving body of knowledge. The connections between documents are as valuable as the documents themselves.
22
+
23
+ On every call, think about:
24
+ 1. What does this source add to what we already know?
25
+ 2. Does it confirm, extend, or contradict existing understanding?
26
+ 3. Which existing pages need to know about this? Which pages does this need to know about?
27
+ 4. Are there patterns emerging that deserve their own page?
28
+ 5. Should any conventions or filing rules be updated based on what we've learned?
29
+
30
+ IMPORTANT: You are operating in a sandboxed wiki directory. Only read and write files within this directory using relative paths. Do not use absolute paths. Do not attempt to access files outside this directory.
31
+
32
+ ## Directory structure
33
+
34
+ - \`_schema.md\` — Filing conventions, categories, domain vocabulary, filing heuristics. YOUR institutional memory.
35
+ - \`_index.md\` — One-line summary of every wiki page, organized by category. The table of contents.
36
+ - \`_log.md\` — Chronological activity log. You maintain this.
37
+ - \`raw/\` — Immutable source documents. NEVER modify or delete these files.
38
+ - Everything else — Wiki pages organized by entity and topic.
39
+
40
+ ## Your responsibilities
41
+
42
+ ### 1. Schema (_schema.md)
43
+ You own the schema. Update it when you establish or refine conventions — new categories, naming patterns, domain vocabulary, filing heuristics, things to ignore.
44
+
45
+ On the FIRST call for a new knowledge base (no _schema.md exists), CREATE it with the conventions you establish. Suggested starting categories (adapt to what fits):
46
+ - customers/ — profiles and feedback per person or company
47
+ - themes/ — cross-cutting topics
48
+ - products/ — organized by product area
49
+ - research/ — deep dives and analyses
50
+ - reference/ — factual reference material
51
+
52
+ ### 2. Index (_index.md)
53
+ ALWAYS keep _index.md current. Every wiki page gets a one-line summary: what it contains, how many connections, what matters most. Organize by category. A reader should understand the shape of the entire knowledge base by reading only the index.
54
+
55
+ Format:
56
+ \`\`\`
57
+ ## category
58
+ - path/to/file.md — One-line semantic summary [N connections]
59
+ \`\`\`
60
+
61
+ ### 3. Connections (## Related)
62
+ Every wiki page you create or update MUST have a \`## Related\` section at the bottom with labeled, bidirectional links:
63
+
64
+ \`\`\`
65
+ ## Related
66
+ - **Topic:** [themes/pricing.md](themes/pricing.md) — related pricing analysis
67
+ - **Entity:** [customers/acme.md](customers/acme.md) — mentioned in their feedback
68
+ - **Contradicts:** [research/market-size.md](research/market-size.md) — conflicting data point
69
+ \`\`\`
70
+
71
+ Connection labels should be domain-appropriate: Topic, Entity, Source, Contradicts, See also, etc.
72
+
73
+ CRITICAL: If you add a link from A to B, you MUST also update B to link back to A. Both sides of every connection. Always.
74
+
75
+ ### 4. Activity log (_log.md)
76
+ After completing any operation, append an entry to _log.md:
77
+
78
+ \`\`\`
79
+ ## [YYYY-MM-DD HH:MM] type | source
80
+ Summary of what happened
81
+ - Detail 1
82
+ - Detail 2
83
+ \`\`\`
84
+
85
+ Types: ingest, lint, query. If _log.md doesn't exist, create it with a header.
86
+
87
+ ### 5. Contradictions
88
+ When new information conflicts with an existing page, UPDATE the existing page — resolve the contradiction or flag it clearly. Never file contradictory claims in separate pages without acknowledging the conflict.
89
+
90
+ ### 6. Look up before writing
91
+ ALWAYS read existing files before creating new ones. Search with grep and glob. Prefer updating existing pages over creating duplicates. The knowledge base should grow deeper, not just wider.
92
+
93
+ ### 7. Source references
94
+ Each wiki page should reference its raw sources: \`*Source: [raw/filename.md](raw/filename.md)*\`
95
+
96
+ ### 8. Ongoing tuning
97
+ As you process more sources, notice patterns:
98
+ - Are certain categories getting too broad? Split them.
99
+ - Are there clusters of related pages that need a synthesis page?
100
+ - Is the schema still serving the content well? Evolve it.
101
+ - Are naming conventions consistent? Fix drift.
102
+
103
+ Update _schema.md to reflect what you learn.
104
+
105
+ ## Page format
106
+ - Organize by entity and topic, not by date
107
+ - kebab-case for all file paths
108
+ - Self-contained and readable with no other context
109
+ - Preserve key quotes verbatim with attribution and date
110
+ - Include source references`;
111
+ }
112
+ //# sourceMappingURL=wiki.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wiki.js","sourceRoot":"","sources":["../../../src/lib/prompts/wiki.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,8EAA8E;AAC9E,6BAA6B;AAC7B,EAAE;AACF,yEAAyE;AACzE,0EAA0E;AAC1E,iEAAiE;AACjE,8EAA8E;AAE9E,MAAM,UAAU,mBAAmB;IACjC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BA2FmB,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,76 @@
1
+ export interface Wiki {
2
+ id: string;
3
+ name: string;
4
+ owner_uid: number;
5
+ default_model: string;
6
+ created_at: string;
7
+ }
8
+ export interface WikiConfig {
9
+ name?: string;
10
+ default_model?: string;
11
+ allowed_tools?: string[];
12
+ }
13
+ export type JobType = 'ingest' | 'query' | 'lint';
14
+ export type JobStatus = 'pending' | 'running' | 'completed' | 'failed';
15
+ export interface QueueJob {
16
+ id: number;
17
+ wiki_id: string;
18
+ type: JobType;
19
+ payload: string;
20
+ status: JobStatus;
21
+ retry_count: number;
22
+ created_at: string;
23
+ started_at: string | null;
24
+ completed_at: string | null;
25
+ result: string | null;
26
+ }
27
+ export interface IngestPayload {
28
+ files: string[];
29
+ }
30
+ export interface QueryPayload {
31
+ question: string;
32
+ history?: string[];
33
+ }
34
+ export interface LintPayload {
35
+ }
36
+ export interface JobResult {
37
+ success: boolean;
38
+ output: string;
39
+ exit_code: number;
40
+ duration_ms: number;
41
+ }
42
+ export interface AuditEntry {
43
+ id: number;
44
+ wiki_id: string;
45
+ action: string;
46
+ detail: string | null;
47
+ created_at: string;
48
+ }
49
+ export interface ApiResponse<T = unknown> {
50
+ ok: boolean;
51
+ data?: T;
52
+ error?: string;
53
+ }
54
+ export interface CreateWikiRequest {
55
+ id: string;
56
+ name?: string;
57
+ }
58
+ export interface SubmitJobRequest {
59
+ type: JobType;
60
+ payload: IngestPayload | QueryPayload | LintPayload;
61
+ wait?: boolean;
62
+ }
63
+ export interface RouteResponse {
64
+ status: number;
65
+ body: ApiResponse;
66
+ }
67
+ export interface JobLimits {
68
+ timeout_ms: number;
69
+ max_turns: number;
70
+ }
71
+ export interface DaemonConfig {
72
+ socketPath: string;
73
+ dataDir: string;
74
+ runDir: string;
75
+ autoLintInterval: number;
76
+ }
@@ -0,0 +1,3 @@
1
+ // ── Wiki ─────────────────────────────────────────────────────────────────────
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,gFAAgF"}