247-cli 2.23.2 → 2.23.4
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/agent/dist/db/index.d.ts +0 -1
- package/agent/dist/db/index.d.ts.map +1 -1
- package/agent/dist/db/index.js +85 -382
- package/agent/dist/db/index.js.map +1 -1
- package/agent/dist/db/schema.d.ts +3 -49
- package/agent/dist/db/schema.d.ts.map +1 -1
- package/agent/dist/db/schema.js +34 -44
- package/agent/dist/db/schema.js.map +1 -1
- package/agent/dist/db/sessions.d.ts +2 -52
- package/agent/dist/db/sessions.d.ts.map +1 -1
- package/agent/dist/db/sessions.js +8 -194
- package/agent/dist/db/sessions.js.map +1 -1
- package/agent/dist/routes/index.d.ts +0 -1
- package/agent/dist/routes/index.d.ts.map +1 -1
- package/agent/dist/routes/index.js +0 -1
- package/agent/dist/routes/index.js.map +1 -1
- package/agent/dist/routes/sessions.d.ts +1 -0
- package/agent/dist/routes/sessions.d.ts.map +1 -1
- package/agent/dist/routes/sessions.js +16 -375
- package/agent/dist/routes/sessions.js.map +1 -1
- package/agent/dist/server.d.ts.map +1 -1
- package/agent/dist/server.js +22 -17
- package/agent/dist/server.js.map +1 -1
- package/agent/dist/services/index.d.ts +1 -6
- package/agent/dist/services/index.d.ts.map +1 -1
- package/agent/dist/services/index.js +4 -4
- package/agent/dist/services/index.js.map +1 -1
- package/agent/dist/terminal.d.ts +0 -11
- package/agent/dist/terminal.d.ts.map +1 -1
- package/agent/dist/terminal.js +6 -60
- package/agent/dist/terminal.js.map +1 -1
- package/agent/dist/updater.d.ts +1 -2
- package/agent/dist/updater.d.ts.map +1 -1
- package/agent/dist/updater.js +3 -25
- package/agent/dist/updater.js.map +1 -1
- package/agent/dist/websocket-handlers.d.ts +17 -3
- package/agent/dist/websocket-handlers.d.ts.map +1 -1
- package/agent/dist/websocket-handlers.js +81 -127
- package/agent/dist/websocket-handlers.js.map +1 -1
- package/agent/node_modules/247-shared/dist/types/index.d.ts +1 -111
- package/agent/node_modules/247-shared/dist/types/index.d.ts.map +1 -1
- package/agent/node_modules/247-shared/dist/types/index.js +1 -47
- package/agent/node_modules/247-shared/dist/types/index.js.map +1 -1
- package/agent/node_modules/247-shared/package.json +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +5 -23
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +0 -11
- package/dist/commands/status.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/paths.d.ts +1 -3
- package/dist/lib/paths.d.ts.map +1 -1
- package/dist/lib/paths.js +1 -2
- package/dist/lib/paths.js.map +1 -1
- package/package.json +1 -1
- package/agent/dist/db/history.d.ts +0 -37
- package/agent/dist/db/history.d.ts.map +0 -1
- package/agent/dist/db/history.js +0 -98
- package/agent/dist/db/history.js.map +0 -1
- package/agent/dist/routes/attention.d.ts +0 -10
- package/agent/dist/routes/attention.d.ts.map +0 -1
- package/agent/dist/routes/attention.js +0 -123
- package/agent/dist/routes/attention.js.map +0 -1
- package/agent/dist/services/cleanup.d.ts +0 -45
- package/agent/dist/services/cleanup.d.ts.map +0 -1
- package/agent/dist/services/cleanup.js +0 -130
- package/agent/dist/services/cleanup.js.map +0 -1
- package/agent/dist/services/execution.d.ts +0 -53
- package/agent/dist/services/execution.d.ts.map +0 -1
- package/agent/dist/services/execution.js +0 -75
- package/agent/dist/services/execution.js.map +0 -1
- package/agent/dist/services/worktree.d.ts +0 -41
- package/agent/dist/services/worktree.d.ts.map +0 -1
- package/agent/dist/services/worktree.js +0 -139
- package/agent/dist/services/worktree.js.map +0 -1
- package/agent/dist/setup-hooks.d.ts +0 -10
- package/agent/dist/setup-hooks.d.ts.map +0 -1
- package/agent/dist/setup-hooks.js +0 -157
- package/agent/dist/setup-hooks.js.map +0 -1
- package/agent/dist/status.d.ts +0 -51
- package/agent/dist/status.d.ts.map +0 -1
- package/agent/dist/status.js +0 -142
- package/agent/dist/status.js.map +0 -1
- package/dist/commands/hooks.d.ts +0 -3
- package/dist/commands/hooks.d.ts.map +0 -1
- package/dist/commands/hooks.js +0 -85
- package/dist/commands/hooks.js.map +0 -1
- package/dist/hooks/installer.d.ts +0 -21
- package/dist/hooks/installer.d.ts.map +0 -1
- package/dist/hooks/installer.js +0 -114
- package/dist/hooks/installer.js.map +0 -1
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { getCleanableWorktreeSessions, clearSessionWorktree } from '../db/sessions.js';
|
|
2
|
-
import { worktreeManager } from './worktree.js';
|
|
3
|
-
// Default: 72 hours before cleaning up archived session worktrees
|
|
4
|
-
const DEFAULT_MAX_IDLE_MS = 72 * 60 * 60 * 1000;
|
|
5
|
-
// Default: run cleanup every 30 minutes
|
|
6
|
-
const DEFAULT_CLEANUP_INTERVAL_MS = 30 * 60 * 1000;
|
|
7
|
-
/**
|
|
8
|
-
* CleanupService - Automatically cleans up stale worktrees.
|
|
9
|
-
* Runs periodically to remove worktrees from archived sessions.
|
|
10
|
-
*/
|
|
11
|
-
export class CleanupService {
|
|
12
|
-
intervalHandle = null;
|
|
13
|
-
config;
|
|
14
|
-
projectPathResolver;
|
|
15
|
-
constructor(projectPathResolver, config = {}) {
|
|
16
|
-
this.projectPathResolver = projectPathResolver;
|
|
17
|
-
this.config = {
|
|
18
|
-
maxIdleMs: config.maxIdleMs ?? DEFAULT_MAX_IDLE_MS,
|
|
19
|
-
intervalMs: config.intervalMs ?? DEFAULT_CLEANUP_INTERVAL_MS,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Start the cleanup job.
|
|
24
|
-
*/
|
|
25
|
-
start() {
|
|
26
|
-
if (this.intervalHandle) {
|
|
27
|
-
console.log('[Cleanup] Already running');
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
console.log(`[Cleanup] Starting cleanup job (interval: ${this.config.intervalMs / 1000 / 60}min, max idle: ${this.config.maxIdleMs / 1000 / 60 / 60}h)`);
|
|
31
|
-
// Run immediately on start
|
|
32
|
-
this.runCleanup().catch((err) => {
|
|
33
|
-
console.error('[Cleanup] Initial cleanup failed:', err);
|
|
34
|
-
});
|
|
35
|
-
// Then run periodically
|
|
36
|
-
this.intervalHandle = setInterval(() => {
|
|
37
|
-
this.runCleanup().catch((err) => {
|
|
38
|
-
console.error('[Cleanup] Periodic cleanup failed:', err);
|
|
39
|
-
});
|
|
40
|
-
}, this.config.intervalMs);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Stop the cleanup job.
|
|
44
|
-
*/
|
|
45
|
-
stop() {
|
|
46
|
-
if (this.intervalHandle) {
|
|
47
|
-
clearInterval(this.intervalHandle);
|
|
48
|
-
this.intervalHandle = null;
|
|
49
|
-
console.log('[Cleanup] Stopped cleanup job');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Run a cleanup cycle.
|
|
54
|
-
* Returns info about what was cleaned up.
|
|
55
|
-
*/
|
|
56
|
-
async runCleanup() {
|
|
57
|
-
const result = {
|
|
58
|
-
cleanedSessions: [],
|
|
59
|
-
errors: [],
|
|
60
|
-
};
|
|
61
|
-
try {
|
|
62
|
-
// Get archived sessions with worktrees that are old enough to clean
|
|
63
|
-
const sessions = getCleanableWorktreeSessions(this.config.maxIdleMs);
|
|
64
|
-
if (sessions.length === 0) {
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
console.log(`[Cleanup] Found ${sessions.length} sessions to clean up`);
|
|
68
|
-
for (const session of sessions) {
|
|
69
|
-
if (!session.worktree_path)
|
|
70
|
-
continue;
|
|
71
|
-
try {
|
|
72
|
-
const projectPath = this.projectPathResolver(session.project);
|
|
73
|
-
// Remove the worktree
|
|
74
|
-
const removed = await worktreeManager.remove(projectPath, session.worktree_path);
|
|
75
|
-
if (removed) {
|
|
76
|
-
// Clear worktree info in DB
|
|
77
|
-
clearSessionWorktree(session.name);
|
|
78
|
-
result.cleanedSessions.push(session.name);
|
|
79
|
-
console.log(`[Cleanup] Cleaned up worktree for session ${session.name}`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
84
|
-
result.errors.push({ session: session.name, error: errorMsg });
|
|
85
|
-
console.error(`[Cleanup] Failed to clean up session ${session.name}:`, error);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (result.cleanedSessions.length > 0) {
|
|
89
|
-
console.log(`[Cleanup] Cleaned up ${result.cleanedSessions.length} worktrees`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
console.error('[Cleanup] Error during cleanup:', error);
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Check if cleanup job is running.
|
|
99
|
-
*/
|
|
100
|
-
isRunning() {
|
|
101
|
-
return this.intervalHandle !== null;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Update cleanup configuration.
|
|
105
|
-
*/
|
|
106
|
-
updateConfig(config) {
|
|
107
|
-
if (config.maxIdleMs !== undefined) {
|
|
108
|
-
this.config.maxIdleMs = config.maxIdleMs;
|
|
109
|
-
}
|
|
110
|
-
if (config.intervalMs !== undefined) {
|
|
111
|
-
this.config.intervalMs = config.intervalMs;
|
|
112
|
-
// Restart with new interval if running
|
|
113
|
-
if (this.isRunning()) {
|
|
114
|
-
this.stop();
|
|
115
|
-
this.start();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// Factory function to create cleanup service
|
|
121
|
-
// Needs to be initialized with project path resolver
|
|
122
|
-
let cleanupService = null;
|
|
123
|
-
export function initCleanupService(projectPathResolver, config) {
|
|
124
|
-
cleanupService = new CleanupService(projectPathResolver, config);
|
|
125
|
-
return cleanupService;
|
|
126
|
-
}
|
|
127
|
-
export function getCleanupService() {
|
|
128
|
-
return cleanupService;
|
|
129
|
-
}
|
|
130
|
-
//# sourceMappingURL=cleanup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../src/services/cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,kEAAkE;AAClE,MAAM,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAChD,wCAAwC;AACxC,MAAM,2BAA2B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAYnD;;;GAGG;AACH,MAAM,OAAO,cAAc;IACjB,cAAc,GAA0C,IAAI,CAAC;IAC7D,MAAM,CAAgB;IACtB,mBAAmB,CAA8B;IAEzD,YACE,mBAAgD,EAChD,SAAiC,EAAE;QAEnC,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG;YACZ,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,mBAAmB;YAClD,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,2BAA2B;SAC7D,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;YACzC,OAAO;QACT,CAAC;QAED,OAAO,CAAC,GAAG,CACT,6CAA6C,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,kBAAkB,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,IAAI,CAC5I,CAAC;QAEF,2BAA2B;QAC3B,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK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Y,CAAC,MAA8B;QACzC,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAC3C,CAAC;QACD,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;YAC3C,uCAAuC;YACvC,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;gBACrB,IAAI,CAAC,IAAI,EAAE,CAAC;gBACZ,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,6CAA6C;AAC7C,qDAAqD;AACrD,IAAI,cAAc,GAA0B,IAAI,CAAC;AAEjD,MAAM,UAAU,kBAAkB,CAChC,mBAAgD,EAChD,MAA+B;IAE/B,cAAc,GAAG,IAAI,cAAc,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IACjE,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ExecutionManager - Manages parallel session execution limits.
|
|
3
|
-
* Limits the number of concurrent Claude sessions to prevent resource exhaustion.
|
|
4
|
-
*/
|
|
5
|
-
export interface SessionInfo {
|
|
6
|
-
project: string;
|
|
7
|
-
worktreePath: string | null;
|
|
8
|
-
startedAt: number;
|
|
9
|
-
}
|
|
10
|
-
export interface CapacityInfo {
|
|
11
|
-
max: number;
|
|
12
|
-
running: number;
|
|
13
|
-
available: number;
|
|
14
|
-
}
|
|
15
|
-
export declare class ExecutionManager {
|
|
16
|
-
private maxParallel;
|
|
17
|
-
private running;
|
|
18
|
-
constructor(maxParallel?: number);
|
|
19
|
-
/**
|
|
20
|
-
* Check if a new session can be started.
|
|
21
|
-
*/
|
|
22
|
-
canStart(): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Register a running session.
|
|
25
|
-
*/
|
|
26
|
-
register(sessionName: string, project: string, worktreePath: string | null): void;
|
|
27
|
-
/**
|
|
28
|
-
* Unregister a session when it stops.
|
|
29
|
-
*/
|
|
30
|
-
unregister(sessionName: string): void;
|
|
31
|
-
/**
|
|
32
|
-
* Get current capacity information.
|
|
33
|
-
*/
|
|
34
|
-
getCapacity(): CapacityInfo;
|
|
35
|
-
/**
|
|
36
|
-
* Get information about a specific running session.
|
|
37
|
-
*/
|
|
38
|
-
getSession(sessionName: string): SessionInfo | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* Get all running sessions.
|
|
41
|
-
*/
|
|
42
|
-
getRunningSessions(): Map<string, SessionInfo>;
|
|
43
|
-
/**
|
|
44
|
-
* Check if a specific session is running.
|
|
45
|
-
*/
|
|
46
|
-
isRunning(sessionName: string): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Update the maximum parallel sessions limit.
|
|
49
|
-
*/
|
|
50
|
-
setMaxParallel(max: number): void;
|
|
51
|
-
}
|
|
52
|
-
export declare const executionManager: ExecutionManager;
|
|
53
|
-
//# sourceMappingURL=execution.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/services/execution.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAA2B;gBAE9B,WAAW,GAAE,MAAU;IAKnC;;OAEG;IACH,QAAQ,IAAI,OAAO;IAInB;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAWjF;;OAEG;IACH,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAQrC;;OAEG;IACH,WAAW,IAAI,YAAY;IAQ3B;;OAEG;IACH,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAIxD;;OAEG;IACH,kBAAkB,IAAI,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC;IAI9C;;OAEG;IACH,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAIvC;;OAEG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAIlC;AAGD,eAAO,MAAM,gBAAgB,kBAA0B,CAAC"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ExecutionManager - Manages parallel session execution limits.
|
|
3
|
-
* Limits the number of concurrent Claude sessions to prevent resource exhaustion.
|
|
4
|
-
*/
|
|
5
|
-
export class ExecutionManager {
|
|
6
|
-
maxParallel;
|
|
7
|
-
running;
|
|
8
|
-
constructor(maxParallel = 3) {
|
|
9
|
-
this.maxParallel = maxParallel;
|
|
10
|
-
this.running = new Map();
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Check if a new session can be started.
|
|
14
|
-
*/
|
|
15
|
-
canStart() {
|
|
16
|
-
return this.running.size < this.maxParallel;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Register a running session.
|
|
20
|
-
*/
|
|
21
|
-
register(sessionName, project, worktreePath) {
|
|
22
|
-
this.running.set(sessionName, {
|
|
23
|
-
project,
|
|
24
|
-
worktreePath,
|
|
25
|
-
startedAt: Date.now(),
|
|
26
|
-
});
|
|
27
|
-
console.log(`[Execution] Registered session ${sessionName} (${this.running.size}/${this.maxParallel})`);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Unregister a session when it stops.
|
|
31
|
-
*/
|
|
32
|
-
unregister(sessionName) {
|
|
33
|
-
if (this.running.delete(sessionName)) {
|
|
34
|
-
console.log(`[Execution] Unregistered session ${sessionName} (${this.running.size}/${this.maxParallel})`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Get current capacity information.
|
|
39
|
-
*/
|
|
40
|
-
getCapacity() {
|
|
41
|
-
return {
|
|
42
|
-
max: this.maxParallel,
|
|
43
|
-
running: this.running.size,
|
|
44
|
-
available: this.maxParallel - this.running.size,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Get information about a specific running session.
|
|
49
|
-
*/
|
|
50
|
-
getSession(sessionName) {
|
|
51
|
-
return this.running.get(sessionName);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Get all running sessions.
|
|
55
|
-
*/
|
|
56
|
-
getRunningSessions() {
|
|
57
|
-
return new Map(this.running);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Check if a specific session is running.
|
|
61
|
-
*/
|
|
62
|
-
isRunning(sessionName) {
|
|
63
|
-
return this.running.has(sessionName);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Update the maximum parallel sessions limit.
|
|
67
|
-
*/
|
|
68
|
-
setMaxParallel(max) {
|
|
69
|
-
this.maxParallel = max;
|
|
70
|
-
console.log(`[Execution] Max parallel sessions set to ${max}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Singleton instance with default max of 3
|
|
74
|
-
export const executionManager = new ExecutionManager(3);
|
|
75
|
-
//# sourceMappingURL=execution.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/services/execution.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH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EG;IACH,kBAAkB;QAChB,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,WAAmB;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,GAAW;QACxB,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,4CAA4C,GAAG,EAAE,CAAC,CAAC;IACjE,CAAC;CACF;AAED,2CAA2C;AAC3C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export interface WorktreeInfo {
|
|
2
|
-
worktreePath: string;
|
|
3
|
-
branch: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Manages Git worktrees for session isolation.
|
|
7
|
-
* Each session gets its own worktree with a dedicated branch.
|
|
8
|
-
*/
|
|
9
|
-
export declare class WorktreeManager {
|
|
10
|
-
private basePath;
|
|
11
|
-
constructor(basePath?: string);
|
|
12
|
-
/**
|
|
13
|
-
* Create a new worktree for a session.
|
|
14
|
-
* If branchName is not provided, creates a branch named `session/<sessionName>`.
|
|
15
|
-
*/
|
|
16
|
-
create(projectPath: string, sessionName: string, branchName?: string): Promise<WorktreeInfo>;
|
|
17
|
-
/**
|
|
18
|
-
* Remove a worktree.
|
|
19
|
-
* Uses --force to remove even if there are uncommitted changes.
|
|
20
|
-
*/
|
|
21
|
-
remove(projectPath: string, worktreePath: string): Promise<boolean>;
|
|
22
|
-
/**
|
|
23
|
-
* List all worktrees for a project.
|
|
24
|
-
*/
|
|
25
|
-
list(projectPath: string): Promise<string[]>;
|
|
26
|
-
/**
|
|
27
|
-
* Check if a worktree exists for a session.
|
|
28
|
-
*/
|
|
29
|
-
exists(sessionName: string): Promise<boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* Get the worktree path for a session.
|
|
32
|
-
*/
|
|
33
|
-
getPath(sessionName: string): string;
|
|
34
|
-
/**
|
|
35
|
-
* Copy Claude configuration files (CLAUDE.md, .claude/) from source to destination.
|
|
36
|
-
* These files contain project-specific context that Claude needs.
|
|
37
|
-
*/
|
|
38
|
-
private copyClaudeConfig;
|
|
39
|
-
}
|
|
40
|
-
export declare const worktreeManager: WorktreeManager;
|
|
41
|
-
//# sourceMappingURL=worktree.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worktree.d.ts","sourceRoot":"","sources":["../../src/services/worktree.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAS;gBAEb,QAAQ,GAAE,MAAuB;IAI7C;;;OAGG;IACG,MAAM,CACV,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,YAAY,CAAC;IAwCxB;;;OAGG;IACG,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAsBzE;;OAEG;IACG,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAmBlD;;OAEG;IACG,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKnD;;OAEG;IACH,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAIpC;;;OAGG;YACW,gBAAgB;CAsB/B;AAGD,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { execa } from 'execa';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
|
-
import { mkdir, stat, copyFile, cp } from 'fs/promises';
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
const WORKTREES_BASE = '/tmp/247-workspaces';
|
|
6
|
-
/**
|
|
7
|
-
* Manages Git worktrees for session isolation.
|
|
8
|
-
* Each session gets its own worktree with a dedicated branch.
|
|
9
|
-
*/
|
|
10
|
-
export class WorktreeManager {
|
|
11
|
-
basePath;
|
|
12
|
-
constructor(basePath = WORKTREES_BASE) {
|
|
13
|
-
this.basePath = basePath;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Create a new worktree for a session.
|
|
17
|
-
* If branchName is not provided, creates a branch named `session/<sessionName>`.
|
|
18
|
-
*/
|
|
19
|
-
async create(projectPath, sessionName, branchName) {
|
|
20
|
-
const branch = branchName || `session/${sessionName}`;
|
|
21
|
-
const worktreePath = join(this.basePath, sessionName);
|
|
22
|
-
// Ensure base directory exists
|
|
23
|
-
await mkdir(this.basePath, { recursive: true });
|
|
24
|
-
// Check if worktree already exists
|
|
25
|
-
if (existsSync(worktreePath)) {
|
|
26
|
-
console.log(`[Worktree] Worktree already exists at ${worktreePath}`);
|
|
27
|
-
return { worktreePath, branch };
|
|
28
|
-
}
|
|
29
|
-
// Check if branch already exists
|
|
30
|
-
const { exitCode } = await execa('git', ['rev-parse', '--verify', branch], {
|
|
31
|
-
cwd: projectPath,
|
|
32
|
-
reject: false,
|
|
33
|
-
});
|
|
34
|
-
if (exitCode !== 0) {
|
|
35
|
-
// Branch doesn't exist - create new branch with worktree
|
|
36
|
-
console.log(`[Worktree] Creating new worktree with branch ${branch}`);
|
|
37
|
-
await execa('git', ['worktree', 'add', '-b', branch, worktreePath], {
|
|
38
|
-
cwd: projectPath,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
// Branch exists - create worktree on existing branch
|
|
43
|
-
console.log(`[Worktree] Creating worktree on existing branch ${branch}`);
|
|
44
|
-
await execa('git', ['worktree', 'add', worktreePath, branch], {
|
|
45
|
-
cwd: projectPath,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
// Copy Claude configuration files
|
|
49
|
-
await this.copyClaudeConfig(projectPath, worktreePath);
|
|
50
|
-
console.log(`[Worktree] Created worktree at ${worktreePath} on branch ${branch}`);
|
|
51
|
-
return { worktreePath, branch };
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Remove a worktree.
|
|
55
|
-
* Uses --force to remove even if there are uncommitted changes.
|
|
56
|
-
*/
|
|
57
|
-
async remove(projectPath, worktreePath) {
|
|
58
|
-
try {
|
|
59
|
-
// First try to prune any stale worktrees
|
|
60
|
-
await execa('git', ['worktree', 'prune'], {
|
|
61
|
-
cwd: projectPath,
|
|
62
|
-
reject: false,
|
|
63
|
-
});
|
|
64
|
-
// Then remove the specific worktree
|
|
65
|
-
await execa('git', ['worktree', 'remove', worktreePath, '--force'], {
|
|
66
|
-
cwd: projectPath,
|
|
67
|
-
reject: false,
|
|
68
|
-
});
|
|
69
|
-
console.log(`[Worktree] Removed worktree at ${worktreePath}`);
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
console.error(`[Worktree] Failed to remove worktree at ${worktreePath}:`, error);
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* List all worktrees for a project.
|
|
79
|
-
*/
|
|
80
|
-
async list(projectPath) {
|
|
81
|
-
try {
|
|
82
|
-
const { stdout } = await execa('git', ['worktree', 'list', '--porcelain'], {
|
|
83
|
-
cwd: projectPath,
|
|
84
|
-
});
|
|
85
|
-
const worktrees = [];
|
|
86
|
-
for (const line of stdout.split('\n')) {
|
|
87
|
-
if (line.startsWith('worktree ')) {
|
|
88
|
-
worktrees.push(line.replace('worktree ', ''));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return worktrees;
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
console.error(`[Worktree] Failed to list worktrees:`, error);
|
|
95
|
-
return [];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Check if a worktree exists for a session.
|
|
100
|
-
*/
|
|
101
|
-
async exists(sessionName) {
|
|
102
|
-
const worktreePath = join(this.basePath, sessionName);
|
|
103
|
-
return existsSync(worktreePath);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Get the worktree path for a session.
|
|
107
|
-
*/
|
|
108
|
-
getPath(sessionName) {
|
|
109
|
-
return join(this.basePath, sessionName);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Copy Claude configuration files (CLAUDE.md, .claude/) from source to destination.
|
|
113
|
-
* These files contain project-specific context that Claude needs.
|
|
114
|
-
*/
|
|
115
|
-
async copyClaudeConfig(src, dest) {
|
|
116
|
-
const filesToCopy = ['CLAUDE.md', '.claude'];
|
|
117
|
-
for (const file of filesToCopy) {
|
|
118
|
-
const srcPath = join(src, file);
|
|
119
|
-
const destPath = join(dest, file);
|
|
120
|
-
try {
|
|
121
|
-
const fileStat = await stat(srcPath);
|
|
122
|
-
if (fileStat.isDirectory()) {
|
|
123
|
-
await cp(srcPath, destPath, { recursive: true });
|
|
124
|
-
console.log(`[Worktree] Copied directory ${file}`);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
await copyFile(srcPath, destPath);
|
|
128
|
-
console.log(`[Worktree] Copied file ${file}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
// File doesn't exist, skip silently
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
// Singleton instance
|
|
138
|
-
export const worktreeManager = new WorktreeManager();
|
|
139
|
-
//# sourceMappingURL=worktree.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worktree.js","sourceRoot":"","sources":["../../src/services/worktree.ts"],"names":[],"mappings":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OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAElC,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;gBAErC,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;oBAC3B,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;oBACjD,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,EAAE,CAAC,CAAC;gBACrD,CAAC;qBAAM,CAAC;oBACN,MAAM,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;oBAClC,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC;gBAChD,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,oCAAoC;YACtC,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-configuration for Claude Code attention hook integration.
|
|
3
|
-
* Creates the attention script and configures Claude settings at agent startup.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Ensure attention hook is configured for 247 integration.
|
|
7
|
-
* Called at agent startup.
|
|
8
|
-
*/
|
|
9
|
-
export declare function ensureHooksConfigured(): void;
|
|
10
|
-
//# sourceMappingURL=setup-hooks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup-hooks.d.ts","sourceRoot":"","sources":["../src/setup-hooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAQ5C"}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-configuration for Claude Code attention hook integration.
|
|
3
|
-
* Creates the attention script and configures Claude settings at agent startup.
|
|
4
|
-
*/
|
|
5
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync, chmodSync } from 'fs';
|
|
6
|
-
import { homedir } from 'os';
|
|
7
|
-
import { join } from 'path';
|
|
8
|
-
const CLAUDE_SETTINGS_PATH = join(homedir(), '.claude', 'settings.json');
|
|
9
|
-
const HOOK_DIR = join(homedir(), '.247');
|
|
10
|
-
const ATTENTION_SCRIPT_PATH = join(HOOK_DIR, 'attention.sh');
|
|
11
|
-
// Patterns to detect old hooks that need cleanup
|
|
12
|
-
const OLD_HOOK_PATTERNS = [
|
|
13
|
-
/statusline\.sh/,
|
|
14
|
-
/notification\.sh/,
|
|
15
|
-
/stop\.sh/,
|
|
16
|
-
/notify-status\.sh/,
|
|
17
|
-
/packages\/hooks/,
|
|
18
|
-
];
|
|
19
|
-
/**
|
|
20
|
-
* Ensure attention hook is configured for 247 integration.
|
|
21
|
-
* Called at agent startup.
|
|
22
|
-
*/
|
|
23
|
-
export function ensureHooksConfigured() {
|
|
24
|
-
try {
|
|
25
|
-
ensureAttentionScript();
|
|
26
|
-
ensureClaudeSettings();
|
|
27
|
-
console.log('[Setup] Attention hook configured successfully');
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
console.error('[Setup] Failed to configure hooks:', err);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Create the attention.sh script that forwards Claude Code notifications to the agent.
|
|
35
|
-
* This is called when Claude needs user attention (permission, input, etc.)
|
|
36
|
-
*/
|
|
37
|
-
function ensureAttentionScript() {
|
|
38
|
-
if (!existsSync(HOOK_DIR)) {
|
|
39
|
-
mkdirSync(HOOK_DIR, { recursive: true });
|
|
40
|
-
}
|
|
41
|
-
const script = `#!/bin/bash
|
|
42
|
-
# 247 Attention Hook - forwards Claude Code attention events to agent
|
|
43
|
-
# Auto-generated by 247 agent - do not edit manually
|
|
44
|
-
|
|
45
|
-
INPUT=$(cat)
|
|
46
|
-
TMUX_SESSION="\${CLAUDE_TMUX_SESSION:-}"
|
|
47
|
-
|
|
48
|
-
# Only forward if we're in a tmux session managed by 247
|
|
49
|
-
[ -z "$TMUX_SESSION" ] && exit 0
|
|
50
|
-
|
|
51
|
-
# Forward JSON to agent (add tmux_session field)
|
|
52
|
-
echo "$INPUT" | jq --arg ts "$TMUX_SESSION" '. + {tmux_session: $ts}' | \\
|
|
53
|
-
curl -s -X POST "http://localhost:4678/api/attention" \\
|
|
54
|
-
-H "Content-Type: application/json" \\
|
|
55
|
-
-d @- > /dev/null 2>&1 &
|
|
56
|
-
|
|
57
|
-
exit 0
|
|
58
|
-
`;
|
|
59
|
-
writeFileSync(ATTENTION_SCRIPT_PATH, script);
|
|
60
|
-
chmodSync(ATTENTION_SCRIPT_PATH, 0o755);
|
|
61
|
-
console.log(`[Setup] Created attention script at ${ATTENTION_SCRIPT_PATH}`);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Remove old 247 hooks from settings.json.
|
|
65
|
-
*/
|
|
66
|
-
function cleanupOldHooks(settings) {
|
|
67
|
-
let cleaned = false;
|
|
68
|
-
// Clean statusLine if it's one of ours
|
|
69
|
-
const statusLine = settings.statusLine;
|
|
70
|
-
if (statusLine?.command && OLD_HOOK_PATTERNS.some((p) => p.test(statusLine.command || ''))) {
|
|
71
|
-
delete settings.statusLine;
|
|
72
|
-
console.log('[Setup] Removed old statusLine from settings.json');
|
|
73
|
-
cleaned = true;
|
|
74
|
-
}
|
|
75
|
-
// Clean old hooks
|
|
76
|
-
const hooks = settings.hooks;
|
|
77
|
-
if (hooks) {
|
|
78
|
-
for (const hookType of ['Notification', 'Stop', 'PreToolUse', 'PostToolUse']) {
|
|
79
|
-
const hookList = hooks[hookType];
|
|
80
|
-
if (hookList) {
|
|
81
|
-
const filtered = hookList.filter((h) => !h.hooks?.some((hook) => OLD_HOOK_PATTERNS.some((p) => p.test(hook.command || ''))));
|
|
82
|
-
if (filtered.length !== hookList.length) {
|
|
83
|
-
if (filtered.length === 0) {
|
|
84
|
-
delete hooks[hookType];
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
hooks[hookType] = filtered;
|
|
88
|
-
}
|
|
89
|
-
console.log(`[Setup] Cleaned old ${hookType} hooks from settings.json`);
|
|
90
|
-
cleaned = true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// Remove hooks object if empty
|
|
95
|
-
if (Object.keys(hooks).length === 0) {
|
|
96
|
-
delete settings.hooks;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return cleaned;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Configure Claude settings.json to use our attention hook.
|
|
103
|
-
*/
|
|
104
|
-
function ensureClaudeSettings() {
|
|
105
|
-
const claudeDir = join(homedir(), '.claude');
|
|
106
|
-
// Ensure .claude directory exists
|
|
107
|
-
if (!existsSync(claudeDir)) {
|
|
108
|
-
mkdirSync(claudeDir, { recursive: true });
|
|
109
|
-
}
|
|
110
|
-
// Read existing settings or start fresh
|
|
111
|
-
let settings = {};
|
|
112
|
-
if (existsSync(CLAUDE_SETTINGS_PATH)) {
|
|
113
|
-
try {
|
|
114
|
-
settings = JSON.parse(readFileSync(CLAUDE_SETTINGS_PATH, 'utf-8'));
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
117
|
-
console.warn('[Setup] Could not parse existing settings.json, will create new');
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// Clean up old hooks if present
|
|
121
|
-
const cleaned = cleanupOldHooks(settings);
|
|
122
|
-
const expectedAttentionCommand = `bash ${ATTENTION_SCRIPT_PATH}`;
|
|
123
|
-
// Check if Notification hook is already configured correctly
|
|
124
|
-
const currentHooks = settings.hooks;
|
|
125
|
-
const notificationHooks = currentHooks?.Notification;
|
|
126
|
-
const attentionConfigured = notificationHooks?.some((h) => h.hooks?.some((hook) => hook.command === expectedAttentionCommand));
|
|
127
|
-
if (attentionConfigured && !cleaned) {
|
|
128
|
-
console.log('[Setup] Attention hook already configured');
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
// Configure hooks
|
|
132
|
-
const hooks = (settings.hooks || {});
|
|
133
|
-
// Add our Notification hook (this fires when Claude needs attention)
|
|
134
|
-
if (!attentionConfigured) {
|
|
135
|
-
// Get existing user hooks (preserve them)
|
|
136
|
-
const existingHooks = (hooks.Notification || []);
|
|
137
|
-
// Filter out any old 247 hooks
|
|
138
|
-
const userHooks = existingHooks.filter((h) => !h.hooks?.some((hook) => hook.command?.includes('.247/')));
|
|
139
|
-
hooks.Notification = [
|
|
140
|
-
...userHooks,
|
|
141
|
-
{
|
|
142
|
-
matcher: '*',
|
|
143
|
-
hooks: [
|
|
144
|
-
{
|
|
145
|
-
type: 'command',
|
|
146
|
-
command: expectedAttentionCommand,
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
];
|
|
151
|
-
console.log('[Setup] Configured Notification hook');
|
|
152
|
-
}
|
|
153
|
-
settings.hooks = hooks;
|
|
154
|
-
writeFileSync(CLAUDE_SETTINGS_PATH, JSON.stringify(settings, null, 2));
|
|
155
|
-
console.log(`[Setup] Configured Claude settings in ${CLAUDE_SETTINGS_PATH}`);
|
|
156
|
-
}
|
|
157
|
-
//# sourceMappingURL=setup-hooks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup-hooks.js","sourceRoot":"","sources":["../src/setup-hooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B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