@groundnuty/macf 0.2.16 → 0.2.18

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.
@@ -0,0 +1,168 @@
1
+ import type { MacfAgentConfig } from './config.js';
2
+ /**
3
+ * Generate `.claude/.macf/env._helpers` content.
4
+ *
5
+ * Defines shell helper FUNCTIONS used by sibling env.* files. The
6
+ * underscore prefix sorts this file BEFORE alphabetical-letter siblings
7
+ * (`env.certs`, `env.github`, `env.identity`, etc.), so when claude.sh
8
+ * sources `env.*` in alphabetical order via shell glob, this file's
9
+ * functions are defined before any caller is sourced.
10
+ *
11
+ * Currently exports one helper:
12
+ *
13
+ * macf_settings_get(var_name)
14
+ * Reads `.env.<var_name>` from `<workspace>/.claude/settings.local.json`
15
+ * via jq. Returns empty string if the file/key is missing or jq isn't
16
+ * installed. Used by:
17
+ * - env.identity — 3-layer settings priority for MACF_AGENT_NAME / ROLE
18
+ * - env.telemetry — 4-layer endpoint chain for MACF_OTEL_ENDPOINT
19
+ *
20
+ * **No exports** — this is a function-definition file. Sourcing it has
21
+ * no observable effect beyond making functions callable in the sourcing
22
+ * shell. macf#313 introduced the helper inline in claude.sh; macf#342
23
+ * extracted it here so multiple env.* files can share it without each
24
+ * file having to redeclare it (PR-A had `macf_settings_get` duplicated
25
+ * inside generateEnvIdentity to make env.identity self-contained;
26
+ * macf#342 PR-B moves the single source-of-truth into env._helpers).
27
+ *
28
+ * Pure function — no I/O. Doesn't take a config arg because the helper
29
+ * body is config-independent (it reads from settings.local.json at
30
+ * runtime, not from baked values).
31
+ */
32
+ export declare function generateEnvHelpers(): string;
33
+ /**
34
+ * Generate `.claude/.macf/env.identity` content.
35
+ *
36
+ * The 5 identity vars currently set BEFORE the tmux self-wrap in
37
+ * `claude-sh.ts`:
38
+ *
39
+ * MACF_WORKSPACE_DIR — absolute path to the workspace (cross-repo cwd
40
+ * safety, see #161 + coordination.md)
41
+ * MACF_PROJECT — project name
42
+ * MACF_AGENT_NAME — agent identifier (with 3-layer settings priority)
43
+ * MACF_AGENT_ROLE — agent role (with 3-layer settings priority)
44
+ * MACF_AGENT_TYPE — `permanent` | `worker`
45
+ *
46
+ * MACF_AGENT_NAME and MACF_AGENT_ROLE preserve the post-#313 settings-driven
47
+ * 3-layer priority (env > settings.local.json > baked default). Reading
48
+ * settings.local.json requires the `macf_settings_get` helper, which is
49
+ * defined in `env._helpers` (sourced before this file alphabetically by
50
+ * claude.sh's `for f in env.*` glob — underscore prefix sorts first).
51
+ *
52
+ * **Note on SCRIPT_DIR**: `MACF_WORKSPACE_DIR=$SCRIPT_DIR` requires that
53
+ * the sourcing script (claude.sh) sets SCRIPT_DIR before sourcing. That
54
+ * contract is documented in claude.sh; this file trusts it.
55
+ */
56
+ export declare function generateEnvIdentity(config: MacfAgentConfig): string;
57
+ /**
58
+ * Generate `.claude/.macf/env.github` content.
59
+ *
60
+ * Emits APP_ID / INSTALL_ID / KEY_PATH App-cred exports + the relative-
61
+ * path resolver + the fail-loud `macf-gh-token.sh` invocation + git
62
+ * author/committer name exports.
63
+ *
64
+ * **Empty placeholder in local-mode** (cfg.registry.type === 'local',
65
+ * DR-024). The body is just the header + schema_version + a comment
66
+ * explaining why — no GitHub App tokens are minted in local-registry
67
+ * mode (commits land as the local user, not as `app/<bot>[bot]`). The
68
+ * absence of GH_TOKEN-mint logic is what makes local-mode work without
69
+ * GitHub credentials.
70
+ */
71
+ export declare function generateEnvGitHub(config: MacfAgentConfig): string;
72
+ /**
73
+ * Generate `.claude/.macf/env.certs` content.
74
+ *
75
+ * CA + agent cert paths + log path. Local-mode CAs live next to the
76
+ * registry file (`~/.macf/registry/<project>.ca.{crt,key}`), GitHub-mode
77
+ * CAs live under `~/.macf/certs/<project>/`. Both modes need
78
+ * MACF_CA_CERT/MACF_CA_KEY exported for channel-server mTLS.
79
+ */
80
+ export declare function generateEnvCerts(config: MacfAgentConfig): string;
81
+ /**
82
+ * Generate `.claude/.macf/env.registry` content.
83
+ *
84
+ * MACF_REGISTRY_TYPE + per-type vars. Mirrors `claude-sh.ts`'s
85
+ * `registryEnvLines` exhaustive switch (so a new RegistryConfig variant
86
+ * fails the build here too, forcing a paired update).
87
+ */
88
+ export declare function generateEnvRegistry(config: MacfAgentConfig): string;
89
+ /**
90
+ * Generate `.claude/.macf/env.telemetry` content.
91
+ *
92
+ * The 3 OTel mandatory gates + per-signal exporters + endpoint resolution.
93
+ * Mirrors `claude-sh.ts`'s `otelTelemetryLines` (including the same
94
+ * shell-unsafe-char rejection on MACF_OTEL_ENDPOINT and the same default
95
+ * endpoint `http://localhost:14318` per macf-devops-toolkit canonical k3d
96
+ * topology).
97
+ *
98
+ * **Minimal placeholder when `MACF_OTEL_DISABLED=1`** (operator opt-out at
99
+ * template-time per macf#197). Body shrinks to header + schema_version +
100
+ * a comment explaining the opt-out — no OTel exports emitted, so sourcing
101
+ * the file is a no-op.
102
+ *
103
+ * @param env — defaults to `process.env`; tests inject a fake.
104
+ */
105
+ export declare function generateEnvTelemetry(config: MacfAgentConfig, env?: NodeJS.ProcessEnv): string;
106
+ /**
107
+ * Generate `.claude/.macf/env.tmux` content.
108
+ *
109
+ * MACF_TMUX_SESSION + MACF_TMUX_WINDOW for the on-notify wake path
110
+ * (macf#185). When the channel server's onNotify handler fires, it shells
111
+ * out to `tmux-send-to-claude.sh <session>:<window> <prompt>` to inject
112
+ * the notification as the TUI's next input turn.
113
+ *
114
+ * **Minimal placeholder when neither field is set in config.** The wake
115
+ * path falls back to auto-detect from $TMUX in that case (existing
116
+ * behavior — no env var needed). Avoids generating an empty-export file.
117
+ */
118
+ export declare function generateEnvTmux(config: MacfAgentConfig): string;
119
+ /**
120
+ * Result of `writeEnvFiles` — lists of file paths that were written and
121
+ * (currently empty; reserved for PR-C migration logic that may skip
122
+ * operator-managed files when they already exist) skipped.
123
+ *
124
+ * Returned so callers (init.ts, update.ts in PR-C) can log a summary
125
+ * line ("Wrote 7 env files to .claude/.macf/") without re-deriving the
126
+ * file list from an external mapping.
127
+ */
128
+ export interface WriteEnvFilesResult {
129
+ readonly written: readonly string[];
130
+ readonly skipped: readonly string[];
131
+ }
132
+ /**
133
+ * Write all 7 per-concern env files into `<projectDir>/.claude/.macf/`.
134
+ *
135
+ * env._helpers — library file (sourced first per alphabetical order)
136
+ * env.certs — cert + log paths
137
+ * env.github — App creds + GH_TOKEN mint (empty-comment in local-mode)
138
+ * env.identity — MACF_PROJECT / MACF_AGENT_NAME / ROLE / TYPE / WORKSPACE_DIR
139
+ * env.registry — MACF_REGISTRY_TYPE + per-type vars
140
+ * env.telemetry — OTel gates + endpoint (operator-managed)
141
+ * env.tmux — MACF_TMUX_SESSION / MACF_TMUX_WINDOW (operator-managed)
142
+ *
143
+ * **Always emits all 7 files** — even when the concern is empty (e.g.,
144
+ * env.tmux with no tmux_session set, env.github in local-mode). The
145
+ * generators emit a header + comment explaining the empty case. This
146
+ * keeps the on-disk layout uniform across configs, so claude.sh's
147
+ * source-loop pattern (`for f in env.*; do source "$f"; done`) is
148
+ * deterministic — no "did the file get skipped" branching for the
149
+ * sourcing script to consider.
150
+ *
151
+ * **Mode 0644** — these are sourced, not executed; no execute bit needed.
152
+ *
153
+ * **Overwrites unconditionally** — macf-managed files have a managed
154
+ * header warning operators not to edit. Operator-managed files
155
+ * (env.telemetry, env.tmux) get overwritten too in PR-B because PR-C
156
+ * hasn't added the preserve-existing logic yet. Init's contract is
157
+ * "fresh write"; update's preserve-existing contract lands in PR-C.
158
+ *
159
+ * **Creates `.claude/.macf/`** with mkdir -p semantics. The directory
160
+ * may not exist on a fresh init (the `.claude/` parent often does
161
+ * because of `settings.json` / `rules/`, but `.macf/` under it is new
162
+ * to PR-B).
163
+ *
164
+ * @returns Lists of absolute file paths for caller logging. `skipped`
165
+ * is reserved for PR-C and currently always empty.
166
+ */
167
+ export declare function writeEnvFiles(projectDir: string, config: MacfAgentConfig): WriteEnvFilesResult;
168
+ //# sourceMappingURL=env-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-files.d.ts","sourceRoot":"","sources":["../../src/cli/env-files.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAiHnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAwB3C;AAMD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CA6BnE;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAkEjE;AAMD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CA+BhE;AAMD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAuCnE;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,eAAe,EACvB,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,CA8DR;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAiC/D;AAMD;;;;;;;;GAQG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,eAAe,GACtB,mBAAmB,CA2BrB"}