@ccx-agent/opencode-ccx 0.2.7 → 0.2.9

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.
@@ -16,6 +16,5 @@ type ChatMessageOutput = {
16
16
  [key: string]: unknown;
17
17
  }>;
18
18
  };
19
- export declare function recordToolCall(sessionID: string, tool: string, file?: string): void;
20
19
  export declare function createChatMessageHook(_config: OhMyCCAgentConfig): (input: ChatMessageInput, _output: ChatMessageOutput) => Promise<void>;
21
20
  export {};
@@ -11,8 +11,9 @@ type ChatParamsInput = {
11
11
  type ChatParamsOutput = {
12
12
  temperature: number;
13
13
  topP: number;
14
+ top_p?: number;
14
15
  topK: number;
15
16
  options: Record<string, unknown>;
16
17
  };
17
- export declare function createChatParamsHook(): (input: ChatParamsInput, output: ChatParamsOutput) => Promise<void>;
18
+ export declare function createChatParamsHook(): (_input: ChatParamsInput, output: ChatParamsOutput) => Promise<void>;
18
19
  export {};
@@ -1,6 +1,4 @@
1
1
  import type { OhMyCCAgentConfig } from "../config/schema";
2
- export declare function trackFileEdit(sessionID: string, filePath: string): void;
3
- export declare function markVerificationTriggered(sessionID: string): void;
4
2
  export declare function createDynamicSystemPrompt(config: OhMyCCAgentConfig, directory: string): (input: {
5
3
  sessionID?: string;
6
4
  model: unknown;
@@ -0,0 +1,2 @@
1
+ export declare function getGitSnapshotSection(sessionID: string): string | null;
2
+ export declare function createGitContextHook(directory: string): (input: unknown, _output: unknown) => Promise<void>;
@@ -1,2 +1,8 @@
1
1
  import type { OhMyCCAgentConfig } from "../config/schema";
2
2
  export declare function createVerificationReminder(config: OhMyCCAgentConfig): (input: unknown, _output: unknown) => Promise<void>;
3
+ export declare function getVerificationState(sessionID: string): {
4
+ editedFilesCount: number;
5
+ verificationTriggered: boolean;
6
+ };
7
+ export declare function listEditedFiles(sessionID: string, limit?: number): string[];
8
+ export declare function requiresVerification(sessionID: string, minFileEdits: number): boolean;
package/dist/index.js CHANGED
@@ -13638,82 +13638,7 @@ function loadConfig(directory) {
13638
13638
  return readConfigFile(projectConfigPath) ?? readConfigFile(userConfigPath) ?? defaults;
13639
13639
  }
13640
13640
 
13641
- // src/hooks/dynamic-system-prompt.ts
13642
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
13643
- import { join as join2 } from "path";
13644
- var sessionStates = new Map;
13645
- function getState(sessionID) {
13646
- const existing = sessionStates.get(sessionID);
13647
- if (existing)
13648
- return existing;
13649
- const state = {
13650
- editedFiles: new Set,
13651
- verificationTriggered: false,
13652
- turnCount: 0
13653
- };
13654
- sessionStates.set(sessionID, state);
13655
- return state;
13656
- }
13657
- function trackFileEdit(sessionID, filePath) {
13658
- getState(sessionID).editedFiles.add(filePath);
13659
- }
13660
- function loadProjectInstructions(directory) {
13661
- const candidates = ["CLAUDE.md", ".claude/instructions.md", "AGENTS.md"];
13662
- for (const name of candidates) {
13663
- const fullPath = join2(directory, name);
13664
- if (existsSync2(fullPath)) {
13665
- try {
13666
- const content = readFileSync2(fullPath, "utf-8").trim();
13667
- if (content)
13668
- return content;
13669
- } catch {
13670
- continue;
13671
- }
13672
- }
13673
- }
13674
- return null;
13675
- }
13676
- function createDynamicSystemPrompt(config2, directory) {
13677
- const projectInstructions = loadProjectInstructions(directory);
13678
- return async (input, output) => {
13679
- if (!config2.enabled)
13680
- return;
13681
- const sessionID = input.sessionID;
13682
- if (projectInstructions) {
13683
- output.system.push(`# Project Instructions
13684
-
13685
- The following instructions were found in the project root and MUST be followed:
13686
-
13687
- ${projectInstructions}`);
13688
- }
13689
- if (sessionID) {
13690
- const state = getState(sessionID);
13691
- state.turnCount++;
13692
- if (state.editedFiles.size > 0) {
13693
- const fileList = [...state.editedFiles].slice(-20).join(", ");
13694
- output.system.push(`# Session Context
13695
-
13696
- Files edited in this session (${state.editedFiles.size} total): ${fileList}`);
13697
- }
13698
- if (config2.verification.auto_remind && state.editedFiles.size >= config2.verification.min_file_edits && !state.verificationTriggered) {
13699
- output.system.push(`# Verification Reminder
13700
-
13701
- You have edited ${state.editedFiles.size} files in this session. You MUST run verification (via ccx-verification subagent) before declaring the task complete. This is not optional.`);
13702
- }
13703
- }
13704
- };
13705
- }
13706
-
13707
13641
  // src/hooks/chat-message.ts
13708
- var EDIT_TOOLS = new Set(["edit", "write"]);
13709
- var recentToolCalls = new Map;
13710
- function recordToolCall(sessionID, tool, file2) {
13711
- const calls = recentToolCalls.get(sessionID) ?? [];
13712
- calls.push({ tool, file: file2 });
13713
- if (calls.length > 50)
13714
- calls.shift();
13715
- recentToolCalls.set(sessionID, calls);
13716
- }
13717
13642
  function createChatMessageHook(_config) {
13718
13643
  return async (input, _output) => {
13719
13644
  if (!_config.enabled)
@@ -13721,37 +13646,22 @@ function createChatMessageHook(_config) {
13721
13646
  const { sessionID, agent } = input;
13722
13647
  if (!sessionID)
13723
13648
  return;
13724
- const calls = recentToolCalls.get(sessionID);
13725
- if (calls && calls.length > 0) {
13726
- const editedInRecent = calls.filter((c) => EDIT_TOOLS.has(c.tool) && c.file).map((c) => c.file);
13727
- for (const file2 of editedInRecent) {
13728
- trackFileEdit(sessionID, file2);
13729
- }
13730
- }
13731
13649
  if (agent && !agent.startsWith("ccx"))
13732
13650
  return;
13733
13651
  };
13734
13652
  }
13735
13653
 
13736
13654
  // src/hooks/chat-params.ts
13737
- var AGENT_PARAMS = {
13738
- "ccx-plan": { temperature: 0.3 },
13739
- "ccx-verification": { temperature: 0.2 },
13740
- "ccx-explore": { temperature: 0.5 },
13741
- "ccx-coordinator": { temperature: 0.4 },
13742
- "ccx-general-purpose": { temperature: 0.5 }
13743
- };
13744
13655
  function createChatParamsHook() {
13745
- return async (input, output) => {
13746
- const agentParams = AGENT_PARAMS[input.agent];
13747
- if (!agentParams)
13748
- return;
13749
- if (agentParams.temperature !== undefined)
13750
- output.temperature = agentParams.temperature;
13751
- if (agentParams.topP !== undefined)
13752
- output.topP = agentParams.topP;
13753
- if (agentParams.topK !== undefined)
13754
- output.topK = agentParams.topK;
13656
+ return async (_input, output) => {
13657
+ const out = output;
13658
+ const hasTemperature = out.temperature !== undefined;
13659
+ const hasTopP = out.topP !== undefined || out.top_p !== undefined;
13660
+ const hasBoth = hasTemperature && hasTopP;
13661
+ if (hasBoth) {
13662
+ delete out.topP;
13663
+ delete out.top_p;
13664
+ }
13755
13665
  };
13756
13666
  }
13757
13667
 
@@ -13816,8 +13726,8 @@ function getDoingTasksSection() {
13816
13726
  }
13817
13727
 
13818
13728
  // src/prompts/environment.ts
13819
- import { existsSync as existsSync3 } from "fs";
13820
- import { join as join3 } from "path";
13729
+ import { existsSync as existsSync2 } from "fs";
13730
+ import { join as join2 } from "path";
13821
13731
  import { type as osType, release as osRelease } from "os";
13822
13732
  function normalizeShell(shell) {
13823
13733
  if (shell.includes("zsh"))
@@ -13843,7 +13753,7 @@ function getOsVersion() {
13843
13753
  }
13844
13754
  function detectGit(cwd) {
13845
13755
  try {
13846
- return existsSync3(join3(cwd, ".git"));
13756
+ return existsSync2(join2(cwd, ".git"));
13847
13757
  } catch {
13848
13758
  return false;
13849
13759
  }
@@ -13948,18 +13858,86 @@ function getUsingToolsSection(toolNames) {
13948
13858
  `);
13949
13859
  }
13950
13860
 
13861
+ // src/prompts/section-registry.ts
13862
+ function createPromptSection(args) {
13863
+ return args;
13864
+ }
13865
+ async function resolvePromptSections(args) {
13866
+ const disabled = new Set(args.disabledSectionIDs ?? []);
13867
+ const selected = args.sections.filter((section) => {
13868
+ if (section.kind !== args.kind)
13869
+ return false;
13870
+ if (disabled.has(section.id))
13871
+ return false;
13872
+ return true;
13873
+ });
13874
+ const resolved = await Promise.all(selected.map((section) => section.resolve()));
13875
+ return resolved.filter((section) => typeof section === "string" && section.length > 0);
13876
+ }
13877
+
13951
13878
  // src/prompts/compose.ts
13952
- function composeSystemPrompt(options) {
13953
- return [
13954
- getIntroSection(options.outputStyle),
13955
- getSystemRulesSection(),
13956
- getDoingTasksSection(),
13957
- getActionsSection(),
13958
- getUsingToolsSection(options.toolNames),
13959
- getToneStyleSection(),
13960
- getOutputEfficiencySection(),
13961
- getEnvironmentSection(options.env)
13879
+ var DISABLED_SECTION_ALIASES = {
13880
+ "system-rules": "system",
13881
+ doing_tasks: "doing-tasks",
13882
+ using_tools: "using-tools",
13883
+ "tone-style": "tone-style",
13884
+ tone_style: "tone-style",
13885
+ "output-efficiency": "output-efficiency",
13886
+ output_efficiency: "output-efficiency"
13887
+ };
13888
+ function normalizeDisabledSectionIDs(ids) {
13889
+ if (!ids || ids.length === 0)
13890
+ return [];
13891
+ return ids.map((id) => DISABLED_SECTION_ALIASES[id] ?? id);
13892
+ }
13893
+ async function composeSystemPrompt(options) {
13894
+ const sections = [
13895
+ createPromptSection({
13896
+ id: "intro",
13897
+ kind: "static",
13898
+ resolve: () => getIntroSection(options.outputStyle)
13899
+ }),
13900
+ createPromptSection({
13901
+ id: "system",
13902
+ kind: "static",
13903
+ resolve: () => getSystemRulesSection()
13904
+ }),
13905
+ createPromptSection({
13906
+ id: "doing-tasks",
13907
+ kind: "static",
13908
+ resolve: () => getDoingTasksSection()
13909
+ }),
13910
+ createPromptSection({
13911
+ id: "actions",
13912
+ kind: "static",
13913
+ resolve: () => getActionsSection()
13914
+ }),
13915
+ createPromptSection({
13916
+ id: "using-tools",
13917
+ kind: "static",
13918
+ resolve: () => getUsingToolsSection(options.toolNames)
13919
+ }),
13920
+ createPromptSection({
13921
+ id: "tone-style",
13922
+ kind: "static",
13923
+ resolve: () => getToneStyleSection()
13924
+ }),
13925
+ createPromptSection({
13926
+ id: "output-efficiency",
13927
+ kind: "static",
13928
+ resolve: () => getOutputEfficiencySection()
13929
+ }),
13930
+ createPromptSection({
13931
+ id: "environment",
13932
+ kind: "static",
13933
+ resolve: () => getEnvironmentSection(options.env)
13934
+ })
13962
13935
  ];
13936
+ return resolvePromptSections({
13937
+ sections,
13938
+ kind: "static",
13939
+ disabledSectionIDs: normalizeDisabledSectionIDs(options.disabledSectionIDs)
13940
+ });
13963
13941
  }
13964
13942
 
13965
13943
  // src/agents/explore.ts
@@ -14435,7 +14413,7 @@ function createConfigHook(config2, directory) {
14435
14413
  if (!config2.enabled)
14436
14414
  return;
14437
14415
  const existingAgents = input.agent ?? {};
14438
- const systemSections = composeSystemPrompt({
14416
+ const systemSections = await composeSystemPrompt({
14439
14417
  toolNames: { bash: "Bash", read: "Read", edit: "Edit", write: "Write", glob: "Glob", grep: "Grep" },
14440
14418
  env: {
14441
14419
  cwd: directory,
@@ -14443,7 +14421,8 @@ function createConfigHook(config2, directory) {
14443
14421
  platform: process.platform,
14444
14422
  shell: process.env.SHELL ?? "unknown"
14445
14423
  },
14446
- outputStyle: config2.output_style ?? undefined
14424
+ outputStyle: config2.output_style ?? undefined,
14425
+ disabledSectionIDs: config2.disabled_sections
14447
14426
  });
14448
14427
  const subagentGuidance = buildSubagentGuidance();
14449
14428
  const mainPrompt = [...systemSections, subagentGuidance].join(`
@@ -14475,20 +14454,260 @@ function createConfigHook(config2, directory) {
14475
14454
  };
14476
14455
  }
14477
14456
 
14457
+ // src/hooks/dynamic-system-prompt.ts
14458
+ import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
14459
+ import { join as join3 } from "path";
14460
+
14461
+ // src/hooks/git-context.ts
14462
+ import { execFile } from "child_process";
14463
+ import { promisify } from "util";
14464
+ var execFileAsync = promisify(execFile);
14465
+ var MAX_STATUS_CHARS = 2000;
14466
+ var snapshotBySession = new Map;
14467
+ function isRecord(value) {
14468
+ return typeof value === "object" && value !== null;
14469
+ }
14470
+ async function runGit(cwd, args) {
14471
+ const { stdout } = await execFileAsync("git", args, {
14472
+ cwd,
14473
+ timeout: 1e4,
14474
+ maxBuffer: 1024 * 1024
14475
+ });
14476
+ return stdout.trim();
14477
+ }
14478
+ async function resolveDefaultBranch(cwd) {
14479
+ try {
14480
+ const symbolic = await runGit(cwd, [
14481
+ "symbolic-ref",
14482
+ "refs/remotes/origin/HEAD",
14483
+ "--short"
14484
+ ]);
14485
+ const parts = symbolic.split("/");
14486
+ return parts[parts.length - 1] || "main";
14487
+ } catch {
14488
+ return "main";
14489
+ }
14490
+ }
14491
+ function getGitSnapshotSection(sessionID) {
14492
+ const snapshot = snapshotBySession.get(sessionID);
14493
+ if (!snapshot)
14494
+ return null;
14495
+ return [
14496
+ "# Git Context",
14497
+ "This is a snapshot at the start of the session and may be stale now.",
14498
+ `Current branch: ${snapshot.branch}`,
14499
+ `Main branch: ${snapshot.mainBranch}`,
14500
+ `Status:
14501
+ ${snapshot.status || "(clean)"}`,
14502
+ `Recent commits:
14503
+ ${snapshot.recentCommits || "(none)"}`
14504
+ ].join(`
14505
+
14506
+ `);
14507
+ }
14508
+ function createGitContextHook(directory) {
14509
+ return async (input, _output) => {
14510
+ if (!isRecord(input))
14511
+ return;
14512
+ const rawEvent = input.event;
14513
+ if (!isRecord(rawEvent) || rawEvent.type !== "session.created")
14514
+ return;
14515
+ const sessionID = typeof rawEvent.sessionID === "string" ? rawEvent.sessionID : typeof rawEvent.sessionId === "string" ? rawEvent.sessionId : undefined;
14516
+ if (!sessionID || snapshotBySession.has(sessionID))
14517
+ return;
14518
+ try {
14519
+ const [branch, mainBranch, statusRaw, recentCommits] = await Promise.all([
14520
+ runGit(directory, ["rev-parse", "--abbrev-ref", "HEAD"]),
14521
+ resolveDefaultBranch(directory),
14522
+ runGit(directory, ["--no-optional-locks", "status", "--short"]),
14523
+ runGit(directory, ["--no-optional-locks", "log", "--oneline", "-n", "5"])
14524
+ ]);
14525
+ const status = statusRaw.length > MAX_STATUS_CHARS ? `${statusRaw.slice(0, MAX_STATUS_CHARS)}
14526
+ ... (truncated because it exceeds 2k characters)` : statusRaw;
14527
+ snapshotBySession.set(sessionID, {
14528
+ branch,
14529
+ mainBranch,
14530
+ status,
14531
+ recentCommits
14532
+ });
14533
+ } catch {}
14534
+ };
14535
+ }
14536
+
14537
+ // src/hooks/verification-reminder.ts
14538
+ var sessionStateById = new Map;
14539
+ var EDIT_TOOL_NAMES = new Set(["edit", "write"]);
14540
+ var TASK_TOOL_NAMES = new Set(["task", "taskcreate", "task_create"]);
14541
+ function isRecord2(value) {
14542
+ return typeof value === "object" && value !== null;
14543
+ }
14544
+ function getSessionState(sessionID) {
14545
+ const existing = sessionStateById.get(sessionID);
14546
+ if (existing) {
14547
+ return existing;
14548
+ }
14549
+ const created = {
14550
+ editedFiles: new Set,
14551
+ verificationTriggered: false
14552
+ };
14553
+ sessionStateById.set(sessionID, created);
14554
+ return created;
14555
+ }
14556
+ function getFilePath(value) {
14557
+ if (!isRecord2(value)) {
14558
+ return;
14559
+ }
14560
+ const candidates = [value.filePath, value.path, value.filename];
14561
+ return candidates.find((candidate) => typeof candidate === "string");
14562
+ }
14563
+ function createVerificationReminder(config2) {
14564
+ return async (input, _output) => {
14565
+ if (!config2.verification.auto_remind || !isRecord2(input)) {
14566
+ return;
14567
+ }
14568
+ const sessionID = typeof input.sessionID === "string" ? input.sessionID : undefined;
14569
+ const toolName = typeof input.tool === "string" ? input.tool.toLowerCase() : undefined;
14570
+ if (!sessionID || !toolName) {
14571
+ return;
14572
+ }
14573
+ if (TASK_TOOL_NAMES.has(toolName)) {
14574
+ const rawArgs = isRecord2(input.args) ? input.args : {};
14575
+ const subagentType = typeof rawArgs.subagent_type === "string" ? rawArgs.subagent_type.toLowerCase() : typeof rawArgs.subagentType === "string" ? rawArgs.subagentType.toLowerCase() : "";
14576
+ if (subagentType === "ccx-verification" || subagentType === "verification") {
14577
+ getSessionState(sessionID).verificationTriggered = true;
14578
+ }
14579
+ return;
14580
+ }
14581
+ if (!EDIT_TOOL_NAMES.has(toolName)) {
14582
+ return;
14583
+ }
14584
+ const filePath = getFilePath(input.args);
14585
+ if (!filePath) {
14586
+ return;
14587
+ }
14588
+ const state = getSessionState(sessionID);
14589
+ state.editedFiles.add(filePath);
14590
+ };
14591
+ }
14592
+ function getVerificationState(sessionID) {
14593
+ const state = getSessionState(sessionID);
14594
+ return {
14595
+ editedFilesCount: state.editedFiles.size,
14596
+ verificationTriggered: state.verificationTriggered
14597
+ };
14598
+ }
14599
+ function listEditedFiles(sessionID, limit = 20) {
14600
+ const state = getSessionState(sessionID);
14601
+ return [...state.editedFiles].slice(-limit);
14602
+ }
14603
+ function requiresVerification(sessionID, minFileEdits) {
14604
+ const state = getSessionState(sessionID);
14605
+ return state.editedFiles.size >= minFileEdits && !state.verificationTriggered;
14606
+ }
14607
+
14608
+ // src/hooks/dynamic-system-prompt.ts
14609
+ function loadProjectInstructions(directory) {
14610
+ const candidates = ["CLAUDE.md", ".claude/instructions.md", "AGENTS.md"];
14611
+ for (const name of candidates) {
14612
+ const fullPath = join3(directory, name);
14613
+ if (existsSync3(fullPath)) {
14614
+ try {
14615
+ const content = readFileSync2(fullPath, "utf-8").trim();
14616
+ if (content)
14617
+ return content;
14618
+ } catch {
14619
+ continue;
14620
+ }
14621
+ }
14622
+ }
14623
+ return null;
14624
+ }
14625
+ function createDynamicSystemPrompt(config2, directory) {
14626
+ const projectInstructions = loadProjectInstructions(directory);
14627
+ return async (input, output) => {
14628
+ if (!config2.enabled)
14629
+ return;
14630
+ const sessionID = input.sessionID;
14631
+ const sections = [
14632
+ createPromptSection({
14633
+ id: "project-instructions",
14634
+ kind: "dynamic",
14635
+ resolve: () => {
14636
+ if (!projectInstructions)
14637
+ return null;
14638
+ return `# Project Instructions
14639
+
14640
+ The following instructions were found in the project root and MUST be followed:
14641
+
14642
+ ${projectInstructions}`;
14643
+ }
14644
+ }),
14645
+ createPromptSection({
14646
+ id: "git-context",
14647
+ kind: "dynamic",
14648
+ resolve: () => {
14649
+ if (!sessionID)
14650
+ return null;
14651
+ return getGitSnapshotSection(sessionID);
14652
+ }
14653
+ }),
14654
+ createPromptSection({
14655
+ id: "session-context",
14656
+ kind: "dynamic",
14657
+ resolve: () => {
14658
+ if (!sessionID)
14659
+ return null;
14660
+ const { editedFilesCount } = getVerificationState(sessionID);
14661
+ if (editedFilesCount === 0)
14662
+ return null;
14663
+ const editedFiles = listEditedFiles(sessionID, 20);
14664
+ const suffix = editedFilesCount > editedFiles.length ? `, ... and ${editedFilesCount - editedFiles.length} more` : "";
14665
+ return `# Session Context
14666
+
14667
+ Files edited in this session (${editedFilesCount} total): ${editedFiles.join(", ")}${suffix}`;
14668
+ }
14669
+ }),
14670
+ createPromptSection({
14671
+ id: "verification-reminder",
14672
+ kind: "dynamic",
14673
+ resolve: () => {
14674
+ if (!sessionID)
14675
+ return null;
14676
+ if (!config2.verification.auto_remind)
14677
+ return null;
14678
+ if (!requiresVerification(sessionID, config2.verification.min_file_edits)) {
14679
+ return null;
14680
+ }
14681
+ const { editedFilesCount } = getVerificationState(sessionID);
14682
+ return `# Verification Reminder
14683
+
14684
+ You have edited ${editedFilesCount} files in this session. You MUST run verification (via ccx-verification subagent) before declaring the task complete. This is not optional.`;
14685
+ }
14686
+ })
14687
+ ];
14688
+ const dynamicSections = await resolvePromptSections({
14689
+ sections,
14690
+ kind: "dynamic",
14691
+ disabledSectionIDs: config2.disabled_sections
14692
+ });
14693
+ output.system.push(...dynamicSections);
14694
+ };
14695
+ }
14696
+
14478
14697
  // src/hooks/environment-context.ts
14479
14698
  import { existsSync as existsSync4 } from "fs";
14480
14699
  import { join as join4 } from "path";
14481
14700
  var environmentBySession = new Map;
14482
- function isRecord(value) {
14701
+ function isRecord3(value) {
14483
14702
  return typeof value === "object" && value !== null;
14484
14703
  }
14485
14704
  function createEnvironmentContext(directory) {
14486
14705
  return async (input, output) => {
14487
- if (!isRecord(input) || !isRecord(output)) {
14706
+ if (!isRecord3(input) || !isRecord3(output)) {
14488
14707
  return;
14489
14708
  }
14490
14709
  const rawEvent = input.event;
14491
- if (!isRecord(rawEvent) || rawEvent.type !== "session.created") {
14710
+ if (!isRecord3(rawEvent) || rawEvent.type !== "session.created") {
14492
14711
  return;
14493
14712
  }
14494
14713
  const event = rawEvent;
@@ -14502,7 +14721,7 @@ function createEnvironmentContext(directory) {
14502
14721
  if (sessionID) {
14503
14722
  environmentBySession.set(sessionID, environment);
14504
14723
  }
14505
- const existingContext = isRecord(output.context) ? output.context : {};
14724
+ const existingContext = isRecord3(output.context) ? output.context : {};
14506
14725
  existingContext.environment = environment;
14507
14726
  output.context = existingContext;
14508
14727
  };
@@ -14589,11 +14808,11 @@ function createMessageTransformHook() {
14589
14808
  }
14590
14809
 
14591
14810
  // src/hooks/idle-compaction.ts
14592
- var sessionStates2 = new Map;
14811
+ var sessionStates = new Map;
14593
14812
  var IDLE_THRESHOLD_MS = 30 * 60 * 1000;
14594
14813
  var MIN_TURNS_BEFORE_COMPACT = 10;
14595
14814
  function getIdleState(sessionID) {
14596
- const existing = sessionStates2.get(sessionID);
14815
+ const existing = sessionStates.get(sessionID);
14597
14816
  if (existing)
14598
14817
  return existing;
14599
14818
  const state = {
@@ -14601,7 +14820,7 @@ function getIdleState(sessionID) {
14601
14820
  turnCount: 0,
14602
14821
  compactedAt: 0
14603
14822
  };
14604
- sessionStates2.set(sessionID, state);
14823
+ sessionStates.set(sessionID, state);
14605
14824
  return state;
14606
14825
  }
14607
14826
  function recordSessionIdle(sessionID) {
@@ -14663,7 +14882,7 @@ var RISK_PATTERNS = [
14663
14882
  /truncate\s+table\b/i,
14664
14883
  /delete\s+from\b/i
14665
14884
  ];
14666
- function isRecord2(value) {
14885
+ function isRecord4(value) {
14667
14886
  return typeof value === "object" && value !== null;
14668
14887
  }
14669
14888
  function collectRiskText(value) {
@@ -14673,14 +14892,14 @@ function collectRiskText(value) {
14673
14892
  if (Array.isArray(value)) {
14674
14893
  return value.flatMap((item) => collectRiskText(item));
14675
14894
  }
14676
- if (isRecord2(value)) {
14895
+ if (isRecord4(value)) {
14677
14896
  return Object.values(value).flatMap((item) => collectRiskText(item));
14678
14897
  }
14679
14898
  return [];
14680
14899
  }
14681
14900
  function createRiskGuard() {
14682
14901
  return async (input, output) => {
14683
- if (!isRecord2(output)) {
14902
+ if (!isRecord4(output)) {
14684
14903
  return;
14685
14904
  }
14686
14905
  const argsText = collectRiskText(output.args).join(`
@@ -14689,10 +14908,10 @@ function createRiskGuard() {
14689
14908
  if (!matchedPattern) {
14690
14909
  return;
14691
14910
  }
14692
- const toolName = isRecord2(input) && typeof input.tool === "string" ? input.tool : "tool";
14911
+ const toolName = isRecord4(input) && typeof input.tool === "string" ? input.tool : "tool";
14693
14912
  const warning = `Potentially destructive ${toolName} invocation detected. Review arguments carefully before continuing.`;
14694
14913
  output.warning = warning;
14695
- const metadata = isRecord2(output.metadata) ? output.metadata : {};
14914
+ const metadata = isRecord4(output.metadata) ? output.metadata : {};
14696
14915
  metadata.riskGuard = {
14697
14916
  flagged: true,
14698
14917
  pattern: matchedPattern.source
@@ -14730,49 +14949,6 @@ ${contextHint}`;
14730
14949
  };
14731
14950
  }
14732
14951
 
14733
- // src/hooks/verification-reminder.ts
14734
- var sessionStateById = new Map;
14735
- var EDIT_TOOL_NAMES = new Set(["edit", "write"]);
14736
- function isRecord3(value) {
14737
- return typeof value === "object" && value !== null;
14738
- }
14739
- function getSessionState(sessionID) {
14740
- const existing = sessionStateById.get(sessionID);
14741
- if (existing) {
14742
- return existing;
14743
- }
14744
- const created = {
14745
- editedFiles: new Set
14746
- };
14747
- sessionStateById.set(sessionID, created);
14748
- return created;
14749
- }
14750
- function getFilePath(value) {
14751
- if (!isRecord3(value)) {
14752
- return;
14753
- }
14754
- const candidates = [value.filePath, value.path, value.filename];
14755
- return candidates.find((candidate) => typeof candidate === "string");
14756
- }
14757
- function createVerificationReminder(config2) {
14758
- return async (input, _output) => {
14759
- if (!config2.verification.auto_remind || !isRecord3(input)) {
14760
- return;
14761
- }
14762
- const sessionID = typeof input.sessionID === "string" ? input.sessionID : undefined;
14763
- const toolName = typeof input.tool === "string" ? input.tool.toLowerCase() : undefined;
14764
- if (!sessionID || !toolName || !EDIT_TOOL_NAMES.has(toolName)) {
14765
- return;
14766
- }
14767
- const filePath = getFilePath(input.args);
14768
- if (!filePath) {
14769
- return;
14770
- }
14771
- const state = getSessionState(sessionID);
14772
- state.editedFiles.add(filePath);
14773
- };
14774
- }
14775
-
14776
14952
  // node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/external.js
14777
14953
  var exports_external2 = {};
14778
14954
  __export(exports_external2, {
@@ -27133,6 +27309,7 @@ function createPluginInterface(args) {
27133
27309
  const riskGuard = createRiskGuard();
27134
27310
  const verificationReminder = createVerificationReminder(config3);
27135
27311
  const environmentContext = createEnvironmentContext(ctx.directory);
27312
+ const gitContext = createGitContextHook(ctx.directory);
27136
27313
  const dynamicSystemPrompt = createDynamicSystemPrompt(config3, ctx.directory);
27137
27314
  const chatMessageHook = createChatMessageHook(config3);
27138
27315
  const chatParamsHook = createChatParamsHook();
@@ -27146,16 +27323,10 @@ function createPluginInterface(args) {
27146
27323
  "tool.execute.before": riskGuard,
27147
27324
  "tool.execute.after": async (input, output) => {
27148
27325
  await verificationReminder(input, output);
27149
- const sessionID = typeof input.sessionID === "string" ? input.sessionID : undefined;
27150
- const tool3 = typeof input.tool === "string" ? input.tool.toLowerCase() : undefined;
27151
- if (sessionID && tool3) {
27152
- const args2 = input.args;
27153
- const file3 = typeof args2?.filePath === "string" ? args2.filePath : typeof args2?.path === "string" ? args2.path : undefined;
27154
- recordToolCall(sessionID, tool3, file3);
27155
- }
27156
27326
  },
27157
27327
  event: async (input) => {
27158
27328
  await environmentContext(input, {});
27329
+ await gitContext(input, {});
27159
27330
  const rawEvent = input.event;
27160
27331
  if (rawEvent) {
27161
27332
  await idleCompaction.onEvent(rawEvent);
@@ -5,4 +5,5 @@ export declare function composeSystemPrompt(options: {
5
5
  toolNames: ToolNames;
6
6
  env: EnvInfo;
7
7
  outputStyle?: string;
8
- }): string[];
8
+ disabledSectionIDs?: string[];
9
+ }): Promise<string[]>;
@@ -0,0 +1,16 @@
1
+ export type PromptSectionKind = "static" | "dynamic";
2
+ export type PromptSection = {
3
+ id: string;
4
+ kind: PromptSectionKind;
5
+ resolve: () => string | null | Promise<string | null>;
6
+ };
7
+ export declare function createPromptSection(args: {
8
+ id: string;
9
+ kind: PromptSectionKind;
10
+ resolve: () => string | null | Promise<string | null>;
11
+ }): PromptSection;
12
+ export declare function resolvePromptSections(args: {
13
+ sections: PromptSection[];
14
+ kind: PromptSectionKind;
15
+ disabledSectionIDs?: string[];
16
+ }): Promise<string[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccx-agent/opencode-ccx",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
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",
@@ -1,2 +0,0 @@
1
- import type { OhMyCCAgentConfig } from "../config/schema";
2
- export declare function createSystemPromptInjector(config: OhMyCCAgentConfig): (input: unknown, output: unknown) => Promise<void>;