dlw-machine-setup 0.4.4 → 0.4.5

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 (2) hide show
  1. package/bin/installer.js +47 -13
  2. package/package.json +1 -1
package/bin/installer.js CHANGED
@@ -3845,6 +3845,20 @@ function buildMCPSection(mcpConfig) {
3845
3845
  }
3846
3846
  return lines2.join("\n");
3847
3847
  }
3848
+ function resolveDomainFolder(domain) {
3849
+ if ((0, import_fs4.existsSync)(CONTEXTS_DIR)) {
3850
+ try {
3851
+ const entries = (0, import_fs4.readdirSync)(CONTEXTS_DIR);
3852
+ const match = entries.find((e) => e.toLowerCase() === domain.toLowerCase());
3853
+ if (match) {
3854
+ return { folderName: match, folderPath: (0, import_path4.join)(CONTEXTS_DIR, match) };
3855
+ }
3856
+ } catch {
3857
+ }
3858
+ }
3859
+ const fallback = domain.toUpperCase();
3860
+ return { folderName: fallback, folderPath: (0, import_path4.join)(CONTEXTS_DIR, fallback) };
3861
+ }
3848
3862
  function buildContextRefsSection(domains) {
3849
3863
  const lines2 = [
3850
3864
  `## Context References`,
@@ -3854,26 +3868,25 @@ function buildContextRefsSection(domains) {
3854
3868
  ];
3855
3869
  let hasAnyFiles = false;
3856
3870
  for (const domain of domains) {
3857
- const domainUpper = domain.toUpperCase();
3858
- const domainPath = (0, import_path4.join)(CONTEXTS_DIR, domainUpper);
3871
+ const { folderName, folderPath: domainPath } = resolveDomainFolder(domain);
3859
3872
  if (!(0, import_fs4.existsSync)(domainPath)) continue;
3860
3873
  const domainFiles = [];
3861
3874
  const ctxInstructions = (0, import_path4.join)(domainPath, "context-instructions.md");
3862
3875
  if ((0, import_fs4.existsSync)(ctxInstructions)) {
3863
3876
  const desc = extractFirstHeading(ctxInstructions);
3864
- domainFiles.push(`- \`_ai-context/${domainUpper}/context-instructions.md\` \u2014 ${desc}`);
3877
+ domainFiles.push(`- \`_ai-context/${folderName}/context-instructions.md\` \u2014 ${desc}`);
3865
3878
  }
3866
3879
  const instructionsMd = (0, import_path4.join)(domainPath, "core", "instructions.md");
3867
3880
  if ((0, import_fs4.existsSync)(instructionsMd)) {
3868
3881
  const desc = extractFirstHeading(instructionsMd);
3869
- domainFiles.push(`- \`_ai-context/${domainUpper}/core/instructions.md\` \u2014 ${desc} (start here)`);
3882
+ domainFiles.push(`- \`_ai-context/${folderName}/core/instructions.md\` \u2014 ${desc} (start here)`);
3870
3883
  }
3871
3884
  const coreDir = (0, import_path4.join)(domainPath, "core");
3872
3885
  if ((0, import_fs4.existsSync)(coreDir)) {
3873
3886
  const coreFiles = collectMdFiles(coreDir).filter((f) => f !== "instructions.md" && !f.startsWith("instructions/"));
3874
3887
  for (const file of coreFiles) {
3875
3888
  const desc = extractFirstHeading((0, import_path4.join)(coreDir, file));
3876
- domainFiles.push(`- \`_ai-context/${domainUpper}/core/${file}\` \u2014 ${desc}`);
3889
+ domainFiles.push(`- \`_ai-context/${folderName}/core/${file}\` \u2014 ${desc}`);
3877
3890
  }
3878
3891
  }
3879
3892
  const refDir = (0, import_path4.join)(domainPath, "reference");
@@ -3884,13 +3897,13 @@ function buildContextRefsSection(domains) {
3884
3897
  domainFiles.push(`**Reference & cheat sheets:**`);
3885
3898
  for (const file of refFiles) {
3886
3899
  const desc = extractFirstHeading((0, import_path4.join)(refDir, file));
3887
- domainFiles.push(`- \`_ai-context/${domainUpper}/reference/${file}\` \u2014 ${desc}`);
3900
+ domainFiles.push(`- \`_ai-context/${folderName}/reference/${file}\` \u2014 ${desc}`);
3888
3901
  }
3889
3902
  }
3890
3903
  }
3891
3904
  if (domainFiles.length === 0) continue;
3892
3905
  hasAnyFiles = true;
3893
- lines2.push(`### ${domainUpper}`);
3906
+ lines2.push(`### ${folderName}`);
3894
3907
  lines2.push(...domainFiles);
3895
3908
  lines2.push(``);
3896
3909
  }
@@ -4143,12 +4156,28 @@ async function execute(config, token, repo) {
4143
4156
  result.success = false;
4144
4157
  return result;
4145
4158
  }
4159
+ const statePath = (0, import_path5.join)(config.projectPath, ".one-shot-state.json");
4160
+ let previousState = {};
4161
+ try {
4162
+ if ((0, import_fs5.existsSync)(statePath)) {
4163
+ previousState = JSON.parse((0, import_fs5.readFileSync)(statePath, "utf-8"));
4164
+ }
4165
+ } catch {
4166
+ }
4167
+ const allDomains = [.../* @__PURE__ */ new Set([
4168
+ ...previousState.domains ?? [],
4169
+ ...result.domainsInstalled
4170
+ ])];
4171
+ const mergedMcpConfig = {
4172
+ ...previousState.mcpConfigs ?? {},
4173
+ ...config.mcpConfig
4174
+ };
4146
4175
  process.stdout.write(` Writing ${instructionFilePath}... `);
4147
4176
  try {
4148
4177
  await setupInstructions({
4149
- domains: result.domainsInstalled,
4178
+ domains: allDomains,
4150
4179
  agent: config.agent,
4151
- mcpConfig: config.mcpConfig
4180
+ mcpConfig: mergedMcpConfig
4152
4181
  });
4153
4182
  result.instructionsCreated = true;
4154
4183
  console.log("\u2713");
@@ -4173,12 +4202,17 @@ async function execute(config, token, repo) {
4173
4202
  console.log(` Path: ${mcpConfigPath}`);
4174
4203
  }
4175
4204
  result.success = result.domainsFailed.length === 0 && result.instructionsCreated && result.mcpConfigured;
4205
+ const allPersonas = [.../* @__PURE__ */ new Set([
4206
+ ...previousState.personas ?? [],
4207
+ ...config.personas.map((p) => p.id)
4208
+ ])];
4176
4209
  const state = {
4177
4210
  installedAt: (/* @__PURE__ */ new Date()).toISOString(),
4178
4211
  agent: config.agent,
4179
- personas: config.personas.map((p) => p.id),
4180
- domains: result.domainsInstalled,
4181
- mcpServers: Object.keys(config.mcpConfig),
4212
+ personas: allPersonas,
4213
+ domains: allDomains,
4214
+ mcpServers: Object.keys(mergedMcpConfig),
4215
+ mcpConfigs: mergedMcpConfig,
4182
4216
  files: {
4183
4217
  instructions: instructionFilePath,
4184
4218
  mcpConfig: mcpConfigPath,
@@ -4186,7 +4220,7 @@ async function execute(config, token, repo) {
4186
4220
  }
4187
4221
  };
4188
4222
  try {
4189
- (0, import_fs5.writeFileSync)((0, import_path5.join)(config.projectPath, ".one-shot-state.json"), JSON.stringify(state, null, 2), "utf-8");
4223
+ (0, import_fs5.writeFileSync)(statePath, JSON.stringify(state, null, 2), "utf-8");
4190
4224
  } catch {
4191
4225
  }
4192
4226
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dlw-machine-setup",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "One-shot installer for The Machine toolchain",
5
5
  "bin": {
6
6
  "dlw-machine-setup": "bin/installer.js"