zenox 1.4.0 → 1.4.2

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.
@@ -9,8 +9,7 @@
9
9
  * - Skips child sessions (background tasks)
10
10
  * - Cooldown to prevent spam (10 seconds between reminders)
11
11
  * - Shows toast notification when enforcing
12
- *
13
- * Inspired by oh-my-opencode's todo-continuation-enforcer
12
+ * - Mode-aware: preserves Plan/Build agent context
14
13
  */
15
14
  import type { PluginInput } from "@opencode-ai/plugin";
16
15
  import type { Event } from "@opencode-ai/sdk";
package/dist/index.js CHANGED
@@ -823,6 +823,41 @@ The system automatically reminds you if you go idle with incomplete tasks.
823
823
  - The session goes idle
824
824
  - There's been sufficient time since the last reminder
825
825
  `;
826
+ function getOrchestrationPrompt(agent) {
827
+ switch (agent) {
828
+ case "build":
829
+ return ORCHESTRATION_PROMPT;
830
+ case "plan":
831
+ return ORCHESTRATION_PROMPT;
832
+ default:
833
+ return;
834
+ }
835
+ }
836
+
837
+ // src/orchestration/session-agent-tracker.ts
838
+ var sessionAgentMap = new Map;
839
+ function setSessionAgent(sessionID, agent) {
840
+ if (agent) {
841
+ sessionAgentMap.set(sessionID, agent);
842
+ }
843
+ }
844
+ function getSessionAgent(sessionID) {
845
+ return sessionAgentMap.get(sessionID);
846
+ }
847
+ function clearSessionAgent(sessionID) {
848
+ if (sessionID) {
849
+ sessionAgentMap.delete(sessionID);
850
+ }
851
+ }
852
+ function getOrchestrationAgentType(agent) {
853
+ if (agent === "build")
854
+ return "build";
855
+ if (agent === "plan")
856
+ return "plan";
857
+ if (agent === undefined)
858
+ return;
859
+ return agent;
860
+ }
826
861
 
827
862
  // node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
828
863
  var exports_external = {};
@@ -17799,6 +17834,7 @@ ${primaryKeyword.context}`;
17799
17834
  // src/hooks/todo-enforcer/index.ts
17800
17835
  var COOLDOWN_MS = 1e4;
17801
17836
  var TOAST_DURATION3 = 3000;
17837
+ var SKIP_AGENTS = ["plan"];
17802
17838
  var CONTINUATION_PROMPT = `[TODO CONTINUATION REMINDER]
17803
17839
 
17804
17840
  You have incomplete tasks in your todo list. Continue working on them.
@@ -17836,6 +17872,7 @@ function createTodoEnforcerHook(ctx) {
17836
17872
  if (now - state.lastEnforcedAt < COOLDOWN_MS) {
17837
17873
  return;
17838
17874
  }
17875
+ let agent;
17839
17876
  try {
17840
17877
  const sessionResult = await ctx.client.session.get({
17841
17878
  path: { id: sessionID }
@@ -17844,9 +17881,24 @@ function createTodoEnforcerHook(ctx) {
17844
17881
  if (session?.parentID) {
17845
17882
  return;
17846
17883
  }
17884
+ const msgs = await ctx.client.session.messages({
17885
+ path: { id: sessionID },
17886
+ query: { limit: 5 }
17887
+ });
17888
+ const messages = msgs.data ?? [];
17889
+ for (let i = messages.length - 1;i >= 0; i--) {
17890
+ const info = messages[i]?.info;
17891
+ if (info?.agent) {
17892
+ agent = info.agent;
17893
+ break;
17894
+ }
17895
+ }
17847
17896
  } catch {
17848
17897
  return;
17849
17898
  }
17899
+ if (agent && SKIP_AGENTS.includes(agent)) {
17900
+ return;
17901
+ }
17850
17902
  let todos = [];
17851
17903
  try {
17852
17904
  const todosResult = await ctx.client.session.todo({
@@ -17878,23 +17930,38 @@ Current incomplete tasks:
17878
17930
  ${todoList}
17879
17931
 
17880
17932
  ${statusLine}`;
