@ccx-agent/opencode-ccx 0.2.12 → 0.2.13

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/README.md CHANGED
@@ -134,7 +134,7 @@ The main agent comes with 8 composable system prompt sections derived from Claud
134
134
  | **ccx-general-purpose** | read-write | on | Multi-strategy worker for tasks outside other specialists |
135
135
  | **ccx-coordinator** | orchestrator | off | Decomposes complex work into Research, Synthesis, Implementation, Verification across parallel workers. Tool surface is restricted to `task` + `question` |
136
136
 
137
- ### 10 Runtime Hooks
137
+ ### 12 Runtime Hooks
138
138
 
139
139
  ccx uses every major hook point in the OpenCode plugin API to dynamically shape agent behavior:
140
140
 
@@ -149,7 +149,7 @@ ccx uses every major hook point in the OpenCode plugin API to dynamically shape
149
149
 
150
150
  | Hook | What it does |
151
151
  |------|-------------|
152
- | **chat.message** | Tracks file edits across the session for verification threshold detection |
152
+ | **chat.message** | Tracks file edits across the session for verification threshold detection, and routes inline session-workflow commands (`/ccx-fork`, `/ccx-bg`, `/ccx-fullctx`, `/ccx-bg-status`) |
153
153
  | **chat.params** | Tunes temperature/topP per agent — low for plan/verification (precision), higher for explore (creativity) |
154
154
  | **experimental.chat.system.transform** | Dynamically injects project instructions (CLAUDE.md), session context (edited files list), and verification reminders into the system prompt |
155
155
  | **tool.definition** | Appends safety rules to bash/edit/write tool descriptions, usage hints to glob/grep/read |
@@ -159,10 +159,23 @@ ccx uses every major hook point in the OpenCode plugin API to dynamically shape
159
159
 
160
160
  | Hook | What it does |
161
161
  |------|-------------|
162
- | **tool.execute.before** | Risk Guard — flags `rm -rf`, `git push --force`, `DROP TABLE`, and other destructive patterns |
162
+ | **tool.execute.before** | Two stages: (1) Context-Bundle injects cwd / git snapshot / recently changed files into `task` tool args so subagents share a baseline; (2) Risk Guard flags `rm -rf`, `git push --force`, `DROP TABLE`, and other destructive patterns |
163
163
  | **tool.execute.after** | Tracks file edits, feeds the dynamic verification reminder system |
164
164
  | **experimental.session.compacting** | Customizes context compaction to preserve: original task, implementation plan, edited files, verification status, architectural decisions |
165
165
 
166
+ #### Session Workflow Commands
167
+
168
+ ccx exposes inline commands inside any chat message. They drive the underlying OpenCode session APIs directly so you can branch, dispatch, and replay work without waiting for the main agent to finish its turn:
169
+
170
+ | Command | Backed by | Purpose |
171
+ |---------|-----------|---------|
172
+ | `/ccx-fork [messageID]` | `POST /session/{id}/fork` | Fork the current session at the latest message (or at an explicit `messageID`) for what-if branching |
173
+ | `/ccx-bg [agent] <prompt>` | `POST /session/{id}/prompt_async` | Queue a background prompt against the current session, optionally targeting a specific agent |
174
+ | `/ccx-fullctx <agent> <prompt>` | `POST /session/{id}/fork` + `POST /session/{id}/prompt_async` | Create a fork-child session that inherits full parent context, then dispatch the subtask asynchronously to the named agent |
175
+ | `/ccx-bg-status [taskID]` | in-memory task registry + `GET /session/{id}/message` | Show recent background tasks, or inspect one task and refresh its running/completed/failed state |
176
+
177
+ All commands are opt-in via `subagent_orchestration.session_workflows.enabled` and the literals are configurable.
178
+
166
179
  ---
167
180
 
168
181
  ## Claude Code Alignment
@@ -206,6 +219,8 @@ With the default ccx config shown below, workflow behavior is aligned to Claude
206
219
  - recursive subagent delegation is discouraged by default
207
220
  - strict mandatory verification contract is off by default (opt-in)
208
221
  - when enabled, coordinator runs orchestration-only with a constrained tool surface (`task` + `question`)
222
+ - every dispatched subagent receives an automatically injected context bundle (cwd / git snapshot / recently changed files) so it starts from the same baseline as the parent
223
+ - inline `/ccx-fork`, `/ccx-bg`, `/ccx-fullctx`, and `/ccx-bg-status` commands let users branch sessions, queue background prompts, dispatch full-context fork subtasks, and inspect async task state
209
224
 
210
225
  This is behavior-level parity, not engine-level identity. Engine internals (runtime schedulers, fork execution model, feature-flag infrastructure) are different and remain outside plugin scope.
211
226
 
@@ -301,7 +316,21 @@ Example:
301
316
  "subagent_orchestration": {
302
317
  "explore_min_queries": 3,
303
318
  "coordinator_enabled": false,
304
- "allow_subagent_delegation": false
319
+ "allow_subagent_delegation": false,
320
+ "context_bundle": {
321
+ "enabled": true,
322
+ "include_cwd": true,
323
+ "include_git": true,
324
+ "include_recent_files": true,
325
+ "max_recent_files": 8
326
+ },
327
+ "session_workflows": {
328
+ "enabled": true,
329
+ "fork_command": "/ccx-fork",
330
+ "background_command": "/ccx-bg",
331
+ "full_context_command": "/ccx-fullctx",
332
+ "status_command": "/ccx-bg-status"
333
+ }
305
334
  }
306
335
  }
