@agimon-ai/po-config 0.0.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +170 -0
- package/dist/agentPluginMcp.cjs +322 -0
- package/dist/agentPluginMcp.cjs.map +1 -0
- package/dist/agentPluginMcp.d.mts +38 -0
- package/dist/agentPluginMcp.d.mts.map +1 -0
- package/dist/agentPluginMcp.mjs +318 -0
- package/dist/agentPluginMcp.mjs.map +1 -0
- package/dist/apiContracts.cjs +203 -0
- package/dist/apiContracts.cjs.map +1 -0
- package/dist/apiContracts.d.mts +53 -0
- package/dist/apiContracts.d.mts.map +1 -0
- package/dist/apiContracts.mjs +198 -0
- package/dist/apiContracts.mjs.map +1 -0
- package/dist/atomicJson-1W0WhuFF.mjs +44 -0
- package/dist/atomicJson-1W0WhuFF.mjs.map +1 -0
- package/dist/atomicJson-Dt2z_DXl.cjs +52 -0
- package/dist/atomicJson-Dt2z_DXl.cjs.map +1 -0
- package/dist/atomicJson.cjs +3 -0
- package/dist/atomicJson.d.mts +2 -0
- package/dist/atomicJson.mjs +2 -0
- package/dist/config-BUw5kHsx.cjs +219 -0
- package/dist/config-BUw5kHsx.cjs.map +1 -0
- package/dist/config-CKA07FxG.mjs +162 -0
- package/dist/config-CKA07FxG.mjs.map +1 -0
- package/dist/config-Cm3EV1jp.d.mts +320 -0
- package/dist/config-Cm3EV1jp.d.mts.map +1 -0
- package/dist/config-NSHRd6na.mjs +2 -0
- package/dist/config-zZz80Mh5.cjs +1 -0
- package/dist/config.cjs +24 -0
- package/dist/config.d.mts +3 -0
- package/dist/config.mjs +3 -0
- package/dist/configPolicy--TNX7feH.mjs +718 -0
- package/dist/configPolicy--TNX7feH.mjs.map +1 -0
- package/dist/configPolicy-DmsZEp0t.cjs +795 -0
- package/dist/configPolicy-DmsZEp0t.cjs.map +1 -0
- package/dist/configSchema.cjs +0 -0
- package/dist/configSchema.d.mts +2 -0
- package/dist/configSchema.mjs +1 -0
- package/dist/configWriter-BTuinLjs.cjs +150 -0
- package/dist/configWriter-BTuinLjs.cjs.map +1 -0
- package/dist/configWriter-BgkGaLrf.mjs +130 -0
- package/dist/configWriter-BgkGaLrf.mjs.map +1 -0
- package/dist/configWriter.cjs +5 -0
- package/dist/configWriter.d.mts +2 -0
- package/dist/configWriter.mjs +2 -0
- package/dist/domains-CBYkuxs5.cjs +727 -0
- package/dist/domains-CBYkuxs5.cjs.map +1 -0
- package/dist/domains-DZOu9vYM.mjs +633 -0
- package/dist/domains-DZOu9vYM.mjs.map +1 -0
- package/dist/domains.cjs +19 -0
- package/dist/domains.d.mts +3 -0
- package/dist/domains.mjs +3 -0
- package/dist/extensions/mcp-ui.mjs +101 -0
- package/dist/extensions/mcp-ui.mjs.map +1 -0
- package/dist/extensions/mcp.cjs +171 -0
- package/dist/extensions/mcp.cjs.map +1 -0
- package/dist/extensions/mcp.d.mts +5 -0
- package/dist/extensions/mcp.d.mts.map +1 -0
- package/dist/extensions/mcp.mjs +166 -0
- package/dist/extensions/mcp.mjs.map +1 -0
- package/dist/extensions/server.cjs +504 -0
- package/dist/extensions/server.cjs.map +1 -0
- package/dist/extensions/server.d.mts +5 -0
- package/dist/extensions/server.d.mts.map +1 -0
- package/dist/extensions/server.mjs +499 -0
- package/dist/extensions/server.mjs.map +1 -0
- package/dist/harnessState-CCyBeutB.cjs +188 -0
- package/dist/harnessState-CCyBeutB.cjs.map +1 -0
- package/dist/harnessState-Dn_S7fB9.mjs +163 -0
- package/dist/harnessState-Dn_S7fB9.mjs.map +1 -0
- package/dist/harnessState.cjs +6 -0
- package/dist/harnessState.d.mts +2 -0
- package/dist/harnessState.mjs +2 -0
- package/dist/harnessStore-CJSxdSkV.cjs +343 -0
- package/dist/harnessStore-CJSxdSkV.cjs.map +1 -0
- package/dist/harnessStore-CltwLB7M.mjs +262 -0
- package/dist/harnessStore-CltwLB7M.mjs.map +1 -0
- package/dist/harnessStore.cjs +15 -0
- package/dist/harnessStore.d.mts +2 -0
- package/dist/harnessStore.mjs +2 -0
- package/dist/index-BAaTySaM.d.mts +35 -0
- package/dist/index-BAaTySaM.d.mts.map +1 -0
- package/dist/index-BT29GZx5.d.mts +142 -0
- package/dist/index-BT29GZx5.d.mts.map +1 -0
- package/dist/index-B_lp0W3U.d.mts +114 -0
- package/dist/index-B_lp0W3U.d.mts.map +1 -0
- package/dist/index-C6GaYjq-.d.mts +6 -0
- package/dist/index-C6GaYjq-.d.mts.map +1 -0
- package/dist/index-CIQrKS1A.d.mts +50 -0
- package/dist/index-CIQrKS1A.d.mts.map +1 -0
- package/dist/index-CRcoVYXz.d.mts +39 -0
- package/dist/index-CRcoVYXz.d.mts.map +1 -0
- package/dist/index-CVlciCJF.d.mts +40 -0
- package/dist/index-CVlciCJF.d.mts.map +1 -0
- package/dist/index-CeOk2kqs.d.mts +118 -0
- package/dist/index-CeOk2kqs.d.mts.map +1 -0
- package/dist/index-Ch7ptOkW.d.mts +54 -0
- package/dist/index-Ch7ptOkW.d.mts.map +1 -0
- package/dist/index-Cvdt-Y-i.d.mts +66 -0
- package/dist/index-Cvdt-Y-i.d.mts.map +1 -0
- package/dist/index-DJpG-I9K.d.mts +122 -0
- package/dist/index-DJpG-I9K.d.mts.map +1 -0
- package/dist/index-DNk4q0Qm.d.mts +81 -0
- package/dist/index-DNk4q0Qm.d.mts.map +1 -0
- package/dist/index.cjs +121 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.mjs +15 -0
- package/dist/init-C_9nyp3-.cjs +448 -0
- package/dist/init-C_9nyp3-.cjs.map +1 -0
- package/dist/init-DJ6wm-dr.mjs +415 -0
- package/dist/init-DJ6wm-dr.mjs.map +1 -0
- package/dist/init.cjs +7 -0
- package/dist/init.d.mts +2 -0
- package/dist/init.mjs +2 -0
- package/dist/layeredConfig-B922ibgn.mjs +67 -0
- package/dist/layeredConfig-B922ibgn.mjs.map +1 -0
- package/dist/layeredConfig-DdI5ysUf.cjs +94 -0
- package/dist/layeredConfig-DdI5ysUf.cjs.map +1 -0
- package/dist/layeredConfig.cjs +6 -0
- package/dist/layeredConfig.d.mts +2 -0
- package/dist/layeredConfig.mjs +2 -0
- package/dist/majorModes-CmPLEpMT.mjs +333 -0
- package/dist/majorModes-CmPLEpMT.mjs.map +1 -0
- package/dist/majorModes-DPhVMuhT.cjs +383 -0
- package/dist/majorModes-DPhVMuhT.cjs.map +1 -0
- package/dist/majorModes.cjs +10 -0
- package/dist/majorModes.d.mts +2 -0
- package/dist/majorModes.mjs +2 -0
- package/dist/piConfig-Bx26HMb_.d.mts +33 -0
- package/dist/piConfig-Bx26HMb_.d.mts.map +1 -0
- package/dist/piConfig-CCBdZXQr.cjs +260 -0
- package/dist/piConfig-CCBdZXQr.cjs.map +1 -0
- package/dist/piConfig-qGyCbcVj.mjs +197 -0
- package/dist/piConfig-qGyCbcVj.mjs.map +1 -0
- package/dist/piConfig.cjs +12 -0
- package/dist/piConfig.d.mts +2 -0
- package/dist/piConfig.mjs +2 -0
- package/dist/piContext.cjs +18 -0
- package/dist/piContext.d.mts +3 -0
- package/dist/piContext.mjs +2 -0
- package/dist/profiles-CTrUCmIh.d.mts +27 -0
- package/dist/profiles-CTrUCmIh.d.mts.map +1 -0
- package/dist/profiles-DnF9DBpd.cjs +552 -0
- package/dist/profiles-DnF9DBpd.cjs.map +1 -0
- package/dist/profiles-fujQKrS0.mjs +483 -0
- package/dist/profiles-fujQKrS0.mjs.map +1 -0
- package/dist/profiles.cjs +13 -0
- package/dist/profiles.d.mts +25 -0
- package/dist/profiles.d.mts.map +1 -0
- package/dist/profiles.mjs +2 -0
- package/dist/rolldown-runtime-VH7oDXx4.cjs +28 -0
- package/dist/selectionSwitch.cjs +70 -0
- package/dist/selectionSwitch.cjs.map +1 -0
- package/dist/selectionSwitch.d.mts +30 -0
- package/dist/selectionSwitch.d.mts.map +1 -0
- package/dist/selectionSwitch.mjs +64 -0
- package/dist/selectionSwitch.mjs.map +1 -0
- package/dist/sessionConfig-Boh4Fdje.cjs +342 -0
- package/dist/sessionConfig-Boh4Fdje.cjs.map +1 -0
- package/dist/sessionConfig-CtLoc-lO.mjs +240 -0
- package/dist/sessionConfig-CtLoc-lO.mjs.map +1 -0
- package/dist/types.cjs +9 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +2 -0
- package/llms.txt +12 -0
- package/package.json +206 -0
- package/src/prompts/po-author-config/SKILL.md +26 -0
- package/src/prompts/po-author-config/agents/openai.yaml +4 -0
- package/src/prompts/po-author-config/references/config-contract.md +201 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { t as globalDoomConfigDirectory } from "./config-CKA07FxG.mjs";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
//#region src/services/init/index.ts
|
|
7
|
+
const PRIVATE_DIRECTORY_MODE = 448;
|
|
8
|
+
const PRIVATE_FILE_MODE = 384;
|
|
9
|
+
const REPOSITORY_DIRECTORY_MODE = 493;
|
|
10
|
+
const REPOSITORY_FILE_MODE = 420;
|
|
11
|
+
const DOOM_DIRECTORY = ".po";
|
|
12
|
+
const UTF8_ENCODING = "utf8";
|
|
13
|
+
const FILE_ALREADY_EXISTS = "EEXIST";
|
|
14
|
+
const FILE_NOT_FOUND = "ENOENT";
|
|
15
|
+
/** The global seed files are processed in this fixed order. */
|
|
16
|
+
const GLOBAL_DOOM_SEED_FILES = [
|
|
17
|
+
"config.yaml",
|
|
18
|
+
"modes.yaml",
|
|
19
|
+
"domains.yaml",
|
|
20
|
+
"profiles.yaml"
|
|
21
|
+
];
|
|
22
|
+
/** Portable defaults for a new global Doom configuration directory. */
|
|
23
|
+
const DOOM_CONFIG_TEMPLATES = {
|
|
24
|
+
"config.yaml": `projectTrust: ask
|
|
25
|
+
|
|
26
|
+
# Autonomous voice is opt-in and uses an explicitly configured Pi model.
|
|
27
|
+
# voice:
|
|
28
|
+
# autoCapture:
|
|
29
|
+
# model: provider/model-id
|
|
30
|
+
# startPhrases:
|
|
31
|
+
# - hey doom
|
|
32
|
+
# stopPhrases:
|
|
33
|
+
# - stop speaking
|
|
34
|
+
# utteranceIdleMs: 3000
|
|
35
|
+
# # Long prompts only: open a draft, keep talking, then send it in one piece.
|
|
36
|
+
# # Short utterances are delivered as you finish them and need no phrase.
|
|
37
|
+
# composeOpenPhrases:
|
|
38
|
+
# - hey doom
|
|
39
|
+
# composeSendPhrases:
|
|
40
|
+
# - that's it
|
|
41
|
+
# composeCancelPhrases:
|
|
42
|
+
# - scratch that
|
|
43
|
+
# # Endpoint window while a draft collects, so a short command lands on its own.
|
|
44
|
+
# composeUtteranceIdleMs: 1200
|
|
45
|
+
# # Silence before Voice reminds you a draft is open. 0 turns the reminder off.
|
|
46
|
+
# composeNudgeMs: 10000
|
|
47
|
+
# tts:
|
|
48
|
+
# engine: macos-say
|
|
49
|
+
# voice: Samantha
|
|
50
|
+
# rate: 190
|
|
51
|
+
`,
|
|
52
|
+
"modes.yaml": `# A layer is a reusable named bundle of packages, built-in or local extensions,
|
|
53
|
+
# and hook groups. Major modes below choose which layers load together for a session.
|
|
54
|
+
#
|
|
55
|
+
# Layers and modes defined here apply to every repository. A repository's own
|
|
56
|
+
# .po/modes.yaml is read after this file and replaces any layer or mode of the
|
|
57
|
+
# same name, so a repository can override one entry without restating the rest.
|
|
58
|
+
#
|
|
59
|
+
# Add a layer by giving it a unique name under layers. Local Pi scripts belong
|
|
60
|
+
# under extensions, while installed Pi packages belong under packages:
|
|
61
|
+
# review-tools:
|
|
62
|
+
# extensions:
|
|
63
|
+
# - './extensions/local-review.ts'
|
|
64
|
+
# packages:
|
|
65
|
+
# - '@scope/review-extension'
|
|
66
|
+
# A bare extension name selects a Po built-in. A path beginning with ./ or
|
|
67
|
+
# ../ loads a custom script or extension directory. A bare package loads its
|
|
68
|
+
# ordered package.json pi.extensions entries, while an exported subpath selects
|
|
69
|
+
# one adapter. Relative paths resolve beside this file here (~/.po), or
|
|
70
|
+
# from the repository root in .po/modes.yaml.
|
|
71
|
+
#
|
|
72
|
+
# Use a package mapping when that package accepts configuration. Configuration
|
|
73
|
+
# belongs under the package entry that consumes it, not beside packages.
|
|
74
|
+
# The top-level default bundle loads before every major mode. Replace this whole
|
|
75
|
+
# packages list to customize the distribution defaults. Po core packages
|
|
76
|
+
# remain active independently of this list.
|
|
77
|
+
default:
|
|
78
|
+
packages:
|
|
79
|
+
- '@agimon-ai/po-help'
|
|
80
|
+
- '@agimon-ai/po-hook'
|
|
81
|
+
- '@agimon-ai/po-goal'
|
|
82
|
+
- '@agimon-ai/po-voice'
|
|
83
|
+
- '@agimon-ai/po-runner'
|
|
84
|
+
- '@agimon-ai/po-read'
|
|
85
|
+
- '@agimon-ai/po-grep'
|
|
86
|
+
- '@agimon-ai/po-edit'
|
|
87
|
+
- '@agimon-ai/po-file-edit'
|
|
88
|
+
- '@agimon-ai/po-autocompact'
|
|
89
|
+
- '@agimon-ai/po-loop'
|
|
90
|
+
- '@agimon-ai/po-plan'
|
|
91
|
+
- '@agimon-ai/po-workflow'
|
|
92
|
+
- '@agimon-ai/po-log'
|
|
93
|
+
- '@agimon-ai/po-mcp'
|
|
94
|
+
- '@agimon-ai/po-template-elegant'
|
|
95
|
+
layers:
|
|
96
|
+
team:
|
|
97
|
+
packages:
|
|
98
|
+
- name: '@agimon-ai/po-team'
|
|
99
|
+
# Optional Team configuration. Uncomment and choose models available to Pi.
|
|
100
|
+
# config:
|
|
101
|
+
# models:
|
|
102
|
+
# - model: openai-codex/gpt-5.6-luna
|
|
103
|
+
# thinking: xhigh
|
|
104
|
+
# # Tool names excluded from subagents launched by this package. These
|
|
105
|
+
# # remove model-visible tools while preserving hidden team transport.
|
|
106
|
+
# excludeTools: [ask_user_question, intercom, subagent]
|
|
107
|
+
ask-user:
|
|
108
|
+
packages:
|
|
109
|
+
- '@agimon-ai/po-user-feedback'
|
|
110
|
+
task:
|
|
111
|
+
packages:
|
|
112
|
+
- '@agimon-ai/po-task'
|
|
113
|
+
# A major mode explains when it should be used and names its ordered layers.
|
|
114
|
+
# Add another entry under majorMode, then select it with
|
|
115
|
+
# po --major-mode <name>. Change defaultMajorMode to make it the default.
|
|
116
|
+
defaultMajorMode: copilot
|
|
117
|
+
majorMode:
|
|
118
|
+
minimal:
|
|
119
|
+
description: Lean mode with Team delegation and persistent tasks.
|
|
120
|
+
layers: [team, task]
|
|
121
|
+
copilot:
|
|
122
|
+
description: General-purpose coding mode with Team delegation, persistent tasks, supervised commands, and structured user feedback.
|
|
123
|
+
layers: [team, ask-user, task]
|
|
124
|
+
# review:
|
|
125
|
+
# description: Focused review mode for inspecting changes and reporting risks.
|
|
126
|
+
# layers: [team, task, ask-user]
|
|
127
|
+
`,
|
|
128
|
+
"domains.yaml": `# Plugins are named once in this catalog, then selected by one or more domains.
|
|
129
|
+
# Po automatically inspects personal and repository Codex marketplaces.
|
|
130
|
+
# Each configured root may also be a folder whose direct children are plugins;
|
|
131
|
+
# use roots: [plugins] to discover a repository plugin folder without one entry
|
|
132
|
+
# per plugin. Discovery never scans recursively.
|
|
133
|
+
defaultDomains: [default]
|
|
134
|
+
plugins:
|
|
135
|
+
roots: []
|
|
136
|
+
entries: {}
|
|
137
|
+
# Local paths resolve beside this file in ~/.po. Repository paths in a
|
|
138
|
+
# repository .po/domains.yaml resolve from that repository root.
|
|
139
|
+
# entries:
|
|
140
|
+
# development:
|
|
141
|
+
# source: local
|
|
142
|
+
# path: plugins/development
|
|
143
|
+
# remote-review:
|
|
144
|
+
# source: url
|
|
145
|
+
# url: https://github.com/acme/review-plugin.git
|
|
146
|
+
# ref: v1.2.0
|
|
147
|
+
# published-review:
|
|
148
|
+
# source: npm
|
|
149
|
+
# package: '@acme/review-plugin'
|
|
150
|
+
# version: 1.2.0
|
|
151
|
+
# Domains carry descriptions and refer to catalog names, not filesystem paths.
|
|
152
|
+
domains:
|
|
153
|
+
default:
|
|
154
|
+
description: Shared skills and repository MCP only.
|
|
155
|
+
plugins: []
|
|
156
|
+
# development:
|
|
157
|
+
# description: TypeScript implementation and review tools.
|
|
158
|
+
# plugins:
|
|
159
|
+
# - development
|
|
160
|
+
# # Mapping form can load only selected resources from a shared plugin.
|
|
161
|
+
# - name: remote-review
|
|
162
|
+
# skills: [typescript]
|
|
163
|
+
# agents: [reviewer]
|
|
164
|
+
# hooks: false
|
|
165
|
+
# mcp: true
|
|
166
|
+
# # Set false only when this domain should omit shared .claude/skills.
|
|
167
|
+
# sharedSkills: false
|
|
168
|
+
# # Domain mcp is an allowlist over servers configured elsewhere, not a
|
|
169
|
+
# # request to start new ones. Listing servers here drops the tool schemas
|
|
170
|
+
# # of the ones left out, usually the largest context saving a domain can
|
|
171
|
+
# # make. Run po --explain to see the token cost before and after.
|
|
172
|
+
# # Filtering applies only when every selected domain declares mcp, so a
|
|
173
|
+
# # selection mixing this with a domain that omits it stays unfiltered.
|
|
174
|
+
# mcp:
|
|
175
|
+
# servers: [code-intel]
|
|
176
|
+
# proxy: [repository-search]
|
|
177
|
+
# Select it with po --domains development, or add it to defaultDomains.
|
|
178
|
+
#
|
|
179
|
+
# Aliases let one selection enable multiple domains. Replace the empty mapping
|
|
180
|
+
# below with entries like the commented example.
|
|
181
|
+
aliases: {}
|
|
182
|
+
# aliases:
|
|
183
|
+
# work: [default, development]
|
|
184
|
+
`,
|
|
185
|
+
"profiles.yaml": `# Profiles select a persona and optional environment defaults for a session.
|
|
186
|
+
# Each configured root may itself be a profile or contain direct-child profile
|
|
187
|
+
# folders. A folder is discovered when it contains profile.md, SOUL.md, or
|
|
188
|
+
# AGENTS.md; discovery never scans recursively.
|
|
189
|
+
profiles:
|
|
190
|
+
roots: []
|
|
191
|
+
entries: {}
|
|
192
|
+
# Roots resolve beside this file in ~/.po. Repository roots in a
|
|
193
|
+
# repository .po/profiles.yaml resolve from that repository root.
|
|
194
|
+
# roots: [agents/acme]
|
|
195
|
+
# Explicit entries override an automatically discovered folder of the same
|
|
196
|
+
# name. Environment values must be strings; already exported values win.
|
|
197
|
+
# entries:
|
|
198
|
+
# writer:
|
|
199
|
+
# persona: agents/special/writer
|
|
200
|
+
# env:
|
|
201
|
+
# BRAND: acme
|
|
202
|
+
# TONE: concise
|
|
203
|
+
# Doom Pi concatenates profile.md, SOUL.md, then AGENTS.md for the persona.
|
|
204
|
+
# Select one with: po --profile writer
|
|
205
|
+
`
|
|
206
|
+
};
|
|
207
|
+
/** Standalone defaults for a repository that is trying Po through DPI. */
|
|
208
|
+
const REPOSITORY_DOOM_CONFIG_TEMPLATES = {
|
|
209
|
+
"config.yaml": DOOM_CONFIG_TEMPLATES["config.yaml"],
|
|
210
|
+
"modes.yaml": `# Repository-local layers and major modes. These entries override personal
|
|
211
|
+
# entries with the same name from ~/.po/modes.yaml.
|
|
212
|
+
# This repository-local default replaces the personal top-level default as one
|
|
213
|
+
# whole package list. Edit it to customize the standalone package baseline.
|
|
214
|
+
default:
|
|
215
|
+
packages:
|
|
216
|
+
- '@agimon-ai/po-help'
|
|
217
|
+
- '@agimon-ai/po-hook'
|
|
218
|
+
- '@agimon-ai/po-goal'
|
|
219
|
+
- '@agimon-ai/po-voice'
|
|
220
|
+
- '@agimon-ai/po-runner'
|
|
221
|
+
- '@agimon-ai/po-read'
|
|
222
|
+
- '@agimon-ai/po-grep'
|
|
223
|
+
- '@agimon-ai/po-edit'
|
|
224
|
+
- '@agimon-ai/po-file-edit'
|
|
225
|
+
- '@agimon-ai/po-autocompact'
|
|
226
|
+
- '@agimon-ai/po-loop'
|
|
227
|
+
- '@agimon-ai/po-plan'
|
|
228
|
+
- '@agimon-ai/po-workflow'
|
|
229
|
+
- '@agimon-ai/po-log'
|
|
230
|
+
- '@agimon-ai/po-mcp'
|
|
231
|
+
- '@agimon-ai/po-template-elegant'
|
|
232
|
+
layers:
|
|
233
|
+
team:
|
|
234
|
+
packages:
|
|
235
|
+
- name: '@agimon-ai/po-team'
|
|
236
|
+
ask-user:
|
|
237
|
+
packages:
|
|
238
|
+
- '@agimon-ai/po-user-feedback'
|
|
239
|
+
task:
|
|
240
|
+
packages:
|
|
241
|
+
- '@agimon-ai/po-task'
|
|
242
|
+
defaultMajorMode: copilot
|
|
243
|
+
majorMode:
|
|
244
|
+
minimal:
|
|
245
|
+
description: Lean mode with Team delegation and persistent tasks.
|
|
246
|
+
layers: [team, task]
|
|
247
|
+
copilot:
|
|
248
|
+
description: General-purpose coding mode with delegation, persistent tasks, supervised commands, and structured user feedback.
|
|
249
|
+
layers: [team, ask-user, task]
|
|
250
|
+
`,
|
|
251
|
+
"domains.yaml": `# Repository-local plugin catalog and domain selection.
|
|
252
|
+
defaultDomains: [default]
|
|
253
|
+
plugins:
|
|
254
|
+
roots: []
|
|
255
|
+
entries: {}
|
|
256
|
+
domains:
|
|
257
|
+
default:
|
|
258
|
+
description: Shared skills and repository MCP only.
|
|
259
|
+
plugins: []
|
|
260
|
+
aliases: {}
|
|
261
|
+
`,
|
|
262
|
+
"profiles.yaml": `# Repository-local persona roots and environment defaults.
|
|
263
|
+
profiles:
|
|
264
|
+
roots: []
|
|
265
|
+
entries: {}
|
|
266
|
+
`
|
|
267
|
+
};
|
|
268
|
+
function errorCode(error) {
|
|
269
|
+
if (!(error instanceof Error)) return void 0;
|
|
270
|
+
const code = error.code;
|
|
271
|
+
return typeof code === "string" ? code : void 0;
|
|
272
|
+
}
|
|
273
|
+
function ensureDirectory(directory, mode) {
|
|
274
|
+
let stats;
|
|
275
|
+
try {
|
|
276
|
+
stats = fs.lstatSync(directory);
|
|
277
|
+
} catch (error) {
|
|
278
|
+
if (errorCode(error) !== FILE_NOT_FOUND) throw error;
|
|
279
|
+
try {
|
|
280
|
+
fs.mkdirSync(directory, { mode });
|
|
281
|
+
stats = fs.lstatSync(directory);
|
|
282
|
+
} catch (mkdirError) {
|
|
283
|
+
if (errorCode(mkdirError) !== FILE_ALREADY_EXISTS) throw mkdirError;
|
|
284
|
+
stats = fs.lstatSync(directory);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (stats.isSymbolicLink()) throw new Error(`Refusing to initialize through symlinked directory: ${directory}`);
|
|
288
|
+
if (!stats.isDirectory()) throw new Error(`Doom config path is not a directory: ${directory}`);
|
|
289
|
+
}
|
|
290
|
+
function ensureDoomDirectory(directory, mode) {
|
|
291
|
+
ensureDirectory(path.dirname(directory), mode);
|
|
292
|
+
ensureDirectory(directory, mode);
|
|
293
|
+
}
|
|
294
|
+
function classifyTarget(targetPath) {
|
|
295
|
+
let stats;
|
|
296
|
+
try {
|
|
297
|
+
stats = fs.lstatSync(targetPath);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if (errorCode(error) === FILE_NOT_FOUND) return "missing";
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
if (stats.isFile()) return "file";
|
|
303
|
+
if (stats.isSymbolicLink()) try {
|
|
304
|
+
if (fs.statSync(targetPath).isFile()) return "file";
|
|
305
|
+
} catch (error) {
|
|
306
|
+
throw new Error(`Doom config seed symlink is not file-like: ${targetPath}`, { cause: error });
|
|
307
|
+
}
|
|
308
|
+
throw new Error(`Doom config seed path is not file-like: ${targetPath}`);
|
|
309
|
+
}
|
|
310
|
+
function cleanupTemporaryFile(temporaryPath) {
|
|
311
|
+
try {
|
|
312
|
+
fs.unlinkSync(temporaryPath);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (errorCode(error) !== FILE_NOT_FOUND) throw error;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function publishExclusively(targetPath, content, mode) {
|
|
318
|
+
const temporaryPath = `${targetPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
319
|
+
let fileDescriptor;
|
|
320
|
+
try {
|
|
321
|
+
fileDescriptor = fs.openSync(temporaryPath, "wx", mode);
|
|
322
|
+
fs.writeFileSync(fileDescriptor, content, UTF8_ENCODING);
|
|
323
|
+
fs.fchmodSync(fileDescriptor, mode);
|
|
324
|
+
fs.fsyncSync(fileDescriptor);
|
|
325
|
+
const descriptorToClose = fileDescriptor;
|
|
326
|
+
fileDescriptor = void 0;
|
|
327
|
+
fs.closeSync(descriptorToClose);
|
|
328
|
+
try {
|
|
329
|
+
fs.linkSync(temporaryPath, targetPath);
|
|
330
|
+
return true;
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (errorCode(error) === FILE_ALREADY_EXISTS && classifyTarget(targetPath) === "file") return false;
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
} finally {
|
|
336
|
+
if (fileDescriptor !== void 0) {
|
|
337
|
+
const descriptorToClose = fileDescriptor;
|
|
338
|
+
fileDescriptor = void 0;
|
|
339
|
+
fs.closeSync(descriptorToClose);
|
|
340
|
+
}
|
|
341
|
+
cleanupTemporaryFile(temporaryPath);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Replaces a seed file with the template, atomically.
|
|
346
|
+
*
|
|
347
|
+
* The rename swaps the directory entry in one step, so a reader either sees the
|
|
348
|
+
* whole old file or the whole new one. Renaming onto a symlinked seed replaces
|
|
349
|
+
* the link rather than writing through it.
|
|
350
|
+
*/
|
|
351
|
+
function publishForcefully(targetPath, content, mode) {
|
|
352
|
+
const temporaryPath = `${targetPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
353
|
+
let fileDescriptor;
|
|
354
|
+
try {
|
|
355
|
+
fileDescriptor = fs.openSync(temporaryPath, "wx", mode);
|
|
356
|
+
fs.writeFileSync(fileDescriptor, content, UTF8_ENCODING);
|
|
357
|
+
fs.fchmodSync(fileDescriptor, mode);
|
|
358
|
+
fs.fsyncSync(fileDescriptor);
|
|
359
|
+
const descriptorToClose = fileDescriptor;
|
|
360
|
+
fileDescriptor = void 0;
|
|
361
|
+
fs.closeSync(descriptorToClose);
|
|
362
|
+
fs.renameSync(temporaryPath, targetPath);
|
|
363
|
+
} finally {
|
|
364
|
+
if (fileDescriptor !== void 0) {
|
|
365
|
+
const descriptorToClose = fileDescriptor;
|
|
366
|
+
fileDescriptor = void 0;
|
|
367
|
+
fs.closeSync(descriptorToClose);
|
|
368
|
+
}
|
|
369
|
+
cleanupTemporaryFile(temporaryPath);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function initializeDoomConfig(directory, templates, options, directoryMode, fileMode) {
|
|
373
|
+
ensureDoomDirectory(directory, directoryMode);
|
|
374
|
+
const created = [];
|
|
375
|
+
const preserved = [];
|
|
376
|
+
const replaced = [];
|
|
377
|
+
for (const fileName of GLOBAL_DOOM_SEED_FILES) {
|
|
378
|
+
const targetPath = path.join(directory, fileName);
|
|
379
|
+
const existed = classifyTarget(targetPath) === "file";
|
|
380
|
+
if (options.force) {
|
|
381
|
+
publishForcefully(targetPath, templates[fileName], fileMode);
|
|
382
|
+
(existed ? replaced : created).push(fileName);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (existed) {
|
|
386
|
+
preserved.push(fileName);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (publishExclusively(targetPath, templates[fileName], fileMode)) created.push(fileName);
|
|
390
|
+
else preserved.push(fileName);
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
directory,
|
|
394
|
+
created,
|
|
395
|
+
preserved,
|
|
396
|
+
replaced
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Fills missing global seed files.
|
|
401
|
+
*
|
|
402
|
+
* Existing files are left alone so that re-running init never discards
|
|
403
|
+
* hand-edited config; pass `force` to overwrite them from the template.
|
|
404
|
+
*/
|
|
405
|
+
function initializeGlobalDoomConfig(homeDirectory = os.homedir(), options = {}) {
|
|
406
|
+
return initializeDoomConfig(globalDoomConfigDirectory(homeDirectory), DOOM_CONFIG_TEMPLATES, options, PRIVATE_DIRECTORY_MODE, PRIVATE_FILE_MODE);
|
|
407
|
+
}
|
|
408
|
+
/** Seeds repository-local configuration without creating or changing Pi settings. */
|
|
409
|
+
function initializeRepositoryDoomConfig(repositoryRoot = process.cwd(), options = {}) {
|
|
410
|
+
return initializeDoomConfig(path.join(path.resolve(repositoryRoot), DOOM_DIRECTORY), REPOSITORY_DOOM_CONFIG_TEMPLATES, options, REPOSITORY_DIRECTORY_MODE, REPOSITORY_FILE_MODE);
|
|
411
|
+
}
|
|
412
|
+
//#endregion
|
|
413
|
+
export { initializeRepositoryDoomConfig as a, initializeGlobalDoomConfig as i, GLOBAL_DOOM_SEED_FILES as n, REPOSITORY_DOOM_CONFIG_TEMPLATES as r, DOOM_CONFIG_TEMPLATES as t };
|
|
414
|
+
|
|
415
|
+
//# sourceMappingURL=init-DJ6wm-dr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-DJ6wm-dr.mjs","names":[],"sources":["../src/services/init/index.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { globalDoomConfigDirectory } from '../config';\n\nconst PRIVATE_DIRECTORY_MODE = 0o700;\nconst PRIVATE_FILE_MODE = 0o600;\nconst REPOSITORY_DIRECTORY_MODE = 0o755;\nconst REPOSITORY_FILE_MODE = 0o644;\nconst DOOM_DIRECTORY = '.po';\nconst UTF8_ENCODING = 'utf8';\nconst FILE_ALREADY_EXISTS = 'EEXIST';\nconst FILE_NOT_FOUND = 'ENOENT';\n\n/** The global seed files are processed in this fixed order. */\nexport const GLOBAL_DOOM_SEED_FILES = ['config.yaml', 'modes.yaml', 'domains.yaml', 'profiles.yaml'] as const;\n\ntype DoomSeedFile = (typeof GLOBAL_DOOM_SEED_FILES)[number];\n\n/** Portable defaults for a new global Doom configuration directory. */\nexport const DOOM_CONFIG_TEMPLATES: Readonly<Record<DoomSeedFile, string>> = {\n 'config.yaml': `projectTrust: ask\n\n# Autonomous voice is opt-in and uses an explicitly configured Pi model.\n# voice:\n# autoCapture:\n# model: provider/model-id\n# startPhrases:\n# - hey doom\n# stopPhrases:\n# - stop speaking\n# utteranceIdleMs: 3000\n# # Long prompts only: open a draft, keep talking, then send it in one piece.\n# # Short utterances are delivered as you finish them and need no phrase.\n# composeOpenPhrases:\n# - hey doom\n# composeSendPhrases:\n# - that's it\n# composeCancelPhrases:\n# - scratch that\n# # Endpoint window while a draft collects, so a short command lands on its own.\n# composeUtteranceIdleMs: 1200\n# # Silence before Voice reminds you a draft is open. 0 turns the reminder off.\n# composeNudgeMs: 10000\n# tts:\n# engine: macos-say\n# voice: Samantha\n# rate: 190\n`,\n 'modes.yaml': `# A layer is a reusable named bundle of packages, built-in or local extensions,\n# and hook groups. Major modes below choose which layers load together for a session.\n#\n# Layers and modes defined here apply to every repository. A repository's own\n# .po/modes.yaml is read after this file and replaces any layer or mode of the\n# same name, so a repository can override one entry without restating the rest.\n#\n# Add a layer by giving it a unique name under layers. Local Pi scripts belong\n# under extensions, while installed Pi packages belong under packages:\n# review-tools:\n# extensions:\n# - './extensions/local-review.ts'\n# packages:\n# - '@scope/review-extension'\n# A bare extension name selects a Po built-in. A path beginning with ./ or\n# ../ loads a custom script or extension directory. A bare package loads its\n# ordered package.json pi.extensions entries, while an exported subpath selects\n# one adapter. Relative paths resolve beside this file here (~/.po), or\n# from the repository root in .po/modes.yaml.\n#\n# Use a package mapping when that package accepts configuration. Configuration\n# belongs under the package entry that consumes it, not beside packages.\n# The top-level default bundle loads before every major mode. Replace this whole\n# packages list to customize the distribution defaults. Po core packages\n# remain active independently of this list.\ndefault:\n packages:\n - '@agimon-ai/po-help'\n - '@agimon-ai/po-hook'\n - '@agimon-ai/po-goal'\n - '@agimon-ai/po-voice'\n - '@agimon-ai/po-runner'\n - '@agimon-ai/po-read'\n - '@agimon-ai/po-grep'\n - '@agimon-ai/po-edit'\n - '@agimon-ai/po-file-edit'\n - '@agimon-ai/po-autocompact'\n - '@agimon-ai/po-loop'\n - '@agimon-ai/po-plan'\n - '@agimon-ai/po-workflow'\n - '@agimon-ai/po-log'\n - '@agimon-ai/po-mcp'\n - '@agimon-ai/po-template-elegant'\nlayers:\n team:\n packages:\n - name: '@agimon-ai/po-team'\n # Optional Team configuration. Uncomment and choose models available to Pi.\n # config:\n # models:\n # - model: openai-codex/gpt-5.6-luna\n # thinking: xhigh\n # # Tool names excluded from subagents launched by this package. These\n # # remove model-visible tools while preserving hidden team transport.\n # excludeTools: [ask_user_question, intercom, subagent]\n ask-user:\n packages:\n - '@agimon-ai/po-user-feedback'\n task:\n packages:\n - '@agimon-ai/po-task'\n# A major mode explains when it should be used and names its ordered layers.\n# Add another entry under majorMode, then select it with\n# po --major-mode <name>. Change defaultMajorMode to make it the default.\ndefaultMajorMode: copilot\nmajorMode:\n minimal:\n description: Lean mode with Team delegation and persistent tasks.\n layers: [team, task]\n copilot:\n description: General-purpose coding mode with Team delegation, persistent tasks, supervised commands, and structured user feedback.\n layers: [team, ask-user, task]\n # review:\n # description: Focused review mode for inspecting changes and reporting risks.\n # layers: [team, task, ask-user]\n`,\n 'domains.yaml': `# Plugins are named once in this catalog, then selected by one or more domains.\n# Po automatically inspects personal and repository Codex marketplaces.\n# Each configured root may also be a folder whose direct children are plugins;\n# use roots: [plugins] to discover a repository plugin folder without one entry\n# per plugin. Discovery never scans recursively.\ndefaultDomains: [default]\nplugins:\n roots: []\n entries: {}\n # Local paths resolve beside this file in ~/.po. Repository paths in a\n # repository .po/domains.yaml resolve from that repository root.\n # entries:\n # development:\n # source: local\n # path: plugins/development\n # remote-review:\n # source: url\n # url: https://github.com/acme/review-plugin.git\n # ref: v1.2.0\n # published-review:\n # source: npm\n # package: '@acme/review-plugin'\n # version: 1.2.0\n# Domains carry descriptions and refer to catalog names, not filesystem paths.\ndomains:\n default:\n description: Shared skills and repository MCP only.\n plugins: []\n # development:\n # description: TypeScript implementation and review tools.\n # plugins:\n # - development\n # # Mapping form can load only selected resources from a shared plugin.\n # - name: remote-review\n # skills: [typescript]\n # agents: [reviewer]\n # hooks: false\n # mcp: true\n # # Set false only when this domain should omit shared .claude/skills.\n # sharedSkills: false\n # # Domain mcp is an allowlist over servers configured elsewhere, not a\n # # request to start new ones. Listing servers here drops the tool schemas\n # # of the ones left out, usually the largest context saving a domain can\n # # make. Run po --explain to see the token cost before and after.\n # # Filtering applies only when every selected domain declares mcp, so a\n # # selection mixing this with a domain that omits it stays unfiltered.\n # mcp:\n # servers: [code-intel]\n # proxy: [repository-search]\n# Select it with po --domains development, or add it to defaultDomains.\n#\n# Aliases let one selection enable multiple domains. Replace the empty mapping\n# below with entries like the commented example.\naliases: {}\n# aliases:\n# work: [default, development]\n`,\n 'profiles.yaml': `# Profiles select a persona and optional environment defaults for a session.\n# Each configured root may itself be a profile or contain direct-child profile\n# folders. A folder is discovered when it contains profile.md, SOUL.md, or\n# AGENTS.md; discovery never scans recursively.\nprofiles:\n roots: []\n entries: {}\n # Roots resolve beside this file in ~/.po. Repository roots in a\n # repository .po/profiles.yaml resolve from that repository root.\n # roots: [agents/acme]\n # Explicit entries override an automatically discovered folder of the same\n # name. Environment values must be strings; already exported values win.\n # entries:\n # writer:\n # persona: agents/special/writer\n # env:\n # BRAND: acme\n # TONE: concise\n# Doom Pi concatenates profile.md, SOUL.md, then AGENTS.md for the persona.\n# Select one with: po --profile writer\n`,\n};\n\n/** Standalone defaults for a repository that is trying Po through DPI. */\nexport const REPOSITORY_DOOM_CONFIG_TEMPLATES: Readonly<Record<DoomSeedFile, string>> = {\n 'config.yaml': DOOM_CONFIG_TEMPLATES['config.yaml'],\n 'modes.yaml': `# Repository-local layers and major modes. These entries override personal\n# entries with the same name from ~/.po/modes.yaml.\n# This repository-local default replaces the personal top-level default as one\n# whole package list. Edit it to customize the standalone package baseline.\ndefault:\n packages:\n - '@agimon-ai/po-help'\n - '@agimon-ai/po-hook'\n - '@agimon-ai/po-goal'\n - '@agimon-ai/po-voice'\n - '@agimon-ai/po-runner'\n - '@agimon-ai/po-read'\n - '@agimon-ai/po-grep'\n - '@agimon-ai/po-edit'\n - '@agimon-ai/po-file-edit'\n - '@agimon-ai/po-autocompact'\n - '@agimon-ai/po-loop'\n - '@agimon-ai/po-plan'\n - '@agimon-ai/po-workflow'\n - '@agimon-ai/po-log'\n - '@agimon-ai/po-mcp'\n - '@agimon-ai/po-template-elegant'\nlayers:\n team:\n packages:\n - name: '@agimon-ai/po-team'\n ask-user:\n packages:\n - '@agimon-ai/po-user-feedback'\n task:\n packages:\n - '@agimon-ai/po-task'\ndefaultMajorMode: copilot\nmajorMode:\n minimal:\n description: Lean mode with Team delegation and persistent tasks.\n layers: [team, task]\n copilot:\n description: General-purpose coding mode with delegation, persistent tasks, supervised commands, and structured user feedback.\n layers: [team, ask-user, task]\n`,\n 'domains.yaml': `# Repository-local plugin catalog and domain selection.\ndefaultDomains: [default]\nplugins:\n roots: []\n entries: {}\ndomains:\n default:\n description: Shared skills and repository MCP only.\n plugins: []\naliases: {}\n`,\n 'profiles.yaml': `# Repository-local persona roots and environment defaults.\nprofiles:\n roots: []\n entries: {}\n`,\n};\n\n/** Result of filling a Doom seed directory. File arrays contain names in seed order. */\nexport interface GlobalDoomInitResult {\n directory: string;\n created: string[];\n preserved: string[];\n /** Existing files overwritten from the template. Only ever non-empty under `force`. */\n replaced: string[];\n}\n\nexport interface GlobalDoomInitOptions {\n /**\n * Overwrite existing seed files instead of preserving them.\n *\n * Off by default: init is safe to re-run, and hand-edited config is the\n * normal case rather than the exception.\n */\n force?: boolean;\n}\n\nexport type RepositoryDoomInitOptions = GlobalDoomInitOptions;\nexport type RepositoryDoomInitResult = GlobalDoomInitResult;\n\nfunction errorCode(error: unknown): string | undefined {\n if (!(error instanceof Error)) return undefined;\n const code = (error as NodeJS.ErrnoException).code;\n return typeof code === 'string' ? code : undefined;\n}\n\nfunction ensureDirectory(directory: string, mode: number): void {\n let stats: fs.Stats;\n try {\n stats = fs.lstatSync(directory);\n } catch (error) {\n if (errorCode(error) !== FILE_NOT_FOUND) throw error;\n try {\n fs.mkdirSync(directory, { mode });\n stats = fs.lstatSync(directory);\n } catch (mkdirError) {\n if (errorCode(mkdirError) !== FILE_ALREADY_EXISTS) throw mkdirError;\n stats = fs.lstatSync(directory);\n }\n }\n\n if (stats.isSymbolicLink()) {\n throw new Error(`Refusing to initialize through symlinked directory: ${directory}`);\n }\n if (!stats.isDirectory()) {\n throw new Error(`Doom config path is not a directory: ${directory}`);\n }\n}\n\nfunction ensureDoomDirectory(directory: string, mode: number): void {\n ensureDirectory(path.dirname(directory), mode);\n ensureDirectory(directory, mode);\n}\n\nfunction classifyTarget(targetPath: string): 'missing' | 'file' {\n let stats: fs.Stats;\n try {\n stats = fs.lstatSync(targetPath);\n } catch (error) {\n if (errorCode(error) === FILE_NOT_FOUND) return 'missing';\n throw error;\n }\n\n if (stats.isFile()) return 'file';\n if (stats.isSymbolicLink()) {\n try {\n if (fs.statSync(targetPath).isFile()) return 'file';\n } catch (error) {\n throw new Error(`Doom config seed symlink is not file-like: ${targetPath}`, { cause: error });\n }\n }\n throw new Error(`Doom config seed path is not file-like: ${targetPath}`);\n}\n\nfunction cleanupTemporaryFile(temporaryPath: string): void {\n try {\n fs.unlinkSync(temporaryPath);\n } catch (error) {\n if (errorCode(error) !== FILE_NOT_FOUND) throw error;\n }\n}\n\nfunction publishExclusively(targetPath: string, content: string, mode: number): boolean {\n const temporaryPath = `${targetPath}.${process.pid}.${randomUUID()}.tmp`;\n let fileDescriptor: number | undefined;\n try {\n fileDescriptor = fs.openSync(temporaryPath, 'wx', mode);\n fs.writeFileSync(fileDescriptor, content, UTF8_ENCODING);\n fs.fchmodSync(fileDescriptor, mode);\n fs.fsyncSync(fileDescriptor);\n const descriptorToClose = fileDescriptor;\n fileDescriptor = undefined;\n fs.closeSync(descriptorToClose);\n\n try {\n fs.linkSync(temporaryPath, targetPath);\n return true;\n } catch (error) {\n if (errorCode(error) === FILE_ALREADY_EXISTS && classifyTarget(targetPath) === 'file') return false;\n throw error;\n }\n } finally {\n if (fileDescriptor !== undefined) {\n const descriptorToClose = fileDescriptor;\n fileDescriptor = undefined;\n fs.closeSync(descriptorToClose);\n }\n cleanupTemporaryFile(temporaryPath);\n }\n}\n\n/**\n * Replaces a seed file with the template, atomically.\n *\n * The rename swaps the directory entry in one step, so a reader either sees the\n * whole old file or the whole new one. Renaming onto a symlinked seed replaces\n * the link rather than writing through it.\n */\nfunction publishForcefully(targetPath: string, content: string, mode: number): void {\n const temporaryPath = `${targetPath}.${process.pid}.${randomUUID()}.tmp`;\n let fileDescriptor: number | undefined;\n try {\n fileDescriptor = fs.openSync(temporaryPath, 'wx', mode);\n fs.writeFileSync(fileDescriptor, content, UTF8_ENCODING);\n fs.fchmodSync(fileDescriptor, mode);\n fs.fsyncSync(fileDescriptor);\n const descriptorToClose = fileDescriptor;\n fileDescriptor = undefined;\n fs.closeSync(descriptorToClose);\n\n fs.renameSync(temporaryPath, targetPath);\n } finally {\n if (fileDescriptor !== undefined) {\n const descriptorToClose = fileDescriptor;\n fileDescriptor = undefined;\n fs.closeSync(descriptorToClose);\n }\n cleanupTemporaryFile(temporaryPath);\n }\n}\n\nfunction initializeDoomConfig(\n directory: string,\n templates: Readonly<Record<DoomSeedFile, string>>,\n options: GlobalDoomInitOptions,\n directoryMode: number,\n fileMode: number,\n): GlobalDoomInitResult {\n ensureDoomDirectory(directory, directoryMode);\n\n const created: string[] = [];\n const preserved: string[] = [];\n const replaced: string[] = [];\n for (const fileName of GLOBAL_DOOM_SEED_FILES) {\n const targetPath = path.join(directory, fileName);\n const existed = classifyTarget(targetPath) === 'file';\n\n if (options.force) {\n publishForcefully(targetPath, templates[fileName], fileMode);\n (existed ? replaced : created).push(fileName);\n continue;\n }\n if (existed) {\n preserved.push(fileName);\n continue;\n }\n if (publishExclusively(targetPath, templates[fileName], fileMode)) created.push(fileName);\n else preserved.push(fileName);\n }\n\n return { directory, created, preserved, replaced };\n}\n\n/**\n * Fills missing global seed files.\n *\n * Existing files are left alone so that re-running init never discards\n * hand-edited config; pass `force` to overwrite them from the template.\n */\nexport function initializeGlobalDoomConfig(\n homeDirectory = os.homedir(),\n options: GlobalDoomInitOptions = {},\n): GlobalDoomInitResult {\n return initializeDoomConfig(\n globalDoomConfigDirectory(homeDirectory),\n DOOM_CONFIG_TEMPLATES,\n options,\n PRIVATE_DIRECTORY_MODE,\n PRIVATE_FILE_MODE,\n );\n}\n\n/** Seeds repository-local configuration without creating or changing Pi settings. */\nexport function initializeRepositoryDoomConfig(\n repositoryRoot = process.cwd(),\n options: RepositoryDoomInitOptions = {},\n): RepositoryDoomInitResult {\n return initializeDoomConfig(\n path.join(path.resolve(repositoryRoot), DOOM_DIRECTORY),\n REPOSITORY_DOOM_CONFIG_TEMPLATES,\n options,\n REPOSITORY_DIRECTORY_MODE,\n REPOSITORY_FILE_MODE,\n );\n}\n"],"mappings":"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"}
|
package/dist/init.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_init = require("./init-C_9nyp3-.cjs");
|
|
3
|
+
exports.DOOM_CONFIG_TEMPLATES = require_init.DOOM_CONFIG_TEMPLATES;
|
|
4
|
+
exports.GLOBAL_DOOM_SEED_FILES = require_init.GLOBAL_DOOM_SEED_FILES;
|
|
5
|
+
exports.REPOSITORY_DOOM_CONFIG_TEMPLATES = require_init.REPOSITORY_DOOM_CONFIG_TEMPLATES;
|
|
6
|
+
exports.initializeGlobalDoomConfig = require_init.initializeGlobalDoomConfig;
|
|
7
|
+
exports.initializeRepositoryDoomConfig = require_init.initializeRepositoryDoomConfig;
|
package/dist/init.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as REPOSITORY_DOOM_CONFIG_TEMPLATES, c as initializeGlobalDoomConfig, i as GlobalDoomInitResult, l as initializeRepositoryDoomConfig, n as GLOBAL_DOOM_SEED_FILES, o as RepositoryDoomInitOptions, r as GlobalDoomInitOptions, s as RepositoryDoomInitResult, t as DOOM_CONFIG_TEMPLATES } from "./index-CRcoVYXz.mjs";
|
|
2
|
+
export { DOOM_CONFIG_TEMPLATES, GLOBAL_DOOM_SEED_FILES, type GlobalDoomInitOptions, type GlobalDoomInitResult, REPOSITORY_DOOM_CONFIG_TEMPLATES, type RepositoryDoomInitOptions, type RepositoryDoomInitResult, initializeGlobalDoomConfig, initializeRepositoryDoomConfig };
|
package/dist/init.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as initializeRepositoryDoomConfig, i as initializeGlobalDoomConfig, n as GLOBAL_DOOM_SEED_FILES, r as REPOSITORY_DOOM_CONFIG_TEMPLATES, t as DOOM_CONFIG_TEMPLATES } from "./init-DJ6wm-dr.mjs";
|
|
2
|
+
export { DOOM_CONFIG_TEMPLATES, GLOBAL_DOOM_SEED_FILES, REPOSITORY_DOOM_CONFIG_TEMPLATES, initializeGlobalDoomConfig, initializeRepositoryDoomConfig };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { r as isGlobalDoomConfigRoot, t as globalDoomConfigDirectory } from "./config-CKA07FxG.mjs";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import { parse } from "yaml";
|
|
6
|
+
//#region src/services/layeredConfig/index.ts
|
|
7
|
+
/** Repository-local po configuration directory, committed to git. */
|
|
8
|
+
const DOOM_DIR = ".po";
|
|
9
|
+
const TEXT_ENCODING = "utf8";
|
|
10
|
+
/**
|
|
11
|
+
* Reads one named `.po` document from the global and repository config
|
|
12
|
+
* directories, lowest precedence first.
|
|
13
|
+
*
|
|
14
|
+
* A missing or empty file contributes nothing, so either location on its own is
|
|
15
|
+
* a complete configuration. Documents are deliberately returned unmerged:
|
|
16
|
+
* merging is by name, and only the caller knows what a name means in its own
|
|
17
|
+
* document, so each one folds the sources itself with the repository last.
|
|
18
|
+
*/
|
|
19
|
+
function doomConfigCandidates(fileName, repoRoot, homeDirectory = os.homedir()) {
|
|
20
|
+
const globalDirectory = globalDoomConfigDirectory(homeDirectory);
|
|
21
|
+
const globalCandidate = {
|
|
22
|
+
filePath: path.join(globalDirectory, fileName),
|
|
23
|
+
baseDirectory: globalDirectory
|
|
24
|
+
};
|
|
25
|
+
if (isGlobalDoomConfigRoot(repoRoot, homeDirectory)) return [globalCandidate];
|
|
26
|
+
return [globalCandidate, {
|
|
27
|
+
filePath: path.join(repoRoot, ".po", fileName),
|
|
28
|
+
baseDirectory: repoRoot
|
|
29
|
+
}];
|
|
30
|
+
}
|
|
31
|
+
function readDoomConfigSources(fileName, repoRoot, homeDirectory = os.homedir()) {
|
|
32
|
+
const candidates = doomConfigCandidates(fileName, repoRoot, homeDirectory);
|
|
33
|
+
const sources = [];
|
|
34
|
+
for (const candidate of candidates) {
|
|
35
|
+
if (!fs.existsSync(candidate.filePath)) continue;
|
|
36
|
+
const text = fs.readFileSync(candidate.filePath, TEXT_ENCODING);
|
|
37
|
+
const document = parse(text);
|
|
38
|
+
if (document === null || document === void 0) continue;
|
|
39
|
+
sources.push({
|
|
40
|
+
...candidate,
|
|
41
|
+
text,
|
|
42
|
+
document
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return sources;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Merges same-named records across sources, tagging each entry with the base
|
|
49
|
+
* directory of the document that supplied it.
|
|
50
|
+
*
|
|
51
|
+
* Later sources win outright rather than being deep-merged: a repository that
|
|
52
|
+
* redefines a name is replacing it, and a half-inherited definition whose paths
|
|
53
|
+
* straddle two roots would be impossible to resolve.
|
|
54
|
+
*/
|
|
55
|
+
function mergeNamedSources(sources, select) {
|
|
56
|
+
const merged = {};
|
|
57
|
+
for (const source of sources) for (const [name, entry] of Object.entries(select(source.document) ?? {})) merged[name] = {
|
|
58
|
+
...entry,
|
|
59
|
+
baseDirectory: source.baseDirectory,
|
|
60
|
+
filePath: source.filePath
|
|
61
|
+
};
|
|
62
|
+
return merged;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { readDoomConfigSources as i, doomConfigCandidates as n, mergeNamedSources as r, DOOM_DIR as t };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=layeredConfig-B922ibgn.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layeredConfig-B922ibgn.mjs","names":["parseYaml"],"sources":["../src/services/layeredConfig/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { parse as parseYaml } from 'yaml';\n\nimport { globalDoomConfigDirectory, isGlobalDoomConfigRoot } from '../config';\n\n/** Repository-local po configuration directory, committed to git. */\nexport const DOOM_DIR = '.po';\n\nconst TEXT_ENCODING = 'utf8';\n\n/** Source identity retained for diagnostics and composition fingerprints. */\nexport interface DoomConfigProvenance {\n /** Absolute path of the declaring configuration file. */\n filePath: string;\n /** Directory used to resolve paths authored by that file. */\n baseDirectory: string;\n}\n\n/** One `.po` document plus the root its relative paths resolve against. */\nexport interface DoomConfigSource<TDocument> extends DoomConfigProvenance {\n /** Absolute path of the file the document was read from. */\n filePath: string;\n /**\n * Where relative paths inside this document point.\n *\n * A repository document resolves against the repository root, so `plugins/x`\n * keeps meaning the same thing it always has. A global document resolves\n * against the global `.po` directory, so it can name plugins and extensions\n * that live beside it in `~/.po` rather than inside whichever\n * repository happens to be open.\n */\n baseDirectory: string;\n /** Raw file contents, for callers that cache parsed results by source text. */\n text: string;\n document: TDocument;\n}\n\n/**\n * Reads one named `.po` document from the global and repository config\n * directories, lowest precedence first.\n *\n * A missing or empty file contributes nothing, so either location on its own is\n * a complete configuration. Documents are deliberately returned unmerged:\n * merging is by name, and only the caller knows what a name means in its own\n * document, so each one folds the sources itself with the repository last.\n */\nexport function doomConfigCandidates(\n fileName: string,\n repoRoot: string,\n homeDirectory: string = os.homedir(),\n): Array<{ filePath: string; baseDirectory: string }> {\n const globalDirectory = globalDoomConfigDirectory(homeDirectory);\n const globalCandidate = { filePath: path.join(globalDirectory, fileName), baseDirectory: globalDirectory };\n if (isGlobalDoomConfigRoot(repoRoot, homeDirectory)) return [globalCandidate];\n return [globalCandidate, { filePath: path.join(repoRoot, DOOM_DIR, fileName), baseDirectory: repoRoot }];\n}\n\nexport function readDoomConfigSources<TDocument>(\n fileName: string,\n repoRoot: string,\n homeDirectory: string = os.homedir(),\n): Array<DoomConfigSource<TDocument>> {\n const candidates = doomConfigCandidates(fileName, repoRoot, homeDirectory);\n\n const sources: Array<DoomConfigSource<TDocument>> = [];\n for (const candidate of candidates) {\n if (!fs.existsSync(candidate.filePath)) continue;\n const text = fs.readFileSync(candidate.filePath, TEXT_ENCODING);\n const document = parseYaml(text) as TDocument | null | undefined;\n // An empty file parses to null and is treated as an absent one, so a seeded\n // placeholder never has to be deleted to get out of the way.\n if (document === null || document === undefined) continue;\n sources.push({ ...candidate, text, document });\n }\n return sources;\n}\n\n/**\n * Merges same-named records across sources, tagging each entry with the base\n * directory of the document that supplied it.\n *\n * Later sources win outright rather than being deep-merged: a repository that\n * redefines a name is replacing it, and a half-inherited definition whose paths\n * straddle two roots would be impossible to resolve.\n */\nexport function mergeNamedSources<TDocument, TEntry extends object>(\n sources: ReadonlyArray<DoomConfigSource<TDocument>>,\n select: (document: TDocument) => Record<string, TEntry> | undefined,\n): Record<string, TEntry & DoomConfigProvenance> {\n const merged: Record<string, TEntry & DoomConfigProvenance> = {};\n for (const source of sources) {\n for (const [name, entry] of Object.entries(select(source.document) ?? {})) {\n merged[name] = {\n ...entry,\n baseDirectory: source.baseDirectory,\n filePath: source.filePath,\n };\n }\n }\n return merged;\n}\n"],"mappings":";;;;;;;AASA,MAAa,WAAW;AAExB,MAAM,gBAAgB;;;;;;;;;;AAsCtB,SAAgB,qBACd,UACA,UACA,gBAAwB,GAAG,QAAQ,GACiB;CACpD,MAAM,kBAAkB,0BAA0B,aAAa;CAC/D,MAAM,kBAAkB;EAAE,UAAU,KAAK,KAAK,iBAAiB,QAAQ;EAAG,eAAe;CAAgB;CACzG,IAAI,uBAAuB,UAAU,aAAa,GAAG,OAAO,CAAC,eAAe;CAC5E,OAAO,CAAC,iBAAiB;EAAE,UAAU,KAAK,KAAK,UAAA,OAAoB,QAAQ;EAAG,eAAe;CAAS,CAAC;AACzG;AAEA,SAAgB,sBACd,UACA,UACA,gBAAwB,GAAG,QAAQ,GACC;CACpC,MAAM,aAAa,qBAAqB,UAAU,UAAU,aAAa;CAEzE,MAAM,UAA8C,CAAC;CACrD,KAAK,MAAM,aAAa,YAAY;EAClC,IAAI,CAAC,GAAG,WAAW,UAAU,QAAQ,GAAG;EACxC,MAAM,OAAO,GAAG,aAAa,UAAU,UAAU,aAAa;EAC9D,MAAM,WAAWA,MAAU,IAAI;EAG/B,IAAI,aAAa,QAAQ,aAAa,KAAA,GAAW;EACjD,QAAQ,KAAK;GAAE,GAAG;GAAW;GAAM;EAAS,CAAC;CAC/C;CACA,OAAO;AACT;;;;;;;;;AAUA,SAAgB,kBACd,SACA,QAC+C;CAC/C,MAAM,SAAwD,CAAC;CAC/D,KAAK,MAAM,UAAU,SACnB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,OAAO,OAAO,QAAQ,KAAK,CAAC,CAAC,GACtE,OAAO,QAAQ;EACb,GAAG;EACH,eAAe,OAAO;EACtB,UAAU,OAAO;CACnB;CAGJ,OAAO;AACT"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
|
|
2
|
+
const require_config = require("./config-BUw5kHsx.cjs");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
7
|
+
let node_os = require("node:os");
|
|
8
|
+
node_os = require_rolldown_runtime.__toESM(node_os, 1);
|
|
9
|
+
let yaml = require("yaml");
|
|
10
|
+
//#region src/services/layeredConfig/index.ts
|
|
11
|
+
/** Repository-local po configuration directory, committed to git. */
|
|
12
|
+
const DOOM_DIR = ".po";
|
|
13
|
+
const TEXT_ENCODING = "utf8";
|
|
14
|
+
/**
|
|
15
|
+
* Reads one named `.po` document from the global and repository config
|
|
16
|
+
* directories, lowest precedence first.
|
|
17
|
+
*
|
|
18
|
+
* A missing or empty file contributes nothing, so either location on its own is
|
|
19
|
+
* a complete configuration. Documents are deliberately returned unmerged:
|
|
20
|
+
* merging is by name, and only the caller knows what a name means in its own
|
|
21
|
+
* document, so each one folds the sources itself with the repository last.
|
|
22
|
+
*/
|
|
23
|
+
function doomConfigCandidates(fileName, repoRoot, homeDirectory = node_os.default.homedir()) {
|
|
24
|
+
const globalDirectory = require_config.globalDoomConfigDirectory(homeDirectory);
|
|
25
|
+
const globalCandidate = {
|
|
26
|
+
filePath: node_path.default.join(globalDirectory, fileName),
|
|
27
|
+
baseDirectory: globalDirectory
|
|
28
|
+
};
|
|
29
|
+
if (require_config.isGlobalDoomConfigRoot(repoRoot, homeDirectory)) return [globalCandidate];
|
|
30
|
+
return [globalCandidate, {
|
|
31
|
+
filePath: node_path.default.join(repoRoot, ".po", fileName),
|
|
32
|
+
baseDirectory: repoRoot
|
|
33
|
+
}];
|
|
34
|
+
}
|
|
35
|
+
function readDoomConfigSources(fileName, repoRoot, homeDirectory = node_os.default.homedir()) {
|
|
36
|
+
const candidates = doomConfigCandidates(fileName, repoRoot, homeDirectory);
|
|
37
|
+
const sources = [];
|
|
38
|
+
for (const candidate of candidates) {
|
|
39
|
+
if (!node_fs.default.existsSync(candidate.filePath)) continue;
|
|
40
|
+
const text = node_fs.default.readFileSync(candidate.filePath, TEXT_ENCODING);
|
|
41
|
+
const document = (0, yaml.parse)(text);
|
|
42
|
+
if (document === null || document === void 0) continue;
|
|
43
|
+
sources.push({
|
|
44
|
+
...candidate,
|
|
45
|
+
text,
|
|
46
|
+
document
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return sources;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Merges same-named records across sources, tagging each entry with the base
|
|
53
|
+
* directory of the document that supplied it.
|
|
54
|
+
*
|
|
55
|
+
* Later sources win outright rather than being deep-merged: a repository that
|
|
56
|
+
* redefines a name is replacing it, and a half-inherited definition whose paths
|
|
57
|
+
* straddle two roots would be impossible to resolve.
|
|
58
|
+
*/
|
|
59
|
+
function mergeNamedSources(sources, select) {
|
|
60
|
+
const merged = {};
|
|
61
|
+
for (const source of sources) for (const [name, entry] of Object.entries(select(source.document) ?? {})) merged[name] = {
|
|
62
|
+
...entry,
|
|
63
|
+
baseDirectory: source.baseDirectory,
|
|
64
|
+
filePath: source.filePath
|
|
65
|
+
};
|
|
66
|
+
return merged;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
Object.defineProperty(exports, "DOOM_DIR", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function() {
|
|
72
|
+
return DOOM_DIR;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "doomConfigCandidates", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function() {
|
|
78
|
+
return doomConfigCandidates;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, "mergeNamedSources", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function() {
|
|
84
|
+
return mergeNamedSources;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, "readDoomConfigSources", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function() {
|
|
90
|
+
return readDoomConfigSources;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=layeredConfig-DdI5ysUf.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layeredConfig-DdI5ysUf.cjs","names":["os","globalDoomConfigDirectory","path","isGlobalDoomConfigRoot","fs","parseYaml"],"sources":["../src/services/layeredConfig/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { parse as parseYaml } from 'yaml';\n\nimport { globalDoomConfigDirectory, isGlobalDoomConfigRoot } from '../config';\n\n/** Repository-local po configuration directory, committed to git. */\nexport const DOOM_DIR = '.po';\n\nconst TEXT_ENCODING = 'utf8';\n\n/** Source identity retained for diagnostics and composition fingerprints. */\nexport interface DoomConfigProvenance {\n /** Absolute path of the declaring configuration file. */\n filePath: string;\n /** Directory used to resolve paths authored by that file. */\n baseDirectory: string;\n}\n\n/** One `.po` document plus the root its relative paths resolve against. */\nexport interface DoomConfigSource<TDocument> extends DoomConfigProvenance {\n /** Absolute path of the file the document was read from. */\n filePath: string;\n /**\n * Where relative paths inside this document point.\n *\n * A repository document resolves against the repository root, so `plugins/x`\n * keeps meaning the same thing it always has. A global document resolves\n * against the global `.po` directory, so it can name plugins and extensions\n * that live beside it in `~/.po` rather than inside whichever\n * repository happens to be open.\n */\n baseDirectory: string;\n /** Raw file contents, for callers that cache parsed results by source text. */\n text: string;\n document: TDocument;\n}\n\n/**\n * Reads one named `.po` document from the global and repository config\n * directories, lowest precedence first.\n *\n * A missing or empty file contributes nothing, so either location on its own is\n * a complete configuration. Documents are deliberately returned unmerged:\n * merging is by name, and only the caller knows what a name means in its own\n * document, so each one folds the sources itself with the repository last.\n */\nexport function doomConfigCandidates(\n fileName: string,\n repoRoot: string,\n homeDirectory: string = os.homedir(),\n): Array<{ filePath: string; baseDirectory: string }> {\n const globalDirectory = globalDoomConfigDirectory(homeDirectory);\n const globalCandidate = { filePath: path.join(globalDirectory, fileName), baseDirectory: globalDirectory };\n if (isGlobalDoomConfigRoot(repoRoot, homeDirectory)) return [globalCandidate];\n return [globalCandidate, { filePath: path.join(repoRoot, DOOM_DIR, fileName), baseDirectory: repoRoot }];\n}\n\nexport function readDoomConfigSources<TDocument>(\n fileName: string,\n repoRoot: string,\n homeDirectory: string = os.homedir(),\n): Array<DoomConfigSource<TDocument>> {\n const candidates = doomConfigCandidates(fileName, repoRoot, homeDirectory);\n\n const sources: Array<DoomConfigSource<TDocument>> = [];\n for (const candidate of candidates) {\n if (!fs.existsSync(candidate.filePath)) continue;\n const text = fs.readFileSync(candidate.filePath, TEXT_ENCODING);\n const document = parseYaml(text) as TDocument | null | undefined;\n // An empty file parses to null and is treated as an absent one, so a seeded\n // placeholder never has to be deleted to get out of the way.\n if (document === null || document === undefined) continue;\n sources.push({ ...candidate, text, document });\n }\n return sources;\n}\n\n/**\n * Merges same-named records across sources, tagging each entry with the base\n * directory of the document that supplied it.\n *\n * Later sources win outright rather than being deep-merged: a repository that\n * redefines a name is replacing it, and a half-inherited definition whose paths\n * straddle two roots would be impossible to resolve.\n */\nexport function mergeNamedSources<TDocument, TEntry extends object>(\n sources: ReadonlyArray<DoomConfigSource<TDocument>>,\n select: (document: TDocument) => Record<string, TEntry> | undefined,\n): Record<string, TEntry & DoomConfigProvenance> {\n const merged: Record<string, TEntry & DoomConfigProvenance> = {};\n for (const source of sources) {\n for (const [name, entry] of Object.entries(select(source.document) ?? {})) {\n merged[name] = {\n ...entry,\n baseDirectory: source.baseDirectory,\n filePath: source.filePath,\n };\n }\n }\n return merged;\n}\n"],"mappings":";;;;;;;;;;;AASA,MAAa,WAAW;AAExB,MAAM,gBAAgB;;;;;;;;;;AAsCtB,SAAgB,qBACd,UACA,UACA,gBAAwBA,QAAAA,QAAG,QAAQ,GACiB;CACpD,MAAM,kBAAkBC,eAAAA,0BAA0B,aAAa;CAC/D,MAAM,kBAAkB;EAAE,UAAUC,UAAAA,QAAK,KAAK,iBAAiB,QAAQ;EAAG,eAAe;CAAgB;CACzG,IAAIC,eAAAA,uBAAuB,UAAU,aAAa,GAAG,OAAO,CAAC,eAAe;CAC5E,OAAO,CAAC,iBAAiB;EAAE,UAAUD,UAAAA,QAAK,KAAK,UAAA,OAAoB,QAAQ;EAAG,eAAe;CAAS,CAAC;AACzG;AAEA,SAAgB,sBACd,UACA,UACA,gBAAwBF,QAAAA,QAAG,QAAQ,GACC;CACpC,MAAM,aAAa,qBAAqB,UAAU,UAAU,aAAa;CAEzE,MAAM,UAA8C,CAAC;CACrD,KAAK,MAAM,aAAa,YAAY;EAClC,IAAI,CAACI,QAAAA,QAAG,WAAW,UAAU,QAAQ,GAAG;EACxC,MAAM,OAAOA,QAAAA,QAAG,aAAa,UAAU,UAAU,aAAa;EAC9D,MAAM,YAAA,GAAWC,KAAAA,MAAAA,CAAU,IAAI;EAG/B,IAAI,aAAa,QAAQ,aAAa,KAAA,GAAW;EACjD,QAAQ,KAAK;GAAE,GAAG;GAAW;GAAM;EAAS,CAAC;CAC/C;CACA,OAAO;AACT;;;;;;;;;AAUA,SAAgB,kBACd,SACA,QAC+C;CAC/C,MAAM,SAAwD,CAAC;CAC/D,KAAK,MAAM,UAAU,SACnB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,OAAO,OAAO,QAAQ,KAAK,CAAC,CAAC,GACtE,OAAO,QAAQ;EACb,GAAG;EACH,eAAe,OAAO;EACtB,UAAU,OAAO;CACnB;CAGJ,OAAO;AACT"}
|