rigjs 4.0.5 → 4.0.6

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.
@@ -1,104 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import print from '../print';
4
- import {
5
- loadRegistry,
6
- saveRegistry,
7
- loadVaultConfig,
8
- saveVaultConfig,
9
- VaultConfig,
10
- } from './config';
11
-
12
- interface RegisterOpts {
13
- as?: string;
14
- force?: boolean;
15
- }
16
-
17
- /**
18
- * `rig wiki register [path]`
19
- *
20
- * 1. Resolve the vault dir (explicit arg, or walk up from CWD looking for
21
- * a directory that already has `purpose.md`).
22
- * 2. Ensure `<vault>/.rig/config.yml` exists. Create it from defaults if
23
- * missing; otherwise keep whatever the user authored.
24
- * 3. Apply the optional `--as <slug>` override to the vault config's name.
25
- * 4. Append the absolute vault path to `~/.rig/wikis.yml` (the
26
- * discovery-only registry). No-op if already present.
27
- */
28
- export default function wikiRegister(givenPath: string | undefined, opts: RegisterOpts): void {
29
- const vaultPath = path.resolve(givenPath || detectVaultPath(process.cwd()) || process.cwd());
30
- if (!fs.existsSync(vaultPath)) {
31
- print.error(`path does not exist: ${vaultPath}`);
32
- process.exit(1);
33
- }
34
- if (!fs.existsSync(path.join(vaultPath, 'purpose.md'))) {
35
- print.error(`not a wiki vault (no purpose.md): ${vaultPath}`);
36
- print.info(`run \`rig wiki init ${shortPath(vaultPath)}\` first.`);
37
- process.exit(1);
38
- }
39
-
40
- // Load or seed the per-vault config.
41
- let vault = loadVaultConfig(vaultPath);
42
- if (!vault) {
43
- vault = defaultVaultConfig(path.basename(vaultPath));
44
- }
45
- const desiredName = (opts.as || vault.name || path.basename(vaultPath)).trim();
46
- if (!desiredName) {
47
- print.error('failed to derive a wiki name; pass --as <slug>');
48
- process.exit(1);
49
- }
50
-
51
- // Name collision in the registry — surfaced by composing the registry.
52
- const reg = loadRegistry();
53
- for (const existingPath of reg.wikis) {
54
- if (existingPath === vaultPath) continue;
55
- const other = loadVaultConfig(existingPath);
56
- if (other && other.name === desiredName) {
57
- if (!opts.force) {
58
- print.error(`wiki "${desiredName}" already registered at ${existingPath}; pass --force to overwrite`);
59
- process.exit(1);
60
- }
61
- // --force: drop the old entry, the new one wins.
62
- reg.wikis = reg.wikis.filter(p => p !== existingPath);
63
- }
64
- }
65
-
66
- vault.name = desiredName;
67
- saveVaultConfig(vaultPath, vault);
68
-
69
- if (!reg.wikis.includes(vaultPath)) reg.wikis.push(vaultPath);
70
- saveRegistry(reg);
71
-
72
- print.succeed(`registered wiki "${desiredName}" -> ${vaultPath}`);
73
- }
74
-
75
- function detectVaultPath(start: string): string | undefined {
76
- const candidates = ['harness/llm-wiki', 'wiki'];
77
- let dir = start;
78
- while (true) {
79
- if (fs.existsSync(path.join(dir, 'purpose.md'))) return dir;
80
- for (const c of candidates) {
81
- const cand = path.join(dir, c);
82
- if (fs.existsSync(path.join(cand, 'purpose.md'))) return cand;
83
- }
84
- const parent = path.dirname(dir);
85
- if (parent === dir) return undefined;
86
- dir = parent;
87
- }
88
- }
89
-
90
- function defaultVaultConfig(vaultBasename: string): VaultConfig {
91
- return {
92
- name: vaultBasename,
93
- root: '..',
94
- include: ['**/*.md'],
95
- exclude: [`${vaultBasename}/**`, 'node_modules/**', '.git/**'],
96
- schedule: { scan: '0 */6 * * *', lint: '0 3 * * *', ingest: null },
97
- ingestRules: [{ match: 'raw/**/*.md', mode: 'auto-on-new' }],
98
- };
99
- }
100
-
101
- function shortPath(p: string): string {
102
- const home = process.env.HOME || '';
103
- return home && p.startsWith(home) ? '~' + p.slice(home.length) : p;
104
- }
@@ -1,28 +0,0 @@
1
- import path from 'path';
2
- import print from '../print';
3
- import { loadRegistry, saveRegistry, loadVaultConfig } from './config';
4
-
5
- /**
6
- * `rig wiki unregister <nameOrPath>` — drop a vault path from
7
- * `~/.rig/wikis.yml`. The vault's own `<vault>/.rig/config.yml` (and the
8
- * rest of its on-disk contents) is left untouched.
9
- */
10
- export default function wikiUnregister(nameOrPath: string): void {
11
- const reg = loadRegistry();
12
- const targetAbs = path.resolve(nameOrPath);
13
- const before = reg.wikis.length;
14
-
15
- reg.wikis = reg.wikis.filter(p => {
16
- if (p === targetAbs) return false;
17
- const v = loadVaultConfig(p);
18
- if (v && v.name === nameOrPath) return false;
19
- return true;
20
- });
21
-
22
- if (reg.wikis.length === before) {
23
- print.error(`no registered wiki matches "${nameOrPath}"`);
24
- process.exit(1);
25
- }
26
- saveRegistry(reg);
27
- print.succeed(`unregistered "${nameOrPath}" (disk contents untouched)`);
28
- }