@ccx-agent/opencode-ccx 0.2.8 → 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.
- package/dist/hooks/chat-message.d.ts +0 -1
- package/dist/hooks/dynamic-system-prompt.d.ts +0 -2
- package/dist/hooks/git-context.d.ts +2 -0
- package/dist/hooks/verification-reminder.d.ts +6 -0
- package/dist/index.js +338 -159
- package/dist/prompts/compose.d.ts +2 -1
- package/dist/prompts/section-registry.d.ts +16 -0
- package/package.json +1 -1
- package/dist/hooks/system-prompt-injector.d.ts +0 -2
|
@@ -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 {};
|
|
@@ -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;
|
|
@@ -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,13 +13646,6 @@ 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
|
};
|
|
@@ -13808,8 +13726,8 @@ function getDoingTasksSection() {
|
|
|
13808
13726
|
}
|
|
13809
13727
|
|
|
13810
13728
|
// src/prompts/environment.ts
|
|
13811
|
-
import { existsSync as
|
|
13812
|
-
import { join as
|
|
13729
|
+
import { existsSync as existsSync2 } from "fs";
|
|
13730
|
+
import { join as join2 } from "path";
|
|
13813
13731
|
import { type as osType, release as osRelease } from "os";
|
|
13814
13732
|
function normalizeShell(shell) {
|
|
13815
13733
|
if (shell.includes("zsh"))
|
|
@@ -13835,7 +13753,7 @@ function getOsVersion() {
|
|
|
13835
13753
|
}
|
|
13836
13754
|
function detectGit(cwd) {
|
|
13837
13755
|
try {
|
|
13838
|
-
return
|
|
13756
|
+
return existsSync2(join2(cwd, ".git"));
|
|
13839
13757
|
} catch {
|
|
13840
13758
|
return false;
|
|
13841
13759
|
}
|
|
@@ -13940,18 +13858,86 @@ function getUsingToolsSection(toolNames) {
|
|
|
13940
13858
|
`);
|
|
13941
13859
|
}
|
|
13942
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
|
+
|
|
13943
13878
|
// src/prompts/compose.ts
|
|
13944
|
-
|
|
13945
|
-
|
|
13946
|
-
|
|
13947
|
-
|
|
13948
|
-
|
|
13949
|
-
|
|
13950
|
-
|
|
13951
|
-
|
|
13952
|
-
|
|
13953
|
-
|
|
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
|
+
})
|
|
13954
13935
|
];
|
|
13936
|
+
return resolvePromptSections({
|
|
13937
|
+
sections,
|
|
13938
|
+
kind: "static",
|
|
13939
|
+
disabledSectionIDs: normalizeDisabledSectionIDs(options.disabledSectionIDs)
|
|
13940
|
+
});
|
|
13955
13941
|
}
|
|
13956
13942
|
|
|
13957
13943
|
// src/agents/explore.ts
|
|
@@ -14427,7 +14413,7 @@ function createConfigHook(config2, directory) {
|
|
|
14427
14413
|
if (!config2.enabled)
|
|
14428
14414
|
return;
|
|
14429
14415
|
const existingAgents = input.agent ?? {};
|
|
14430
|
-
const systemSections = composeSystemPrompt({
|
|
14416
|
+
const systemSections = await composeSystemPrompt({
|
|
14431
14417
|
toolNames: { bash: "Bash", read: "Read", edit: "Edit", write: "Write", glob: "Glob", grep: "Grep" },
|
|
14432
14418
|
env: {
|
|
14433
14419
|
cwd: directory,
|
|
@@ -14435,7 +14421,8 @@ function createConfigHook(config2, directory) {
|
|
|
14435
14421
|
platform: process.platform,
|
|
14436
14422
|
shell: process.env.SHELL ?? "unknown"
|
|
14437
14423
|
},
|
|
14438
|
-
outputStyle: config2.output_style ?? undefined
|
|
14424
|
+
outputStyle: config2.output_style ?? undefined,
|
|
14425
|
+
disabledSectionIDs: config2.disabled_sections
|
|
14439
14426
|
});
|
|
14440
14427
|
const subagentGuidance = buildSubagentGuidance();
|
|
14441
14428
|
const mainPrompt = [...systemSections, subagentGuidance].join(`
|
|
@@ -14467,20 +14454,260 @@ function createConfigHook(config2, directory) {
|
|
|
14467
14454
|
};
|
|
14468
14455
|
}
|
|
14469
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
|
+
|
|
14470
14697
|
// src/hooks/environment-context.ts
|
|
14471
14698
|
import { existsSync as existsSync4 } from "fs";
|
|
14472
14699
|
import { join as join4 } from "path";
|
|
14473
14700
|
var environmentBySession = new Map;
|
|
14474
|
-
function
|
|
14701
|
+
function isRecord3(value) {
|
|
14475
14702
|
return typeof value === "object" && value !== null;
|
|
14476
14703
|
}
|
|
14477
14704
|
function createEnvironmentContext(directory) {
|
|
14478
14705
|
return async (input, output) => {
|
|
14479
|
-
if (!
|
|
14706
|
+
if (!isRecord3(input) || !isRecord3(output)) {
|
|
14480
14707
|
return;
|
|
14481
14708
|
}
|
|
14482
14709
|
const rawEvent = input.event;
|
|
14483
|
-
if (!
|
|
14710
|
+
if (!isRecord3(rawEvent) || rawEvent.type !== "session.created") {
|
|
14484
14711
|
return;
|
|
14485
14712
|
}
|
|
14486
14713
|
const event = rawEvent;
|
|
@@ -14494,7 +14721,7 @@ function createEnvironmentContext(directory) {
|
|
|
14494
14721
|
if (sessionID) {
|
|
14495
14722
|
environmentBySession.set(sessionID, environment);
|
|
14496
14723
|
}
|
|
14497
|
-
const existingContext =
|
|
14724
|
+
const existingContext = isRecord3(output.context) ? output.context : {};
|
|
14498
14725
|
existingContext.environment = environment;
|
|
14499
14726
|
output.context = existingContext;
|
|
14500
14727
|
};
|
|
@@ -14581,11 +14808,11 @@ function createMessageTransformHook() {
|
|
|
14581
14808
|
}
|
|
14582
14809
|
|
|
14583
14810
|
// src/hooks/idle-compaction.ts
|
|
14584
|
-
var
|
|
14811
|
+
var sessionStates = new Map;
|
|
14585
14812
|
var IDLE_THRESHOLD_MS = 30 * 60 * 1000;
|
|
14586
14813
|
var MIN_TURNS_BEFORE_COMPACT = 10;
|
|
14587
14814
|
function getIdleState(sessionID) {
|
|
14588
|
-
const existing =
|
|
14815
|
+
const existing = sessionStates.get(sessionID);
|
|
14589
14816
|
if (existing)
|
|
14590
14817
|
return existing;
|
|
14591
14818
|
const state = {
|
|
@@ -14593,7 +14820,7 @@ function getIdleState(sessionID) {
|
|
|
14593
14820
|
turnCount: 0,
|
|
14594
14821
|
compactedAt: 0
|
|
14595
14822
|
};
|
|
14596
|
-
|
|
14823
|
+
sessionStates.set(sessionID, state);
|
|
14597
14824
|
return state;
|
|
14598
14825
|
}
|
|
14599
14826
|
function recordSessionIdle(sessionID) {
|
|
@@ -14655,7 +14882,7 @@ var RISK_PATTERNS = [
|
|
|
14655
14882
|
/truncate\s+table\b/i,
|
|
14656
14883
|
/delete\s+from\b/i
|
|
14657
14884
|
];
|
|
14658
|
-
function
|
|
14885
|
+
function isRecord4(value) {
|
|
14659
14886
|
return typeof value === "object" && value !== null;
|
|
14660
14887
|
}
|
|
14661
14888
|
function collectRiskText(value) {
|
|
@@ -14665,14 +14892,14 @@ function collectRiskText(value) {
|
|
|
14665
14892
|
if (Array.isArray(value)) {
|
|
14666
14893
|
return value.flatMap((item) => collectRiskText(item));
|
|
14667
14894
|
}
|
|
14668
|
-
if (
|
|
14895
|
+
if (isRecord4(value)) {
|
|
14669
14896
|
return Object.values(value).flatMap((item) => collectRiskText(item));
|
|
14670
14897
|
}
|
|
14671
14898
|
return [];
|
|
14672
14899
|
}
|
|
14673
14900
|
function createRiskGuard() {
|
|
14674
14901
|
return async (input, output) => {
|
|
14675
|
-
if (!
|
|
14902
|
+
if (!isRecord4(output)) {
|
|
14676
14903
|
return;
|
|
14677
14904
|
}
|
|
14678
14905
|
const argsText = collectRiskText(output.args).join(`
|
|
@@ -14681,10 +14908,10 @@ function createRiskGuard() {
|
|
|
14681
14908
|
if (!matchedPattern) {
|
|
14682
14909
|
return;
|
|
14683
14910
|
}
|
|
14684
|
-
const toolName =
|
|
14911
|
+
const toolName = isRecord4(input) && typeof input.tool === "string" ? input.tool : "tool";
|
|
14685
14912
|
const warning = `Potentially destructive ${toolName} invocation detected. Review arguments carefully before continuing.`;
|
|
14686
14913
|
output.warning = warning;
|
|
14687
|
-
const metadata =
|
|
14914
|
+
const metadata = isRecord4(output.metadata) ? output.metadata : {};
|
|
14688
14915
|
metadata.riskGuard = {
|
|
14689
14916
|
flagged: true,
|
|
14690
14917
|
pattern: matchedPattern.source
|
|
@@ -14722,49 +14949,6 @@ ${contextHint}`;
|
|
|
14722
14949
|
};
|
|
14723
14950
|
}
|
|
14724
14951
|
|
|
14725
|
-
// src/hooks/verification-reminder.ts
|
|
14726
|
-
var sessionStateById = new Map;
|
|
14727
|
-
var EDIT_TOOL_NAMES = new Set(["edit", "write"]);
|
|
14728
|
-
function isRecord3(value) {
|
|
14729
|
-
return typeof value === "object" && value !== null;
|
|
14730
|
-
}
|
|
14731
|
-
function getSessionState(sessionID) {
|
|
14732
|
-
const existing = sessionStateById.get(sessionID);
|
|
14733
|
-
if (existing) {
|
|
14734
|
-
return existing;
|
|
14735
|
-
}
|
|
14736
|
-
const created = {
|
|
14737
|
-
editedFiles: new Set
|
|
14738
|
-
};
|
|
14739
|
-
sessionStateById.set(sessionID, created);
|
|
14740
|
-
return created;
|
|
14741
|
-
}
|
|
14742
|
-
function getFilePath(value) {
|
|
14743
|
-
if (!isRecord3(value)) {
|
|
14744
|
-
return;
|
|
14745
|
-
}
|
|
14746
|
-
const candidates = [value.filePath, value.path, value.filename];
|
|
14747
|
-
return candidates.find((candidate) => typeof candidate === "string");
|
|
14748
|
-
}
|
|
14749
|
-
function createVerificationReminder(config2) {
|
|
14750
|
-
return async (input, _output) => {
|
|
14751
|
-
if (!config2.verification.auto_remind || !isRecord3(input)) {
|
|
14752
|
-
return;
|
|
14753
|
-
}
|
|
14754
|
-
const sessionID = typeof input.sessionID === "string" ? input.sessionID : undefined;
|
|
14755
|
-
const toolName = typeof input.tool === "string" ? input.tool.toLowerCase() : undefined;
|
|
14756
|
-
if (!sessionID || !toolName || !EDIT_TOOL_NAMES.has(toolName)) {
|
|
14757
|
-
return;
|
|
14758
|
-
}
|
|
14759
|
-
const filePath = getFilePath(input.args);
|
|
14760
|
-
if (!filePath) {
|
|
14761
|
-
return;
|
|
14762
|
-
}
|
|
14763
|
-
const state = getSessionState(sessionID);
|
|
14764
|
-
state.editedFiles.add(filePath);
|
|
14765
|
-
};
|
|
14766
|
-
}
|
|
14767
|
-
|
|
14768
14952
|
// node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/external.js
|
|
14769
14953
|
var exports_external2 = {};
|
|
14770
14954
|
__export(exports_external2, {
|
|
@@ -27125,6 +27309,7 @@ function createPluginInterface(args) {
|
|
|
27125
27309
|
const riskGuard = createRiskGuard();
|
|
27126
27310
|
const verificationReminder = createVerificationReminder(config3);
|
|
27127
27311
|
const environmentContext = createEnvironmentContext(ctx.directory);
|
|
27312
|
+
const gitContext = createGitContextHook(ctx.directory);
|
|
27128
27313
|
const dynamicSystemPrompt = createDynamicSystemPrompt(config3, ctx.directory);
|
|
27129
27314
|
const chatMessageHook = createChatMessageHook(config3);
|
|
27130
27315
|
const chatParamsHook = createChatParamsHook();
|
|
@@ -27138,16 +27323,10 @@ function createPluginInterface(args) {
|
|
|
27138
27323
|
"tool.execute.before": riskGuard,
|
|
27139
27324
|
"tool.execute.after": async (input, output) => {
|
|
27140
27325
|
await verificationReminder(input, output);
|
|
27141
|
-
const sessionID = typeof input.sessionID === "string" ? input.sessionID : undefined;
|
|
27142
|
-
const tool3 = typeof input.tool === "string" ? input.tool.toLowerCase() : undefined;
|
|
27143
|
-
if (sessionID && tool3) {
|
|
27144
|
-
const args2 = input.args;
|
|
27145
|
-
const file3 = typeof args2?.filePath === "string" ? args2.filePath : typeof args2?.path === "string" ? args2.path : undefined;
|
|
27146
|
-
recordToolCall(sessionID, tool3, file3);
|
|
27147
|
-
}
|
|
27148
27326
|
},
|
|
27149
27327
|
event: async (input) => {
|
|
27150
27328
|
await environmentContext(input, {});
|
|
27329
|
+
await gitContext(input, {});
|
|
27151
27330
|
const rawEvent = input.event;
|
|
27152
27331
|
if (rawEvent) {
|
|
27153
27332
|
await idleCompaction.onEvent(rawEvent);
|
|
@@ -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.
|
|
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",
|