clearctx 3.0.0
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 +71 -0
- package/LICENSE +21 -0
- package/README.md +1006 -0
- package/STRATEGY.md +485 -0
- package/bin/cli.js +1756 -0
- package/bin/continuity-hook.js +118 -0
- package/bin/mcp.js +27 -0
- package/bin/setup.js +929 -0
- package/package.json +56 -0
- package/src/artifact-store.js +710 -0
- package/src/atomic-io.js +99 -0
- package/src/briefing-generator.js +451 -0
- package/src/continuity-hooks.js +253 -0
- package/src/contract-store.js +525 -0
- package/src/decision-journal.js +229 -0
- package/src/delegate.js +348 -0
- package/src/dependency-resolver.js +453 -0
- package/src/diff-engine.js +473 -0
- package/src/file-lock.js +161 -0
- package/src/index.js +61 -0
- package/src/lineage-graph.js +402 -0
- package/src/manager.js +510 -0
- package/src/mcp-server.js +3501 -0
- package/src/pattern-registry.js +221 -0
- package/src/pipeline-engine.js +618 -0
- package/src/prompts.js +1217 -0
- package/src/safety-net.js +170 -0
- package/src/session-snapshot.js +508 -0
- package/src/snapshot-engine.js +490 -0
- package/src/stale-detector.js +169 -0
- package/src/store.js +131 -0
- package/src/stream-session.js +463 -0
- package/src/team-hub.js +615 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* continuity-hook.js — Entry point for Claude Code lifecycle hooks.
|
|
6
|
+
*
|
|
7
|
+
* Claude Code hooks call this script with the event type as the first argument.
|
|
8
|
+
* Hook JSON is passed on stdin.
|
|
9
|
+
*
|
|
10
|
+
* Usage (called by Claude Code, not by users):
|
|
11
|
+
* node continuity-hook.js SessionStart < {hook JSON on stdin}
|
|
12
|
+
* node continuity-hook.js Stop < {hook JSON on stdin}
|
|
13
|
+
* node continuity-hook.js PreCompact < {hook JSON on stdin}
|
|
14
|
+
* node continuity-hook.js SessionEnd < {hook JSON on stdin}
|
|
15
|
+
*
|
|
16
|
+
* The script reads all stdin, parses it as JSON, extracts working_directory
|
|
17
|
+
* and session_id, then calls the appropriate handler from continuity-hooks.js.
|
|
18
|
+
*
|
|
19
|
+
* On SessionStart and PreCompact, the handler can return a JSON object with
|
|
20
|
+
* { additionalContext: "string" } which gets injected into Claude's conversation.
|
|
21
|
+
*
|
|
22
|
+
* On Stop and SessionEnd, there is no return value needed (async hooks).
|
|
23
|
+
*
|
|
24
|
+
* CRITICAL: This script must NEVER crash or throw unhandled errors.
|
|
25
|
+
* A crashing hook blocks Claude Code. Wrap everything in try/catch.
|
|
26
|
+
* On any error, log to stderr and exit 0 (success) so Claude Code continues.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// Top-level try/catch to ensure we NEVER crash
|
|
30
|
+
try {
|
|
31
|
+
// Get the event type from the first CLI argument
|
|
32
|
+
const eventType = process.argv[2];
|
|
33
|
+
|
|
34
|
+
// If no event type provided, exit silently
|
|
35
|
+
if (!eventType) {
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Read all of stdin (it's a single JSON blob, not streaming)
|
|
40
|
+
let stdinData = '';
|
|
41
|
+
const chunks = [];
|
|
42
|
+
|
|
43
|
+
process.stdin.setEncoding('utf8');
|
|
44
|
+
process.stdin.on('data', (chunk) => {
|
|
45
|
+
chunks.push(chunk);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
process.stdin.on('end', () => {
|
|
49
|
+
try {
|
|
50
|
+
stdinData = chunks.join('');
|
|
51
|
+
|
|
52
|
+
// Parse the JSON input from Claude Code
|
|
53
|
+
let input = {};
|
|
54
|
+
if (stdinData.trim()) {
|
|
55
|
+
input = JSON.parse(stdinData);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// For Stop events, check the stop_hook_active flag to prevent infinite loops
|
|
59
|
+
if (eventType === 'Stop' && input.stop_hook_active) {
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Load the handler module
|
|
64
|
+
const handlers = require('../src/continuity-hooks');
|
|
65
|
+
|
|
66
|
+
// Map event types to handler functions
|
|
67
|
+
const handlerMap = {
|
|
68
|
+
'SessionStart': handlers.handleSessionStart,
|
|
69
|
+
'Stop': handlers.handleStop,
|
|
70
|
+
'PreCompact': handlers.handlePreCompact,
|
|
71
|
+
'SessionEnd': handlers.handleSessionEnd
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Find the handler for this event type
|
|
75
|
+
const handler = handlerMap[eventType];
|
|
76
|
+
if (!handler) {
|
|
77
|
+
// Unknown event type — exit silently
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Call the handler with the parsed input
|
|
82
|
+
const result = handler(input);
|
|
83
|
+
|
|
84
|
+
// If the handler returned additionalContext, write it to stdout
|
|
85
|
+
// so Claude Code can inject it into the conversation
|
|
86
|
+
if (result && result.additionalContext) {
|
|
87
|
+
const output = JSON.stringify({
|
|
88
|
+
hookSpecificOutput: {
|
|
89
|
+
additionalContext: result.additionalContext
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
process.stdout.write(output);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
process.exit(0);
|
|
96
|
+
|
|
97
|
+
} catch (err) {
|
|
98
|
+
// Log the error to stderr so it shows in debug logs but doesn't crash Claude Code
|
|
99
|
+
console.error('[continuity-hook] Error:', err.message);
|
|
100
|
+
process.exit(0); // Always exit 0 — never block Claude Code
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Handle stdin errors gracefully
|
|
105
|
+
process.stdin.on('error', () => {
|
|
106
|
+
process.exit(0);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// If stdin is already closed (piped empty), trigger 'end' manually
|
|
110
|
+
if (process.stdin.isTTY) {
|
|
111
|
+
process.stdin.emit('end');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
} catch (err) {
|
|
115
|
+
// Outermost catch — if even requiring modules fails, exit cleanly
|
|
116
|
+
console.error('[continuity-hook] Fatal:', err.message);
|
|
117
|
+
process.exit(0);
|
|
118
|
+
}
|
package/bin/mcp.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* clearctx MCP Server entry point.
|
|
5
|
+
*
|
|
6
|
+
* This starts the MCP (Model Context Protocol) server that exposes
|
|
7
|
+
* multi-session tools to Claude Code as native tools.
|
|
8
|
+
*
|
|
9
|
+
* Claude Code connects to this server via stdio. Once connected,
|
|
10
|
+
* tools like spawn_session, send_message, delegate_task appear
|
|
11
|
+
* in Claude's tool list — just like Read, Edit, Grep, etc.
|
|
12
|
+
*
|
|
13
|
+
* Usage (in Claude Code MCP config):
|
|
14
|
+
* {
|
|
15
|
+
* "mcpServers": {
|
|
16
|
+
* "multi-session": {
|
|
17
|
+
* "command": "ctx-mcp"
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* Or run directly:
|
|
23
|
+
* node bin/mcp.js
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const { startServer } = require('../src/mcp-server');
|
|
27
|
+
startServer();
|