17881
- try {
17933
+ const sendPrompt = async (omitAgent = false) => {
17882
17934
  await ctx.client.session.prompt({
17883
17935
  path: { id: sessionID },
17884
17936
  body: {
17885
17937
  noReply: false,
17938
+ ...omitAgent || !agent ? {} : { agent },
17886
17939
  parts: [{ type: "text", text: prompt }]
17887
17940
  }
17888
17941
  });
17889
- await ctx.client.tui.showToast({
17890
- body: {
17891
- title: "\uD83D\uDCCB Todo Reminder",
17892
- message: `${incomplete.length} task(s) remaining`,
17893
- variant: "info",
17894
- duration: TOAST_DURATION3
17942
+ };
17943
+ try {
17944
+ await sendPrompt();
17945
+ } catch (err) {
17946
+ const errorMsg = err instanceof Error ? err.message : String(err);
17947
+ if (errorMsg.includes("agent") || errorMsg.includes("undefined")) {
17948
+ try {
17949
+ await sendPrompt(true);
17950
+ } catch {
17951
+ return;
17895
17952
  }
17896
- }).catch(() => {});
17897
- } catch {}
17953
+ } else {
17954
+ return;
17955
+ }
17956
+ }
17957
+ await ctx.client.tui.showToast({
17958
+ body: {
17959
+ title: "\uD83D\uDCCB Todo Reminder",
17960
+ message: `${incomplete.length} task(s) remaining`,
17961
+ variant: "info",
17962
+ duration: TOAST_DURATION3
17963
+ }
17964
+ }).catch(() => {});
17898
17965
  if (sessionStates.size > 50) {
17899
17966
  cleanupOldStates();
17900
17967
  }
@@ -18282,6 +18349,7 @@ var ZenoxPlugin = async (ctx) => {
18282
18349
  ...codeIntelligenceTools
18283
18350
  },
18284
18351
  "chat.message": async (input, output) => {
18352
+ setSessionAgent(input.sessionID, input.agent);
18285
18353
  const message = output.message;
18286
18354
  if (firstMessageVariantGate.shouldOverride(input.sessionID)) {
18287
18355
  const variant = resolveAgentVariant(pluginConfig, input.agent);
@@ -18294,6 +18362,17 @@ var ZenoxPlugin = async (ctx) => {
18294
18362
  }
18295
18363
  await keywordDetectorHook["chat.message"]?.(input, output);
18296
18364
  },
18365
+ "experimental.chat.system.transform": async (input, output) => {
18366
+ const { sessionID } = input;
18367
+ if (!sessionID)
18368
+ return;
18369
+ const agent = getSessionAgent(sessionID);
18370
+ const agentType = getOrchestrationAgentType(agent);
18371
+ const prompt = getOrchestrationPrompt(agentType);
18372
+ if (prompt) {
18373
+ output.system.push(prompt);
18374
+ }
18375
+ },
18297
18376
  event: async (input) => {
18298
18377
  const { event } = input;
18299
18378
  await autoUpdateHook.event(input);
@@ -18309,6 +18388,7 @@ var ZenoxPlugin = async (ctx) => {
18309
18388
  const props = event.properties;
18310
18389
  const sessionID = props?.info?.id;
18311
18390
  firstMessageVariantGate.clear(sessionID);
18391
+ clearSessionAgent(sessionID);
18312
18392
  if (sessionID && sessionID === backgroundManager.getMainSession()) {
18313
18393
  backgroundManager.setMainSession(undefined);
18314
18394
  }
@@ -18360,14 +18440,6 @@ var ZenoxPlugin = async (ctx) => {
18360
18440
  if (!disabledAgents.has("ui-planner")) {
18361
18441
  config2.agent["ui-planner"] = applyModelOverride("ui-planner", uiPlannerAgent);
18362
18442
  }
18363
- if (config2.agent.build) {
18364
- const existingPrompt = config2.agent.build.prompt ?? "";
18365
- config2.agent.build.prompt = existingPrompt + ORCHESTRATION_PROMPT;
18366
- }
18367
- if (config2.agent.plan) {
18368
- const existingPrompt = config2.agent.plan.prompt ?? "";
18369
- config2.agent.plan.prompt = existingPrompt + ORCHESTRATION_PROMPT;
18370
- }
18371
18443
  const builtinMcps = createBuiltinMcps(disabledMcps);
18372
18444
  config2.mcp = {
18373
18445
  ...config2.mcp,
@@ -3,3 +3,4 @@
3
3
  * This teaches the primary agents how to delegate to specialized subagents using the Task tool.
4
4
  */
5
5
  export declare const ORCHESTRATION_PROMPT = "\n\n---\n\n## Sub-Agent Delegation\n\nYou have specialized subagents. Use the **Task tool** to delegate work proactively.\n\n### Available Agents\n\n| Agent | Use For | subagent_type |\n|-------|---------|---------------|\n| **Explorer** | Codebase grep - fast pattern matching, \"Where is X?\" | `explorer` |\n| **Librarian** | External grep - docs, GitHub, OSS examples | `librarian` |\n| **Oracle** | Strategic advisor - architecture, debugging, decisions | `oracle` |\n| **UI Planner** | Designer-developer - visual design, CSS, animations | `ui-planner` |\n\n### Quick Rule: Background vs Synchronous\n\n| Agent | Default Execution | Why |\n|-------|-------------------|-----|\n| Explorer | `background_task` | It's codebase grep - fire and continue |\n| Librarian | `background_task` | It's external grep - fire and continue |\n| Oracle | `Task` (sync) | Need strategic answer before proceeding |\n| UI Planner | `Task` (sync) | Implements changes, needs write access |\n\n**Mental Model**: Explorer & Librarian = **grep commands**. You don't wait for grep, you fire it and continue thinking.\n\n### When to Delegate (Fire Immediately)\n\n| Trigger | subagent_type | Why |\n|---------|---------------|-----|\n| \"Where is X?\", \"Find Y\", locate code | `explorer` | Fast codebase search |\n| External library, \"how does X library work?\" | `librarian` | Searches docs, GitHub, OSS |\n| 2+ modules involved, cross-cutting concerns | `explorer` | Multi-file pattern discovery |\n| Architecture decision, \"should I use X or Y?\" | `oracle` | Deep reasoning advisor |\n| Visual/styling, CSS, animations, UI/UX | `ui-planner` | Designer-developer hybrid |\n| After 2+ failed fix attempts | `oracle` | Debugging escalation |\n\n### How to Delegate\n\nUse the Task tool with these parameters:\n\n```\nTask(\n subagent_type: \"explorer\" | \"librarian\" | \"oracle\" | \"ui-planner\",\n description: \"Short 3-5 word task description\",\n prompt: \"Detailed instructions for the agent\"\n)\n```\n\n**Example delegations:**\n\n```\n// Find code in codebase\nTask(\n subagent_type: \"explorer\",\n description: \"Find auth middleware\",\n prompt: \"Find all authentication middleware implementations in this codebase. Return file paths and explain the auth flow.\"\n)\n\n// Research external library\nTask(\n subagent_type: \"librarian\",\n description: \"React Query caching docs\",\n prompt: \"How does React Query handle caching? Find official documentation and real-world examples with GitHub permalinks.\"\n)\n\n// Architecture decision\nTask(\n subagent_type: \"oracle\",\n description: \"Redux vs Zustand analysis\",\n prompt: \"Analyze trade-offs between Redux and Zustand for this project. Consider bundle size, learning curve, and our existing patterns.\"\n)\n\n// UI/Visual work\nTask(\n subagent_type: \"ui-planner\",\n description: \"Redesign dashboard cards\",\n prompt: \"Redesign the dashboard stat cards to be more visually appealing. Use modern aesthetics, subtle animations, and ensure responsive design.\"\n)\n```\n\n### Parallel Execution\n\nTo run multiple agents in parallel, call multiple Task tools in the **same response message**:\n\n```\n// CORRECT: Multiple Task calls in ONE message = parallel execution\nTask(subagent_type: \"explorer\", description: \"Find auth code\", prompt: \"...\")\nTask(subagent_type: \"librarian\", description: \"JWT best practices\", prompt: \"...\")\n// Both run simultaneously\n\n// WRONG: One Task per message = sequential (slow)\nMessage 1: Task(...) \u2192 wait for result\nMessage 2: Task(...) \u2192 wait for result\n```\n\n### Delegation Priority\n\n1. **Explorer FIRST** \u2014 Always locate code before modifying unfamiliar areas\n2. **Librarian** \u2014 When dealing with external libraries/APIs you don't fully understand\n3. **Oracle** \u2014 For complex decisions or after 2+ failed fix attempts\n4. **UI Planner** \u2014 For ANY visual/styling work (never edit CSS/UI yourself)\n\n### Critical Rules\n\n1. **Never touch frontend visual/styling code yourself** \u2014 Always delegate to `ui-planner`\n2. **Fire librarian proactively** when unfamiliar libraries are involved\n3. **Consult oracle BEFORE major architectural decisions**, not after\n4. **Verify delegated work** before marking task complete\n\n### When to Handle Directly (Don't Delegate)\n\n- Single file edits with known location\n- Questions answerable from code already in context\n- Trivial changes requiring no specialist knowledge\n- Tasks you can complete faster than explaining to an agent\n\n---\n\n## Background Tasks (Parallel Research)\n\nFor **independent research tasks** that benefit from parallelism, use background tasks instead of sequential Task calls.\n\n### When to Use Background Tasks\n\n| Scenario | Use Background Tasks |\n|----------|---------------------|\n| User wants \"comprehensive\" / \"thorough\" / \"deep\" exploration | YES - fire 3-4 agents in parallel |\n| Need BOTH codebase search AND external docs | YES - explore + librarian in parallel |\n| Exploring multiple modules/features simultaneously | YES - separate explore for each |\n| Result of Task A needed before Task B | NO - use sequential Task |\n| Single focused lookup | NO - just use Task directly |\n\n### How Background Tasks Work\n\n1. **Fire**: Launch multiple agents with `background_task` - they run in parallel\n2. **Continue**: Keep working while background agents search\n3. **Notify**: You'll be notified when ALL background tasks complete\n4. **Retrieve**: Use `background_output` to get each result\n\n### Usage\n\n```\n// Launch parallel research (all run simultaneously)\nbackground_task(agent=\"explorer\", description=\"Find auth code\", prompt=\"Search for authentication...\")\nbackground_task(agent=\"explorer\", description=\"Find db layer\", prompt=\"Search for database/ORM...\")\nbackground_task(agent=\"librarian\", description=\"Best practices\", prompt=\"Find framework best practices...\")\n\n// Continue working on other things while they run...\n\n// [NOTIFICATION: All background tasks complete!]\n\n// Retrieve results\nbackground_output(task_id=\"bg_abc123\")\nbackground_output(task_id=\"bg_def456\")\nbackground_output(task_id=\"bg_ghi789\")\n```\n\n### Background Tasks vs Task Tool\n\n| Aspect | Task Tool | Background Tasks |\n|--------|-----------|------------------|\n| Execution | Sequential (waits for result) | Parallel (fire-and-forget) |\n| Best for | Dependent tasks, immediate needs | Independent research, breadth |\n| Result | Inline, immediate | Retrieved later via background_output |\n\n### Key Insight\n\n- **Task** = Use when you need the result immediately before proceeding\n- **Background** = Use when researching multiple angles independently\n\n**Both tools coexist - choose based on whether tasks are dependent or independent.**\n\n### The Parallel Research Pattern\n\nFor complex tasks, fire research first, then continue working:\n\n```\n// 1. FIRE parallel research (don't wait!)\nbackground_task(agent=\"explorer\", description=\"Find existing patterns\", prompt=\"...\")\nbackground_task(agent=\"librarian\", description=\"Find best practices\", prompt=\"...\")\n\n// 2. CONTINUE productive work while they run:\n// - Plan your implementation approach\n// - Read files you already know about\n// - Identify edge cases and questions\n\n// 3. When notified \u2192 RETRIEVE and synthesize\nbackground_output(task_id=\"bg_xxx\")\nbackground_output(task_id=\"bg_yyy\")\n```\n\n**Anti-pattern**: Firing background tasks then doing nothing. Always continue productive work!\n\n---\n\n## Keyword Triggers (Power User)\n\nInclude these keywords in your prompt to unlock special modes:\n\n| Keyword | Effect |\n|---------|--------|\n| `ultrawork` or `ulw` | Maximum multi-agent coordination - aggressive parallel research |\n| `deep research` | Comprehensive exploration - fires 3-4 background agents |\n| `explore codebase` | Codebase mapping - multiple explorers in parallel |\n\n---\n\n## Session History Tools\n\nYou have tools to learn from past work sessions:\n\n| Tool | Use For |\n|------|---------|\n| `session_list` | List recent sessions to find relevant past work |\n| `session_search` | Search messages across sessions for how something was done |\n\n### When to Use Session Tools\n\n- **Before implementing unfamiliar features** \u2014 search if done before\n- **When user says \"like before\" or \"last time\"** \u2014 find that session\n- **When debugging** \u2014 check if similar issues were solved previously\n- **For context on ongoing projects** \u2014 understand recent work history\n\n### Example Usage\n\n```\n// Find how authentication was implemented before\nsession_search({ query: \"JWT authentication\" })\n\n// List recent sessions to understand project context\nsession_list({ limit: 5 })\n\n// Find past implementations of a feature\nsession_search({ query: \"rate limiting\" })\n```\n\n---\n\n## Code Intelligence Tools\n\nYou have tools to understand code structure via LSP:\n\n| Tool | Use For |\n|------|---------|\n| `find_symbols` | Search for functions, classes, variables by name |\n| `lsp_status` | Check which language servers are running |\n\n### When to Use Code Intelligence\n\n- **Before editing code** \u2014 find the symbol's definition location\n- **When refactoring** \u2014 search for related symbols\n- **To understand project structure** \u2014 search for key symbols like \"auth\", \"user\", \"api\"\n- **To verify LSP availability** \u2014 check if code intelligence is working\n\n### Example Usage\n\n```\n// Find all auth-related functions/classes\nfind_symbols({ query: \"auth\" })\n\n// Find a specific function\nfind_symbols({ query: \"handleLogin\" })\n\n// Check LSP server status\nlsp_status()\n```\n\n---\n\n## Todo Continuation\n\nThe system automatically reminds you if you go idle with incomplete tasks.\n\n**Best Practices:**\n- Keep your todo list updated with `TodoWrite`\n- Mark tasks complete immediately when finished\n- Use clear, actionable task descriptions\n- The system will prompt you to continue if tasks remain incomplete\n\n**Note:** You don't need to invoke the todo enforcer \u2014 it runs automatically when:\n- You have pending or in-progress todos\n- The session goes idle\n- There's been sufficient time since the last reminder\n";
6
+ export declare function getOrchestrationPrompt(agent: "build" | "plan" | string | undefined): string | undefined;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Session-Agent Tracker
3
+ *
4
+ * Tracks which agent is active for each session, allowing the system transform
5
+ * hook to inject agent-specific prompts.
6
+ *
7
+ * Flow:
8
+ * 1. chat.message hook fires with { sessionID, agent }
9
+ * 2. We store the mapping: sessionID -> agentName
10
+ * 3. experimental.chat.system.transform fires with { sessionID }
11
+ * 4. We look up the agent and inject the appropriate prompt
12
+ */
13
+ /**
14
+ * Record which agent is active for a session.
15
+ * Called from chat.message hook.
16
+ */
17
+ export declare function setSessionAgent(sessionID: string, agent: string | undefined): void;
18
+ /**
19
+ * Get the active agent for a session.
20
+ * Called from experimental.chat.system.transform hook.
21
+ */
22
+ export declare function getSessionAgent(sessionID: string): string | undefined;
23
+ /**
24
+ * Clear tracking for a session (on deletion).
25
+ */
26
+ export declare function clearSessionAgent(sessionID: string | undefined): void;
27
+ /**
28
+ * Check if an agent should receive orchestration injection.
29
+ * Only build and plan agents get the orchestration prompt.
30
+ */
31
+ export declare function shouldInjectOrchestration(agent: string | undefined): boolean;
32
+ /**
33
+ * Get the agent type for prompt selection.
34
+ * Returns "build", "plan", or string for other agents.
35
+ */
36
+ export declare function getOrchestrationAgentType(agent: string | undefined): "build" | "plan" | string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zenox",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "OpenCode plugin with specialized agents (explorer, librarian, oracle, ui-planner), background tasks for parallel execution, and smart orchestration",
5
5
  "author": "Ayush",
6
6
  "license": "MIT",