opencode-manifold 0.4.18 → 0.4.20

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/dist/index.js CHANGED
@@ -1,15 +1,12 @@
1
- import { createRequire } from "node:module";
2
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
-
4
1
  // src/init.ts
5
2
  import { readFile, writeFile, mkdir, readdir } from "fs/promises";
6
3
  import { existsSync } from "fs";
7
4
  import { join, dirname } from "path";
8
5
  import { fileURLToPath } from "url";
9
6
  import { homedir } from "os";
10
- import { createRequire as createRequire2 } from "module";
7
+ import { createRequire } from "module";
11
8
  var __dirname2 = dirname(fileURLToPath(import.meta.url));
12
- var require2 = createRequire2(import.meta.url);
9
+ var require2 = createRequire(import.meta.url);
13
10
  var bundledTemplatesDir = join(__dirname2, "..", "src", "templates");
14
11
  var globalTemplatesDir = join(homedir(), ".config", "opencode", "manifold");
15
12
  async function getPluginVersion() {
@@ -72,6 +69,15 @@ async function copyFiles(src, dest) {
72
69
  }
73
70
  return copied;
74
71
  }
72
+ async function copyFile(src, dest) {
73
+ if (!existsSync(src))
74
+ return;
75
+ const destDir = dirname(dest);
76
+ if (!existsSync(destDir)) {
77
+ await mkdir(destDir, { recursive: true });
78
+ }
79
+ await writeFile(dest, await readFile(src));
80
+ }
75
81
  async function ensureGlobalTemplates(ctx) {
76
82
  await ctx.client.app.log({
77
83
  body: {
@@ -92,9 +98,10 @@ async function ensureGlobalTemplates(ctx) {
92
98
  }
93
99
  await copyFiles(bundledTemplatesDir, globalTemplatesDir);
94
100
  const globalCommandsDir = join(homedir(), ".config", "opencode", "commands");
95
- const bundledCommandsDir = join(bundledTemplatesDir, "commands");
96
- if (existsSync(bundledCommandsDir)) {
97
- await copyFiles(bundledCommandsDir, globalCommandsDir);
101
+ const initCommandSrc = join(bundledTemplatesDir, "commands", "manifold-init.md");
102
+ const initCommandDest = join(globalCommandsDir, "manifold-init.md");
103
+ if (existsSync(initCommandSrc)) {
104
+ await copyFile(initCommandSrc, initCommandDest);
98
105
  }
99
106
  await ctx.client.app.log({
100
107
  body: {
@@ -135,6 +142,20 @@ async function initProject(directory, client) {
135
142
  if (manifoldCopied.length > 0) {
136
143
  initialized.push(`Manifold/ (${manifoldCopied.join(", ")})`);
137
144
  }
145
+ const projectCommandsDir = join(directory, ".opencode", "commands");
146
+ const commandsToCopy = ["manifold-models.md", "manifold-update.md"];
147
+ const commandsInitialized = [];
148
+ for (const cmd of commandsToCopy) {
149
+ const src = join(globalTemplatesDir, "commands", cmd);
150
+ const dest = join(projectCommandsDir, cmd);
151
+ if (existsSync(src) && !existsSync(dest)) {
152
+ await copyFile(src, dest);
153
+ commandsInitialized.push(cmd);
154
+ }
155
+ }
156
+ if (commandsInitialized.length > 0) {
157
+ initialized.push(`commands (${commandsInitialized.join(", ")})`);
158
+ }
138
159
  const version = await getPluginVersion();
139
160
  await writeFile(join(directory, "Manifold", "VERSION"), version + `
140
161
  `);
@@ -4216,6 +4237,484 @@ ${testResult.result.output}`,
4216
4237
  }
4217
4238
  });
4218
4239
 
4240
+ // src/tools/set-subagent-model.ts
4241
+ import { readFile as readFile5, writeFile as writeFile5, readdir as readdir3 } from "fs/promises";
4242
+ import { existsSync as existsSync6 } from "fs";
4243
+ import { join as join6 } from "path";
4244
+ import { homedir as homedir2 } from "os";
4245
+ var MANIFOLD_AGENTS = ["clerk", "senior-dev", "junior-dev", "debug"];
4246
+ async function getManifoldAgents(directory) {
4247
+ const agentsDir = join6(directory, ".opencode", "agents");
4248
+ if (!existsSync6(agentsDir)) {
4249
+ return [];
4250
+ }
4251
+ const files = await readdir3(agentsDir);
4252
+ const agents = [];
4253
+ for (const file of files) {
4254
+ if (!file.endsWith(".md"))
4255
+ continue;
4256
+ const name = file.replace(".md", "");
4257
+ if (MANIFOLD_AGENTS.includes(name)) {
4258
+ agents.push(name);
4259
+ }
4260
+ }
4261
+ return agents;
4262
+ }
4263
+ async function getAvailableModels(client) {
4264
+ try {
4265
+ const result = await client.config.providers();
4266
+ const providers = result.data?.providers || [];
4267
+ const models = [];
4268
+ for (const provider of providers) {
4269
+ if (provider.models) {
4270
+ for (const [modelId, model] of Object.entries(provider.models)) {
4271
+ models.push({
4272
+ id: `${provider.id}/${modelId}`,
4273
+ name: model.name || modelId,
4274
+ providerID: provider.id
4275
+ });
4276
+ }
4277
+ }
4278
+ }
4279
+ return models.sort((a, b) => a.name.localeCompare(b.name));
4280
+ } catch (error) {
4281
+ await client.app.log({
4282
+ body: {
4283
+ service: "opencode-manifold",
4284
+ level: "error",
4285
+ message: `Error fetching models: ${error}`
4286
+ }
4287
+ });
4288
+ return [];
4289
+ }
4290
+ }
4291
+ async function readAgentFile(agentName, directory) {
4292
+ const agentPath = join6(directory, ".opencode", "agents", `${agentName}.md`);
4293
+ if (!existsSync6(agentPath)) {
4294
+ const globalPath = join6(homedir2(), ".config", "opencode", "manifold", "agents", `${agentName}.md`);
4295
+ if (existsSync6(globalPath)) {
4296
+ const content2 = await readFile5(globalPath, "utf-8");
4297
+ const { frontmatter: frontmatter2, body: body2 } = parseFrontmatter(content2);
4298
+ return { content: content2, frontmatter: frontmatter2, body: body2 };
4299
+ }
4300
+ throw new Error(`Agent file not found for ${agentName}`);
4301
+ }
4302
+ const content = await readFile5(agentPath, "utf-8");
4303
+ const { frontmatter, body } = parseFrontmatter(content);
4304
+ return { content, frontmatter, body };
4305
+ }
4306
+ function parseFrontmatter(content) {
4307
+ const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
4308
+ if (!match) {
4309
+ return { frontmatter: {}, body: content };
4310
+ }
4311
+ const frontmatterYaml = match[1];
4312
+ const body = match[2];
4313
+ const frontmatter = jsYaml.load(frontmatterYaml) || {};
4314
+ return { frontmatter, body };
4315
+ }
4316
+ function buildAgentFile(frontmatter, body) {
4317
+ const yamlContent = jsYaml.dump(frontmatter, {
4318
+ lineWidth: -1,
4319
+ noCompatMode: true
4320
+ });
4321
+ return `---
4322
+ ${yamlContent}---
4323
+ ${body}`;
4324
+ }
4325
+ async function updateAgentModel(client, agentName, modelId, directory) {
4326
+ const { frontmatter, body } = await readAgentFile(agentName, directory);
4327
+ frontmatter.model = modelId;
4328
+ const newContent = buildAgentFile(frontmatter, body);
4329
+ const agentPath = join6(directory, ".opencode", "agents", `${agentName}.md`);
4330
+ await writeFile5(agentPath, newContent);
4331
+ await client.app.log({
4332
+ body: {
4333
+ service: "opencode-manifold",
4334
+ level: "info",
4335
+ message: `Updated ${agentName} model to ${modelId}`
4336
+ }
4337
+ });
4338
+ }
4339
+ async function handleSubModelCommand(client, directory) {
4340
+ await client.app.log({
4341
+ body: {
4342
+ service: "opencode-manifold",
4343
+ level: "info",
4344
+ message: "Starting /sub-model command"
4345
+ }
4346
+ });
4347
+ const agents = await getManifoldAgents(directory);
4348
+ if (agents.length === 0) {
4349
+ await client.tui.showToast({
4350
+ body: {
4351
+ type: "error",
4352
+ message: "No Manifold agents found. Run /manifold-init first."
4353
+ }
4354
+ });
4355
+ return;
4356
+ }
4357
+ const models = await getAvailableModels(client);
4358
+ if (models.length === 0) {
4359
+ await client.tui.showToast({
4360
+ body: {
4361
+ type: "error",
4362
+ message: "No models available. Configure providers first."
4363
+ }
4364
+ });
4365
+ return;
4366
+ }
4367
+ const agentList = agents.map((a) => `${a} (sub-agent)`).join(`
4368
+ `);
4369
+ await client.tui.appendPrompt({
4370
+ body: {
4371
+ type: "text",
4372
+ text: `\uD83D\uDCCB Select a Manifold sub-agent to configure:
4373
+
4374
+ ${agentList}`
4375
+ }
4376
+ });
4377
+ await client.tui.publish({
4378
+ body: {
4379
+ type: "tui.prompt_append",
4380
+ data: {
4381
+ type: "text",
4382
+ text: `
4383
+
4384
+ Type the agent name (clerk, senior-dev, junior-dev, or debug): `
4385
+ }
4386
+ }
4387
+ });
4388
+ const agentResponse = await client.tui.control.next();
4389
+ const selectedAgent = agentResponse.data?.input?.trim().toLowerCase();
4390
+ if (!selectedAgent || !MANIFOLD_AGENTS.includes(selectedAgent)) {
4391
+ await client.tui.showToast({
4392
+ body: {
4393
+ type: "error",
4394
+ message: `Invalid agent selection. Must be one of: ${MANIFOLD_AGENTS.join(", ")}`
4395
+ }
4396
+ });
4397
+ return;
4398
+ }
4399
+ if (!agents.includes(selectedAgent)) {
4400
+ await client.tui.showToast({
4401
+ body: {
4402
+ type: "error",
4403
+ message: `Agent ${selectedAgent} not found in .opencode/agents/`
4404
+ }
4405
+ });
4406
+ return;
4407
+ }
4408
+ const currentModel = await readAgentFile(selectedAgent, directory).then((f) => f.frontmatter.model || "not set");
4409
+ const modelList = models.map((m, i2) => `${i2 + 1}. ${m.name} (${m.id})`).join(`
4410
+ `);
4411
+ await client.tui.appendPrompt({
4412
+ body: {
4413
+ type: "text",
4414
+ text: `
4415
+ \uD83D\uDCE6 Available models for ${selectedAgent} (current: ${currentModel}):
4416
+
4417
+ ${modelList}`
4418
+ }
4419
+ });
4420
+ await client.tui.publish({
4421
+ body: {
4422
+ type: "tui.prompt_append",
4423
+ data: {
4424
+ type: "text",
4425
+ text: `
4426
+
4427
+ Type the model number or full model ID (e.g., anthropic/claude-sonnet-4-20250514): `
4428
+ }
4429
+ }
4430
+ });
4431
+ const modelResponse = await client.tui.control.next();
4432
+ const selectedModelInput = modelResponse.data?.input?.trim();
4433
+ if (!selectedModelInput) {
4434
+ await client.tui.showToast({
4435
+ body: {
4436
+ type: "error",
4437
+ message: "No model selected"
4438
+ }
4439
+ });
4440
+ return;
4441
+ }
4442
+ let selectedModelId;
4443
+ const modelIndex = parseInt(selectedModelInput, 10) - 1;
4444
+ if (!isNaN(modelIndex) && modelIndex >= 0 && modelIndex < models.length) {
4445
+ selectedModelId = models[modelIndex].id;
4446
+ } else {
4447
+ const found = models.find((m) => m.id.toLowerCase() === selectedModelInput.toLowerCase());
4448
+ if (found) {
4449
+ selectedModelId = found.id;
4450
+ }
4451
+ }
4452
+ if (!selectedModelId) {
4453
+ await client.tui.showToast({
4454
+ body: {
4455
+ type: "error",
4456
+ message: `Invalid model selection: ${selectedModelInput}`
4457
+ }
4458
+ });
4459
+ return;
4460
+ }
4461
+ await updateAgentModel(client, selectedAgent, selectedModelId, directory);
4462
+ await client.tui.showToast({
4463
+ body: {
4464
+ type: "success",
4465
+ message: `✅ Set ${selectedAgent} to ${selectedModelId}`
4466
+ }
4467
+ });
4468
+ await client.tui.appendPrompt({
4469
+ body: {
4470
+ type: "text",
4471
+ text: `
4472
+ ✅ Model updated for ${selectedAgent}: ${selectedModelId}
4473
+ `
4474
+ }
4475
+ });
4476
+ }
4477
+
4478
+ // src/tools/clear-cache.ts
4479
+ import { rm } from "fs/promises";
4480
+ import { existsSync as existsSync7 } from "fs";
4481
+ import { join as join7, isAbsolute } from "path";
4482
+ import { homedir as homedir3 } from "os";
4483
+ var PROTECTED_PATHS = [
4484
+ "/",
4485
+ "/System",
4486
+ "/Applications",
4487
+ "/Users",
4488
+ "/etc",
4489
+ "/bin",
4490
+ "/sbin",
4491
+ "/usr"
4492
+ ];
4493
+ function resolvePath(pathStr) {
4494
+ const expanded = pathStr.startsWith("~") ? join7(homedir3(), pathStr.slice(1)) : pathStr;
4495
+ return isAbsolute(expanded) ? expanded : join7(process.cwd(), expanded);
4496
+ }
4497
+ function isPathSafe(pathStr) {
4498
+ const normalized = pathStr.toLowerCase();
4499
+ if (normalized.includes("*")) {
4500
+ return { safe: false, reason: "Wildcards are not allowed for safety" };
4501
+ }
4502
+ for (const protectedPath of PROTECTED_PATHS) {
4503
+ if (normalized === protectedPath.toLowerCase() || normalized.startsWith(protectedPath.toLowerCase() + "/") || normalized.startsWith(protectedPath.toLowerCase() + "\\")) {
4504
+ return { safe: false, reason: `Cannot delete protected system path: ${protectedPath}` };
4505
+ }
4506
+ }
4507
+ if (normalized === homedir3().toLowerCase() || normalized.startsWith(homedir3().toLowerCase() + "/") && !normalized.includes("cache") && !normalized.includes("node_modules")) {
4508
+ const parts = normalized.replace(homedir3().toLowerCase(), "").split(/[\/\\]/).filter(Boolean);
4509
+ if (parts.length === 1) {
4510
+ return { safe: false, reason: "Cannot delete directories directly in home folder" };
4511
+ }
4512
+ }
4513
+ return { safe: true };
4514
+ }
4515
+ async function isProjectDirectory(pathStr) {
4516
+ try {
4517
+ const hasGit = existsSync7(join7(pathStr, ".git"));
4518
+ const hasOpencodeConfig = existsSync7(join7(pathStr, "opencode.json"));
4519
+ const hasPackageJson = existsSync7(join7(pathStr, "package.json"));
4520
+ if (hasGit && (hasOpencodeConfig || hasPackageJson)) {
4521
+ return true;
4522
+ }
4523
+ const entries = await Promise.all([
4524
+ existsSync7(join7(pathStr, ".git")) ? "git" : null,
4525
+ existsSync7(join7(pathStr, "opencode.json")) ? "opencode" : null
4526
+ ].filter(Boolean));
4527
+ return entries.length >= 2;
4528
+ } catch {
4529
+ return false;
4530
+ }
4531
+ }
4532
+ async function clearCachePaths(paths) {
4533
+ const cleared = [];
4534
+ const skipped = [];
4535
+ const blocked = [];
4536
+ for (const pathStr of paths) {
4537
+ const resolved = resolvePath(pathStr);
4538
+ const safetyCheck = isPathSafe(resolved);
4539
+ if (!safetyCheck.safe) {
4540
+ blocked.push({ path: resolved, reason: safetyCheck.reason || "Failed safety check" });
4541
+ continue;
4542
+ }
4543
+ if (!existsSync7(resolved)) {
4544
+ skipped.push(resolved);
4545
+ continue;
4546
+ }
4547
+ const isProject = await isProjectDirectory(resolved);
4548
+ if (isProject) {
4549
+ blocked.push({ path: resolved, reason: "Appears to be a project directory (contains .git + config files)" });
4550
+ continue;
4551
+ }
4552
+ try {
4553
+ await rm(resolved, { recursive: true, force: true });
4554
+ cleared.push(resolved);
4555
+ } catch (error) {
4556
+ blocked.push({ path: resolved, reason: `Failed to delete: ${error}` });
4557
+ }
4558
+ }
4559
+ return { cleared, skipped, blocked };
4560
+ }
4561
+ async function handleUpdateCommand(client, directory) {
4562
+ await client.app.log({
4563
+ body: {
4564
+ service: "opencode-manifold",
4565
+ level: "info",
4566
+ message: "Starting /manifold-update command"
4567
+ }
4568
+ });
4569
+ const settings = await readSettings(directory);
4570
+ const configuredPaths = settings.updateCachePaths || [];
4571
+ if (configuredPaths.length === 0) {
4572
+ const examplePaths = [
4573
+ "~/.cache/opencode/packages/opencode-manifold@latest",
4574
+ "~/node_modules/opencode-manifold"
4575
+ ];
4576
+ await client.tui.appendPrompt({
4577
+ body: {
4578
+ type: "text",
4579
+ text: `\uD83D\uDD04 **Manifold Plugin Update**
4580
+
4581
+ No cache paths configured in \`Manifold/settings.json\`.
4582
+
4583
+ To enable this feature, add cache paths to your settings:
4584
+
4585
+ \`\`\`json
4586
+ {
4587
+ "updateCachePaths": [
4588
+ "~/.cache/opencode/packages/opencode-manifold@latest",
4589
+ "~/node_modules/opencode-manifold"
4590
+ ]
4591
+ }
4592
+ \`\`\`
4593
+
4594
+ **Safety features:**
4595
+ • Wildcards are blocked
4596
+ • System directories are protected
4597
+ • Project directories (with .git + config) are protected
4598
+
4599
+ **macOS users:** The paths above are typical cache locations.
4600
+ **Linux/Windows users:** Add your opencode cache paths manually.
4601
+ `
4602
+ }
4603
+ });
4604
+ await client.tui.showToast({
4605
+ body: {
4606
+ type: "info",
4607
+ message: "Configure updateCachePaths in Manifold/settings.json"
4608
+ }
4609
+ });
4610
+ return;
4611
+ }
4612
+ const resolvedPaths = configuredPaths.map(resolvePath);
4613
+ await client.tui.appendPrompt({
4614
+ body: {
4615
+ type: "text",
4616
+ text: `\uD83D\uDD04 **Manifold Plugin Update**
4617
+
4618
+ The following paths will be cleared:
4619
+
4620
+ ${resolvedPaths.map((p) => `• ${p}`).join(`
4621
+ `)}
4622
+
4623
+ ⚠️ **This action is irreversible.** These paths are read from \`Manifold/settings.json\`.
4624
+ `
4625
+ }
4626
+ });
4627
+ await client.tui.publish({
4628
+ body: {
4629
+ type: "tui.prompt_append",
4630
+ data: {
4631
+ type: "text",
4632
+ text: `
4633
+
4634
+ Type 'yes' to confirm and clear cache: `
4635
+ }
4636
+ }
4637
+ });
4638
+ const response = await client.tui.control.next();
4639
+ const answer = response.data?.input?.trim().toLowerCase();
4640
+ if (answer !== "yes" && answer !== "y") {
4641
+ await client.tui.appendPrompt({
4642
+ body: {
4643
+ type: "text",
4644
+ text: `
4645
+ ❌ Cancelled. No cache cleared.
4646
+ `
4647
+ }
4648
+ });
4649
+ return;
4650
+ }
4651
+ const { cleared, skipped, blocked } = await clearCachePaths(configuredPaths);
4652
+ let message = `
4653
+ `;
4654
+ if (cleared.length > 0) {
4655
+ message += `✅ **Cleared:**
4656
+ ${cleared.map((p) => `• ${p}`).join(`
4657
+ `)}
4658
+
4659
+ `;
4660
+ }
4661
+ if (skipped.length > 0) {
4662
+ message += `⏭️ **Already clean / skipped:**
4663
+ ${skipped.map((p) => `• ${p}`).join(`
4664
+ `)}
4665
+
4666
+ `;
4667
+ }
4668
+ if (blocked.length > 0) {
4669
+ message += `\uD83D\uDEAB **Blocked (safety check):**
4670
+ `;
4671
+ for (const item of blocked) {
4672
+ message += `• ${item.path}
4673
+ Reason: ${item.reason}
4674
+ `;
4675
+ }
4676
+ message += `
4677
+ `;
4678
+ }
4679
+ if (cleared.length > 0) {
4680
+ message += `**Next step:** Restart opencode to pull the latest plugin version.
4681
+
4682
+ Your project files (.opencode/, Manifold/) are untouched — only the configured cache paths were cleared.
4683
+ `;
4684
+ } else if (blocked.length > 0) {
4685
+ message += `⚠️ No paths were cleared. Review the blocked paths above and adjust your settings if needed.
4686
+ `;
4687
+ }
4688
+ await client.tui.appendPrompt({
4689
+ body: {
4690
+ type: "text",
4691
+ text: message
4692
+ }
4693
+ });
4694
+ if (cleared.length > 0) {
4695
+ await client.tui.showToast({
4696
+ body: {
4697
+ type: "success",
4698
+ message: `Cache cleared (${cleared.length} paths). Restart opencode to update.`
4699
+ }
4700
+ });
4701
+ } else if (blocked.length > 0) {
4702
+ await client.tui.showToast({
4703
+ body: {
4704
+ type: "error",
4705
+ message: `Cache update blocked (${blocked.length} paths failed safety check)`
4706
+ }
4707
+ });
4708
+ }
4709
+ await client.app.log({
4710
+ body: {
4711
+ service: "opencode-manifold",
4712
+ level: "info",
4713
+ message: `/manifold-update complete: cleared ${cleared.length}, skipped ${skipped.length}, blocked ${blocked.length}`
4714
+ }
4715
+ });
4716
+ }
4717
+
4219
4718
  // src/index.ts
4220
4719
  var ManifoldPlugin = async (ctx) => {
4221
4720
  setPluginContext(ctx.client);
@@ -4249,6 +4748,12 @@ var ManifoldPlugin = async (ctx) => {
4249
4748
  }
4250
4749
  ];
4251
4750
  }
4751
+ } else if (input.command === "manifold-models") {
4752
+ await handleSubModelCommand(ctx.client, ctx.directory);
4753
+ output.parts = [{ type: "text", text: "Manifold sub-agent configuration started." }];
4754
+ } else if (input.command === "manifold-update") {
4755
+ await handleUpdateCommand(ctx.client, ctx.directory);
4756
+ output.parts = [{ type: "text", text: "Manifold update process started." }];
4252
4757
  }
4253
4758
  }
4254
4759
  };