307
336
  ```
@@ -320,6 +349,16 @@ Example:
320
349
  | `subagent_orchestration.explore_min_queries` | `number` | `3` | Escalate to `ccx-explore` when directed lookup likely needs more than this query count |
321
350
  | `subagent_orchestration.coordinator_enabled` | `boolean` | `false` | Register and advertise `ccx-coordinator` subagent |
322
351
  | `subagent_orchestration.allow_subagent_delegation` | `boolean` | `false` | Permit subagents to delegate further. When `false`, runtime recursion guard blocks nested `task` delegation from `ccx-*` subagents unless explicit delegation-approval metadata is present |
352
+ | `subagent_orchestration.context_bundle.enabled` | `boolean` | `true` | Inject a shared context bundle (cwd, git snapshot, recently changed files) into `task` tool args before execution |
353
+ | `subagent_orchestration.context_bundle.include_cwd` | `boolean` | `true` | Include the working directory in the injected bundle |
354
+ | `subagent_orchestration.context_bundle.include_git` | `boolean` | `true` | Include the per-session git snapshot in the injected bundle |
355
+ | `subagent_orchestration.context_bundle.include_recent_files` | `boolean` | `true` | Include `git ls-files --modified --others` output in the injected bundle |
356
+ | `subagent_orchestration.context_bundle.max_recent_files` | `number` | `8` | Cap the number of recent files included in the bundle |
357
+ | `subagent_orchestration.session_workflows.enabled` | `boolean` | `true` | Enable inline session workflow commands (fork, background, full-context) in user messages |
358
+ | `subagent_orchestration.session_workflows.fork_command` | `string` | `/ccx-fork` | Command literal that triggers `session.fork`. Optional argument: explicit `messageID` to fork at |
359
+ | `subagent_orchestration.session_workflows.background_command` | `string` | `/ccx-bg` | Command literal that triggers `session.promptAsync`. Usage: `/ccx-bg [agent] <prompt>` |
360
+ | `subagent_orchestration.session_workflows.full_context_command` | `string` | `/ccx-fullctx` | Command literal that forks the session and dispatches a full-context subtask via `session.fork` + `session.promptAsync`. Usage: `/ccx-fullctx <agent> <prompt>` |
361
+ | `subagent_orchestration.session_workflows.status_command` | `string` | `/ccx-bg-status` | Command literal that lists background tasks or shows status for one task ID |
323
362
 
324
363
  ---
325
364
 
@@ -331,9 +370,12 @@ ccx/
331
370
  │ ├── index.ts # Plugin entry — composes everything
332
371
  │ ├── prompts/ # 8 system prompt sections + composer
333
372
  │ ├── agents/ # 5 subagent definitions with tailored prompts
334
- │ ├── hooks/ # 10 runtime hooks
373
+ │ ├── hooks/ # 12 runtime hooks
335
374
  │ │ ├── config-handler.ts # Agent registration
336
375
  │ │ ├── risk-guard.ts # Destructive command detection
376
+ │ │ ├── context-bundle.ts # Inject cwd/git/recent-files into task tool args
377
+ │ │ ├── session-workflows.ts # /ccx-fork, /ccx-bg, /ccx-fullctx, /ccx-bg-status commands
378
+ │ │ ├── bg-tasks.ts # Background task lifecycle registry
337
379
  │ │ ├── verification-reminder.ts # Edit tracking + nudge
338
380
  │ │ ├── environment-context.ts # Session environment capture
339
381
  │ │ ├── dynamic-system-prompt.ts # Per-turn system prompt injection
@@ -17,6 +17,20 @@ export declare const configSchema: z.ZodObject<{
17
17
  explore_min_queries: z.ZodDefault<z.ZodInt>;
18
18
  coordinator_enabled: z.ZodDefault<z.ZodBoolean>;
19
19
  allow_subagent_delegation: z.ZodDefault<z.ZodBoolean>;
20
+ context_bundle: z.ZodDefault<z.ZodObject<{
21
+ enabled: z.ZodDefault<z.ZodBoolean>;
22
+ include_cwd: z.ZodDefault<z.ZodBoolean>;
23
+ include_git: z.ZodDefault<z.ZodBoolean>;
24
+ include_recent_files: z.ZodDefault<z.ZodBoolean>;
25
+ max_recent_files: z.ZodDefault<z.ZodInt>;
26
+ }, z.core.$strip>>;
27
+ session_workflows: z.ZodDefault<z.ZodObject<{
28
+ enabled: z.ZodDefault<z.ZodBoolean>;
29
+ fork_command: z.ZodDefault<z.ZodString>;
30
+ background_command: z.ZodDefault<z.ZodString>;
31
+ full_context_command: z.ZodDefault<z.ZodString>;
32
+ status_command: z.ZodDefault<z.ZodString>;
33
+ }, z.core.$strip>>;
20
34
  }, z.core.$strip>>;
21
35
  }, z.core.$strip>;
22
36
  export type OhMyCCAgentConfig = z.infer<typeof configSchema>;
@@ -0,0 +1,29 @@
1
+ export type BgTaskStatus = "queued" | "running" | "completed" | "failed";
2
+ export type BgTaskRecord = {
3
+ id: string;
4
+ parentSessionID: string;
5
+ targetSessionID: string;
6
+ requestMessageID: string;
7
+ agent?: string;
8
+ prompt: string;
9
+ status: BgTaskStatus;
10
+ createdAt: number;
11
+ startedAt?: number;
12
+ finishedAt?: number;
13
+ error?: string;
14
+ fullContext: boolean;
15
+ };
16
+ export declare function createBgTask(args: {
17
+ parentSessionID: string;
18
+ targetSessionID: string;
19
+ requestMessageID: string;
20
+ agent?: string;
21
+ prompt: string;
22
+ fullContext: boolean;
23
+ }): BgTaskRecord;
24
+ export declare function markBgTaskRunning(id: string): void;
25
+ export declare function markBgTaskFailed(id: string, error: string): void;
26
+ export declare function markBgTaskCompleted(id: string): void;
27
+ export declare function getBgTask(id: string): BgTaskRecord | undefined;
28
+ export declare function listBgTasksForSession(sessionID: string): BgTaskRecord[];
29
+ export declare function formatBgTaskLine(task: BgTaskRecord): string;
@@ -0,0 +1,5 @@
1
+ import type { OhMyCCAgentConfig } from "../config/schema";
2
+ export declare function createContextBundleHook(args: {
3
+ config: OhMyCCAgentConfig;
4
+ directory: string;
5
+ }): (input: unknown, output: unknown) => Promise<void>;
@@ -0,0 +1,25 @@
1
+ import type { OhMyCCAgentConfig } from "../config/schema";
2
+ type ChatMessageInput = {
3
+ sessionID: string;
4
+ agent?: string;
5
+ model?: {
6
+ providerID: string;
7
+ modelID: string;
8
+ };
9
+ messageID?: string;
10
+ };
11
+ type ChatMessageOutput = {
12
+ message: Record<string, unknown>;
13
+ parts: Array<{
14
+ type: string;
15
+ text?: string;
16
+ [key: string]: unknown;
17
+ }>;
18
+ };
19
+ export declare const FORK_CHILD_MARKER_BEGIN = "<ccx-fork-child>";
20
+ export declare const FORK_CHILD_MARKER_END = "</ccx-fork-child>";
21
+ export declare function createSessionWorkflowsHook(args: {
22
+ config: OhMyCCAgentConfig;
23
+ client: unknown;
24
+ }): (input: ChatMessageInput, output: ChatMessageOutput) => Promise<void>;
25
+ export {};
package/dist/index.js CHANGED
@@ -13561,10 +13561,38 @@ var verificationSchema = exports_external.object({
13561
13561
  var riskGuardSchema = exports_external.object({
13562
13562
  enforce_high_risk_confirmation: exports_external.boolean().default(true)
13563
13563
  });
13564
+ var contextBundleSchema = exports_external.object({
13565
+ enabled: exports_external.boolean().default(true),
13566
+ include_cwd: exports_external.boolean().default(true),
13567
+ include_git: exports_external.boolean().default(true),
13568
+ include_recent_files: exports_external.boolean().default(true),
13569
+ max_recent_files: exports_external.int().nonnegative().default(8)
13570
+ });
13571
+ var sessionWorkflowsSchema = exports_external.object({
13572
+ enabled: exports_external.boolean().default(true),
13573
+ fork_command: exports_external.string().min(1).default("/ccx-fork"),
13574
+ background_command: exports_external.string().min(1).default("/ccx-bg"),
13575
+ full_context_command: exports_external.string().min(1).default("/ccx-fullctx"),
13576
+ status_command: exports_external.string().min(1).default("/ccx-bg-status")
13577
+ });
13564
13578
  var subagentOrchestrationSchema = exports_external.object({
13565
13579
  explore_min_queries: exports_external.int().positive().default(3),
13566
13580
  coordinator_enabled: exports_external.boolean().default(false),
13567
- allow_subagent_delegation: exports_external.boolean().default(false)
13581
+ allow_subagent_delegation: exports_external.boolean().default(false),
13582
+ context_bundle: contextBundleSchema.default({
13583
+ enabled: true,
13584
+ include_cwd: true,
13585
+ include_git: true,
13586
+ include_recent_files: true,
13587
+ max_recent_files: 8
13588
+ }),
13589
+ session_workflows: sessionWorkflowsSchema.default({
13590
+ enabled: true,
13591
+ fork_command: "/ccx-fork",
13592
+ background_command: "/ccx-bg",
13593
+ full_context_command: "/ccx-fullctx",
13594
+ status_command: "/ccx-bg-status"
13595
+ })
13568
13596
  });
13569
13597
  var configSchema = exports_external.object({
13570
13598
  enabled: exports_external.boolean().default(true),
@@ -13583,7 +13611,21 @@ var configSchema = exports_external.object({
13583
13611
  subagent_orchestration: subagentOrchestrationSchema.default({
13584
13612
  explore_min_queries: 3,
13585
13613
  coordinator_enabled: false,
13586
- allow_subagent_delegation: false
13614
+ allow_subagent_delegation: false,
13615
+ context_bundle: {
13616
+ enabled: true,
13617
+ include_cwd: true,
13618
+ include_git: true,
13619
+ include_recent_files: true,
13620
+ max_recent_files: 8
13621
+ },
13622
+ session_workflows: {
13623
+ enabled: true,
13624
+ fork_command: "/ccx-fork",
13625
+ background_command: "/ccx-bg",
13626
+ full_context_command: "/ccx-fullctx",
13627
+ status_command: "/ccx-bg-status"
13628
+ }
13587
13629
  })
13588
13630
  });
13589
13631
 
@@ -14525,9 +14567,9 @@ function createConfigHook(config2, directory) {
14525
14567
  };
14526
14568
  }
14527
14569
 
14528
- // src/hooks/dynamic-system-prompt.ts
14529
- import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
14530
- import { join as join3 } from "path";
14570
+ // src/hooks/context-bundle.ts
14571
+ import { execFile as execFile2 } from "child_process";
14572
+ import { promisify as promisify2 } from "util";
14531
14573
 
14532
14574
  // src/hooks/git-context.ts
14533
14575
  import { execFile } from "child_process";
@@ -14605,11 +14647,109 @@ function createGitContextHook(directory) {
14605
14647
  };
14606
14648
  }
14607
14649
 
14650
+ // src/hooks/context-bundle.ts
14651
+ var execFileAsync2 = promisify2(execFile2);
14652
+ var TASK_TOOL_NAMES = new Set(["task"]);
14653
+ var BUNDLE_MARKER_BEGIN = "<ccx-context-bundle>";
14654
+ var BUNDLE_MARKER_END = "</ccx-context-bundle>";
14655
+ var MAX_LIST_CHARS = 1500;
14656
+ function isRecord2(value) {
14657
+ return typeof value === "object" && value !== null;
14658
+ }
14659
+ function pickPromptFieldName(args) {
14660
+ for (const key of ["message", "prompt", "task", "instruction"]) {
14661
+ if (typeof args[key] === "string")
14662
+ return key;
14663
+ }
14664
+ return null;
14665
+ }
14666
+ async function listRecentFiles(cwd, max) {
14667
+ if (max <= 0)
14668
+ return "";
14669
+ try {
14670
+ const { stdout } = await execFileAsync2("git", ["--no-optional-locks", "ls-files", "--modified", "--others", "--exclude-standard"], { cwd, timeout: 5000, maxBuffer: 1024 * 1024 });
14671
+ const files = stdout.split(`
14672
+ `).map((line) => line.trim()).filter(Boolean).slice(0, max);
14673
+ if (files.length === 0)
14674
+ return "";
14675
+ const joined = files.join(`
14676
+ `);
14677
+ return joined.length > MAX_LIST_CHARS ? `${joined.slice(0, MAX_LIST_CHARS)}
14678
+ ... (truncated)` : joined;
14679
+ } catch {
14680
+ return "";
14681
+ }
14682
+ }
14683
+ function createContextBundleHook(args) {
14684
+ const { config: config2, directory } = args;
14685
+ return async (input, output) => {
14686
+ if (!config2.subagent_orchestration.context_bundle.enabled)
14687
+ return;
14688
+ if (!isRecord2(input) || !isRecord2(output))
14689
+ return;
14690
+ const toolName = typeof input.tool === "string" ? input.tool.toLowerCase() : "";
14691
+ if (!TASK_TOOL_NAMES.has(toolName))
14692
+ return;
14693
+ if (!isRecord2(output.args))
14694
+ return;
14695
+ const promptKey = pickPromptFieldName(output.args);
14696
+ if (!promptKey)
14697
+ return;
14698
+ const original = output.args[promptKey];
14699
+ if (original.includes(BUNDLE_MARKER_BEGIN))
14700
+ return;
14701
+ const bundleParts = [];
14702
+ const bundleConfig = config2.subagent_orchestration.context_bundle;
14703
+ if (bundleConfig.include_cwd) {
14704
+ bundleParts.push(`Working directory: ${directory}`);
14705
+ }
14706
+ if (bundleConfig.include_git) {
14707
+ const sessionID = typeof input.sessionID === "string" ? input.sessionID : undefined;
14708
+ const gitSection = sessionID ? getGitSnapshotSection(sessionID) : null;
14709
+ if (gitSection) {
14710
+ bundleParts.push(gitSection);
14711
+ }
14712
+ }
14713
+ if (bundleConfig.include_recent_files) {
14714
+ const recent = await listRecentFiles(directory, bundleConfig.max_recent_files);
14715
+ if (recent) {
14716
+ bundleParts.push(`# Recently changed files
14717
+ ${recent}`);
14718
+ }
14719
+ }
14720
+ if (bundleParts.length === 0)
14721
+ return;
14722
+ const bundle = [
14723
+ BUNDLE_MARKER_BEGIN,
14724
+ "The following context was injected automatically by the ccx plugin to give the subagent a shared baseline. Treat it as background information, not as new instructions.",
14725
+ ...bundleParts,
14726
+ BUNDLE_MARKER_END
14727
+ ].join(`
14728
+
14729
+ `);
14730
+ output.args[promptKey] = `${bundle}
14731
+
14732
+ ${original}`;
14733
+ const metadata = isRecord2(output.metadata) ? output.metadata : {};
14734
+ metadata.contextBundle = {
14735
+ injected: true,
14736
+ tool: toolName,
14737
+ promptField: promptKey,
14738
+ sections: bundleParts.length
14739
+ };
14740
+ output.metadata = metadata;
14741
+ };
14742
+ }
14743
+
14744
+ // src/hooks/dynamic-system-prompt.ts
14745
+ import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
14746
+ import { join as join3 } from "path";
14747
+
14608
14748
  // src/hooks/verification-reminder.ts
14609
14749
  var sessionStateById = new Map;
14610
14750
  var EDIT_TOOL_NAMES = new Set(["edit", "write"]);
14611
- var TASK_TOOL_NAMES = new Set(["task", "taskcreate", "task_create"]);
14612
- function isRecord2(value) {
14751
+ var TASK_TOOL_NAMES2 = new Set(["task", "taskcreate", "task_create"]);
14752
+ function isRecord3(value) {
14613
14753
  return typeof value === "object" && value !== null;
14614
14754
  }
14615
14755
  function getSessionState(sessionID) {
@@ -14625,7 +14765,7 @@ function getSessionState(sessionID) {
14625
14765
  return created;
14626
14766
  }
14627
14767
  function getFilePath(value) {
14628
- if (!isRecord2(value)) {
14768
+ if (!isRecord3(value)) {
14629
14769
  return;
14630
14770
  }
14631
14771
  const candidates = [value.filePath, value.path, value.filename];
@@ -14633,7 +14773,7 @@ function getFilePath(value) {
14633
14773
  }
14634
14774
  function createVerificationReminder(config2) {
14635
14775
  return async (input, _output) => {
14636
- if (!config2.verification.enforce_contract || !config2.verification.auto_remind || !isRecord2(input)) {
14776
+ if (!config2.verification.enforce_contract || !config2.verification.auto_remind || !isRecord3(input)) {
14637
14777
  return;
14638
14778
  }
14639
14779
  const sessionID = typeof input.sessionID === "string" ? input.sessionID : undefined;
@@ -14641,8 +14781,8 @@ function createVerificationReminder(config2) {
14641
14781
  if (!sessionID || !toolName) {
14642
14782
  return;
14643
14783
  }
14644
- if (TASK_TOOL_NAMES.has(toolName)) {
14645
- const rawArgs = isRecord2(input.args) ? input.args : {};
14784
+ if (TASK_TOOL_NAMES2.has(toolName)) {
14785
+ const rawArgs = isRecord3(input.args) ? input.args : {};
14646
14786
  const subagentType = typeof rawArgs.subagent_type === "string" ? rawArgs.subagent_type.toLowerCase() : typeof rawArgs.subagentType === "string" ? rawArgs.subagentType.toLowerCase() : "";
14647
14787
  if (subagentType === "ccx-verification" || subagentType === "verification") {
14648
14788
  getSessionState(sessionID).verificationTriggered = true;
@@ -14770,16 +14910,16 @@ You have edited ${editedFilesCount} files in this session. It is recommended to
14770
14910
  import { existsSync as existsSync4 } from "fs";
14771
14911
  import { join as join4 } from "path";
14772
14912
  var environmentBySession = new Map;
14773
- function isRecord3(value) {
14913
+ function isRecord4(value) {
14774
14914
  return typeof value === "object" && value !== null;
14775
14915
  }
14776
14916
  function createEnvironmentContext(directory) {
14777
14917
  return async (input, output) => {
14778
- if (!isRecord3(input) || !isRecord3(output)) {
14918
+ if (!isRecord4(input) || !isRecord4(output)) {
14779
14919
  return;
14780
14920
  }
14781
14921
  const rawEvent = input.event;
14782
- if (!isRecord3(rawEvent) || rawEvent.type !== "session.created") {
14922
+ if (!isRecord4(rawEvent) || rawEvent.type !== "session.created") {
14783
14923
  return;
14784
14924
  }
14785
14925
  const event = rawEvent;
@@ -14793,7 +14933,7 @@ function createEnvironmentContext(directory) {
14793
14933
  if (sessionID) {
14794
14934
  environmentBySession.set(sessionID, environment);
14795
14935
  }
14796
- const existingContext = isRecord3(output.context) ? output.context : {};
14936
+ const existingContext = isRecord4(output.context) ? output.context : {};
14797
14937
  existingContext.environment = environment;
14798
14938
  output.context = existingContext;
14799
14939
  };
@@ -14951,7 +15091,7 @@ function isGuardedSubagentName(value) {
14951
15091
  return typeof value === "string" && value.startsWith("ccx-") && value !== "ccx-coordinator";
14952
15092
  }
14953
15093
  function hasExplicitDelegationApproval(value) {
14954
- if (!isRecord4(value))
15094
+ if (!isRecord5(value))
14955
15095
  return false;
14956
15096
  if (value.subagentDelegation === true || value.subagentDelegation === "approved") {
14957
15097
  return true;
@@ -14962,12 +15102,12 @@ function hasExplicitDelegationApproval(value) {
14962
15102
  if (value.ccx_subagent_delegation === true || value.ccxSubagentDelegation === true) {
14963
15103
  return true;
14964
15104
  }
14965
- const metadata = isRecord4(value.metadata) ? value.metadata : undefined;
15105
+ const metadata = isRecord5(value.metadata) ? value.metadata : undefined;
14966
15106
  if (!metadata)
14967
15107
  return false;
14968
15108
  return metadata.subagentDelegation === true || metadata.subagentDelegation === "approved" || metadata.allow_subagent_delegation === true || metadata.allowSubagentDelegation === true || metadata.ccx_subagent_delegation === true || metadata.ccxSubagentDelegation === true;
14969
15109
  }
14970
- function isRecord4(value) {
15110
+ function isRecord5(value) {
14971
15111
  return typeof value === "object" && value !== null;
14972
15112
  }
14973
15113
  function collectRiskText(value) {
@@ -14977,15 +15117,15 @@ function collectRiskText(value) {
14977
15117
  if (Array.isArray(value)) {
14978
15118
  return value.flatMap((item) => collectRiskText(item));
14979
15119
  }
14980
- if (isRecord4(value)) {
15120
+ if (isRecord5(value)) {
14981
15121
  return Object.values(value).flatMap((item) => collectRiskText(item));
14982
15122
  }
14983
15123
  return [];
14984
15124
  }
14985
15125
  function hasExplicitUserConfirmation(value) {
14986
- if (!isRecord4(value))
15126
+ if (!isRecord5(value))
14987
15127
  return false;
14988
- const metadata = isRecord4(value.metadata) ? value.metadata : undefined;
15128
+ const metadata = isRecord5(value.metadata) ? value.metadata : undefined;
14989
15129
  if (!metadata)
14990
15130
  return false;
14991
15131
  const confirmation = metadata.riskConfirmation;
@@ -14993,19 +15133,19 @@ function hasExplicitUserConfirmation(value) {
14993
15133
  }
14994
15134
  function createRiskGuard(config2) {
14995
15135
  return async (input, output) => {
14996
- if (!isRecord4(output)) {
15136
+ if (!isRecord5(output)) {
14997
15137
  return;
14998
15138
  }
14999
- const toolName = isRecord4(input) && typeof input.tool === "string" ? input.tool.toLowerCase() : "";
15139
+ const toolName = isRecord5(input) && typeof input.tool === "string" ? input.tool.toLowerCase() : "";
15000
15140
  if (!config2.subagent_orchestration.allow_subagent_delegation && TASK_LAUNCH_TOOL_NAMES.has(toolName)) {
15001
- const sessionID = isRecord4(input) && typeof input.sessionID === "string" ? input.sessionID : undefined;
15002
- const directAgent = isRecord4(input) && typeof input.agent === "string" ? input.agent : undefined;
15141
+ const sessionID = isRecord5(input) && typeof input.sessionID === "string" ? input.sessionID : undefined;
15142
+ const directAgent = isRecord5(input) && typeof input.agent === "string" ? input.agent : undefined;
15003
15143
  const currentAgent = directAgent ?? (sessionID ? getSessionAgent(sessionID) : undefined);
15004
15144
  const approved = hasExplicitDelegationApproval(input) || hasExplicitDelegationApproval(output.args);
15005
15145
  if (isGuardedSubagentName(currentAgent) && !approved) {
15006
15146
  output.blocked = true;
15007
15147
  output.warning = "Nested subagent delegation is blocked by runtime policy. Execute directly in the current subagent, or provide explicit delegation approval metadata.";
15008
- const metadata2 = isRecord4(output.metadata) ? output.metadata : {};
15148
+ const metadata2 = isRecord5(output.metadata) ? output.metadata : {};
15009
15149
  metadata2.subagentRecursionGuard = {
15010
15150
  flagged: true,
15011
15151
  blocked: true,
@@ -15023,7 +15163,7 @@ function createRiskGuard(config2) {
15023
15163
  if (!matchedRule) {
15024
15164
  return;
15025
15165
  }
15026
- const riskyToolName = isRecord4(input) && typeof input.tool === "string" ? input.tool : "tool";
15166
+ const riskyToolName = isRecord5(input) && typeof input.tool === "string" ? input.tool : "tool";
15027
15167
  const warning = matchedRule.level === "high" ? `High-risk ${riskyToolName} invocation detected (${matchedRule.name}). Explicit user confirmation is required before execution.` : `Potentially destructive ${riskyToolName} invocation detected (${matchedRule.name}). Review arguments carefully before continuing.`;
15028
15168
  if (matchedRule.level === "high" && config2.risk_guard.enforce_high_risk_confirmation) {
15029
15169
  const confirmed = hasExplicitUserConfirmation(input);
@@ -15032,7 +15172,7 @@ function createRiskGuard(config2) {
15032
15172
  }
15033
15173
  }
15034
15174
  output.warning = warning;
15035
- const metadata = isRecord4(output.metadata) ? output.metadata : {};
15175
+ const metadata = isRecord5(output.metadata) ? output.metadata : {};
15036
15176
  metadata.riskGuard = {
15037
15177
  flagged: true,
15038
15178
  level: matchedRule.level,
@@ -15043,6 +15183,453 @@ function createRiskGuard(config2) {
15043
15183
  };
15044
15184
  }
15045
15185
 
15186
+ // src/hooks/bg-tasks.ts
15187
+ var MAX_TASKS_PER_SESSION = 50;
15188
+ var tasksBySession = new Map;
15189
+ var tasksById = new Map;
15190
+ function pushTask(record2) {
15191
+ tasksById.set(record2.id, record2);
15192
+ const list = tasksBySession.get(record2.parentSessionID) ?? [];
15193
+ list.push(record2);
15194
+ if (list.length > MAX_TASKS_PER_SESSION) {
15195
+ const evicted = list.splice(0, list.length - MAX_TASKS_PER_SESSION);
15196
+ for (const item of evicted)
15197
+ tasksById.delete(item.id);
15198
+ }
15199
+ tasksBySession.set(record2.parentSessionID, list);
15200
+ }
15201
+ function createBgTask(args) {
15202
+ const record2 = {
15203
+ id: `ccx-bg-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
15204
+ parentSessionID: args.parentSessionID,
15205
+ targetSessionID: args.targetSessionID,
15206
+ requestMessageID: args.requestMessageID,
15207
+ agent: args.agent,
15208
+ prompt: args.prompt,
15209
+ status: "queued",
15210
+ createdAt: Date.now(),
15211
+ fullContext: args.fullContext
15212
+ };
15213
+ pushTask(record2);
15214
+ return record2;
15215
+ }
15216
+ function markBgTaskRunning(id) {
15217
+ const task = tasksById.get(id);
15218
+ if (!task)
15219
+ return;
15220
+ task.status = "running";
15221
+ task.startedAt = Date.now();
15222
+ }
15223
+ function markBgTaskFailed(id, error48) {
15224
+ const task = tasksById.get(id);
15225
+ if (!task)
15226
+ return;
15227
+ task.status = "failed";
15228
+ task.finishedAt = Date.now();
15229
+ task.error = error48;
15230
+ }
15231
+ function markBgTaskCompleted(id) {
15232
+ const task = tasksById.get(id);
15233
+ if (!task)
15234
+ return;
15235
+ task.status = "completed";
15236
+ task.finishedAt = Date.now();
15237
+ }
15238
+ function getBgTask(id) {
15239
+ return tasksById.get(id);
15240
+ }
15241
+ function listBgTasksForSession(sessionID) {
15242
+ return tasksBySession.get(sessionID)?.slice() ?? [];
15243
+ }
15244
+ function formatBgTaskLine(task) {
15245
+ const age = Math.max(0, Math.round((Date.now() - task.createdAt) / 1000));
15246
+ const agent = task.agent ? ` agent=${task.agent}` : "";
15247
+ const ctx = task.fullContext ? " full-ctx" : "";
15248
+ const target = task.targetSessionID === task.parentSessionID ? "" : ` target=${task.targetSessionID}`;
15249
+ return `${task.id} ${task.status}${agent}${ctx}${target} age=${age}s`;
15250
+ }
15251
+
15252
+ // src/hooks/session-workflows.ts
15253
+ var FORK_CHILD_MARKER_BEGIN = "<ccx-fork-child>";
15254
+ var FORK_CHILD_MARKER_END = "</ccx-fork-child>";
15255
+ var TASK_STATUS_SCAN_LIMIT = 200;
15256
+ var forkChildSessionIDs = new Set;
15257
+ function isRecord6(value) {
15258
+ return typeof value === "object" && value !== null;
15259
+ }
15260
+ function createRequestMessageID() {
15261
+ return `ccx-bg-msg-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
15262
+ }
15263
+ function joinTextParts(parts) {
15264
+ return parts.filter((part) => part.type === "text" && typeof part.text === "string").map((part) => part.text).join(`
15265
+ `).trim();
15266
+ }
15267
+ function findCommandLine(text, command) {
15268
+ if (!text)
15269
+ return null;
15270
+ const lines = text.split(/\r?\n/);
15271
+ for (const line of lines) {
15272
+ const trimmed = line.trim();
15273
+ if (trimmed === command || trimmed.startsWith(`${command} `)) {
15274
+ return trimmed;
15275
+ }
15276
+ }
15277
+ return null;
15278
+ }
15279
+ function parseAgentAndPrompt(rest) {
15280
+ const trimmed = rest.trim();
15281
+ if (!trimmed)
15282
+ return { prompt: "" };
15283
+ const match = trimmed.match(/^([a-zA-Z0-9_-]+)\s+([\s\S]+)$/);
15284
+ if (!match)
15285
+ return { prompt: trimmed };
15286
+ return { agent: match[1], prompt: match[2].trim() };
15287
+ }
15288
+ function appendStatusPart(output, text) {
15289
+ output.parts.push({
15290
+ type: "text",
15291
+ text: `[ccx session-workflow] ${text}`,
15292
+ synthetic: true
15293
+ });
15294
+ }
15295
+ function extractSessionFromResponse(result) {
15296
+ if (!isRecord6(result))
15297
+ return;
15298
+ const data = isRecord6(result.data) ? result.data : result;
15299
+ if (!isRecord6(data))
15300
+ return;
15301
+ if (typeof data.id !== "string")
15302
+ return;
15303
+ return data;
15304
+ }
15305
+ function extractMessageList(result) {
15306
+ if (!result)
15307
+ return [];
15308
+ if (Array.isArray(result))
15309
+ return result;
15310
+ if (isRecord6(result) && Array.isArray(result.data)) {
15311
+ return result.data;
15312
+ }
15313
+ return [];
15314
+ }
15315
+ async function getSessionByID(client, sessionID) {
15316
+ if (!client.session?.get)
15317
+ return;
15318
+ try {
15319
+ const result = await client.session.get({ path: { id: sessionID } });
15320
+ return extractSessionFromResponse(result);
15321
+ } catch {
15322
+ return;
15323
+ }
15324
+ }
15325
+ function messagesContainForkMarker(messages) {
15326
+ for (const entry of messages) {
15327
+ const parts = Array.isArray(entry.parts) ? entry.parts : [];
15328
+ for (const part of parts) {
15329
+ if (!isRecord6(part))
15330
+ continue;
15331
+ if (typeof part.text === "string" && part.text.includes(FORK_CHILD_MARKER_BEGIN)) {
15332
+ return true;
15333
+ }
15334
+ }
15335
+ }
15336
+ return false;
15337
+ }
15338
+ function buildForkChildDirective(args) {
15339
+ const agentLine = args.agent ? `Target agent: ${args.agent}` : "Target agent: (inherit)";
15340
+ return [
15341
+ FORK_CHILD_MARKER_BEGIN,
15342
+ "You are a ccx fork-child. You have inherited the full parent session context above.",
15343
+ "Rules:",
15344
+ "1. Treat the inherited conversation as background. Do NOT re-introduce yourself.",
15345
+ "2. Do NOT fork again. Never invoke /ccx-fork or /ccx-fullctx from within this session.",
15346
+ "3. Focus strictly on the directive below. Report back concisely.",
15347
+ `Parent session: ${args.parentSessionID}`,
15348
+ agentLine,
15349
+ FORK_CHILD_MARKER_END,
15350
+ "",
15351
+ "Directive:",
15352
+ args.prompt
15353
+ ].join(`
15354
+ `);
15355
+ }
15356
+ async function isCurrentSessionForkChild(client, sessionID) {
15357
+ if (forkChildSessionIDs.has(sessionID))
15358
+ return true;
15359
+ const visited = new Set;
15360
+ let cursor = sessionID;
15361
+ for (let depth = 0;depth < 12; depth += 1) {
15362
+ if (!cursor || visited.has(cursor))
15363
+ break;
15364
+ visited.add(cursor);
15365
+ if (forkChildSessionIDs.has(cursor)) {
15366
+ forkChildSessionIDs.add(sessionID);
15367
+ return true;
15368
+ }
15369
+ const session = await getSessionByID(client, cursor);
15370
+ if (!session?.parentID)
15371
+ break;
15372
+ cursor = session.parentID;
15373
+ }
15374
+ if (!client.session?.messages)
15375
+ return false;
15376
+ try {
15377
+ const messages = await client.session.messages({
15378
+ path: { id: sessionID }
15379
+ });
15380
+ const isForkChild = messagesContainForkMarker(extractMessageList(messages));
15381
+ if (isForkChild)
15382
+ forkChildSessionIDs.add(sessionID);
15383
+ return isForkChild;
15384
+ } catch {
15385
+ return false;
15386
+ }
15387
+ }
15388
+ async function handleFork(client, sessionID, rest) {
15389
+ if (!client.session?.fork) {
15390
+ return { ok: false, text: "Fork is not supported by the current client." };
15391
+ }
15392
+ if (await isCurrentSessionForkChild(client, sessionID)) {
15393
+ return {
15394
+ ok: false,
15395
+ text: "Fork refused: current session is already a ccx fork-child (recursion guard)."
15396
+ };
15397
+ }
15398
+ const trimmed = rest.trim();
15399
+ const messageID = trimmed.length > 0 ? trimmed : undefined;
15400
+ try {
15401
+ const result = await client.session.fork({
15402
+ path: { id: sessionID },
15403
+ body: messageID ? { messageID } : {}
15404
+ });
15405
+ const forked = extractSessionFromResponse(result);
15406
+ const suffix = forked ? ` New session: ${forked.id}.` : "";
15407
+ return {
15408
+ ok: true,
15409
+ text: messageID ? `Forked session at message ${messageID}.${suffix}` : `Forked session at the latest message.${suffix}`
15410
+ };
15411
+ } catch (error48) {
15412
+ return {
15413
+ ok: false,
15414
+ text: `Failed to fork session: ${error48?.message ?? String(error48)}`
15415
+ };
15416
+ }
15417
+ }
15418
+ async function dispatchBackgroundPrompt(args) {
15419
+ const { client, targetSessionID, parentSessionID, agent, prompt, fullContext } = args;
15420
+ if (!client.session?.promptAsync) {
15421
+ return {
15422
+ ok: false,
15423
+ text: "Background prompts are not supported by the current client."
15424
+ };
15425
+ }
15426
+ const requestMessageID = createRequestMessageID();
15427
+ const task = createBgTask({
15428
+ parentSessionID,
15429
+ targetSessionID,
15430
+ requestMessageID,
15431
+ agent,
15432
+ prompt,
15433
+ fullContext
15434
+ });
15435
+ const directive = fullContext ? buildForkChildDirective({ agent, prompt, parentSessionID }) : prompt;
15436
+ try {
15437
+ await client.session.promptAsync({
15438
+ path: { id: targetSessionID },
15439
+ body: {
15440
+ messageID: requestMessageID,
15441
+ agent,
15442
+ parts: [{ type: "text", text: directive }]
15443
+ }
15444
+ });
15445
+ markBgTaskRunning(task.id);
15446
+ if (fullContext) {
15447
+ forkChildSessionIDs.add(targetSessionID);
15448
+ }
15449
+ const scope = fullContext ? `full-context subtask (fork session ${targetSessionID})` : agent ? `background prompt to agent "${agent}"` : "background prompt to the active agent";
15450
+ return {
15451
+ ok: true,
15452
+ text: `${scope} dispatched. task=${task.id} (status: running)`
15453
+ };
15454
+ } catch (error48) {
15455
+ const message = error48?.message ?? String(error48);
15456
+ markBgTaskFailed(task.id, message);
15457
+ return {
15458
+ ok: false,
15459
+ text: `Failed to dispatch background prompt: ${message} (task=${task.id})`
15460
+ };
15461
+ }
15462
+ }
15463
+ async function handleBackground(client, sessionID, rest) {
15464
+ const { agent, prompt } = parseAgentAndPrompt(rest);
15465
+ if (!prompt) {
15466
+ return { ok: false, text: "Background prompt requires a non-empty prompt body." };
15467
+ }
15468
+ return dispatchBackgroundPrompt({
15469
+ client,
15470
+ targetSessionID: sessionID,
15471
+ parentSessionID: sessionID,
15472
+ agent,
15473
+ prompt,
15474
+ fullContext: false
15475
+ });
15476
+ }
15477
+ async function handleFullContext(client, sessionID, rest) {
15478
+ if (!client.session?.fork || !client.session.promptAsync) {
15479
+ return {
15480
+ ok: false,
15481
+ text: "Full-context subtask requires session.fork and session.promptAsync support."
15482
+ };
15483
+ }
15484
+ if (await isCurrentSessionForkChild(client, sessionID)) {
15485
+ return {
15486
+ ok: false,
15487
+ text: "Full-context refused: current session is already a ccx fork-child (recursion guard)."
15488
+ };
15489
+ }
15490
+ const { agent, prompt } = parseAgentAndPrompt(rest);
15491
+ if (!agent || !prompt) {
15492
+ return { ok: false, text: "Usage: <command> <agent-name> <prompt>." };
15493
+ }
15494
+ let forkedSession;
15495
+ try {
15496
+ const result = await client.session.fork({
15497
+ path: { id: sessionID },
15498
+ body: {}
15499
+ });
15500
+ forkedSession = extractSessionFromResponse(result);
15501
+ } catch (error48) {
15502
+ return {
15503
+ ok: false,
15504
+ text: `Full-context fork failed: ${error48?.message ?? String(error48)}`
15505
+ };
15506
+ }
15507
+ if (!forkedSession) {
15508
+ return {
15509
+ ok: false,
15510
+ text: "Full-context fork returned no session id."
15511
+ };
15512
+ }
15513
+ return dispatchBackgroundPrompt({
15514
+ client,
15515
+ targetSessionID: forkedSession.id,
15516
+ parentSessionID: sessionID,
15517
+ agent,
15518
+ prompt,
15519
+ fullContext: true
15520
+ });
15521
+ }
15522
+ async function refreshBgTaskStatus(client, task) {
15523
+ if (!task || task.status !== "running")
15524
+ return;
15525
+ if (!client.session?.messages)
15526
+ return;
15527
+ try {
15528
+ const response = await client.session.messages({
15529
+ path: { id: task.targetSessionID },
15530
+ query: { limit: TASK_STATUS_SCAN_LIMIT }
15531
+ });
15532
+ const list = extractMessageList(response);
15533
+ if (list.length === 0)
15534
+ return;
15535
+ let info;
15536
+ for (let index = list.length - 1;index >= 0; index -= 1) {
15537
+ const candidate = list[index];
15538
+ if (!isRecord6(candidate?.info))
15539
+ continue;
15540
+ const messageInfo = candidate.info;
15541
+ if (messageInfo.role !== "assistant")
15542
+ continue;
15543
+ if (messageInfo.parentID !== task.requestMessageID)
15544
+ continue;
15545
+ info = messageInfo;
15546
+ break;
15547
+ }
15548
+ if (!info || info.role !== "assistant")
15549
+ return;
15550
+ const time3 = isRecord6(info.time) ? info.time : undefined;
15551
+ const completed = time3 && typeof time3.completed === "number" ? time3.completed : undefined;
15552
+ if (!completed)
15553
+ return;
15554
+ const errorInfo = isRecord6(info.error) ? info.error : undefined;
15555
+ if (errorInfo) {
15556
+ const errorData = isRecord6(errorInfo.data) ? errorInfo.data : undefined;
15557
+ const message = typeof errorData?.message === "string" ? errorData.message : typeof errorInfo.name === "string" ? errorInfo.name : "assistant reported an error";
15558
+ markBgTaskFailed(task.id, message);
15559
+ return;
15560
+ }
15561
+ markBgTaskCompleted(task.id);
15562
+ } catch {}
15563
+ }
15564
+ async function handleStatus(client, sessionID, rest) {
15565
+ const trimmed = rest.trim();
15566
+ if (trimmed) {
15567
+ const task = getBgTask(trimmed);
15568
+ if (!task) {
15569
+ return { ok: false, text: `No background task with id ${trimmed}.` };
15570
+ }
15571
+ await refreshBgTaskStatus(client, task);
15572
+ const errorLine = task.error ? ` error=${task.error}` : "";
15573
+ return {
15574
+ ok: true,
15575
+ text: `${formatBgTaskLine(task)}${errorLine}`
15576
+ };
15577
+ }
15578
+ const tasks = listBgTasksForSession(sessionID);
15579
+ if (tasks.length === 0) {
15580
+ return { ok: true, text: "No background tasks recorded for this session." };
15581
+ }
15582
+ for (const task of tasks) {
15583
+ await refreshBgTaskStatus(client, task);
15584
+ }
15585
+ const lines = tasks.slice(-10).map((task) => formatBgTaskLine(task));
15586
+ return { ok: true, text: `Recent background tasks:
15587
+ ${lines.join(`
15588
+ `)}` };
15589
+ }
15590
+ function createSessionWorkflowsHook(args) {
15591
+ const { config: config2 } = args;
15592
+ const client = args.client;
15593
+ return async (input, output) => {
15594
+ const workflows = config2.subagent_orchestration.session_workflows;
15595
+ if (!workflows.enabled)
15596
+ return;
15597
+ if (!input?.sessionID)
15598
+ return;
15599
+ if (!output?.parts)
15600
+ return;
15601
+ const text = joinTextParts(output.parts);
15602
+ if (!text)
15603
+ return;
15604
+ const forkLine = findCommandLine(text, workflows.fork_command);
15605
+ const backgroundLine = findCommandLine(text, workflows.background_command);
15606
+ const fullContextLine = findCommandLine(text, workflows.full_context_command);
15607
+ const statusLine = findCommandLine(text, workflows.status_command);
15608
+ if (!forkLine && !backgroundLine && !fullContextLine && !statusLine)
15609
+ return;
15610
+ if (forkLine) {
15611
+ const rest = forkLine.slice(workflows.fork_command.length);
15612
+ const status = await handleFork(client, input.sessionID, rest);
15613
+ appendStatusPart(output, status.text);
15614
+ }
15615
+ if (backgroundLine) {
15616
+ const rest = backgroundLine.slice(workflows.background_command.length);
15617
+ const status = await handleBackground(client, input.sessionID, rest);
15618
+ appendStatusPart(output, status.text);
15619
+ }
15620
+ if (fullContextLine) {
15621
+ const rest = fullContextLine.slice(workflows.full_context_command.length);
15622
+ const status = await handleFullContext(client, input.sessionID, rest);
15623
+ appendStatusPart(output, status.text);
15624
+ }
15625
+ if (statusLine) {
15626
+ const rest = statusLine.slice(workflows.status_command.length);
15627
+ const status = await handleStatus(client, input.sessionID, rest);
15628
+ appendStatusPart(output, status.text);
15629
+ }
15630
+ };
15631
+ }
15632
+
15046
15633
  // src/hooks/tool-definition.ts
15047
15634
  var TOOL_SAFETY_HINTS = {
15048
15635
  bash: "SAFETY: Before executing, verify the command is non-destructive. Never run rm -rf, git push --force, git reset --hard, DROP TABLE, or TRUNCATE TABLE without explicit user approval. Prefer --dry-run flags when available. Quote all file paths containing spaces.",
@@ -27437,11 +28024,13 @@ function createPluginInterface(args) {
27437
28024
  const { ctx, config: config3 } = args;
27438
28025
  const configHook = createConfigHook(config3, ctx.directory);
27439
28026
  const riskGuard = createRiskGuard(config3);
28027
+ const contextBundle = createContextBundleHook({ config: config3, directory: ctx.directory });
27440
28028
  const verificationReminder = createVerificationReminder(config3);
27441
28029
  const environmentContext = createEnvironmentContext(ctx.directory);
27442
28030
  const gitContext = createGitContextHook(ctx.directory);
27443
28031
  const dynamicSystemPrompt = createDynamicSystemPrompt(config3, ctx.directory);
27444
28032
  const chatMessageHook = createChatMessageHook(config3);
28033
+ const sessionWorkflows = createSessionWorkflowsHook({ config: config3, client: ctx.client });
27445
28034
  const chatParamsHook = createChatParamsHook();
27446
28035
  const compactionHook = createCompactionHook();
27447
28036
  const toolDefinitionHook = createToolDefinitionHook();
@@ -27450,7 +28039,10 @@ function createPluginInterface(args) {
27450
28039
  return {
27451
28040
  config: configHook,
27452
28041
  tool: createAgentTools(config3),
27453
- "tool.execute.before": riskGuard,
28042
+ "tool.execute.before": async (input, output) => {
28043
+ await contextBundle(input, output);
28044
+ await riskGuard(input, output);
28045
+ },
27454
28046
  "tool.execute.after": async (input, output) => {
27455
28047
  await verificationReminder(input, output);
27456
28048
  },
@@ -27464,6 +28056,7 @@ function createPluginInterface(args) {
27464
28056
  },
27465
28057
  "chat.message": async (input, output) => {
27466
28058
  await chatMessageHook(input, output);
28059
+ await sessionWorkflows(input, output);
27467
28060
  if (input.sessionID) {
27468
28061
  recordSessionTurn(input.sessionID);
27469
28062
  await idleCompaction.onChatMessage(input.sessionID);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccx-agent/opencode-ccx",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "Production-grade prompt engineering for OpenCode — disciplined coding, risk-aware actions, adversarial verification",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",