@groundnuty/macf 0.2.0-rc.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 (124) hide show
  1. package/dist/.build-info.json +4 -0
  2. package/dist/cli/build-info.d.ts +38 -0
  3. package/dist/cli/build-info.d.ts.map +1 -0
  4. package/dist/cli/build-info.js +119 -0
  5. package/dist/cli/build-info.js.map +1 -0
  6. package/dist/cli/claude-sh.d.ts +42 -0
  7. package/dist/cli/claude-sh.d.ts.map +1 -0
  8. package/dist/cli/claude-sh.js +247 -0
  9. package/dist/cli/claude-sh.js.map +1 -0
  10. package/dist/cli/commands/cd.d.ts +6 -0
  11. package/dist/cli/commands/cd.d.ts.map +1 -0
  12. package/dist/cli/commands/cd.js +17 -0
  13. package/dist/cli/commands/cd.js.map +1 -0
  14. package/dist/cli/commands/certs.d.ts +33 -0
  15. package/dist/cli/commands/certs.d.ts.map +1 -0
  16. package/dist/cli/commands/certs.js +233 -0
  17. package/dist/cli/commands/certs.js.map +1 -0
  18. package/dist/cli/commands/doctor.d.ts +91 -0
  19. package/dist/cli/commands/doctor.d.ts.map +1 -0
  20. package/dist/cli/commands/doctor.js +235 -0
  21. package/dist/cli/commands/doctor.js.map +1 -0
  22. package/dist/cli/commands/init.d.ts +37 -0
  23. package/dist/cli/commands/init.d.ts.map +1 -0
  24. package/dist/cli/commands/init.js +279 -0
  25. package/dist/cli/commands/init.js.map +1 -0
  26. package/dist/cli/commands/list.d.ts +5 -0
  27. package/dist/cli/commands/list.d.ts.map +1 -0
  28. package/dist/cli/commands/list.js +21 -0
  29. package/dist/cli/commands/list.js.map +1 -0
  30. package/dist/cli/commands/migrate-ca-key.d.ts +36 -0
  31. package/dist/cli/commands/migrate-ca-key.d.ts.map +1 -0
  32. package/dist/cli/commands/migrate-ca-key.js +92 -0
  33. package/dist/cli/commands/migrate-ca-key.js.map +1 -0
  34. package/dist/cli/commands/peers.d.ts +8 -0
  35. package/dist/cli/commands/peers.d.ts.map +1 -0
  36. package/dist/cli/commands/peers.js +45 -0
  37. package/dist/cli/commands/peers.js.map +1 -0
  38. package/dist/cli/commands/repo-init.d.ts +43 -0
  39. package/dist/cli/commands/repo-init.d.ts.map +1 -0
  40. package/dist/cli/commands/repo-init.js +304 -0
  41. package/dist/cli/commands/repo-init.js.map +1 -0
  42. package/dist/cli/commands/rules-refresh.d.ts +14 -0
  43. package/dist/cli/commands/rules-refresh.d.ts.map +1 -0
  44. package/dist/cli/commands/rules-refresh.js +67 -0
  45. package/dist/cli/commands/rules-refresh.js.map +1 -0
  46. package/dist/cli/commands/self-update.d.ts +14 -0
  47. package/dist/cli/commands/self-update.d.ts.map +1 -0
  48. package/dist/cli/commands/self-update.js +112 -0
  49. package/dist/cli/commands/self-update.js.map +1 -0
  50. package/dist/cli/commands/status.d.ts +9 -0
  51. package/dist/cli/commands/status.d.ts.map +1 -0
  52. package/dist/cli/commands/status.js +90 -0
  53. package/dist/cli/commands/status.js.map +1 -0
  54. package/dist/cli/commands/update.d.ts +25 -0
  55. package/dist/cli/commands/update.d.ts.map +1 -0
  56. package/dist/cli/commands/update.js +316 -0
  57. package/dist/cli/commands/update.js.map +1 -0
  58. package/dist/cli/config.d.ts +103 -0
  59. package/dist/cli/config.d.ts.map +1 -0
  60. package/dist/cli/config.js +224 -0
  61. package/dist/cli/config.js.map +1 -0
  62. package/dist/cli/index.d.ts +3 -0
  63. package/dist/cli/index.d.ts.map +1 -0
  64. package/dist/cli/index.js +245 -0
  65. package/dist/cli/index.js.map +1 -0
  66. package/dist/cli/plugin-fetcher.d.ts +20 -0
  67. package/dist/cli/plugin-fetcher.d.ts.map +1 -0
  68. package/dist/cli/plugin-fetcher.js +83 -0
  69. package/dist/cli/plugin-fetcher.js.map +1 -0
  70. package/dist/cli/prompt.d.ts +17 -0
  71. package/dist/cli/prompt.d.ts.map +1 -0
  72. package/dist/cli/prompt.js +109 -0
  73. package/dist/cli/prompt.js.map +1 -0
  74. package/dist/cli/registry-helper.d.ts +11 -0
  75. package/dist/cli/registry-helper.d.ts.map +1 -0
  76. package/dist/cli/registry-helper.js +18 -0
  77. package/dist/cli/registry-helper.js.map +1 -0
  78. package/dist/cli/rules.d.ts +39 -0
  79. package/dist/cli/rules.d.ts.map +1 -0
  80. package/dist/cli/rules.js +112 -0
  81. package/dist/cli/rules.js.map +1 -0
  82. package/dist/cli/settings-writer.d.ts +97 -0
  83. package/dist/cli/settings-writer.d.ts.map +1 -0
  84. package/dist/cli/settings-writer.js +270 -0
  85. package/dist/cli/settings-writer.js.map +1 -0
  86. package/dist/cli/version-resolver.d.ts +73 -0
  87. package/dist/cli/version-resolver.d.ts.map +1 -0
  88. package/dist/cli/version-resolver.js +238 -0
  89. package/dist/cli/version-resolver.js.map +1 -0
  90. package/dist/index.d.ts +19 -0
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +22 -0
  93. package/dist/index.js.map +1 -0
  94. package/dist/plugin/bin/macf-plugin-cli.d.ts +13 -0
  95. package/dist/plugin/bin/macf-plugin-cli.d.ts.map +1 -0
  96. package/dist/plugin/bin/macf-plugin-cli.js +127 -0
  97. package/dist/plugin/bin/macf-plugin-cli.js.map +1 -0
  98. package/dist/plugin/lib/format.d.ts +40 -0
  99. package/dist/plugin/lib/format.d.ts.map +1 -0
  100. package/dist/plugin/lib/format.js +137 -0
  101. package/dist/plugin/lib/format.js.map +1 -0
  102. package/dist/plugin/lib/health.d.ts +2 -0
  103. package/dist/plugin/lib/health.d.ts.map +1 -0
  104. package/dist/plugin/lib/health.js +6 -0
  105. package/dist/plugin/lib/health.js.map +1 -0
  106. package/dist/plugin/lib/index.d.ts +7 -0
  107. package/dist/plugin/lib/index.d.ts.map +1 -0
  108. package/dist/plugin/lib/index.js +5 -0
  109. package/dist/plugin/lib/index.js.map +1 -0
  110. package/dist/plugin/lib/registry.d.ts +18 -0
  111. package/dist/plugin/lib/registry.d.ts.map +1 -0
  112. package/dist/plugin/lib/registry.js +17 -0
  113. package/dist/plugin/lib/registry.js.map +1 -0
  114. package/dist/plugin/lib/work.d.ts +13 -0
  115. package/dist/plugin/lib/work.d.ts.map +1 -0
  116. package/dist/plugin/lib/work.js +27 -0
  117. package/dist/plugin/lib/work.js.map +1 -0
  118. package/package.json +43 -0
  119. package/plugin/rules/coordination.md +224 -0
  120. package/scripts/check-gh-token.sh +102 -0
  121. package/scripts/macf-gh-token.sh +130 -0
  122. package/scripts/macf-whoami.sh +51 -0
  123. package/scripts/tmux-send-to-claude.sh +51 -0
  124. package/scripts/write-build-info.mjs +48 -0
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Terminal prompt helpers.
3
+ *
4
+ * `promptPassword` reads a passphrase from stdin with each character echoed
5
+ * as `*` so the user gets visual feedback for length and typos but the
6
+ * real text never reaches the terminal scrollback or screen recordings.
7
+ *
8
+ * Uses raw mode (byte-by-byte) when stdin is a TTY. Falls back to plain
9
+ * readline (unmasked) when stdin is piped — masking piped input is both
10
+ * impossible and unnecessary since there's no observer.
11
+ */
12
+ import { createInterface } from 'node:readline';
13
+ export class PromptCancelled extends Error {
14
+ constructor() {
15
+ super('Prompt cancelled by user (Ctrl+C)');
16
+ this.name = 'PromptCancelled';
17
+ }
18
+ }
19
+ /**
20
+ * Check if a readable stream is a TTY that supports raw mode.
21
+ * Typed loosely because Node's type def for Readable doesn't include TTY fields.
22
+ */
23
+ function isRawModeTTY(stream) {
24
+ return Boolean(stream.isTTY) && typeof stream.setRawMode === 'function';
25
+ }
26
+ /**
27
+ * Prompt the user for a password, echoing '*' per character.
28
+ *
29
+ * Rejects with PromptCancelled on Ctrl+C. Restores TTY state on success,
30
+ * cancel, and error paths.
31
+ */
32
+ export function promptPassword(options) {
33
+ const input = options.input ?? process.stdin;
34
+ const output = options.output ?? process.stderr;
35
+ // Non-TTY (piped/redirected stdin): fall back to plain readline.
36
+ // Masking is meaningless when there's no terminal observer.
37
+ if (!isRawModeTTY(input)) {
38
+ return new Promise((resolve) => {
39
+ const rl = createInterface({ input, output });
40
+ rl.question(options.message, (answer) => {
41
+ rl.close();
42
+ resolve(answer);
43
+ });
44
+ });
45
+ }
46
+ return new Promise((resolve, reject) => {
47
+ output.write(options.message);
48
+ let settled = false;
49
+ let buffer = '';
50
+ const finish = (resultOrErr) => {
51
+ if (settled)
52
+ return;
53
+ settled = true;
54
+ input.setRawMode(false);
55
+ input.pause();
56
+ input.removeListener('data', onData);
57
+ if (resultOrErr instanceof Error) {
58
+ reject(resultOrErr);
59
+ }
60
+ else {
61
+ resolve(resultOrErr);
62
+ }
63
+ };
64
+ const onData = (chunk) => {
65
+ const bytes = chunk;
66
+ for (let i = 0; i < bytes.length; i++) {
67
+ const b = bytes[i];
68
+ // Enter (LF or CR) → submit
69
+ if (b === 0x0a || b === 0x0d) {
70
+ output.write('\n');
71
+ finish(buffer);
72
+ return;
73
+ }
74
+ // Ctrl+C (0x03) → cancel
75
+ if (b === 0x03) {
76
+ output.write('^C\n');
77
+ finish(new PromptCancelled());
78
+ return;
79
+ }
80
+ // Ctrl+D (0x04) → treat as cancel (EOF in raw mode). Without this,
81
+ // an empty-buffer EOF would leak through as a silent empty password.
82
+ if (b === 0x04) {
83
+ output.write('\n');
84
+ finish(new PromptCancelled());
85
+ return;
86
+ }
87
+ // Backspace (0x7f DEL on most terminals, 0x08 legacy)
88
+ if (b === 0x7f || b === 0x08) {
89
+ if (buffer.length > 0) {
90
+ buffer = buffer.slice(0, -1);
91
+ // Erase one asterisk: backspace, space, backspace
92
+ output.write('\b \b');
93
+ }
94
+ continue;
95
+ }
96
+ // Other control chars — ignore
97
+ if (b < 0x20)
98
+ continue;
99
+ // Printable character — append and echo '*'
100
+ buffer += String.fromCharCode(b);
101
+ output.write('*');
102
+ }
103
+ };
104
+ input.setRawMode(true);
105
+ input.resume();
106
+ input.on('data', onData);
107
+ });
108
+ }
109
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/cli/prompt.ts"],"names":[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gBACtD,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;oBAC7B,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBACtB,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;wBAC7B,kDAAkD;wBAClD,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;oBACxB,CAAC;oBACD,SAAS;gBACX,CAAC;gBAED,+BAA+B;gBAC/B,IAAI,CAAC,GAAG,IAAI;oBAAE,SAAS;gBAEvB,4CAA4C;gBAC5C,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBACjC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;QACH,CAAC,CAAC;QAEF,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACvB,KAAK,CAAC,MAAM,EAAE,CAAC;QACf,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { MacfAgentConfig } from './config.js';
2
+ import type { GitHubVariablesClient } from '@groundnuty/macf-core';
3
+ /**
4
+ * Build the GitHub Variables API path prefix from agent config.
5
+ */
6
+ export declare function registryPathPrefix(registry: MacfAgentConfig['registry']): string;
7
+ /**
8
+ * Create a GitHubVariablesClient from agent config and token.
9
+ */
10
+ export declare function createClientFromConfig(registry: MacfAgentConfig['registry'], token: string): GitHubVariablesClient;
11
+ //# sourceMappingURL=registry-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-helper.d.ts","sourceRoot":"","sources":["../../src/cli/registry-helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,GAAG,MAAM,CAMhF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,EACrC,KAAK,EAAE,MAAM,GACZ,qBAAqB,CAEvB"}
@@ -0,0 +1,18 @@
1
+ import { createGitHubClient } from '@groundnuty/macf-core';
2
+ /**
3
+ * Build the GitHub Variables API path prefix from agent config.
4
+ */
5
+ export function registryPathPrefix(registry) {
6
+ switch (registry.type) {
7
+ case 'org': return `/orgs/${registry.org}`;
8
+ case 'profile': return `/repos/${registry.user}/${registry.user}`;
9
+ case 'repo': return `/repos/${registry.owner}/${registry.repo}`;
10
+ }
11
+ }
12
+ /**
13
+ * Create a GitHubVariablesClient from agent config and token.
14
+ */
15
+ export function createClientFromConfig(registry, token) {
16
+ return createGitHubClient(registryPathPrefix(registry), token);
17
+ }
18
+ //# sourceMappingURL=registry-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-helper.js","sourceRoot":"","sources":["../../src/cli/registry-helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG3D;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAqC;IACtE,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,KAAK,CAAC,CAAC,OAAO,SAAS,QAAQ,CAAC,GAAG,EAAE,CAAC;QAC3C,KAAK,SAAS,CAAC,CAAC,OAAO,UAAU,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClE,KAAK,MAAM,CAAC,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;IAClE,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAAqC,EACrC,KAAa;IAEb,OAAO,kBAAkB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC;AACjE,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Locate the CLI package root by walking up from this module until a
3
+ * package.json is found. Works for both the dev layout (running from
4
+ * src/cli/) and the installed layout (running from dist/cli/).
5
+ */
6
+ export declare function findCliPackageRoot(startUrl?: string): string;
7
+ /**
8
+ * Path to the canonical rules directory shipped with the CLI.
9
+ */
10
+ export declare function canonicalRulesDir(packageRoot?: string): string;
11
+ /**
12
+ * Copy every .md file from the canonical rules dir to <workspace>/.claude/rules/.
13
+ * Existing files are overwritten (the canonical source wins).
14
+ *
15
+ * Returns the list of copied filenames (basenames). Returns empty array if
16
+ * the canonical dir doesn't exist (e.g. CLI installed without the rules
17
+ * payload — unlikely but safe to handle).
18
+ */
19
+ export declare function copyCanonicalRules(workspaceDir: string, options?: {
20
+ readonly canonicalDir?: string;
21
+ }): readonly string[];
22
+ /**
23
+ * Path to the canonical scripts directory shipped with the CLI.
24
+ */
25
+ export declare function canonicalScriptsDir(packageRoot?: string): string;
26
+ /**
27
+ * Copy every .sh file from the canonical scripts dir to
28
+ * <workspace>/.claude/scripts/. Preserves executable mode (0o755).
29
+ *
30
+ * Unlike copyCanonicalRules, no header is injected — shell scripts
31
+ * can't take HTML comments, and the shebang + usage comment in the
32
+ * source already documents managed status.
33
+ *
34
+ * Returns copied basenames. Empty array if the canonical dir is missing.
35
+ */
36
+ export declare function copyCanonicalScripts(workspaceDir: string, options?: {
37
+ readonly canonicalDir?: string;
38
+ }): readonly string[];
39
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/cli/rules.ts"],"names":[],"mappings":"AA4BA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,GAAE,MAAwB,GAAG,MAAM,CAU7E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,GAAE,MAA6B,GAAG,MAAM,CAEpF;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE;IAChE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,SAAS,MAAM,EAAE,CAmBzB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,GAAE,MAA6B,GAAG,MAAM,CAEtF;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE;IAClE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,SAAS,MAAM,EAAE,CAiBzB"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Distribute canonical assets (coordination rules, helper scripts) from
3
+ * the CLI package to each agent workspace's .claude/ subdirectory.
4
+ *
5
+ * The canonical files live at <package-root>/plugin/rules/*.md and
6
+ * <package-root>/scripts/*.sh, shipped with the CLI (their version is
7
+ * tied to the CLI version). On `macf init` we copy them once; on
8
+ * `macf update` we re-copy (overwriting) so a CLI version bump
9
+ * propagates updates to existing workspaces.
10
+ *
11
+ * Workspace rule copies get a header warning against direct edits.
12
+ * Workspace script copies preserve 0755 mode so the hooks that call
13
+ * them can execute.
14
+ */
15
+ import { fileURLToPath } from 'node:url';
16
+ import { dirname, join, resolve } from 'node:path';
17
+ import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
18
+ const MANAGED_HEADER = [
19
+ '<!--',
20
+ ' This file is managed by `macf`. Do not edit directly — edits are',
21
+ ' overwritten on the next `macf update`. The canonical source lives at',
22
+ ' groundnuty/macf:plugin/rules/. To change a rule, file an issue or PR',
23
+ ' against that file in the macf repo, then run `macf update` here.',
24
+ '-->',
25
+ '',
26
+ ].join('\n');
27
+ /**
28
+ * Locate the CLI package root by walking up from this module until a
29
+ * package.json is found. Works for both the dev layout (running from
30
+ * src/cli/) and the installed layout (running from dist/cli/).
31
+ */
32
+ export function findCliPackageRoot(startUrl = import.meta.url) {
33
+ let dir = dirname(fileURLToPath(startUrl));
34
+ for (;;) {
35
+ if (existsSync(join(dir, 'package.json')))
36
+ return dir;
37
+ const parent = dirname(dir);
38
+ if (parent === dir) {
39
+ throw new Error(`Could not locate CLI package root walking up from ${fileURLToPath(startUrl)}`);
40
+ }
41
+ dir = parent;
42
+ }
43
+ }
44
+ /**
45
+ * Path to the canonical rules directory shipped with the CLI.
46
+ */
47
+ export function canonicalRulesDir(packageRoot = findCliPackageRoot()) {
48
+ return join(packageRoot, 'plugin', 'rules');
49
+ }
50
+ /**
51
+ * Copy every .md file from the canonical rules dir to <workspace>/.claude/rules/.
52
+ * Existing files are overwritten (the canonical source wins).
53
+ *
54
+ * Returns the list of copied filenames (basenames). Returns empty array if
55
+ * the canonical dir doesn't exist (e.g. CLI installed without the rules
56
+ * payload — unlikely but safe to handle).
57
+ */
58
+ export function copyCanonicalRules(workspaceDir, options = {}) {
59
+ const sourceDir = options.canonicalDir ?? canonicalRulesDir();
60
+ if (!existsSync(sourceDir))
61
+ return [];
62
+ const targetDir = join(resolve(workspaceDir), '.claude', 'rules');
63
+ mkdirSync(targetDir, { recursive: true });
64
+ const copied = [];
65
+ for (const entry of readdirSync(sourceDir, { withFileTypes: true })) {
66
+ if (!entry.isFile() || !entry.name.endsWith('.md'))
67
+ continue;
68
+ const src = join(sourceDir, entry.name);
69
+ const dst = join(targetDir, entry.name);
70
+ const content = readFileSync(src, 'utf-8');
71
+ // Avoid double-prepending the header on re-copy.
72
+ const out = content.startsWith('<!--') ? content : MANAGED_HEADER + content;
73
+ writeFileSync(dst, out);
74
+ copied.push(entry.name);
75
+ }
76
+ return copied;
77
+ }
78
+ /**
79
+ * Path to the canonical scripts directory shipped with the CLI.
80
+ */
81
+ export function canonicalScriptsDir(packageRoot = findCliPackageRoot()) {
82
+ return join(packageRoot, 'scripts');
83
+ }
84
+ /**
85
+ * Copy every .sh file from the canonical scripts dir to
86
+ * <workspace>/.claude/scripts/. Preserves executable mode (0o755).
87
+ *
88
+ * Unlike copyCanonicalRules, no header is injected — shell scripts
89
+ * can't take HTML comments, and the shebang + usage comment in the
90
+ * source already documents managed status.
91
+ *
92
+ * Returns copied basenames. Empty array if the canonical dir is missing.
93
+ */
94
+ export function copyCanonicalScripts(workspaceDir, options = {}) {
95
+ const sourceDir = options.canonicalDir ?? canonicalScriptsDir();
96
+ if (!existsSync(sourceDir))
97
+ return [];
98
+ const targetDir = join(resolve(workspaceDir), '.claude', 'scripts');
99
+ mkdirSync(targetDir, { recursive: true });
100
+ const copied = [];
101
+ for (const entry of readdirSync(sourceDir, { withFileTypes: true })) {
102
+ if (!entry.isFile() || !entry.name.endsWith('.sh'))
103
+ continue;
104
+ const src = join(sourceDir, entry.name);
105
+ const dst = join(targetDir, entry.name);
106
+ copyFileSync(src, dst);
107
+ chmodSync(dst, 0o755);
108
+ copied.push(entry.name);
109
+ }
110
+ return copied;
111
+ }
112
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/cli/rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEnH,MAAM,cAAc,GAAG;IACrB,MAAM;IACN,oEAAoE;IACpE,wEAAwE;IACxE,wEAAwE;IACxE,oEAAoE;IACpE,KAAK;IACL,EAAE;CACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC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,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,SAAS;QAC7D,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACxC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACvB,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The command path written into settings.json. Workspace-relative so
3
+ * it matches what `copyCanonicalScripts` places at
4
+ * `<workspace>/.claude/scripts/check-gh-token.sh`.
5
+ */
6
+ export declare const MACF_HOOK_COMMAND = ".claude/scripts/check-gh-token.sh";
7
+ /**
8
+ * Permission patterns pre-approving the 4 `macf-agent` plugin skills.
9
+ * Without these, every first invocation of a skill (e.g. `/macf-status`
10
+ * during the SessionStart auto-pickup hook) fires an interactive
11
+ * approval dialog — blocking autonomy for the time operator takes to
12
+ * click through. See macf#189 sub-item 2 (bilateral e2e demo friction
13
+ * point: operator had to approve 4-5 dialogs per fresh workspace).
14
+ *
15
+ * Concrete patterns (not a wildcard `Skill(macf-agent:*)`): operator
16
+ * deliberately installed the plugin at v0.1.N, so pre-trusting THE
17
+ * SKILLS CURRENTLY KNOWN TO EXIST at this CLI version is safe. A
18
+ * future plugin version adding new skills would need a `macf update`
19
+ * run — which refreshes these patterns from the updated constant —
20
+ * before the new skills auto-approve. Wildcard would auto-approve
21
+ * anything shipped under the plugin namespace including future
22
+ * unreviewed additions; we opt out of that security posture.
23
+ *
24
+ * Keep in lockstep with the 4 skills shipped by
25
+ * `groundnuty/macf-marketplace/macf-agent/skills/`. When plugin adds
26
+ * a skill, add its pattern here + bump CLI version.
27
+ */
28
+ export declare const PLUGIN_SKILL_PERMISSIONS: readonly string[];
29
+ /**
30
+ * Sandbox filesystem read-allow pattern for Claude Code's Bash-tool
31
+ * harness. Every Bash invocation's spawned shell reads `/proc/self/fd/3`
32
+ * (or higher fds in future builds) for stdin / command-input passed
33
+ * by the harness. Without this pattern in the sandbox allowlist, the
34
+ * read is denied → `zsh:4: permission denied: /proc/self/fd/3` →
35
+ * every Bash tool call fails (or falls back to
36
+ * `dangerouslyDisableSandbox`, defeating isolation). Hit every MACF
37
+ * agent before macf#200.
38
+ *
39
+ * Claude Code's `sandbox.filesystem.allowRead` takes **literal path
40
+ * prefixes**, not globs. Bare `/proc/self/fd` matches every
41
+ * descriptor at any depth (`/proc/self/fd/3`, `/proc/self/fd/4`, ...)
42
+ * via prefix semantics. An earlier draft used `/proc/self/fd/**` on
43
+ * the assumption it was a glob; it isn't — the double-star was
44
+ * treated as a literal and didn't match. See macf#208 for the
45
+ * empirical surfacing of the bug.
46
+ */
47
+ export declare const SANDBOX_FD_READ_PATTERN = "/proc/self/fd";
48
+ /**
49
+ * Read `.claude/settings.json`'s `sandbox.filesystem.allowRead` array
50
+ * as a list of strings. Returns an empty array if the file doesn't
51
+ * exist or the nested shape is absent/alien. Throws on malformed
52
+ * JSON — consistent with `installSandboxFdAllowRead`'s posture (we
53
+ * don't silently treat a broken file as "no entries"; that would
54
+ * mask operator-authored state).
55
+ *
56
+ * Used by `macf doctor` (macf#202) to report whether the workspace
57
+ * has the `/proc/self/fd` prefix pattern without duplicating the
58
+ * JSON-read + deep-narrow logic in two places.
59
+ */
60
+ export declare function getSandboxAllowRead(workspaceDir: string): readonly string[];
61
+ /**
62
+ * Install (or refresh) the `/proc/self/fd` entry in
63
+ * `.claude/settings.json`'s `sandbox.filesystem.allowRead` array.
64
+ * Creates each nested key if absent. Idempotent — repeated calls
65
+ * don't duplicate. Operator-authored `allowRead` entries are
66
+ * preserved; stale MACF-managed patterns (see
67
+ * MACF_LEGACY_FD_PATTERNS) are dropped before the current pattern
68
+ * is installed.
69
+ *
70
+ * Opt-out: if `MACF_SANDBOX_FD_FIX_SKIP` is `1` or `true` at call
71
+ * time (during `macf init` / `macf update`), no change is made. Lets
72
+ * operators manage their own sandbox block entirely. Accepts both
73
+ * shapes to stay aligned with `MACF_OTEL_DISABLED` (see
74
+ * `claude-sh.ts` — same family of opt-out env knobs).
75
+ *
76
+ * See macf#200 (original fd-deny bug), macf#208 (pattern-literal fix).
77
+ */
78
+ export declare function installSandboxFdAllowRead(workspaceDir: string): void;
79
+ /**
80
+ * Install (or refresh) the MACF plugin-skill pre-approval entries in
81
+ * `.claude/settings.json`'s `permissions.allow` array. Idempotent:
82
+ * stale entries (e.g. from a prior CLI version that listed a since-
83
+ * removed skill) are dropped + replaced with the current set.
84
+ * Non-MACF entries in `permissions.allow` are preserved.
85
+ *
86
+ * Creates the `.claude/` directory + settings.json if missing.
87
+ */
88
+ export declare function installPluginSkillPermissions(workspaceDir: string): void;
89
+ /**
90
+ * Install (or refresh) the MACF PreToolUse hook entry for
91
+ * `check-gh-token.sh` in `<workspaceDir>/.claude/settings.json`.
92
+ * Creates the `.claude/` directory and the file if either is missing.
93
+ *
94
+ * Idempotent: repeated calls don't duplicate the entry.
95
+ */
96
+ export declare function installGhTokenHook(workspaceDir: string): void;
97
+ //# sourceMappingURL=settings-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-writer.d.ts","sourceRoot":"","sources":["../../src/cli/settings-writer.ts"],"names":[],"mappings":"AAuBA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,sCAAsC,CAAC;AA0DrE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAKrD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,uBAAuB,kBAAkB,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAS3E;AAaD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CA+CpE;AASD;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CA+BxE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAkC7D"}