@ccx-agent/opencode-ccx 0.2.3 → 0.2.5
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.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OhMyCCAgentConfig } from "../config/schema";
|
|
2
|
+
export declare function recordSessionIdle(sessionID: string): void;
|
|
3
|
+
export declare function recordSessionTurn(sessionID: string): void;
|
|
4
|
+
export declare function shouldCompactOnReturn(sessionID: string): boolean;
|
|
5
|
+
export declare function markCompacted(sessionID: string): void;
|
|
6
|
+
export declare function createIdleCompactionHook(config: OhMyCCAgentConfig, client: unknown): {
|
|
7
|
+
onEvent: (event: {
|
|
8
|
+
type: string;
|
|
9
|
+
properties?: {
|
|
10
|
+
sessionID?: string;
|
|
11
|
+
};
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
onChatMessage: (sessionID: string) => Promise<void>;
|
|
14
|
+
};
|
|
@@ -7,9 +7,11 @@ type MessageInfo = {
|
|
|
7
7
|
type: string;
|
|
8
8
|
text?: string;
|
|
9
9
|
output?: string;
|
|
10
|
+
tool?: string;
|
|
10
11
|
[key: string]: unknown;
|
|
11
12
|
}>;
|
|
12
13
|
};
|
|
14
|
+
export declare function enableMicrocompact(): void;
|
|
13
15
|
export declare function createMessageTransformHook(): (_input: Record<string, unknown>, output: {
|
|
14
16
|
messages: MessageInfo[];
|
|
15
17
|
}) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -13748,11 +13748,11 @@ function createChatMessageHook(config2) {
|
|
|
13748
13748
|
|
|
13749
13749
|
// src/hooks/chat-params.ts
|
|
13750
13750
|
var AGENT_PARAMS = {
|
|
13751
|
-
"ccx-plan": { temperature: 0.3
|
|
13752
|
-
"ccx-verification": { temperature: 0.2
|
|
13753
|
-
"ccx-explore": { temperature: 0.5
|
|
13754
|
-
"ccx-coordinator": { temperature: 0.4
|
|
13755
|
-
"ccx-general-purpose": { temperature: 0.5
|
|
13751
|
+
"ccx-plan": { temperature: 0.3 },
|
|
13752
|
+
"ccx-verification": { temperature: 0.2 },
|
|
13753
|
+
"ccx-explore": { temperature: 0.5 },
|
|
13754
|
+
"ccx-coordinator": { temperature: 0.4 },
|
|
13755
|
+
"ccx-general-purpose": { temperature: 0.5 }
|
|
13756
13756
|
};
|
|
13757
13757
|
function createChatParamsHook() {
|
|
13758
13758
|
return async (input, output) => {
|
|
@@ -14524,6 +14524,33 @@ function createEnvironmentContext(directory) {
|
|
|
14524
14524
|
// src/hooks/message-transform.ts
|
|
14525
14525
|
var MAX_TOOL_OUTPUT_LENGTH = 8000;
|
|
14526
14526
|
var TOOL_OUTPUT_TRIM_TO = 4000;
|
|
14527
|
+
var KEEP_RECENT_TOOL_OUTPUTS = 5;
|
|
14528
|
+
var CLEARABLE_TOOLS = new Set(["read", "grep", "glob", "bash", "webfetch"]);
|
|
14529
|
+
var CLEARED_MARKER = "[Old tool result content cleared]";
|
|
14530
|
+
function microcompactOldToolOutputs(messages) {
|
|
14531
|
+
const toolParts = [];
|
|
14532
|
+
for (let i = 0;i < messages.length; i++) {
|
|
14533
|
+
const msg = messages[i];
|
|
14534
|
+
if (msg.info.role !== "assistant")
|
|
14535
|
+
continue;
|
|
14536
|
+
for (const part of msg.parts) {
|
|
14537
|
+
if (part.type !== "tool")
|
|
14538
|
+
continue;
|
|
14539
|
+
const toolName = typeof part.tool === "string" ? part.tool.toLowerCase() : "";
|
|
14540
|
+
if (!CLEARABLE_TOOLS.has(toolName))
|
|
14541
|
+
continue;
|
|
14542
|
+
if (typeof part.output !== "string" || part.output === CLEARED_MARKER)
|
|
14543
|
+
continue;
|
|
14544
|
+
toolParts.push({ part, index: i });
|
|
14545
|
+
}
|
|
14546
|
+
}
|
|
14547
|
+
const clearCount = toolParts.length - KEEP_RECENT_TOOL_OUTPUTS;
|
|
14548
|
+
if (clearCount <= 0)
|
|
14549
|
+
return;
|
|
14550
|
+
for (let i = 0;i < clearCount; i++) {
|
|
14551
|
+
toolParts[i].part.output = CLEARED_MARKER;
|
|
14552
|
+
}
|
|
14553
|
+
}
|
|
14527
14554
|
function trimLongToolOutputs(messages) {
|
|
14528
14555
|
for (const msg of messages) {
|
|
14529
14556
|
if (msg.info.role !== "assistant")
|
|
@@ -14559,13 +14586,87 @@ function collapseConsecutiveReasoningParts(messages) {
|
|
|
14559
14586
|
msg.parts = collapsed;
|
|
14560
14587
|
}
|
|
14561
14588
|
}
|
|
14589
|
+
var microcompactEnabled = false;
|
|
14590
|
+
function enableMicrocompact() {
|
|
14591
|
+
microcompactEnabled = true;
|
|
14592
|
+
}
|
|
14562
14593
|
function createMessageTransformHook() {
|
|
14563
14594
|
return async (_input, output) => {
|
|
14595
|
+
if (microcompactEnabled) {
|
|
14596
|
+
microcompactOldToolOutputs(output.messages);
|
|
14597
|
+
microcompactEnabled = false;
|
|
14598
|
+
}
|
|
14564
14599
|
trimLongToolOutputs(output.messages);
|
|
14565
14600
|
collapseConsecutiveReasoningParts(output.messages);
|
|
14566
14601
|
};
|
|
14567
14602
|
}
|
|
14568
14603
|
|
|
14604
|
+
// src/hooks/idle-compaction.ts
|
|
14605
|
+
var sessionStates2 = new Map;
|
|
14606
|
+
var IDLE_THRESHOLD_MS = 30 * 60 * 1000;
|
|
14607
|
+
var MIN_TURNS_BEFORE_COMPACT = 10;
|
|
14608
|
+
function getIdleState(sessionID) {
|
|
14609
|
+
const existing = sessionStates2.get(sessionID);
|
|
14610
|
+
if (existing)
|
|
14611
|
+
return existing;
|
|
14612
|
+
const state = {
|
|
14613
|
+
lastIdleTimestamp: 0,
|
|
14614
|
+
turnCount: 0,
|
|
14615
|
+
compactedAt: 0
|
|
14616
|
+
};
|
|
14617
|
+
sessionStates2.set(sessionID, state);
|
|
14618
|
+
return state;
|
|
14619
|
+
}
|
|
14620
|
+
function recordSessionIdle(sessionID) {
|
|
14621
|
+
const state = getIdleState(sessionID);
|
|
14622
|
+
state.lastIdleTimestamp = Date.now();
|
|
14623
|
+
}
|
|
14624
|
+
function recordSessionTurn(sessionID) {
|
|
14625
|
+
getIdleState(sessionID).turnCount++;
|
|
14626
|
+
}
|
|
14627
|
+
function shouldCompactOnReturn(sessionID) {
|
|
14628
|
+
const state = getIdleState(sessionID);
|
|
14629
|
+
if (state.lastIdleTimestamp === 0)
|
|
14630
|
+
return false;
|
|
14631
|
+
if (state.turnCount < MIN_TURNS_BEFORE_COMPACT)
|
|
14632
|
+
return false;
|
|
14633
|
+
const idleDuration = Date.now() - state.lastIdleTimestamp;
|
|
14634
|
+
if (idleDuration < IDLE_THRESHOLD_MS)
|
|
14635
|
+
return false;
|
|
14636
|
+
const turnsSinceCompact = state.turnCount - state.compactedAt;
|
|
14637
|
+
return turnsSinceCompact >= MIN_TURNS_BEFORE_COMPACT;
|
|
14638
|
+
}
|
|
14639
|
+
function markCompacted(sessionID) {
|
|
14640
|
+
const state = getIdleState(sessionID);
|
|
14641
|
+
state.compactedAt = state.turnCount;
|
|
14642
|
+
}
|
|
14643
|
+
function createIdleCompactionHook(config2, client) {
|
|
14644
|
+
const typedClient = client;
|
|
14645
|
+
return {
|
|
14646
|
+
onEvent: async (event) => {
|
|
14647
|
+
if (!config2.enabled)
|
|
14648
|
+
return;
|
|
14649
|
+
if (event.type !== "session.idle")
|
|
14650
|
+
return;
|
|
14651
|
+
const sessionID = event.properties?.sessionID;
|
|
14652
|
+
if (!sessionID)
|
|
14653
|
+
return;
|
|
14654
|
+
recordSessionIdle(sessionID);
|
|
14655
|
+
},
|
|
14656
|
+
onChatMessage: async (sessionID) => {
|
|
14657
|
+
if (!config2.enabled)
|
|
14658
|
+
return;
|
|
14659
|
+
if (!shouldCompactOnReturn(sessionID))
|
|
14660
|
+
return;
|
|
14661
|
+
enableMicrocompact();
|
|
14662
|
+
try {
|
|
14663
|
+
await typedClient.session.summarize({ path: { id: sessionID } });
|
|
14664
|
+
markCompacted(sessionID);
|
|
14665
|
+
} catch {}
|
|
14666
|
+
}
|
|
14667
|
+
};
|
|
14668
|
+
}
|
|
14669
|
+
|
|
14569
14670
|
// src/hooks/risk-guard.ts
|
|
14570
14671
|
var RISK_PATTERNS = [
|
|
14571
14672
|
/rm\s+-rf\b/i,
|
|
@@ -27069,6 +27170,7 @@ function createPluginInterface(args) {
|
|
|
27069
27170
|
const compactionHook = createCompactionHook();
|
|
27070
27171
|
const toolDefinitionHook = createToolDefinitionHook();
|
|
27071
27172
|
const messageTransformHook = createMessageTransformHook();
|
|
27173
|
+
const idleCompaction = createIdleCompactionHook(config3, ctx.client);
|
|
27072
27174
|
return {
|
|
27073
27175
|
config: configHook,
|
|
27074
27176
|
tool: createAgentTools(),
|
|
@@ -27085,8 +27187,18 @@ function createPluginInterface(args) {
|
|
|
27085
27187
|
},
|
|
27086
27188
|
event: async (input) => {
|
|
27087
27189
|
await environmentContext(input, {});
|
|
27190
|
+
const rawEvent = input.event;
|
|
27191
|
+
if (rawEvent) {
|
|
27192
|
+
await idleCompaction.onEvent(rawEvent);
|
|
27193
|
+
}
|
|
27194
|
+
},
|
|
27195
|
+
"chat.message": async (input, output) => {
|
|
27196
|
+
await chatMessageHook(input, output);
|
|
27197
|
+
if (input.sessionID) {
|
|
27198
|
+
recordSessionTurn(input.sessionID);
|
|
27199
|
+
await idleCompaction.onChatMessage(input.sessionID);
|
|
27200
|
+
}
|
|
27088
27201
|
},
|
|
27089
|
-
"chat.message": chatMessageHook,
|
|
27090
27202
|
"chat.params": chatParamsHook,
|
|
27091
27203
|
"tool.definition": toolDefinitionHook,
|
|
27092
27204
|
"experimental.chat.system.transform": dynamicSystemPrompt,
|
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.5",
|
|
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",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
],
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@ccx-agent/opencode-ccx": "^0.2.3",
|
|
37
38
|
"@opencode-ai/plugin": "^1.2.24",
|
|
38
39
|
"zod": "^4.1.8"
|
|
39
40
|
},
|