package/dist/tui.js CHANGED
@@ -1,12 +1,3 @@
1
- import { createRequire } from "node:module";
2
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
-
4
- // src/tui.ts
5
- import { existsSync } from "fs";
6
- import { join } from "path";
7
- import { homedir } from "os";
8
- import { readFile, writeFile, readdir } from "fs/promises";
9
-
10
1
  // node_modules/js-yaml/dist/js-yaml.mjs
11
2
  /*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT */
12
3
  function isNothing(subject) {
@@ -2693,65 +2684,6 @@ var jsYaml = {
2693
2684
  };
2694
2685
 
2695
2686
  // src/tui.ts
2696
- var MANIFOLD_AGENTS = ["clerk", "senior-dev", "junior-dev", "debug"];
2697
- async function getManifoldAgents(directory) {
2698
- const agentsDir = join(directory, ".opencode", "agents");
2699
- if (!existsSync(agentsDir)) {
2700
- return [];
2701
- }
2702
- const files = await readdir(agentsDir);
2703
- const agents = [];
2704
- for (const file of files) {
2705
- if (!file.endsWith(".md"))
2706
- continue;
2707
- const name = file.replace(".md", "");
2708
- if (MANIFOLD_AGENTS.includes(name)) {
2709
- agents.push(name);
2710
- }
2711
- }
2712
- return agents;
2713
- }
2714
- async function readAgentFile(agentName, directory) {
2715
- const agentPath = join(directory, ".opencode", "agents", `${agentName}.md`);
2716
- if (!existsSync(agentPath)) {
2717
- const globalPath = join(homedir(), ".config", "opencode", "manifold", "agents", `${agentName}.md`);
2718
- if (existsSync(globalPath)) {
2719
- const content2 = await readFile(globalPath, "utf-8");
2720
- const { frontmatter: frontmatter2, body: body2 } = parseFrontmatter(content2);
2721
- return { content: content2, frontmatter: frontmatter2, body: body2 };
2722
- }
2723
- throw new Error(`Agent file not found for ${agentName}`);
2724
- }
2725
- const content = await readFile(agentPath, "utf-8");
2726
- const { frontmatter, body } = parseFrontmatter(content);
2727
- return { content, frontmatter, body };
2728
- }
2729
- function parseFrontmatter(content) {
2730
- const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
2731
- if (!match) {
2732
- return { frontmatter: {}, body: content };
2733
- }
2734
- const frontmatterYaml = match[1];
2735
- const body = match[2];
2736
- const frontmatter = jsYaml.load(frontmatterYaml) || {};
2737
- return { frontmatter, body };
2738
- }
2739
- function buildAgentFile(frontmatter, body) {
2740
- const yamlContent = jsYaml.dump(frontmatter, {
2741
- lineWidth: -1,
2742
- noCompatMode: true
2743
- });
2744
- return `---
2745
- ${yamlContent}---
2746
- ${body}`;
2747
- }
2748
- async function updateAgentModel(agentName, modelId, directory) {
2749
- const { frontmatter, body } = await readAgentFile(agentName, directory);
2750
- frontmatter.model = modelId;
2751
- const newContent = buildAgentFile(frontmatter, body);
2752
- const agentPath = join(directory, ".opencode", "agents", `${agentName}.md`);
2753
- await writeFile(agentPath, newContent);
2754
- }
2755
2687
  var tui = async (api) => {
2756
2688
  api.command.register(() => [
2757
2689
  {
@@ -2768,156 +2700,21 @@ var tui = async (api) => {
2768
2700
  value: "manifold-models",
2769
2701
  description: "Set the model for a Manifold sub-agent",
2770
2702
  category: "Manifold",
2771
- onSelect: () => handleManifoldModels(api)
2703
+ slash: {
2704
+ name: "manifold-models"
2705
+ }
2772
2706
  },
2773
2707
  {
2774
2708
  title: "Manifold Update",
2775
2709
  value: "manifold-update",
2776
2710
  description: "Clear opencode-manifold plugin cache and prompt for restart",
2777
2711
  category: "Manifold",
2778
- onSelect: () => handleManifoldUpdate(api)
2712
+ slash: {
2713
+ name: "manifold-update"
2714
+ }
2779
2715
  }
2780
2716
  ]);
2781
2717
  };
2782
- function handleManifoldModels(api) {
2783
- const directory = api.state.path.directory;
2784
- getManifoldAgents(directory).then((agents) => {
2785
- if (agents.length === 0) {
2786
- api.ui.toast({
2787
- variant: "error",
2788
- message: "No Manifold agents found. Run /manifold-init first."
2789
- });
2790
- return;
2791
- }
2792
- const providers = api.state.provider;
2793
- const models = [];
2794
- for (const provider of providers) {
2795
- if (provider.models) {
2796
- for (const [modelId, model] of Object.entries(provider.models)) {
2797
- models.push({
2798
- id: `${provider.id}/${modelId}`,
2799
- name: model.name || modelId,
2800
- providerID: provider.id
2801
- });
2802
- }
2803
- }
2804
- }
2805
- if (models.length === 0) {
2806
- api.ui.toast({
2807
- variant: "error",
2808
- message: "No models available. Configure providers first."
2809
- });
2810
- return;
2811
- }
2812
- models.sort((a, b) => a.name.localeCompare(b.name));
2813
- const agentOptions = agents.map((agent) => ({
2814
- title: `${agent} (sub-agent)`,
2815
- value: agent,
2816
- description: `Configure model for ${agent}`
2817
- }));
2818
- api.ui.dialog.replace(() => api.ui.DialogSelect({
2819
- title: "Select Manifold Sub-Agent",
2820
- options: agentOptions,
2821
- onSelect: (option) => {
2822
- const selectedAgent = option.value;
2823
- readAgentFile(selectedAgent, directory).then(({ frontmatter }) => {
2824
- const currentModel = frontmatter.model || "not set";
2825
- const modelOptions = models.map((model) => ({
2826
- title: `${model.name}`,
2827
- value: model.id,
2828
- description: model.id,
2829
- footer: model.id === currentModel ? "✓ Current" : undefined
2830
- }));
2831
- api.ui.dialog.replace(() => api.ui.DialogSelect({
2832
- title: `Select Model for ${selectedAgent}`,
2833
- options: modelOptions,
2834
- current: currentModel !== "not set" ? currentModel : undefined,
2835
- onSelect: (modelOption) => {
2836
- const selectedModelId = modelOption.value;
2837
- updateAgentModel(selectedAgent, selectedModelId, directory).then(() => {
2838
- api.ui.toast({
2839
- variant: "success",
2840
- message: `Set ${selectedAgent} to ${selectedModelId}`
2841
- });
2842
- api.ui.dialog.clear();
2843
- });
2844
- }
2845
- }));
2846
- }).catch(() => {
2847
- api.ui.toast({
2848
- variant: "error",
2849
- message: `Error reading agent file for ${selectedAgent}`
2850
- });
2851
- });
2852
- }
2853
- }));
2854
- });
2855
- }
2856
- function handleManifoldUpdate(api) {
2857
- const directory = api.state.path.directory;
2858
- const settingsPath = join(directory, "Manifold", "settings.json");
2859
- const proceed = (settings) => {
2860
- const globalConfigDir = join(homedir(), ".config", "opencode", "manifold");
2861
- const configuredPaths = settings.updateCachePaths || [];
2862
- const pathsToClear = [...new Set([...configuredPaths, globalConfigDir])];
2863
- const resolvedPaths = pathsToClear.map((p) => {
2864
- const expanded = p.startsWith("~") ? join(homedir(), p.slice(1)) : p;
2865
- return expanded;
2866
- });
2867
- api.ui.dialog.replace(() => api.ui.DialogSelect({
2868
- title: "Manifold Plugin Update",
2869
- options: [
2870
- {
2871
- title: "Clear Plugin & Template Cache",
2872
- value: "confirm",
2873
- description: `Will clear ${resolvedPaths.length} path(s) including global templates`,
2874
- footer: resolvedPaths.map((p) => `• ${p}`).join(`
2875
- `)
2876
- },
2877
- {
2878
- title: "Cancel",
2879
- value: "cancel",
2880
- description: "Do not clear cache"
2881
- }
2882
- ],
2883
- onSelect: (option) => {
2884
- if (option.value === "cancel") {
2885
- api.ui.dialog.clear();
2886
- return;
2887
- }
2888
- import("fs/promises").then(({ rm }) => {
2889
- const cleared = [];
2890
- const promises = resolvedPaths.map((pathStr) => {
2891
- if (existsSync(pathStr)) {
2892
- return rm(pathStr, { recursive: true, force: true }).then(() => {
2893
- cleared.push(pathStr);
2894
- }).catch(() => {});
2895
- }
2896
- return Promise.resolve();
2897
- });
2898
- Promise.all(promises).then(() => {
2899
- api.ui.toast({
2900
- variant: cleared.length > 0 ? "success" : "error",
2901
- message: cleared.length > 0 ? `Cache cleared. Restart opencode to update.` : `No paths cleared or update blocked`
2902
- });
2903
- api.ui.dialog.clear();
2904
- });
2905
- });
2906
- }
2907
- }));
2908
- };
2909
- if (existsSync(settingsPath)) {
2910
- readFile(settingsPath, "utf-8").then((content) => {
2911
- try {
2912
- proceed(JSON.parse(content));
2913
- } catch {
2914
- proceed({});
2915
- }
2916
- }).catch(() => proceed({}));
2917
- } else {
2918
- proceed({});
2919
- }
2920
- }
2921
2718
  export {
2922
2719
  tui
2923
2720
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-manifold",
3
- "version": "0.4.18",
3
+ "version": "0.4.20",
4
4
  "description": "Multi-agent development system for opencode with persistent knowledge",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Set the model for a Manifold sub-agent
3
+ agent: manifold
4
+ ---
5
+ Setting up sub-agent models...
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Clear opencode-manifold plugin cache and prompt for restart
3
+ agent: manifold
4
+ ---
5
+ Starting Manifold update process...