attocode 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +91 -1
- package/README.md +7 -0
- package/dist/src/adapters.d.ts +6 -1
- package/dist/src/adapters.d.ts.map +1 -1
- package/dist/src/adapters.js +8 -1
- package/dist/src/adapters.js.map +1 -1
- package/dist/src/agent.d.ts +35 -4
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +361 -45
- package/dist/src/agent.js.map +1 -1
- package/dist/src/defaults.d.ts +1 -1
- package/dist/src/defaults.d.ts.map +1 -1
- package/dist/src/defaults.js +2 -0
- package/dist/src/defaults.js.map +1 -1
- package/dist/src/integrations/agent-registry.d.ts +2 -0
- package/dist/src/integrations/agent-registry.d.ts.map +1 -1
- package/dist/src/integrations/agent-registry.js.map +1 -1
- package/dist/src/integrations/async-subagent.d.ts +135 -0
- package/dist/src/integrations/async-subagent.d.ts.map +1 -0
- package/dist/src/integrations/async-subagent.js +213 -0
- package/dist/src/integrations/async-subagent.js.map +1 -0
- package/dist/src/integrations/auto-checkpoint.d.ts +98 -0
- package/dist/src/integrations/auto-checkpoint.d.ts.map +1 -0
- package/dist/src/integrations/auto-checkpoint.js +252 -0
- package/dist/src/integrations/auto-checkpoint.js.map +1 -0
- package/dist/src/integrations/complexity-classifier.d.ts +86 -0
- package/dist/src/integrations/complexity-classifier.d.ts.map +1 -0
- package/dist/src/integrations/complexity-classifier.js +233 -0
- package/dist/src/integrations/complexity-classifier.js.map +1 -0
- package/dist/src/integrations/delegation-protocol.d.ts +86 -0
- package/dist/src/integrations/delegation-protocol.d.ts.map +1 -0
- package/dist/src/integrations/delegation-protocol.js +127 -0
- package/dist/src/integrations/delegation-protocol.js.map +1 -0
- package/dist/src/integrations/dynamic-budget.d.ts +81 -0
- package/dist/src/integrations/dynamic-budget.d.ts.map +1 -0
- package/dist/src/integrations/dynamic-budget.js +151 -0
- package/dist/src/integrations/dynamic-budget.js.map +1 -0
- package/dist/src/integrations/economics.d.ts +44 -1
- package/dist/src/integrations/economics.d.ts.map +1 -1
- package/dist/src/integrations/economics.js +182 -3
- package/dist/src/integrations/economics.js.map +1 -1
- package/dist/src/integrations/environment-facts.d.ts +52 -0
- package/dist/src/integrations/environment-facts.d.ts.map +1 -0
- package/dist/src/integrations/environment-facts.js +84 -0
- package/dist/src/integrations/environment-facts.js.map +1 -0
- package/dist/src/integrations/index.d.ts +16 -1
- package/dist/src/integrations/index.d.ts.map +1 -1
- package/dist/src/integrations/index.js +31 -1
- package/dist/src/integrations/index.js.map +1 -1
- package/dist/src/integrations/injection-budget.d.ts +71 -0
- package/dist/src/integrations/injection-budget.d.ts.map +1 -0
- package/dist/src/integrations/injection-budget.js +136 -0
- package/dist/src/integrations/injection-budget.js.map +1 -0
- package/dist/src/integrations/mcp-client.d.ts.map +1 -1
- package/dist/src/integrations/mcp-client.js +14 -0
- package/dist/src/integrations/mcp-client.js.map +1 -1
- package/dist/src/integrations/mcp-custom-tools.d.ts +102 -0
- package/dist/src/integrations/mcp-custom-tools.d.ts.map +1 -0
- package/dist/src/integrations/mcp-custom-tools.js +232 -0
- package/dist/src/integrations/mcp-custom-tools.js.map +1 -0
- package/dist/src/integrations/mcp-tool-validator.d.ts +60 -0
- package/dist/src/integrations/mcp-tool-validator.d.ts.map +1 -0
- package/dist/src/integrations/mcp-tool-validator.js +141 -0
- package/dist/src/integrations/mcp-tool-validator.js.map +1 -0
- package/dist/src/integrations/self-improvement.d.ts +90 -0
- package/dist/src/integrations/self-improvement.d.ts.map +1 -0
- package/dist/src/integrations/self-improvement.js +217 -0
- package/dist/src/integrations/self-improvement.js.map +1 -0
- package/dist/src/integrations/smart-decomposer.d.ts +4 -0
- package/dist/src/integrations/smart-decomposer.d.ts.map +1 -1
- package/dist/src/integrations/smart-decomposer.js +55 -28
- package/dist/src/integrations/smart-decomposer.js.map +1 -1
- package/dist/src/integrations/subagent-output-store.d.ts +91 -0
- package/dist/src/integrations/subagent-output-store.d.ts.map +1 -0
- package/dist/src/integrations/subagent-output-store.js +257 -0
- package/dist/src/integrations/subagent-output-store.js.map +1 -0
- package/dist/src/integrations/swarm/index.d.ts +1 -1
- package/dist/src/integrations/swarm/index.d.ts.map +1 -1
- package/dist/src/integrations/swarm/index.js +1 -1
- package/dist/src/integrations/swarm/index.js.map +1 -1
- package/dist/src/integrations/swarm/model-selector.d.ts +1 -0
- package/dist/src/integrations/swarm/model-selector.d.ts.map +1 -1
- package/dist/src/integrations/swarm/model-selector.js +37 -3
- package/dist/src/integrations/swarm/model-selector.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-config-loader.d.ts +10 -1
- package/dist/src/integrations/swarm/swarm-config-loader.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-config-loader.js +72 -6
- package/dist/src/integrations/swarm/swarm-config-loader.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-event-bridge.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-event-bridge.js +26 -4
- package/dist/src/integrations/swarm/swarm-event-bridge.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-events.d.ts +11 -0
- package/dist/src/integrations/swarm/swarm-events.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-events.js +4 -0
- package/dist/src/integrations/swarm/swarm-events.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-orchestrator.d.ts +11 -0
- package/dist/src/integrations/swarm/swarm-orchestrator.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-orchestrator.js +233 -10
- package/dist/src/integrations/swarm/swarm-orchestrator.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-quality-gate.d.ts +9 -2
- package/dist/src/integrations/swarm/swarm-quality-gate.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-quality-gate.js +128 -11
- package/dist/src/integrations/swarm/swarm-quality-gate.js.map +1 -1
- package/dist/src/integrations/swarm/task-queue.d.ts +11 -1
- package/dist/src/integrations/swarm/task-queue.d.ts.map +1 -1
- package/dist/src/integrations/swarm/task-queue.js +125 -15
- package/dist/src/integrations/swarm/task-queue.js.map +1 -1
- package/dist/src/integrations/swarm/types.d.ts +40 -1
- package/dist/src/integrations/swarm/types.d.ts.map +1 -1
- package/dist/src/integrations/swarm/types.js +6 -1
- package/dist/src/integrations/swarm/types.js.map +1 -1
- package/dist/src/integrations/swarm/worker-pool.d.ts +9 -3
- package/dist/src/integrations/swarm/worker-pool.d.ts.map +1 -1
- package/dist/src/integrations/swarm/worker-pool.js +89 -17
- package/dist/src/integrations/swarm/worker-pool.js.map +1 -1
- package/dist/src/integrations/thinking-strategy.d.ts +52 -0
- package/dist/src/integrations/thinking-strategy.d.ts.map +1 -0
- package/dist/src/integrations/thinking-strategy.js +129 -0
- package/dist/src/integrations/thinking-strategy.js.map +1 -0
- package/dist/src/integrations/tool-recommendation.d.ts +58 -0
- package/dist/src/integrations/tool-recommendation.d.ts.map +1 -0
- package/dist/src/integrations/tool-recommendation.js +215 -0
- package/dist/src/integrations/tool-recommendation.js.map +1 -0
- package/dist/src/integrations/verification-gate.d.ts +80 -0
- package/dist/src/integrations/verification-gate.d.ts.map +1 -0
- package/dist/src/integrations/verification-gate.js +146 -0
- package/dist/src/integrations/verification-gate.js.map +1 -0
- package/dist/src/integrations/work-log.d.ts +87 -0
- package/dist/src/integrations/work-log.d.ts.map +1 -0
- package/dist/src/integrations/work-log.js +275 -0
- package/dist/src/integrations/work-log.js.map +1 -0
- package/dist/src/main.js +5 -4
- package/dist/src/main.js.map +1 -1
- package/dist/src/modes.d.ts +6 -0
- package/dist/src/modes.d.ts.map +1 -1
- package/dist/src/modes.js +73 -2
- package/dist/src/modes.js.map +1 -1
- package/dist/src/tools/bash.d.ts +6 -0
- package/dist/src/tools/bash.d.ts.map +1 -1
- package/dist/src/tools/bash.js +12 -0
- package/dist/src/tools/bash.js.map +1 -1
- package/dist/src/tools/standard.d.ts +17 -1
- package/dist/src/tools/standard.d.ts.map +1 -1
- package/dist/src/tools/standard.js +64 -11
- package/dist/src/tools/standard.js.map +1 -1
- package/dist/src/types.d.ts +18 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-Checkpoint Resumption
|
|
3
|
+
*
|
|
4
|
+
* Saves lightweight checkpoints at key execution points so that
|
|
5
|
+
* work can be recovered if the agent crashes or times out.
|
|
6
|
+
*
|
|
7
|
+
* Key points where checkpoints are saved:
|
|
8
|
+
* - After each tool batch execution
|
|
9
|
+
* - Before LLM calls (so the prompt is recoverable)
|
|
10
|
+
* - After significant state changes (plan approval, mode switch)
|
|
11
|
+
*
|
|
12
|
+
* On startup, detects recent sessions (<5 min) and offers auto-resume.
|
|
13
|
+
*/
|
|
14
|
+
export interface Checkpoint {
|
|
15
|
+
/** Unique checkpoint ID */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Label describing the checkpoint point */
|
|
18
|
+
label: string;
|
|
19
|
+
/** Session ID this checkpoint belongs to */
|
|
20
|
+
sessionId: string;
|
|
21
|
+
/** Timestamp of the checkpoint */
|
|
22
|
+
timestamp: number;
|
|
23
|
+
/** Agent iteration count at this point */
|
|
24
|
+
iteration: number;
|
|
25
|
+
/** Messages up to this point (serialized) */
|
|
26
|
+
messages?: unknown[];
|
|
27
|
+
/** Current objective/task */
|
|
28
|
+
objective?: string;
|
|
29
|
+
/** Current mode */
|
|
30
|
+
mode?: string;
|
|
31
|
+
/** Files modified since last checkpoint */
|
|
32
|
+
filesModified?: string[];
|
|
33
|
+
/** Token usage at this point */
|
|
34
|
+
tokensUsed?: number;
|
|
35
|
+
/** Tool call history summary */
|
|
36
|
+
toolCallSummary?: string;
|
|
37
|
+
/** Custom metadata */
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface AutoCheckpointConfig {
|
|
41
|
+
/** Directory for checkpoint storage (default: '.agent/checkpoints') */
|
|
42
|
+
checkpointDir: string;
|
|
43
|
+
/** Maximum checkpoints to keep per session (default: 10) */
|
|
44
|
+
maxCheckpointsPerSession: number;
|
|
45
|
+
/** Auto-cleanup checkpoints older than this (ms, default: 3600000 = 1hr) */
|
|
46
|
+
maxAge: number;
|
|
47
|
+
/** Whether checkpointing is enabled (default: true) */
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
/** Minimum interval between checkpoints (ms, default: 30000) */
|
|
50
|
+
minInterval: number;
|
|
51
|
+
}
|
|
52
|
+
export interface ResumeCandidate {
|
|
53
|
+
/** Session ID */
|
|
54
|
+
sessionId: string;
|
|
55
|
+
/** Most recent checkpoint */
|
|
56
|
+
checkpoint: Checkpoint;
|
|
57
|
+
/** Age of the checkpoint in ms */
|
|
58
|
+
ageMs: number;
|
|
59
|
+
/** Number of checkpoints available */
|
|
60
|
+
checkpointCount: number;
|
|
61
|
+
}
|
|
62
|
+
export declare class AutoCheckpointManager {
|
|
63
|
+
private config;
|
|
64
|
+
private lastCheckpointTime;
|
|
65
|
+
private checkpointCount;
|
|
66
|
+
constructor(config?: Partial<AutoCheckpointConfig>);
|
|
67
|
+
/**
|
|
68
|
+
* Save a checkpoint at a key execution point.
|
|
69
|
+
* Respects minInterval to avoid excessive I/O.
|
|
70
|
+
*/
|
|
71
|
+
save(checkpoint: Omit<Checkpoint, 'id' | 'timestamp'>): string | null;
|
|
72
|
+
/**
|
|
73
|
+
* Load a specific checkpoint.
|
|
74
|
+
*/
|
|
75
|
+
load(sessionId: string, checkpointId: string): Checkpoint | null;
|
|
76
|
+
/**
|
|
77
|
+
* Find sessions with recent checkpoints that could be resumed.
|
|
78
|
+
*/
|
|
79
|
+
findResumeCandidates(maxAgeMs?: number): ResumeCandidate[];
|
|
80
|
+
/**
|
|
81
|
+
* Load all checkpoints for a session, sorted by timestamp.
|
|
82
|
+
*/
|
|
83
|
+
loadSessionCheckpoints(sessionId: string): Checkpoint[];
|
|
84
|
+
/**
|
|
85
|
+
* Get a summary of a checkpoint for display.
|
|
86
|
+
*/
|
|
87
|
+
formatCheckpointSummary(checkpoint: Checkpoint): string;
|
|
88
|
+
/**
|
|
89
|
+
* Clean up old checkpoints globally.
|
|
90
|
+
*/
|
|
91
|
+
cleanupAll(): number;
|
|
92
|
+
private cleanupSession;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create an auto-checkpoint manager.
|
|
96
|
+
*/
|
|
97
|
+
export declare function createAutoCheckpointManager(config?: Partial<AutoCheckpointConfig>): AutoCheckpointManager;
|
|
98
|
+
//# sourceMappingURL=auto-checkpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-checkpoint.d.ts","sourceRoot":"","sources":["../../../src/integrations/auto-checkpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH,MAAM,WAAW,UAAU;IACzB,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,gCAAgC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,oBAAoB;IACnC,uEAAuE;IACvE,aAAa,EAAE,MAAM,CAAC;IACtB,4DA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oint Resumption
|
|
3
|
+
*
|
|
4
|
+
* Saves lightweight checkpoints at key execution points so that
|
|
5
|
+
* work can be recovered if the agent crashes or times out.
|
|
6
|
+
*
|
|
7
|
+
* Key points where checkpoints are saved:
|
|
8
|
+
* - After each tool batch execution
|
|
9
|
+
* - Before LLM calls (so the prompt is recoverable)
|
|
10
|
+
* - After significant state changes (plan approval, mode switch)
|
|
11
|
+
*
|
|
12
|
+
* On startup, detects recent sessions (<5 min) and offers auto-resume.
|
|
13
|
+
*/
|
|
14
|
+
import { writeFileSync, readFileSync, mkdirSync, existsSync, readdirSync, statSync, unlinkSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// CONSTANTS
|
|
18
|
+
// =============================================================================
|
|
19
|
+
const DEFAULT_CONFIG = {
|
|
20
|
+
checkpointDir: '.agent/checkpoints',
|
|
21
|
+
maxCheckpointsPerSession: 10,
|
|
22
|
+
maxAge: 3600000, // 1 hour
|
|
23
|
+
enabled: true,
|
|
24
|
+
minInterval: 30000, // 30 seconds
|
|
25
|
+
};
|
|
26
|
+
// =============================================================================
|
|
27
|
+
// AUTO-CHECKPOINT MANAGER
|
|
28
|
+
// =============================================================================
|
|
29
|
+
export class AutoCheckpointManager {
|
|
30
|
+
config;
|
|
31
|
+
lastCheckpointTime = 0;
|
|
32
|
+
checkpointCount = 0;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
35
|
+
if (this.config.enabled) {
|
|
36
|
+
try {
|
|
37
|
+
mkdirSync(this.config.checkpointDir, { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Directory creation may fail
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Save a checkpoint at a key execution point.
|
|
46
|
+
* Respects minInterval to avoid excessive I/O.
|
|
47
|
+
*/
|
|
48
|
+
save(checkpoint) {
|
|
49
|
+
if (!this.config.enabled)
|
|
50
|
+
return null;
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
if (now - this.lastCheckpointTime < this.config.minInterval) {
|
|
53
|
+
return null; // Too soon since last checkpoint
|
|
54
|
+
}
|
|
55
|
+
const id = `ckpt-${now}-${Math.random().toString(36).slice(2, 6)}`;
|
|
56
|
+
const fullCheckpoint = {
|
|
57
|
+
...checkpoint,
|
|
58
|
+
id,
|
|
59
|
+
timestamp: now,
|
|
60
|
+
};
|
|
61
|
+
try {
|
|
62
|
+
const sessionDir = join(this.config.checkpointDir, checkpoint.sessionId);
|
|
63
|
+
mkdirSync(sessionDir, { recursive: true });
|
|
64
|
+
const filePath = join(sessionDir, `${id}.json`);
|
|
65
|
+
// Don't persist full messages array to save space - just metadata
|
|
66
|
+
const persistable = {
|
|
67
|
+
...fullCheckpoint,
|
|
68
|
+
messages: undefined, // Strip messages to keep checkpoints small
|
|
69
|
+
_messageCount: fullCheckpoint.messages?.length ?? 0,
|
|
70
|
+
};
|
|
71
|
+
writeFileSync(filePath, JSON.stringify(persistable, null, 2), 'utf-8');
|
|
72
|
+
this.lastCheckpointTime = now;
|
|
73
|
+
this.checkpointCount++;
|
|
74
|
+
// Cleanup old checkpoints for this session
|
|
75
|
+
this.cleanupSession(checkpoint.sessionId);
|
|
76
|
+
return id;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Load a specific checkpoint.
|
|
84
|
+
*/
|
|
85
|
+
load(sessionId, checkpointId) {
|
|
86
|
+
try {
|
|
87
|
+
const filePath = join(this.config.checkpointDir, sessionId, `${checkpointId}.json`);
|
|
88
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
89
|
+
return JSON.parse(content);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Find sessions with recent checkpoints that could be resumed.
|
|
97
|
+
*/
|
|
98
|
+
findResumeCandidates(maxAgeMs) {
|
|
99
|
+
const maxAge = maxAgeMs ?? 300000; // Default: 5 minutes
|
|
100
|
+
const now = Date.now();
|
|
101
|
+
const candidates = [];
|
|
102
|
+
try {
|
|
103
|
+
if (!existsSync(this.config.checkpointDir))
|
|
104
|
+
return [];
|
|
105
|
+
const sessions = readdirSync(this.config.checkpointDir);
|
|
106
|
+
for (const sessionId of sessions) {
|
|
107
|
+
const sessionDir = join(this.config.checkpointDir, sessionId);
|
|
108
|
+
try {
|
|
109
|
+
const stat = statSync(sessionDir);
|
|
110
|
+
if (!stat.isDirectory())
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const checkpoints = this.loadSessionCheckpoints(sessionId);
|
|
117
|
+
if (checkpoints.length === 0)
|
|
118
|
+
continue;
|
|
119
|
+
// Most recent checkpoint
|
|
120
|
+
const latest = checkpoints[checkpoints.length - 1];
|
|
121
|
+
const age = now - latest.timestamp;
|
|
122
|
+
if (age <= maxAge) {
|
|
123
|
+
candidates.push({
|
|
124
|
+
sessionId,
|
|
125
|
+
checkpoint: latest,
|
|
126
|
+
ageMs: age,
|
|
127
|
+
checkpointCount: checkpoints.length,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Directory reading may fail
|
|
134
|
+
}
|
|
135
|
+
// Sort by recency (most recent first)
|
|
136
|
+
return candidates.sort((a, b) => a.ageMs - b.ageMs);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Load all checkpoints for a session, sorted by timestamp.
|
|
140
|
+
*/
|
|
141
|
+
loadSessionCheckpoints(sessionId) {
|
|
142
|
+
const sessionDir = join(this.config.checkpointDir, sessionId);
|
|
143
|
+
const checkpoints = [];
|
|
144
|
+
try {
|
|
145
|
+
if (!existsSync(sessionDir))
|
|
146
|
+
return [];
|
|
147
|
+
const files = readdirSync(sessionDir).filter(f => f.endsWith('.json'));
|
|
148
|
+
for (const file of files) {
|
|
149
|
+
try {
|
|
150
|
+
const content = readFileSync(join(sessionDir, file), 'utf-8');
|
|
151
|
+
checkpoints.push(JSON.parse(content));
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Skip malformed checkpoints
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
return checkpoints.sort((a, b) => a.timestamp - b.timestamp);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get a summary of a checkpoint for display.
|
|
165
|
+
*/
|
|
166
|
+
formatCheckpointSummary(checkpoint) {
|
|
167
|
+
const age = Date.now() - checkpoint.timestamp;
|
|
168
|
+
const ageStr = age < 60000
|
|
169
|
+
? `${Math.round(age / 1000)}s ago`
|
|
170
|
+
: `${Math.round(age / 60000)}m ago`;
|
|
171
|
+
const lines = [
|
|
172
|
+
`Session: ${checkpoint.sessionId}`,
|
|
173
|
+
`Checkpoint: ${checkpoint.label} (${ageStr})`,
|
|
174
|
+
`Iteration: ${checkpoint.iteration}`,
|
|
175
|
+
];
|
|
176
|
+
if (checkpoint.objective) {
|
|
177
|
+
lines.push(`Objective: ${checkpoint.objective.slice(0, 100)}`);
|
|
178
|
+
}
|
|
179
|
+
if (checkpoint.tokensUsed) {
|
|
180
|
+
lines.push(`Tokens used: ${checkpoint.tokensUsed}`);
|
|
181
|
+
}
|
|
182
|
+
if (checkpoint.filesModified && checkpoint.filesModified.length > 0) {
|
|
183
|
+
lines.push(`Files modified: ${checkpoint.filesModified.join(', ')}`);
|
|
184
|
+
}
|
|
185
|
+
return lines.join('\n');
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Clean up old checkpoints globally.
|
|
189
|
+
*/
|
|
190
|
+
cleanupAll() {
|
|
191
|
+
let cleaned = 0;
|
|
192
|
+
const now = Date.now();
|
|
193
|
+
try {
|
|
194
|
+
if (!existsSync(this.config.checkpointDir))
|
|
195
|
+
return 0;
|
|
196
|
+
const sessions = readdirSync(this.config.checkpointDir);
|
|
197
|
+
for (const sessionId of sessions) {
|
|
198
|
+
const sessionDir = join(this.config.checkpointDir, sessionId);
|
|
199
|
+
try {
|
|
200
|
+
const stat = statSync(sessionDir);
|
|
201
|
+
if (!stat.isDirectory())
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const checkpoints = this.loadSessionCheckpoints(sessionId);
|
|
208
|
+
for (const ckpt of checkpoints) {
|
|
209
|
+
if (now - ckpt.timestamp > this.config.maxAge) {
|
|
210
|
+
try {
|
|
211
|
+
unlinkSync(join(sessionDir, `${ckpt.id}.json`));
|
|
212
|
+
cleaned++;
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
// Deletion may fail
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
// Directory operations may fail
|
|
223
|
+
}
|
|
224
|
+
return cleaned;
|
|
225
|
+
}
|
|
226
|
+
// ===========================================================================
|
|
227
|
+
// INTERNAL
|
|
228
|
+
// ===========================================================================
|
|
229
|
+
cleanupSession(sessionId) {
|
|
230
|
+
const checkpoints = this.loadSessionCheckpoints(sessionId);
|
|
231
|
+
if (checkpoints.length > this.config.maxCheckpointsPerSession) {
|
|
232
|
+
// Remove oldest checkpoints
|
|
233
|
+
const toRemove = checkpoints.slice(0, checkpoints.length - this.config.maxCheckpointsPerSession);
|
|
234
|
+
const sessionDir = join(this.config.checkpointDir, sessionId);
|
|
235
|
+
for (const ckpt of toRemove) {
|
|
236
|
+
try {
|
|
237
|
+
unlinkSync(join(sessionDir, `${ckpt.id}.json`));
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
// Deletion may fail
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Create an auto-checkpoint manager.
|
|
248
|
+
*/
|
|
249
|
+
export function createAutoCheckpointManager(config) {
|
|
250
|
+
return new AutoCheckpointManager(config);
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=auto-checkpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-checkpoint.js","sourceRoot":"","sources":["../../../src/integrations/auto-checkpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAyDjC,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,MAAM,cAAc,GAAyB;IAC3C,aAAa,EAAE,oBAAoB;IACnC,wBAAwB,EAAE,EAAE;IAC5B,MAAM,EAAE,OAAO,EAAE,SAAS;IAC1B,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,KAAK,EAAE,aAAa;CAClC,CAAC;AAEF,gFAAgF;AAChF,0BAA0B;AAC1B,gFAAgF;AAEhF,MAAM,OAAO,qBAAqB;IACxB,MAAM,CAAuB;IAC7B,kBAAkB,GAAG,CAAC,CAAC;IACvB,eAAe,GAAG,CAAC,CAAC;IAE5B,YAAY,MAAsC;QAChD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;QAE/C,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC;gBACH,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,SAAS,E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AG,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;4BAChD,OAAO,EAAE,CAAC;wBACZ,CAAC;wBAAC,MAAM,CAAC;4BACP,oBAAoB;wBACtB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,gCAAgC;QAClC,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,8EAA8E;IAC9E,WAAW;IACX,8EAA8E;IAEtE,cAAc,CAAC,SAAiB;QACtC,MAAM,WAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAE3D,IAAI,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,wBAAwB,EAAE,CAAC;YAC9D,4BAA4B;YAC5B,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;YACjG,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;YAE9D,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC5B,IAAI,CAAC;oBACH,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;gBAClD,CAAC;gBAAC,MAAM,CAAC;oBACP,oBAAoB;gBACtB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,MAAsC;IAEtC,OAAO,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complexity Classifier
|
|
3
|
+
*
|
|
4
|
+
* Heuristic-based task complexity assessment that determines
|
|
5
|
+
* the appropriate execution strategy (agent count, tool budget,
|
|
6
|
+
* swarm mode) without requiring an LLM call.
|
|
7
|
+
*
|
|
8
|
+
* Inspired by Anthropic's multi-agent research system's approach
|
|
9
|
+
* to scaling effort based on task complexity.
|
|
10
|
+
*/
|
|
11
|
+
export type ComplexityTier = 'simple' | 'medium' | 'complex' | 'deep_research';
|
|
12
|
+
export interface ComplexityAssessment {
|
|
13
|
+
/** Classified complexity tier */
|
|
14
|
+
tier: ComplexityTier;
|
|
15
|
+
/** Confidence in the classification (0-1) */
|
|
16
|
+
confidence: number;
|
|
17
|
+
/** Human-readable reasoning */
|
|
18
|
+
reasoning: string;
|
|
19
|
+
/** Recommended execution parameters */
|
|
20
|
+
recommendation: ExecutionRecommendation;
|
|
21
|
+
/** Signals that contributed to the classification */
|
|
22
|
+
signals: ComplexitySignal[];
|
|
23
|
+
}
|
|
24
|
+
export interface ExecutionRecommendation {
|
|
25
|
+
/** Number of agents to use */
|
|
26
|
+
agentCount: {
|
|
27
|
+
min: number;
|
|
28
|
+
max: number;
|
|
29
|
+
};
|
|
30
|
+
/** Tool calls per agent */
|
|
31
|
+
toolCallsPerAgent: {
|
|
32
|
+
min: number;
|
|
33
|
+
max: number;
|
|
34
|
+
};
|
|
35
|
+
/** Whether to use swarm mode */
|
|
36
|
+
useSwarmMode: boolean;
|
|
37
|
+
/** Suggested agent types */
|
|
38
|
+
suggestedAgents: string[];
|
|
39
|
+
/** Budget multiplier relative to standard */
|
|
40
|
+
budgetMultiplier: number;
|
|
41
|
+
/** Whether extended thinking is recommended */
|
|
42
|
+
useExtendedThinking: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface ComplexitySignal {
|
|
45
|
+
name: string;
|
|
46
|
+
value: number;
|
|
47
|
+
weight: number;
|
|
48
|
+
description: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ClassificationContext {
|
|
51
|
+
/** Number of files in the project */
|
|
52
|
+
projectFileCount?: number;
|
|
53
|
+
/** Whether the task references specific files */
|
|
54
|
+
referencesFiles?: boolean;
|
|
55
|
+
/** Previous task in the session (for context) */
|
|
56
|
+
previousTask?: string;
|
|
57
|
+
/** Currently active plan */
|
|
58
|
+
hasActivePlan?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Classify task complexity using heuristic signals.
|
|
62
|
+
* No LLM call needed — fast and deterministic.
|
|
63
|
+
*/
|
|
64
|
+
export declare function classifyComplexity(task: string, context?: ClassificationContext): ComplexityAssessment;
|
|
65
|
+
/**
|
|
66
|
+
* Generate scaling guidance for injection into the agent's system prompt.
|
|
67
|
+
* This follows Anthropic's pattern of embedding scaling rules directly in prompts.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getScalingGuidance(assessment: ComplexityAssessment): string;
|
|
70
|
+
/**
|
|
71
|
+
* Create a complexity classifier with custom thresholds.
|
|
72
|
+
*/
|
|
73
|
+
export declare function createComplexityClassifier(config?: {
|
|
74
|
+
simpleThreshold?: number;
|
|
75
|
+
mediumThreshold?: number;
|
|
76
|
+
complexThreshold?: number;
|
|
77
|
+
}): {
|
|
78
|
+
classify: (task: string, context?: ClassificationContext) => ComplexityAssessment;
|
|
79
|
+
getScalingGuidance: typeof getScalingGuidance;
|
|
80
|
+
thresholds: {
|
|
81
|
+
simple: number;
|
|
82
|
+
medium: number;
|
|
83
|
+
complex: number;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=complexity-classifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complexity-classifier.d.ts","sourceRoot":"","sources":["../../../src/integrations/complexity-classifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,eAAe,CAAC;AAE/E,MAAM,WAAW,oBAAoB;IACnC,iCAAiC;IACjC,IAAI,EAAE,cAAc,CAAC;IACrB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;I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