@tiflis-io/tiflis-code-workstation 0.3.5 → 0.3.6
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/main.js +1580 -36
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "./chunk-JSN52PLR.js";
|
|
6
6
|
|
|
7
7
|
// src/main.ts
|
|
8
|
-
import { randomUUID as
|
|
8
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
9
9
|
|
|
10
10
|
// src/app.ts
|
|
11
11
|
import Fastify from "fastify";
|
|
@@ -129,7 +129,14 @@ var EnvSchema = z.object({
|
|
|
129
129
|
/** Terminal output buffer size (number of messages, in-memory only, does not survive restarts) */
|
|
130
130
|
TERMINAL_OUTPUT_BUFFER_SIZE: z.coerce.number().default(100),
|
|
131
131
|
// Legacy (fallback for STT/TTS if specific keys not set)
|
|
132
|
-
OPENAI_API_KEY: z.string().optional()
|
|
132
|
+
OPENAI_API_KEY: z.string().optional(),
|
|
133
|
+
// ─────────────────────────────────────────────────────────────
|
|
134
|
+
// Mock Mode Configuration (for screenshot automation)
|
|
135
|
+
// ─────────────────────────────────────────────────────────────
|
|
136
|
+
/** Enable mock mode for screenshot automation tests */
|
|
137
|
+
MOCK_MODE: z.string().transform((val) => val?.toLowerCase() === "true").default("false"),
|
|
138
|
+
/** Path to mock fixtures directory (defaults to built-in fixtures) */
|
|
139
|
+
MOCK_FIXTURES_PATH: z.string().optional()
|
|
133
140
|
});
|
|
134
141
|
function parseAgentAliases() {
|
|
135
142
|
const aliases = /* @__PURE__ */ new Map();
|
|
@@ -433,14 +440,21 @@ function getAgentConfig(agentName) {
|
|
|
433
440
|
}
|
|
434
441
|
function getWorkstationVersion() {
|
|
435
442
|
try {
|
|
436
|
-
const
|
|
437
|
-
const
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
443
|
+
const __filename2 = fileURLToPath(import.meta.url);
|
|
444
|
+
const __dirname2 = dirname(__filename2);
|
|
445
|
+
const possiblePaths = [
|
|
446
|
+
join2(__dirname2, "../package.json"),
|
|
447
|
+
join2(__dirname2, "../../package.json")
|
|
448
|
+
];
|
|
449
|
+
for (const packageJsonPath of possiblePaths) {
|
|
450
|
+
try {
|
|
451
|
+
const packageJsonContent = readFileSync(packageJsonPath, "utf-8");
|
|
452
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
453
|
+
if (packageJson.name === "@tiflis-io/tiflis-code-workstation" && typeof packageJson.version === "string" && packageJson.version.length > 0) {
|
|
454
|
+
return packageJson.version;
|
|
455
|
+
}
|
|
456
|
+
} catch {
|
|
457
|
+
}
|
|
444
458
|
}
|
|
445
459
|
return "0.0.0";
|
|
446
460
|
} catch {
|
|
@@ -2195,6 +2209,186 @@ var FileSystemWorkspaceDiscovery = class {
|
|
|
2195
2209
|
worktrees: []
|
|
2196
2210
|
};
|
|
2197
2211
|
}
|
|
2212
|
+
/**
|
|
2213
|
+
* Gets current branch and uncommitted changes status for a project.
|
|
2214
|
+
*/
|
|
2215
|
+
async getBranchStatus(workspace, project) {
|
|
2216
|
+
const projectPath = join4(this.workspacesRoot, workspace, project);
|
|
2217
|
+
if (!await this.isGitRepository(projectPath)) {
|
|
2218
|
+
throw new Error(`Project "${project}" is not a git repository`);
|
|
2219
|
+
}
|
|
2220
|
+
try {
|
|
2221
|
+
const currentBranch = execSync("git rev-parse --abbrev-ref HEAD", {
|
|
2222
|
+
cwd: projectPath,
|
|
2223
|
+
encoding: "utf-8"
|
|
2224
|
+
}).trim();
|
|
2225
|
+
const statusOutput = execSync("git status --porcelain", {
|
|
2226
|
+
cwd: projectPath,
|
|
2227
|
+
encoding: "utf-8"
|
|
2228
|
+
});
|
|
2229
|
+
const uncommittedChanges = statusOutput.trim().split("\n").filter((line) => line.length > 0);
|
|
2230
|
+
let aheadCommits = 0;
|
|
2231
|
+
const mainBranches = ["main", "master"];
|
|
2232
|
+
for (const mainBranch of mainBranches) {
|
|
2233
|
+
try {
|
|
2234
|
+
aheadCommits = parseInt(execSync(`git rev-list --count ${mainBranch}..${currentBranch}`, {
|
|
2235
|
+
cwd: projectPath,
|
|
2236
|
+
encoding: "utf-8"
|
|
2237
|
+
}).trim(), 10);
|
|
2238
|
+
break;
|
|
2239
|
+
} catch {
|
|
2240
|
+
continue;
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
return {
|
|
2244
|
+
currentBranch,
|
|
2245
|
+
uncommittedChanges,
|
|
2246
|
+
aheadCommits,
|
|
2247
|
+
isClean: uncommittedChanges.length === 0
|
|
2248
|
+
};
|
|
2249
|
+
} catch {
|
|
2250
|
+
throw new Error("Failed to get branch status");
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
/**
|
|
2254
|
+
* Merges source branch into target branch with safety checks.
|
|
2255
|
+
*/
|
|
2256
|
+
async mergeBranch(workspace, project, sourceBranch, targetBranch = "main", options = {}) {
|
|
2257
|
+
const projectPath = join4(this.workspacesRoot, workspace, project);
|
|
2258
|
+
if (!await this.isGitRepository(projectPath)) {
|
|
2259
|
+
throw new Error(`Project "${project}" is not a git repository`);
|
|
2260
|
+
}
|
|
2261
|
+
try {
|
|
2262
|
+
if (!options.skipPreCheck) {
|
|
2263
|
+
const status = await this.getBranchStatus(workspace, project);
|
|
2264
|
+
if (!status.isClean) {
|
|
2265
|
+
return {
|
|
2266
|
+
success: false,
|
|
2267
|
+
message: `Cannot merge: uncommitted changes exist in ${status.currentBranch}`
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
execSync(`git checkout "${targetBranch}"`, { cwd: projectPath });
|
|
2272
|
+
try {
|
|
2273
|
+
execSync(`git pull origin "${targetBranch}"`, { cwd: projectPath });
|
|
2274
|
+
} catch {
|
|
2275
|
+
console.warn(`Failed to pull ${targetBranch} from remote, continuing with local merge`);
|
|
2276
|
+
}
|
|
2277
|
+
try {
|
|
2278
|
+
execSync(`git merge "${sourceBranch}"`, { cwd: projectPath });
|
|
2279
|
+
} catch (error) {
|
|
2280
|
+
const conflicts = execSync("git diff --name-only --diff-filter=U", {
|
|
2281
|
+
cwd: projectPath,
|
|
2282
|
+
encoding: "utf-8"
|
|
2283
|
+
}).trim().split("\n").filter((f) => f.length > 0);
|
|
2284
|
+
return {
|
|
2285
|
+
success: false,
|
|
2286
|
+
message: `Merge conflicts in files: ${conflicts.join(", ")}`,
|
|
2287
|
+
conflicts
|
|
2288
|
+
};
|
|
2289
|
+
}
|
|
2290
|
+
if (options.pushAfter) {
|
|
2291
|
+
try {
|
|
2292
|
+
execSync(`git push origin "${targetBranch}"`, { cwd: projectPath });
|
|
2293
|
+
} catch {
|
|
2294
|
+
console.warn(`Failed to push ${targetBranch} to remote`);
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
return {
|
|
2298
|
+
success: true,
|
|
2299
|
+
message: `Successfully merged "${sourceBranch}" into "${targetBranch}"`
|
|
2300
|
+
};
|
|
2301
|
+
} catch (error) {
|
|
2302
|
+
return {
|
|
2303
|
+
success: false,
|
|
2304
|
+
message: `Merge failed: ${error instanceof Error ? error.message : String(error)}`
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
/**
|
|
2309
|
+
* Checks if branch is merged into target branch.
|
|
2310
|
+
*/
|
|
2311
|
+
async isBranchMerged(workspace, project, branch, targetBranch) {
|
|
2312
|
+
const projectPath = join4(this.workspacesRoot, workspace, project);
|
|
2313
|
+
if (!await this.isGitRepository(projectPath)) {
|
|
2314
|
+
return false;
|
|
2315
|
+
}
|
|
2316
|
+
try {
|
|
2317
|
+
const mergeBase = execSync(`git merge-base "${targetBranch}" "${branch}"`, {
|
|
2318
|
+
cwd: projectPath,
|
|
2319
|
+
encoding: "utf-8"
|
|
2320
|
+
}).trim();
|
|
2321
|
+
const branchHead = execSync(`git rev-parse "${branch}"`, {
|
|
2322
|
+
cwd: projectPath,
|
|
2323
|
+
encoding: "utf-8"
|
|
2324
|
+
}).trim();
|
|
2325
|
+
return mergeBase === branchHead;
|
|
2326
|
+
} catch {
|
|
2327
|
+
return false;
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
/**
|
|
2331
|
+
* Cleans up worktree and safely deletes the branch if merged.
|
|
2332
|
+
*/
|
|
2333
|
+
async cleanupWorktreeAndBranch(workspace, project, branch) {
|
|
2334
|
+
const projectPath = join4(this.workspacesRoot, workspace, project);
|
|
2335
|
+
try {
|
|
2336
|
+
let branchDeleted = false;
|
|
2337
|
+
await this.removeWorktree(workspace, project, branch);
|
|
2338
|
+
const mainBranches = ["main", "master"];
|
|
2339
|
+
for (const mainBranch of mainBranches) {
|
|
2340
|
+
try {
|
|
2341
|
+
const isMerged = await this.isBranchMerged(workspace, project, branch, mainBranch);
|
|
2342
|
+
if (isMerged) {
|
|
2343
|
+
execSync(`git branch -d "${branch}"`, { cwd: projectPath });
|
|
2344
|
+
branchDeleted = true;
|
|
2345
|
+
break;
|
|
2346
|
+
}
|
|
2347
|
+
} catch {
|
|
2348
|
+
continue;
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
return {
|
|
2352
|
+
success: true,
|
|
2353
|
+
message: `Cleaned up worktree for "${branch}"${branchDeleted ? " and deleted merged branch" : ""}`,
|
|
2354
|
+
branchDeleted
|
|
2355
|
+
};
|
|
2356
|
+
} catch (error) {
|
|
2357
|
+
return {
|
|
2358
|
+
success: false,
|
|
2359
|
+
message: `Cleanup failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
2360
|
+
branchDeleted: false
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
/**
|
|
2365
|
+
* Lists mergeable branches with their status.
|
|
2366
|
+
*/
|
|
2367
|
+
async listMergeableBranches(workspace, project) {
|
|
2368
|
+
const worktrees = await this.listWorktrees(workspace, project);
|
|
2369
|
+
const mergeableBranches = [];
|
|
2370
|
+
for (const worktree of worktrees) {
|
|
2371
|
+
if (worktree.branch === "main" || worktree.branch === "master") continue;
|
|
2372
|
+
try {
|
|
2373
|
+
const [isMerged, hasChanges, aheadCommits] = await Promise.all([
|
|
2374
|
+
this.isBranchMerged(workspace, project, worktree.branch, "main"),
|
|
2375
|
+
this.getBranchStatus(workspace, project).then((status) => !status.isClean),
|
|
2376
|
+
this.getBranchStatus(workspace, project).then((status) => status.aheadCommits)
|
|
2377
|
+
]);
|
|
2378
|
+
mergeableBranches.push({
|
|
2379
|
+
branch: worktree.branch,
|
|
2380
|
+
path: worktree.path,
|
|
2381
|
+
isMerged: await this.isBranchMerged(workspace, project, worktree.branch, "main"),
|
|
2382
|
+
hasUncommittedChanges: hasChanges,
|
|
2383
|
+
canCleanup: isMerged && !hasChanges,
|
|
2384
|
+
aheadCommits
|
|
2385
|
+
});
|
|
2386
|
+
} catch {
|
|
2387
|
+
continue;
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
return mergeableBranches;
|
|
2391
|
+
}
|
|
2198
2392
|
};
|
|
2199
2393
|
|
|
2200
2394
|
// src/infrastructure/terminal/pty-manager.ts
|
|
@@ -3607,6 +3801,87 @@ var AgentSessionManager = class extends EventEmitter2 {
|
|
|
3607
3801
|
this.terminateSession(id);
|
|
3608
3802
|
}
|
|
3609
3803
|
}
|
|
3804
|
+
/**
|
|
3805
|
+
* Terminates sessions that are running in a specific worktree.
|
|
3806
|
+
* Returns the list of terminated session IDs.
|
|
3807
|
+
*/
|
|
3808
|
+
terminateWorktreeSessions(workspace, project, branch) {
|
|
3809
|
+
const worktreePath = `/${workspace}/${project}--${branch}`;
|
|
3810
|
+
const terminatedSessions = [];
|
|
3811
|
+
for (const [sessionId, state] of this.sessions) {
|
|
3812
|
+
const isInWorktree = state.workingDir.includes(worktreePath) || state.cliSessionId?.includes(`${project}--${branch}`) || state.workingDir.endsWith(`${project}--${branch}`);
|
|
3813
|
+
if (isInWorktree) {
|
|
3814
|
+
try {
|
|
3815
|
+
if (state.isExecuting) {
|
|
3816
|
+
this.cancelCommand(sessionId);
|
|
3817
|
+
}
|
|
3818
|
+
this.terminateSession(sessionId);
|
|
3819
|
+
terminatedSessions.push(sessionId);
|
|
3820
|
+
this.logger.info({ sessionId, workspace, project, branch }, "Terminated worktree session");
|
|
3821
|
+
} catch (error) {
|
|
3822
|
+
this.logger.error({ sessionId, error }, "Failed to terminate worktree session");
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
3826
|
+
return terminatedSessions;
|
|
3827
|
+
}
|
|
3828
|
+
/**
|
|
3829
|
+
* Gets session summary for a specific worktree.
|
|
3830
|
+
*/
|
|
3831
|
+
getWorktreeSessionSummary(workspace, project, branch) {
|
|
3832
|
+
const worktreePath = `/${workspace}/${project}--${branch}`;
|
|
3833
|
+
const activeSessions = Array.from(this.sessions.values()).filter(
|
|
3834
|
+
(session) => session.workingDir.includes(worktreePath) || session.cliSessionId?.includes(`${project}--${branch}`) || session.workingDir.endsWith(`${project}--${branch}`)
|
|
3835
|
+
);
|
|
3836
|
+
const sessionTypes = [...new Set(activeSessions.map((s) => s.agentType))];
|
|
3837
|
+
const executingCount = activeSessions.filter((s) => s.isExecuting).length;
|
|
3838
|
+
return {
|
|
3839
|
+
activeSessions,
|
|
3840
|
+
sessionCount: activeSessions.length,
|
|
3841
|
+
sessionTypes,
|
|
3842
|
+
executingCount
|
|
3843
|
+
};
|
|
3844
|
+
}
|
|
3845
|
+
/**
|
|
3846
|
+
* Lists all sessions with their worktree information.
|
|
3847
|
+
*/
|
|
3848
|
+
listSessionsWithWorktreeInfo() {
|
|
3849
|
+
return Array.from(this.sessions.values()).map((session) => {
|
|
3850
|
+
const worktreeInfo = this.parseWorktreeInfo(session.workingDir);
|
|
3851
|
+
return {
|
|
3852
|
+
sessionId: session.sessionId,
|
|
3853
|
+
agentType: session.agentType,
|
|
3854
|
+
agentName: session.agentName,
|
|
3855
|
+
workingDir: session.workingDir,
|
|
3856
|
+
isExecuting: session.isExecuting,
|
|
3857
|
+
worktreeInfo
|
|
3858
|
+
};
|
|
3859
|
+
});
|
|
3860
|
+
}
|
|
3861
|
+
/**
|
|
3862
|
+
* Parse worktree information from a working directory path.
|
|
3863
|
+
*/
|
|
3864
|
+
parseWorktreeInfo(workingDir) {
|
|
3865
|
+
const parts = workingDir.split("/");
|
|
3866
|
+
if (parts.length < 3) {
|
|
3867
|
+
return { isWorktree: false };
|
|
3868
|
+
}
|
|
3869
|
+
const workspacesIndex = parts.findIndex((part) => part === "workspaces" || part.includes("workspace"));
|
|
3870
|
+
if (workspacesIndex === -1 || workspacesIndex + 2 >= parts.length) {
|
|
3871
|
+
return { isWorktree: false };
|
|
3872
|
+
}
|
|
3873
|
+
const workspace = parts[workspacesIndex + 1];
|
|
3874
|
+
const projectPart = parts[workspacesIndex + 2];
|
|
3875
|
+
if (!projectPart) {
|
|
3876
|
+
return { isWorktree: false };
|
|
3877
|
+
}
|
|
3878
|
+
if (projectPart.includes("--")) {
|
|
3879
|
+
const [project, branch] = projectPart.split("--");
|
|
3880
|
+
return { workspace, project, branch, isWorktree: true };
|
|
3881
|
+
} else {
|
|
3882
|
+
return { workspace, project: projectPart, isWorktree: false };
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3610
3885
|
/**
|
|
3611
3886
|
* Setup event handlers for an executor.
|
|
3612
3887
|
*/
|
|
@@ -4293,7 +4568,14 @@ var SubscriptionService = class {
|
|
|
4293
4568
|
}
|
|
4294
4569
|
const isNew = client.subscribe(session);
|
|
4295
4570
|
if (isNew) {
|
|
4296
|
-
|
|
4571
|
+
try {
|
|
4572
|
+
this.deps.subscriptionRepository.subscribe(deviceId, sessionId);
|
|
4573
|
+
} catch (error) {
|
|
4574
|
+
this.logger.debug(
|
|
4575
|
+
{ deviceId, sessionId, error },
|
|
4576
|
+
"Failed to persist subscription (may be expected in mock mode)"
|
|
4577
|
+
);
|
|
4578
|
+
}
|
|
4297
4579
|
}
|
|
4298
4580
|
let isMaster = false;
|
|
4299
4581
|
let cols;
|
|
@@ -5414,6 +5696,274 @@ var ChatHistoryService = class _ChatHistoryService {
|
|
|
5414
5696
|
);
|
|
5415
5697
|
return agentSessions;
|
|
5416
5698
|
}
|
|
5699
|
+
// ============================================================================
|
|
5700
|
+
// Mock Data Seeding (for Screenshot Automation)
|
|
5701
|
+
// ============================================================================
|
|
5702
|
+
/**
|
|
5703
|
+
* Seeds mock chat history for screenshot automation.
|
|
5704
|
+
* Creates realistic conversation history with voice messages, code blocks, etc.
|
|
5705
|
+
*
|
|
5706
|
+
* @param agentSessions - Object with agent session IDs and their working directories
|
|
5707
|
+
*/
|
|
5708
|
+
seedMockData(agentSessions) {
|
|
5709
|
+
this.logger.info("Seeding mock chat history for screenshots...");
|
|
5710
|
+
this.seedSupervisorHistory();
|
|
5711
|
+
if (agentSessions.claude) {
|
|
5712
|
+
this.ensureAgentSession(agentSessions.claude.id, "claude", agentSessions.claude.workingDir);
|
|
5713
|
+
this.seedClaudeAgentHistory(agentSessions.claude.id);
|
|
5714
|
+
}
|
|
5715
|
+
if (agentSessions.cursor) {
|
|
5716
|
+
this.ensureAgentSession(agentSessions.cursor.id, "cursor", agentSessions.cursor.workingDir);
|
|
5717
|
+
this.seedCursorAgentHistory(agentSessions.cursor.id);
|
|
5718
|
+
}
|
|
5719
|
+
if (agentSessions.opencode) {
|
|
5720
|
+
this.ensureAgentSession(agentSessions.opencode.id, "opencode", agentSessions.opencode.workingDir);
|
|
5721
|
+
this.seedOpenCodeAgentHistory(agentSessions.opencode.id);
|
|
5722
|
+
}
|
|
5723
|
+
this.logger.info("Mock chat history seeded successfully");
|
|
5724
|
+
}
|
|
5725
|
+
/**
|
|
5726
|
+
* Ensures an agent session exists in the database.
|
|
5727
|
+
* Creates it if it doesn't exist.
|
|
5728
|
+
*/
|
|
5729
|
+
ensureAgentSession(sessionId, sessionType, workingDir) {
|
|
5730
|
+
try {
|
|
5731
|
+
const existing = this.sessionRepo.getById(sessionId);
|
|
5732
|
+
if (!existing) {
|
|
5733
|
+
this.sessionRepo.create({
|
|
5734
|
+
id: sessionId,
|
|
5735
|
+
type: sessionType,
|
|
5736
|
+
workingDir
|
|
5737
|
+
});
|
|
5738
|
+
this.logger.debug({ sessionId, sessionType }, "Created agent session in database for seeding");
|
|
5739
|
+
}
|
|
5740
|
+
} catch {
|
|
5741
|
+
}
|
|
5742
|
+
}
|
|
5743
|
+
/**
|
|
5744
|
+
* Seeds Supervisor chat with a realistic voice conversation.
|
|
5745
|
+
*/
|
|
5746
|
+
seedSupervisorHistory() {
|
|
5747
|
+
this.ensureSupervisorSession();
|
|
5748
|
+
const sessionId = _ChatHistoryService.SUPERVISOR_SESSION_ID;
|
|
5749
|
+
this.messageRepo.deleteBySession(sessionId);
|
|
5750
|
+
const voiceInput1 = {
|
|
5751
|
+
id: "vi-1",
|
|
5752
|
+
block_type: "voice_input",
|
|
5753
|
+
content: "Show me the available workspaces",
|
|
5754
|
+
metadata: { duration: 2.1, has_audio: true }
|
|
5755
|
+
};
|
|
5756
|
+
this.messageRepo.create({
|
|
5757
|
+
sessionId,
|
|
5758
|
+
role: "user",
|
|
5759
|
+
contentType: "transcription",
|
|
5760
|
+
content: "Show me the available workspaces",
|
|
5761
|
+
contentBlocks: JSON.stringify([voiceInput1]),
|
|
5762
|
+
isComplete: true
|
|
5763
|
+
});
|
|
5764
|
+
const textBlock1 = {
|
|
5765
|
+
id: "tb-1",
|
|
5766
|
+
block_type: "text",
|
|
5767
|
+
content: "I found 2 workspaces with several projects. The **work** workspace contains my-app and api-service. The **personal** workspace has your blog project. Would you like to start an agent session in any of these?"
|
|
5768
|
+
};
|
|
5769
|
+
const voiceOutput1 = {
|
|
5770
|
+
id: "vo-1",
|
|
5771
|
+
block_type: "voice_output",
|
|
5772
|
+
content: "I found 2 workspaces with several projects.",
|
|
5773
|
+
metadata: { duration: 4.2, has_audio: true }
|
|
5774
|
+
};
|
|
5775
|
+
this.messageRepo.create({
|
|
5776
|
+
sessionId,
|
|
5777
|
+
role: "assistant",
|
|
5778
|
+
contentType: "text",
|
|
5779
|
+
content: "I found 2 workspaces with several projects. The work workspace contains my-app and api-service. The personal workspace has your blog project. Would you like to start an agent session in any of these?",
|
|
5780
|
+
contentBlocks: JSON.stringify([textBlock1, voiceOutput1]),
|
|
5781
|
+
isComplete: true
|
|
5782
|
+
});
|
|
5783
|
+
const voiceInput2 = {
|
|
5784
|
+
id: "vi-2",
|
|
5785
|
+
block_type: "voice_input",
|
|
5786
|
+
content: "Start Claude on my-app",
|
|
5787
|
+
metadata: { duration: 1.8, has_audio: true }
|
|
5788
|
+
};
|
|
5789
|
+
this.messageRepo.create({
|
|
5790
|
+
sessionId,
|
|
5791
|
+
role: "user",
|
|
5792
|
+
contentType: "transcription",
|
|
5793
|
+
content: "Start Claude on my-app",
|
|
5794
|
+
contentBlocks: JSON.stringify([voiceInput2]),
|
|
5795
|
+
isComplete: true
|
|
5796
|
+
});
|
|
5797
|
+
const textBlock2 = {
|
|
5798
|
+
id: "tb-2",
|
|
5799
|
+
block_type: "text",
|
|
5800
|
+
content: "I've started a new Claude Code session in **work/my-app**. You can find it in the sidebar under Agent Sessions. The session is ready for your commands!"
|
|
5801
|
+
};
|
|
5802
|
+
const voiceOutput2 = {
|
|
5803
|
+
id: "vo-2",
|
|
5804
|
+
block_type: "voice_output",
|
|
5805
|
+
content: "I've started a new Claude Code session in work/my-app.",
|
|
5806
|
+
metadata: { duration: 3.5, has_audio: true }
|
|
5807
|
+
};
|
|
5808
|
+
this.messageRepo.create({
|
|
5809
|
+
sessionId,
|
|
5810
|
+
role: "assistant",
|
|
5811
|
+
contentType: "text",
|
|
5812
|
+
content: "I've started a new Claude Code session in work/my-app. You can find it in the sidebar under Agent Sessions. The session is ready for your commands!",
|
|
5813
|
+
contentBlocks: JSON.stringify([textBlock2, voiceOutput2]),
|
|
5814
|
+
isComplete: true
|
|
5815
|
+
});
|
|
5816
|
+
this.logger.debug("Seeded Supervisor history with voice conversation");
|
|
5817
|
+
}
|
|
5818
|
+
/**
|
|
5819
|
+
* Seeds Claude agent chat with code examples and tool use.
|
|
5820
|
+
*/
|
|
5821
|
+
seedClaudeAgentHistory(sessionId) {
|
|
5822
|
+
this.messageRepo.deleteBySession(sessionId);
|
|
5823
|
+
const userVoiceBlock = {
|
|
5824
|
+
id: "vi-claude-1",
|
|
5825
|
+
block_type: "voice_input",
|
|
5826
|
+
content: "Add a health check endpoint to the API",
|
|
5827
|
+
metadata: {
|
|
5828
|
+
duration: 2.3,
|
|
5829
|
+
has_audio: true
|
|
5830
|
+
}
|
|
5831
|
+
};
|
|
5832
|
+
this.messageRepo.create({
|
|
5833
|
+
sessionId,
|
|
5834
|
+
role: "user",
|
|
5835
|
+
contentType: "audio",
|
|
5836
|
+
content: "Add a health check endpoint to the API",
|
|
5837
|
+
contentBlocks: JSON.stringify([userVoiceBlock]),
|
|
5838
|
+
isComplete: true
|
|
5839
|
+
});
|
|
5840
|
+
const thinkingBlock = {
|
|
5841
|
+
id: "think-1",
|
|
5842
|
+
block_type: "thinking",
|
|
5843
|
+
content: "I'll add a simple health check endpoint that returns the server status and version information."
|
|
5844
|
+
};
|
|
5845
|
+
const toolBlock = {
|
|
5846
|
+
id: "tool-1",
|
|
5847
|
+
block_type: "tool",
|
|
5848
|
+
content: "Edit",
|
|
5849
|
+
metadata: {
|
|
5850
|
+
tool_name: "Edit",
|
|
5851
|
+
tool_status: "completed",
|
|
5852
|
+
tool_input: JSON.stringify({ file: "src/routes/health.ts" })
|
|
5853
|
+
}
|
|
5854
|
+
};
|
|
5855
|
+
const codeBlock = {
|
|
5856
|
+
id: "code-1",
|
|
5857
|
+
block_type: "code",
|
|
5858
|
+
content: `import { Router } from 'express';
|
|
5859
|
+
|
|
5860
|
+
const router = Router();
|
|
5861
|
+
|
|
5862
|
+
router.get('/health', (req, res) => {
|
|
5863
|
+
res.json({
|
|
5864
|
+
status: 'healthy',
|
|
5865
|
+
version: process.env.npm_package_version,
|
|
5866
|
+
uptime: process.uptime()
|
|
5867
|
+
});
|
|
5868
|
+
});
|
|
5869
|
+
|
|
5870
|
+
export default router;`,
|
|
5871
|
+
metadata: { language: "typescript" }
|
|
5872
|
+
};
|
|
5873
|
+
const textBlock = {
|
|
5874
|
+
id: "text-1",
|
|
5875
|
+
block_type: "text",
|
|
5876
|
+
content: "I've added a health check endpoint at `/health` that returns the server status, version, and uptime. You can test it with `curl http://localhost:3000/health`."
|
|
5877
|
+
};
|
|
5878
|
+
this.messageRepo.create({
|
|
5879
|
+
sessionId,
|
|
5880
|
+
role: "assistant",
|
|
5881
|
+
contentType: "text",
|
|
5882
|
+
content: "I've added a health check endpoint at /health that returns the server status, version, and uptime.",
|
|
5883
|
+
contentBlocks: JSON.stringify([thinkingBlock, toolBlock, codeBlock, textBlock]),
|
|
5884
|
+
isComplete: true
|
|
5885
|
+
});
|
|
5886
|
+
this.logger.debug({ sessionId }, "Seeded Claude agent history with code example");
|
|
5887
|
+
}
|
|
5888
|
+
/**
|
|
5889
|
+
* Seeds Cursor agent chat.
|
|
5890
|
+
*/
|
|
5891
|
+
seedCursorAgentHistory(sessionId) {
|
|
5892
|
+
this.messageRepo.deleteBySession(sessionId);
|
|
5893
|
+
this.messageRepo.create({
|
|
5894
|
+
sessionId,
|
|
5895
|
+
role: "user",
|
|
5896
|
+
contentType: "text",
|
|
5897
|
+
content: "Explain the project structure",
|
|
5898
|
+
isComplete: true
|
|
5899
|
+
});
|
|
5900
|
+
const textBlock = {
|
|
5901
|
+
id: "text-cursor-1",
|
|
5902
|
+
block_type: "text",
|
|
5903
|
+
content: `This is a **Next.js portfolio site** with the following structure:
|
|
5904
|
+
|
|
5905
|
+
- \`/app\` - App router pages and layouts
|
|
5906
|
+
- \`/components\` - Reusable React components
|
|
5907
|
+
- \`/lib\` - Utility functions and helpers
|
|
5908
|
+
- \`/public\` - Static assets (images, fonts)
|
|
5909
|
+
- \`/styles\` - Global CSS and Tailwind config
|
|
5910
|
+
|
|
5911
|
+
The site uses **Tailwind CSS** for styling and **Framer Motion** for animations. Would you like me to explain any specific part in more detail?`
|
|
5912
|
+
};
|
|
5913
|
+
this.messageRepo.create({
|
|
5914
|
+
sessionId,
|
|
5915
|
+
role: "assistant",
|
|
5916
|
+
contentType: "text",
|
|
5917
|
+
content: "This is a Next.js portfolio site with app router, components, lib, public, and styles directories.",
|
|
5918
|
+
contentBlocks: JSON.stringify([textBlock]),
|
|
5919
|
+
isComplete: true
|
|
5920
|
+
});
|
|
5921
|
+
this.logger.debug({ sessionId }, "Seeded Cursor agent history");
|
|
5922
|
+
}
|
|
5923
|
+
/**
|
|
5924
|
+
* Seeds OpenCode agent chat.
|
|
5925
|
+
*/
|
|
5926
|
+
seedOpenCodeAgentHistory(sessionId) {
|
|
5927
|
+
this.messageRepo.deleteBySession(sessionId);
|
|
5928
|
+
this.messageRepo.create({
|
|
5929
|
+
sessionId,
|
|
5930
|
+
role: "user",
|
|
5931
|
+
contentType: "text",
|
|
5932
|
+
content: "Run the tests",
|
|
5933
|
+
isComplete: true
|
|
5934
|
+
});
|
|
5935
|
+
const statusBlock = {
|
|
5936
|
+
id: "status-1",
|
|
5937
|
+
block_type: "status",
|
|
5938
|
+
content: "Running tests..."
|
|
5939
|
+
};
|
|
5940
|
+
const codeBlock = {
|
|
5941
|
+
id: "code-oc-1",
|
|
5942
|
+
block_type: "code",
|
|
5943
|
+
content: `\u2713 auth.test.ts (3 tests) 120ms
|
|
5944
|
+
\u2713 api.test.ts (8 tests) 340ms
|
|
5945
|
+
\u2713 utils.test.ts (5 tests) 45ms
|
|
5946
|
+
|
|
5947
|
+
Test Files 3 passed (3)
|
|
5948
|
+
Tests 16 passed (16)
|
|
5949
|
+
Time 0.51s`,
|
|
5950
|
+
metadata: { language: "shell" }
|
|
5951
|
+
};
|
|
5952
|
+
const textBlock = {
|
|
5953
|
+
id: "text-oc-1",
|
|
5954
|
+
block_type: "text",
|
|
5955
|
+
content: "All 16 tests passed across 3 test files. The test suite completed in 0.51 seconds."
|
|
5956
|
+
};
|
|
5957
|
+
this.messageRepo.create({
|
|
5958
|
+
sessionId,
|
|
5959
|
+
role: "assistant",
|
|
5960
|
+
contentType: "text",
|
|
5961
|
+
content: "All 16 tests passed across 3 test files.",
|
|
5962
|
+
contentBlocks: JSON.stringify([statusBlock, codeBlock, textBlock]),
|
|
5963
|
+
isComplete: true
|
|
5964
|
+
});
|
|
5965
|
+
this.logger.debug({ sessionId }, "Seeded OpenCode agent history");
|
|
5966
|
+
}
|
|
5417
5967
|
};
|
|
5418
5968
|
|
|
5419
5969
|
// src/infrastructure/persistence/in-memory-session-manager.ts
|
|
@@ -5471,6 +6021,21 @@ var InMemorySessionManager = class extends EventEmitter3 {
|
|
|
5471
6021
|
* Sets up event listeners to sync agent session state.
|
|
5472
6022
|
*/
|
|
5473
6023
|
setupAgentSessionSync() {
|
|
6024
|
+
this.agentSessionManager.on("sessionCreated", (state) => {
|
|
6025
|
+
if (!this.sessions.has(state.sessionId)) {
|
|
6026
|
+
const session = new AgentSession({
|
|
6027
|
+
id: new SessionId(state.sessionId),
|
|
6028
|
+
type: state.agentType,
|
|
6029
|
+
agentName: state.agentName,
|
|
6030
|
+
workingDir: state.workingDir
|
|
6031
|
+
});
|
|
6032
|
+
this.sessions.set(state.sessionId, session);
|
|
6033
|
+
this.logger.debug(
|
|
6034
|
+
{ sessionId: state.sessionId, agentType: state.agentType },
|
|
6035
|
+
"Agent session registered from external creation"
|
|
6036
|
+
);
|
|
6037
|
+
}
|
|
6038
|
+
});
|
|
5474
6039
|
this.agentSessionManager.on("sessionTerminated", (sessionId) => {
|
|
5475
6040
|
const session = this.sessions.get(sessionId);
|
|
5476
6041
|
if (session && isAgentType(session.type)) {
|
|
@@ -5777,7 +6342,7 @@ Path: ${project.path}`;
|
|
|
5777
6342
|
// src/infrastructure/agents/supervisor/tools/worktree-tools.ts
|
|
5778
6343
|
import { tool as tool2 } from "@langchain/core/tools";
|
|
5779
6344
|
import { z as z4 } from "zod";
|
|
5780
|
-
function createWorktreeTools(workspaceDiscovery) {
|
|
6345
|
+
function createWorktreeTools(workspaceDiscovery, _agentSessionManager) {
|
|
5781
6346
|
const listWorktrees = tool2(
|
|
5782
6347
|
async ({ workspace, project }) => {
|
|
5783
6348
|
try {
|
|
@@ -5857,15 +6422,231 @@ ${worktrees.map((w) => `- ${w.name}: ${w.branch} (${w.path})`).join("\n")}`;
|
|
|
5857
6422
|
})
|
|
5858
6423
|
}
|
|
5859
6424
|
);
|
|
5860
|
-
|
|
5861
|
-
}
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
6425
|
+
const branchStatus = tool2(
|
|
6426
|
+
async ({ workspace, project }) => {
|
|
6427
|
+
try {
|
|
6428
|
+
const status = await workspaceDiscovery.getBranchStatus(workspace, project);
|
|
6429
|
+
return {
|
|
6430
|
+
currentBranch: status.currentBranch,
|
|
6431
|
+
uncommittedChanges: status.uncommittedChanges,
|
|
6432
|
+
aheadCommits: status.aheadCommits,
|
|
6433
|
+
isClean: status.isClean,
|
|
6434
|
+
summary: status.isClean ? `Branch "${status.currentBranch}" is clean with ${status.aheadCommits} commits ahead of main` : `Branch "${status.currentBranch}" has ${status.uncommittedChanges.length} uncommitted changes:
|
|
6435
|
+
${status.uncommittedChanges.map((c) => ` ${c}`).join("\n")}`
|
|
6436
|
+
};
|
|
6437
|
+
} catch (error) {
|
|
6438
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
6439
|
+
}
|
|
6440
|
+
},
|
|
6441
|
+
{
|
|
6442
|
+
name: "branch_status",
|
|
6443
|
+
description: "Get current branch status including uncommitted changes and commit count ahead of main",
|
|
6444
|
+
schema: z4.object({
|
|
6445
|
+
workspace: z4.string().describe("Workspace name containing the project"),
|
|
6446
|
+
project: z4.string().describe("Project name to get branch status for")
|
|
6447
|
+
})
|
|
6448
|
+
}
|
|
6449
|
+
);
|
|
6450
|
+
const mergeBranch = tool2(
|
|
6451
|
+
async ({ workspace, project, sourceBranch, targetBranch, pushAfter, skipPreCheck }) => {
|
|
6452
|
+
try {
|
|
6453
|
+
const result = await workspaceDiscovery.mergeBranch(
|
|
6454
|
+
workspace,
|
|
6455
|
+
project,
|
|
6456
|
+
sourceBranch,
|
|
6457
|
+
targetBranch ?? "main",
|
|
6458
|
+
{ pushAfter, skipPreCheck }
|
|
6459
|
+
);
|
|
6460
|
+
return result;
|
|
6461
|
+
} catch (error) {
|
|
6462
|
+
return {
|
|
6463
|
+
success: false,
|
|
6464
|
+
message: `Merge operation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
6465
|
+
};
|
|
6466
|
+
}
|
|
6467
|
+
},
|
|
6468
|
+
{
|
|
6469
|
+
name: "merge_branch",
|
|
6470
|
+
description: "Merge source branch into target branch with safety checks and optional push to remote",
|
|
6471
|
+
schema: z4.object({
|
|
6472
|
+
workspace: z4.string().describe("Workspace name"),
|
|
6473
|
+
project: z4.string().describe("Project name"),
|
|
6474
|
+
sourceBranch: z4.string().describe("Source branch to merge from"),
|
|
6475
|
+
targetBranch: z4.string().optional().describe("Target branch (defaults to main)"),
|
|
6476
|
+
pushAfter: z4.boolean().optional().describe("Push to remote after successful merge"),
|
|
6477
|
+
skipPreCheck: z4.boolean().optional().describe("Skip pre-merge safety checks (not recommended)")
|
|
6478
|
+
})
|
|
6479
|
+
}
|
|
6480
|
+
);
|
|
6481
|
+
const listMergeableBranches = tool2(
|
|
6482
|
+
async ({ workspace, project }) => {
|
|
6483
|
+
try {
|
|
6484
|
+
const branches = await workspaceDiscovery.listMergeableBranches(workspace, project);
|
|
6485
|
+
if (branches.length === 0) {
|
|
6486
|
+
return "No feature branches found.";
|
|
6487
|
+
}
|
|
6488
|
+
const statusLines = branches.map((b) => {
|
|
6489
|
+
const status = [
|
|
6490
|
+
`Branch: ${b.branch}`,
|
|
6491
|
+
`Path: ${b.path}`,
|
|
6492
|
+
`Merged: ${b.isMerged ? "\u2713" : "\u2717"}`,
|
|
6493
|
+
`Clean: ${b.hasUncommittedChanges ? "\u2717 (has changes)" : "\u2713"}`,
|
|
6494
|
+
`Cleanup ready: ${b.canCleanup ? "\u2713" : "\u2717"}`,
|
|
6495
|
+
`Ahead commits: ${b.aheadCommits}`
|
|
6496
|
+
].join(" | ");
|
|
6497
|
+
return `- ${status}`;
|
|
6498
|
+
});
|
|
6499
|
+
const summary = `Found ${branches.length} branches. ${branches.filter((b) => b.canCleanup).length} are ready for cleanup.`;
|
|
6500
|
+
return `${summary}
|
|
6501
|
+
|
|
6502
|
+
${statusLines.join("\n")}`;
|
|
6503
|
+
} catch (error) {
|
|
6504
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
6505
|
+
}
|
|
6506
|
+
},
|
|
6507
|
+
{
|
|
6508
|
+
name: "list_mergeable_branches",
|
|
6509
|
+
description: "List all feature branches and their merge/cleanup status",
|
|
6510
|
+
schema: z4.object({
|
|
6511
|
+
workspace: z4.string().describe("Workspace name"),
|
|
6512
|
+
project: z4.string().describe("Project name")
|
|
6513
|
+
})
|
|
6514
|
+
}
|
|
6515
|
+
);
|
|
6516
|
+
const cleanupWorktree = tool2(
|
|
6517
|
+
async ({ workspace, project, branch, force }) => {
|
|
6518
|
+
try {
|
|
6519
|
+
if (!force) {
|
|
6520
|
+
const status = await workspaceDiscovery.getBranchStatus(workspace, project);
|
|
6521
|
+
if (!status.isClean && status.currentBranch === branch) {
|
|
6522
|
+
return {
|
|
6523
|
+
success: false,
|
|
6524
|
+
message: `Cannot cleanup: uncommitted changes exist in "${branch}". Use force=true to override.`,
|
|
6525
|
+
uncommittedChanges: status.uncommittedChanges
|
|
6526
|
+
};
|
|
6527
|
+
}
|
|
6528
|
+
}
|
|
6529
|
+
const result = await workspaceDiscovery.cleanupWorktreeAndBranch(
|
|
6530
|
+
workspace,
|
|
6531
|
+
project,
|
|
6532
|
+
branch
|
|
6533
|
+
);
|
|
6534
|
+
return result;
|
|
6535
|
+
} catch (error) {
|
|
6536
|
+
return {
|
|
6537
|
+
success: false,
|
|
6538
|
+
message: `Cleanup failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
6539
|
+
branchDeleted: false
|
|
6540
|
+
};
|
|
6541
|
+
}
|
|
6542
|
+
},
|
|
6543
|
+
{
|
|
6544
|
+
name: "cleanup_worktree",
|
|
6545
|
+
description: "Remove worktree and optionally delete the branch if merged",
|
|
6546
|
+
schema: z4.object({
|
|
6547
|
+
workspace: z4.string().describe("Workspace name"),
|
|
6548
|
+
project: z4.string().describe("Project name"),
|
|
6549
|
+
branch: z4.string().describe("Branch/worktree name to cleanup"),
|
|
6550
|
+
force: z4.boolean().optional().describe("Force cleanup even with uncommitted changes")
|
|
6551
|
+
})
|
|
6552
|
+
}
|
|
6553
|
+
);
|
|
6554
|
+
const completeFeature = tool2(
|
|
6555
|
+
async ({ workspace, project, featureBranch, targetBranch, skipConfirmation }) => {
|
|
6556
|
+
try {
|
|
6557
|
+
const results = [];
|
|
6558
|
+
const status = await workspaceDiscovery.getBranchStatus(workspace, project);
|
|
6559
|
+
results.push({
|
|
6560
|
+
step: "status_check",
|
|
6561
|
+
data: {
|
|
6562
|
+
currentBranch: status.currentBranch,
|
|
6563
|
+
isClean: status.isClean,
|
|
6564
|
+
uncommittedChanges: status.uncommittedChanges,
|
|
6565
|
+
aheadCommits: status.aheadCommits
|
|
6566
|
+
}
|
|
6567
|
+
});
|
|
6568
|
+
if (!status.isClean && status.currentBranch === featureBranch && !skipConfirmation) {
|
|
6569
|
+
return {
|
|
6570
|
+
success: false,
|
|
6571
|
+
message: `Cannot complete feature: uncommitted changes exist in "${featureBranch}". Commit or stash changes first.`,
|
|
6572
|
+
results
|
|
6573
|
+
};
|
|
6574
|
+
}
|
|
6575
|
+
const mergeResult = await workspaceDiscovery.mergeBranch(
|
|
6576
|
+
workspace,
|
|
6577
|
+
project,
|
|
6578
|
+
featureBranch,
|
|
6579
|
+
targetBranch ?? "main",
|
|
6580
|
+
{ pushAfter: true }
|
|
6581
|
+
);
|
|
6582
|
+
results.push({
|
|
6583
|
+
step: "merge",
|
|
6584
|
+
data: mergeResult
|
|
6585
|
+
});
|
|
6586
|
+
if (!mergeResult.success) {
|
|
6587
|
+
return {
|
|
6588
|
+
success: false,
|
|
6589
|
+
message: `Merge failed: ${mergeResult.message}`,
|
|
6590
|
+
results
|
|
6591
|
+
};
|
|
6592
|
+
}
|
|
6593
|
+
const cleanupResult = await workspaceDiscovery.cleanupWorktreeAndBranch(
|
|
6594
|
+
workspace,
|
|
6595
|
+
project,
|
|
6596
|
+
featureBranch
|
|
6597
|
+
);
|
|
6598
|
+
results.push({
|
|
6599
|
+
step: "cleanup",
|
|
6600
|
+
data: cleanupResult
|
|
6601
|
+
});
|
|
6602
|
+
return {
|
|
6603
|
+
success: true,
|
|
6604
|
+
message: `\u2705 Feature "${featureBranch}" completed successfully!
|
|
6605
|
+
|
|
6606
|
+
Steps executed:
|
|
6607
|
+
1. \u2705 Branch validated
|
|
6608
|
+
2. \u2705 Merged into ${targetBranch ?? "main"} and pushed
|
|
6609
|
+
3. \u2705 Worktree cleaned up${cleanupResult.branchDeleted ? " and branch deleted" : ""}`,
|
|
6610
|
+
results
|
|
6611
|
+
};
|
|
6612
|
+
} catch (error) {
|
|
6613
|
+
return {
|
|
6614
|
+
success: false,
|
|
6615
|
+
message: `Feature completion failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
6616
|
+
results: []
|
|
6617
|
+
};
|
|
6618
|
+
}
|
|
6619
|
+
},
|
|
6620
|
+
{
|
|
6621
|
+
name: "complete_feature",
|
|
6622
|
+
description: "Complete workflow: merge feature branch into main and cleanup worktree/branch",
|
|
6623
|
+
schema: z4.object({
|
|
6624
|
+
workspace: z4.string().describe("Workspace name"),
|
|
6625
|
+
project: z4.string().describe("Project name"),
|
|
6626
|
+
featureBranch: z4.string().describe("Feature branch name to complete"),
|
|
6627
|
+
targetBranch: z4.string().optional().describe("Target branch (defaults to main)"),
|
|
6628
|
+
skipConfirmation: z4.boolean().optional().describe("Skip safety checks (not recommended)")
|
|
6629
|
+
})
|
|
6630
|
+
}
|
|
6631
|
+
);
|
|
6632
|
+
return [
|
|
6633
|
+
listWorktrees,
|
|
6634
|
+
createWorktree,
|
|
6635
|
+
removeWorktree,
|
|
6636
|
+
branchStatus,
|
|
6637
|
+
mergeBranch,
|
|
6638
|
+
listMergeableBranches,
|
|
6639
|
+
cleanupWorktree,
|
|
6640
|
+
completeFeature
|
|
6641
|
+
];
|
|
6642
|
+
}
|
|
6643
|
+
|
|
6644
|
+
// src/infrastructure/agents/supervisor/tools/session-tools.ts
|
|
6645
|
+
import { tool as tool3 } from "@langchain/core/tools";
|
|
6646
|
+
import { z as z5 } from "zod";
|
|
6647
|
+
function createSessionTools(sessionManager, agentSessionManager, workspaceDiscovery, workspacesRoot, getMessageBroadcaster, getChatHistoryService) {
|
|
6648
|
+
const broadcastTermination = (sessionId) => {
|
|
6649
|
+
const broadcaster = getMessageBroadcaster?.();
|
|
5869
6650
|
if (!broadcaster) return;
|
|
5870
6651
|
const message = {
|
|
5871
6652
|
type: "session.terminated",
|
|
@@ -6148,7 +6929,96 @@ Messages: ${agentState.messages.length}`;
|
|
|
6148
6929
|
})
|
|
6149
6930
|
}
|
|
6150
6931
|
);
|
|
6151
|
-
|
|
6932
|
+
const listSessionsWithWorktrees = tool3(
|
|
6933
|
+
() => {
|
|
6934
|
+
try {
|
|
6935
|
+
const sessions2 = agentSessionManager.listSessionsWithWorktreeInfo();
|
|
6936
|
+
if (sessions2.length === 0) {
|
|
6937
|
+
return "No active sessions.";
|
|
6938
|
+
}
|
|
6939
|
+
const sessionLines = sessions2.map((s) => {
|
|
6940
|
+
const worktreeInfo = s.worktreeInfo ? s.worktreeInfo.isWorktree ? ` (worktree: ${s.worktreeInfo.workspace}/${s.worktreeInfo.project}--${s.worktreeInfo.branch})` : ` (main: ${s.worktreeInfo.workspace}/${s.worktreeInfo.project})` : "";
|
|
6941
|
+
const executing = s.isExecuting ? " [executing]" : "";
|
|
6942
|
+
return `- [${s.agentType}] ${s.sessionId}${executing}${worktreeInfo}
|
|
6943
|
+
Working dir: ${s.workingDir}`;
|
|
6944
|
+
});
|
|
6945
|
+
return `Active sessions:
|
|
6946
|
+
${sessionLines.join("\n")}`;
|
|
6947
|
+
} catch (error) {
|
|
6948
|
+
return `Error listing sessions: ${error instanceof Error ? error.message : String(error)}`;
|
|
6949
|
+
}
|
|
6950
|
+
},
|
|
6951
|
+
{
|
|
6952
|
+
name: "list_sessions_with_worktrees",
|
|
6953
|
+
description: "Lists all active sessions with worktree information for branch management",
|
|
6954
|
+
schema: z5.object({})
|
|
6955
|
+
}
|
|
6956
|
+
);
|
|
6957
|
+
const getWorktreeSessionSummary = tool3(
|
|
6958
|
+
({ workspace, project, branch }) => {
|
|
6959
|
+
try {
|
|
6960
|
+
const summary = agentSessionManager.getWorktreeSessionSummary(workspace, project, branch);
|
|
6961
|
+
if (summary.sessionCount === 0) {
|
|
6962
|
+
return `No active sessions in worktree "${workspace}/${project}--${branch}".`;
|
|
6963
|
+
}
|
|
6964
|
+
const sessionDetails = summary.activeSessions.map(
|
|
6965
|
+
(s) => `- [${s.agentType}] ${s.sessionId} (${s.isExecuting ? "executing" : "idle"})
|
|
6966
|
+
Created: ${new Date(s.createdAt).toISOString()}`
|
|
6967
|
+
).join("\n");
|
|
6968
|
+
return `Worktree "${workspace}/${project}--${branch}" has ${summary.sessionCount} active session(s):
|
|
6969
|
+
${sessionDetails}
|
|
6970
|
+
|
|
6971
|
+
Session types: ${summary.sessionTypes.join(", ")}
|
|
6972
|
+
Executing: ${summary.executingCount}`;
|
|
6973
|
+
} catch (error) {
|
|
6974
|
+
return `Error getting worktree session summary: ${error instanceof Error ? error.message : String(error)}`;
|
|
6975
|
+
}
|
|
6976
|
+
},
|
|
6977
|
+
{
|
|
6978
|
+
name: "get_worktree_session_summary",
|
|
6979
|
+
description: "Gets detailed session information for a specific worktree",
|
|
6980
|
+
schema: z5.object({
|
|
6981
|
+
workspace: z5.string().describe("Workspace name"),
|
|
6982
|
+
project: z5.string().describe("Project name"),
|
|
6983
|
+
branch: z5.string().describe("Branch/worktree name")
|
|
6984
|
+
})
|
|
6985
|
+
}
|
|
6986
|
+
);
|
|
6987
|
+
const terminateWorktreeSessions = tool3(
|
|
6988
|
+
({ workspace, project, branch }) => {
|
|
6989
|
+
try {
|
|
6990
|
+
const terminatedSessions = agentSessionManager.terminateWorktreeSessions(workspace, project, branch);
|
|
6991
|
+
if (terminatedSessions.length === 0) {
|
|
6992
|
+
return `No active sessions to terminate in worktree "${workspace}/${project}--${branch}".`;
|
|
6993
|
+
}
|
|
6994
|
+
return `Terminated ${terminatedSessions.length} session(s) in worktree "${workspace}/${project}--${branch}":
|
|
6995
|
+
${terminatedSessions.map((id) => ` - ${id}`).join("\n")}`;
|
|
6996
|
+
} catch (error) {
|
|
6997
|
+
return `Error terminating worktree sessions: ${error instanceof Error ? error.message : String(error)}`;
|
|
6998
|
+
}
|
|
6999
|
+
},
|
|
7000
|
+
{
|
|
7001
|
+
name: "terminate_worktree_sessions",
|
|
7002
|
+
description: "Terminates all active sessions in a specific worktree",
|
|
7003
|
+
schema: z5.object({
|
|
7004
|
+
workspace: z5.string().describe("Workspace name"),
|
|
7005
|
+
project: z5.string().describe("Project name"),
|
|
7006
|
+
branch: z5.string().describe("Branch/worktree name")
|
|
7007
|
+
})
|
|
7008
|
+
}
|
|
7009
|
+
);
|
|
7010
|
+
return [
|
|
7011
|
+
listSessions,
|
|
7012
|
+
listAvailableAgents,
|
|
7013
|
+
createAgentSession,
|
|
7014
|
+
createTerminalSession,
|
|
7015
|
+
terminateSession,
|
|
7016
|
+
terminateAllSessions,
|
|
7017
|
+
getSessionInfo,
|
|
7018
|
+
listSessionsWithWorktrees,
|
|
7019
|
+
getWorktreeSessionSummary,
|
|
7020
|
+
terminateWorktreeSessions
|
|
7021
|
+
];
|
|
6152
7022
|
}
|
|
6153
7023
|
|
|
6154
7024
|
// src/infrastructure/agents/supervisor/tools/filesystem-tools.ts
|
|
@@ -6280,7 +7150,7 @@ var SupervisorAgent = class extends EventEmitter4 {
|
|
|
6280
7150
|
const llm = this.createLLM(env);
|
|
6281
7151
|
const tools = [
|
|
6282
7152
|
...createWorkspaceTools(config2.workspaceDiscovery),
|
|
6283
|
-
...createWorktreeTools(config2.workspaceDiscovery),
|
|
7153
|
+
...createWorktreeTools(config2.workspaceDiscovery, config2.agentSessionManager),
|
|
6284
7154
|
...createSessionTools(
|
|
6285
7155
|
config2.sessionManager,
|
|
6286
7156
|
config2.agentSessionManager,
|
|
@@ -6574,6 +7444,7 @@ Your role is to help users:
|
|
|
6574
7444
|
2. **Manage git worktrees** - Create, list, and remove worktrees for parallel development
|
|
6575
7445
|
3. **Manage sessions** - Create and terminate agent sessions (Cursor, Claude, OpenCode) and terminal sessions
|
|
6576
7446
|
4. **Navigate the file system** - List directories and read files
|
|
7447
|
+
5. **Complete feature workflows** - Merge branches, clean up worktrees, and manage related sessions
|
|
6577
7448
|
|
|
6578
7449
|
## CRITICAL: Always Use Tools - Never Be Lazy
|
|
6579
7450
|
|
|
@@ -6604,12 +7475,48 @@ Your role is to help users:
|
|
|
6604
7475
|
- Call create_agent_session/create_terminal_session EVERY time user asks to create a session
|
|
6605
7476
|
- Never say "based on our previous conversation" or "as I mentioned earlier" for factual data
|
|
6606
7477
|
|
|
7478
|
+
## Feature Completion & Merge Workflows
|
|
7479
|
+
|
|
7480
|
+
When users ask to "complete the feature", "finish the work", "merge and clean up", or similar requests:
|
|
7481
|
+
|
|
7482
|
+
### Safety Checks First:
|
|
7483
|
+
1. **Check branch status** with \`branch_status\` - Look for uncommitted changes
|
|
7484
|
+
2. **List active sessions** with \`get_worktree_session_summary\` - Find sessions in the worktree
|
|
7485
|
+
3. **Ask for confirmation** if there are uncommitted changes or active sessions
|
|
7486
|
+
|
|
7487
|
+
### Complete Workflow with \`complete_feature\`:
|
|
7488
|
+
- Merges feature branch into main with automatic push
|
|
7489
|
+
- Cleans up the worktree and removes the branch if merged
|
|
7490
|
+
- One-command solution for feature completion
|
|
7491
|
+
|
|
7492
|
+
### Step-by-Step Alternative:
|
|
7493
|
+
1. **Handle uncommitted changes**: Commit, stash, or get user confirmation
|
|
7494
|
+
2. **Terminate sessions**: Use \`terminate_worktree_sessions\` to clean up active sessions
|
|
7495
|
+
3. **Merge branch**: Use \`merge_branch\` with pushAfter=true
|
|
7496
|
+
4. **Cleanup worktree**: Use \`cleanup_worktree\` to remove worktree directory
|
|
7497
|
+
|
|
7498
|
+
### Available Merge Tools:
|
|
7499
|
+
- **branch_status** - Check current branch state and uncommitted changes
|
|
7500
|
+
- **merge_branch** - Safe merge with conflict detection and push
|
|
7501
|
+
- **complete_feature** - Full workflow (merge + cleanup + push)
|
|
7502
|
+
- **cleanup_worktree** - Remove worktree and delete merged branch
|
|
7503
|
+
- **list_mergeable_branches** - Show all branches and their cleanup eligibility
|
|
7504
|
+
- **get_worktree_session_summary** - List sessions in a specific worktree
|
|
7505
|
+
- **terminate_worktree_sessions** - End all sessions in a worktree
|
|
7506
|
+
|
|
7507
|
+
### Error Handling:
|
|
7508
|
+
- **Merge conflicts**: Report conflicting files and suggest manual resolution
|
|
7509
|
+
- **Uncommitted changes**: Offer to commit, stash, or force cleanup
|
|
7510
|
+
- **Active sessions**: List sessions and ask for termination confirmation
|
|
7511
|
+
- **Failed pushes**: Continue with local merge, warn about remote sync
|
|
7512
|
+
|
|
6607
7513
|
## Guidelines:
|
|
6608
7514
|
- Be concise and helpful
|
|
6609
7515
|
- Use tools to gather information before responding
|
|
6610
7516
|
- When creating sessions, always confirm the workspace and project first
|
|
6611
7517
|
- For ambiguous requests, ask clarifying questions
|
|
6612
7518
|
- Format responses for terminal display (avoid markdown links)
|
|
7519
|
+
- ALWAYS prioritize safety - check before deleting/merging
|
|
6613
7520
|
|
|
6614
7521
|
## Session Types:
|
|
6615
7522
|
- **cursor** - Cursor AI agent for code assistance
|
|
@@ -6622,8 +7529,6 @@ When creating agent sessions, by default use the main project directory (main or
|
|
|
6622
7529
|
- **Default behavior**: Omit the \`worktree\` parameter to create session on the main/master branch (project root directory)
|
|
6623
7530
|
- **Specific worktree**: Only specify \`worktree\` when the user explicitly asks for a feature branch worktree (NOT the main branch)
|
|
6624
7531
|
- **IMPORTANT**: When \`list_worktrees\` shows a worktree named "main" with \`isMain: true\`, this represents the project root directory. Do NOT pass \`worktree: "main"\` - instead, omit the worktree parameter entirely to use the project root.
|
|
6625
|
-
- **Example**: If user says "start claude on tiflis-code", create session WITHOUT worktree parameter (uses project root on main branch)
|
|
6626
|
-
- **Example**: If user says "start claude on tiflis-code feature/auth branch", list worktrees, find the feature worktree name (e.g., "feature-auth"), and pass that as worktree
|
|
6627
7532
|
|
|
6628
7533
|
## Worktree Management:
|
|
6629
7534
|
Worktrees allow working on multiple branches simultaneously in separate directories.
|
|
@@ -6632,8 +7537,7 @@ Worktrees allow working on multiple branches simultaneously in separate director
|
|
|
6632
7537
|
- **Creating worktrees**: Use \`create_worktree\` tool with:
|
|
6633
7538
|
- \`createNewBranch: true\` \u2014 Creates a NEW branch and worktree (most common for new features)
|
|
6634
7539
|
- \`createNewBranch: false\` \u2014 Checks out an EXISTING branch into a worktree
|
|
6635
|
-
- \`baseBranch\` \u2014 Optional starting point for new branches (defaults to HEAD, commonly "main")
|
|
6636
|
-
- **Example**: To start work on a new feature, create worktree with \`createNewBranch: true\`, \`branch: "feature/new-keyboard"\`, \`baseBranch: "main"\``;
|
|
7540
|
+
- \`baseBranch\` \u2014 Optional starting point for new branches (defaults to HEAD, commonly "main")`;
|
|
6637
7541
|
return [new HumanMessage(`[System Instructions]
|
|
6638
7542
|
${systemPrompt}
|
|
6639
7543
|
[End Instructions]`)];
|
|
@@ -6663,11 +7567,517 @@ ${systemPrompt}
|
|
|
6663
7567
|
}
|
|
6664
7568
|
};
|
|
6665
7569
|
|
|
7570
|
+
// src/infrastructure/mock/mock-supervisor-agent.ts
|
|
7571
|
+
import { EventEmitter as EventEmitter5 } from "events";
|
|
7572
|
+
|
|
7573
|
+
// src/infrastructure/mock/fixture-loader.ts
|
|
7574
|
+
import { readFileSync as readFileSync2, existsSync as existsSync3 } from "fs";
|
|
7575
|
+
import { join as join7, dirname as dirname2 } from "path";
|
|
7576
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
7577
|
+
var __filename = fileURLToPath2(import.meta.url);
|
|
7578
|
+
var __dirname = dirname2(__filename);
|
|
7579
|
+
var DEFAULT_FIXTURES_PATH = join7(__dirname, "fixtures");
|
|
7580
|
+
var fixtureCache = /* @__PURE__ */ new Map();
|
|
7581
|
+
function loadFixture(name, customPath) {
|
|
7582
|
+
const cacheKey = `${customPath ?? "default"}:${name}`;
|
|
7583
|
+
if (fixtureCache.has(cacheKey)) {
|
|
7584
|
+
return fixtureCache.get(cacheKey);
|
|
7585
|
+
}
|
|
7586
|
+
const fixturesDir = customPath ?? DEFAULT_FIXTURES_PATH;
|
|
7587
|
+
const filePath = join7(fixturesDir, `${name}.json`);
|
|
7588
|
+
if (!existsSync3(filePath)) {
|
|
7589
|
+
console.warn(`[MockMode] Fixture not found: ${filePath}`);
|
|
7590
|
+
return null;
|
|
7591
|
+
}
|
|
7592
|
+
try {
|
|
7593
|
+
const content = readFileSync2(filePath, "utf-8");
|
|
7594
|
+
const fixture = JSON.parse(content);
|
|
7595
|
+
fixtureCache.set(cacheKey, fixture);
|
|
7596
|
+
return fixture;
|
|
7597
|
+
} catch (error) {
|
|
7598
|
+
console.error(`[MockMode] Failed to load fixture ${filePath}:`, error);
|
|
7599
|
+
return null;
|
|
7600
|
+
}
|
|
7601
|
+
}
|
|
7602
|
+
function findMatchingResponse(fixture, input) {
|
|
7603
|
+
const normalizedInput = input.toLowerCase().trim();
|
|
7604
|
+
for (const scenario of Object.values(fixture.scenarios)) {
|
|
7605
|
+
for (const trigger of scenario.triggers) {
|
|
7606
|
+
if (normalizedInput.includes(trigger.toLowerCase())) {
|
|
7607
|
+
return scenario.response;
|
|
7608
|
+
}
|
|
7609
|
+
}
|
|
7610
|
+
}
|
|
7611
|
+
return fixture.default_response;
|
|
7612
|
+
}
|
|
7613
|
+
|
|
7614
|
+
// src/infrastructure/mock/streaming-simulator.ts
|
|
7615
|
+
var DEFAULT_TOKEN_DELAY_MS = 30;
|
|
7616
|
+
async function simulateStreaming(text2, delayMs = DEFAULT_TOKEN_DELAY_MS, onBlock, onComplete) {
|
|
7617
|
+
const tokens = tokenize(text2);
|
|
7618
|
+
let accumulated = "";
|
|
7619
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
7620
|
+
accumulated += tokens[i];
|
|
7621
|
+
const block = {
|
|
7622
|
+
type: "text",
|
|
7623
|
+
text: accumulated
|
|
7624
|
+
};
|
|
7625
|
+
onBlock([block], false);
|
|
7626
|
+
if (i < tokens.length - 1) {
|
|
7627
|
+
await sleep(delayMs);
|
|
7628
|
+
}
|
|
7629
|
+
}
|
|
7630
|
+
const finalBlock = {
|
|
7631
|
+
type: "text",
|
|
7632
|
+
text: accumulated
|
|
7633
|
+
};
|
|
7634
|
+
onBlock([finalBlock], true);
|
|
7635
|
+
onComplete();
|
|
7636
|
+
}
|
|
7637
|
+
function tokenize(text2) {
|
|
7638
|
+
const tokens = [];
|
|
7639
|
+
let current = "";
|
|
7640
|
+
for (const char of text2) {
|
|
7641
|
+
if (char === " ") {
|
|
7642
|
+
if (current) {
|
|
7643
|
+
tokens.push(current);
|
|
7644
|
+
current = "";
|
|
7645
|
+
}
|
|
7646
|
+
tokens.push(" ");
|
|
7647
|
+
} else if (/[.,!?;:\n]/.test(char)) {
|
|
7648
|
+
if (current) {
|
|
7649
|
+
tokens.push(current);
|
|
7650
|
+
current = "";
|
|
7651
|
+
}
|
|
7652
|
+
tokens.push(char);
|
|
7653
|
+
} else {
|
|
7654
|
+
current += char;
|
|
7655
|
+
}
|
|
7656
|
+
}
|
|
7657
|
+
if (current) {
|
|
7658
|
+
tokens.push(current);
|
|
7659
|
+
}
|
|
7660
|
+
return tokens;
|
|
7661
|
+
}
|
|
7662
|
+
function sleep(ms) {
|
|
7663
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
7664
|
+
}
|
|
7665
|
+
|
|
7666
|
+
// src/infrastructure/mock/mock-supervisor-agent.ts
|
|
7667
|
+
var MockSupervisorAgent = class extends EventEmitter5 {
|
|
7668
|
+
logger;
|
|
7669
|
+
fixturesPath;
|
|
7670
|
+
fixture;
|
|
7671
|
+
conversationHistory = [];
|
|
7672
|
+
isExecuting = false;
|
|
7673
|
+
isProcessingCommand = false;
|
|
7674
|
+
isCancelled = false;
|
|
7675
|
+
abortController = null;
|
|
7676
|
+
constructor(config2) {
|
|
7677
|
+
super();
|
|
7678
|
+
this.logger = config2.logger.child({ component: "MockSupervisorAgent" });
|
|
7679
|
+
this.fixturesPath = config2.fixturesPath;
|
|
7680
|
+
this.fixture = loadFixture("supervisor", this.fixturesPath);
|
|
7681
|
+
if (this.fixture) {
|
|
7682
|
+
this.logger.info(
|
|
7683
|
+
{ scenarios: Object.keys(this.fixture.scenarios).length },
|
|
7684
|
+
"Mock Supervisor Agent initialized with fixtures"
|
|
7685
|
+
);
|
|
7686
|
+
} else {
|
|
7687
|
+
this.logger.warn(
|
|
7688
|
+
"Mock Supervisor Agent initialized without fixtures - will return default responses"
|
|
7689
|
+
);
|
|
7690
|
+
}
|
|
7691
|
+
}
|
|
7692
|
+
/**
|
|
7693
|
+
* Executes a command (non-streaming).
|
|
7694
|
+
*/
|
|
7695
|
+
async execute(command, deviceId, _currentSessionId) {
|
|
7696
|
+
this.logger.info({ command, deviceId }, "Mock supervisor execute");
|
|
7697
|
+
const response = this.getResponse(command);
|
|
7698
|
+
this.conversationHistory.push({ role: "user", content: command });
|
|
7699
|
+
this.conversationHistory.push({ role: "assistant", content: response.text });
|
|
7700
|
+
return {
|
|
7701
|
+
output: response.text
|
|
7702
|
+
};
|
|
7703
|
+
}
|
|
7704
|
+
/**
|
|
7705
|
+
* Executes a command with simulated streaming.
|
|
7706
|
+
*/
|
|
7707
|
+
async executeWithStream(command, deviceId) {
|
|
7708
|
+
this.logger.info({ command, deviceId }, "Mock supervisor executeWithStream");
|
|
7709
|
+
this.abortController = new AbortController();
|
|
7710
|
+
this.isExecuting = true;
|
|
7711
|
+
this.isCancelled = false;
|
|
7712
|
+
try {
|
|
7713
|
+
const response = this.getResponse(command);
|
|
7714
|
+
if (this.isExecuting && !this.isCancelled) {
|
|
7715
|
+
const statusBlock = createStatusBlock("Processing...");
|
|
7716
|
+
this.emit("blocks", deviceId, [statusBlock], false);
|
|
7717
|
+
}
|
|
7718
|
+
await this.sleep(100);
|
|
7719
|
+
const allBlocks = [];
|
|
7720
|
+
await simulateStreaming(
|
|
7721
|
+
response.text,
|
|
7722
|
+
response.delay_ms ?? 30,
|
|
7723
|
+
(blocks, isComplete) => {
|
|
7724
|
+
if (this.isExecuting && !this.isCancelled) {
|
|
7725
|
+
this.emit("blocks", deviceId, blocks, false);
|
|
7726
|
+
if (isComplete) {
|
|
7727
|
+
allBlocks.push(...blocks);
|
|
7728
|
+
}
|
|
7729
|
+
}
|
|
7730
|
+
},
|
|
7731
|
+
() => {
|
|
7732
|
+
}
|
|
7733
|
+
);
|
|
7734
|
+
if (this.isExecuting && !this.isCancelled) {
|
|
7735
|
+
this.conversationHistory.push({ role: "user", content: command });
|
|
7736
|
+
this.conversationHistory.push({
|
|
7737
|
+
role: "assistant",
|
|
7738
|
+
content: response.text
|
|
7739
|
+
});
|
|
7740
|
+
const completionBlock = createStatusBlock("Complete");
|
|
7741
|
+
this.emit(
|
|
7742
|
+
"blocks",
|
|
7743
|
+
deviceId,
|
|
7744
|
+
[completionBlock],
|
|
7745
|
+
true,
|
|
7746
|
+
response.text,
|
|
7747
|
+
allBlocks
|
|
7748
|
+
);
|
|
7749
|
+
}
|
|
7750
|
+
} catch (error) {
|
|
7751
|
+
if (this.isCancelled) {
|
|
7752
|
+
this.logger.info({ deviceId }, "Mock supervisor cancelled");
|
|
7753
|
+
return;
|
|
7754
|
+
}
|
|
7755
|
+
this.logger.error({ error, command }, "Mock supervisor error");
|
|
7756
|
+
const errorBlock = createTextBlock(
|
|
7757
|
+
error instanceof Error ? error.message : "An error occurred"
|
|
7758
|
+
);
|
|
7759
|
+
this.emit("blocks", deviceId, [errorBlock], true);
|
|
7760
|
+
} finally {
|
|
7761
|
+
this.isExecuting = false;
|
|
7762
|
+
this.abortController = null;
|
|
7763
|
+
}
|
|
7764
|
+
}
|
|
7765
|
+
/**
|
|
7766
|
+
* Gets the response for a command from fixtures.
|
|
7767
|
+
*/
|
|
7768
|
+
getResponse(command) {
|
|
7769
|
+
if (!this.fixture) {
|
|
7770
|
+
return {
|
|
7771
|
+
text: "I'm the Supervisor agent. I can help you manage workspaces, sessions, and more. What would you like to do?",
|
|
7772
|
+
delay_ms: 30
|
|
7773
|
+
};
|
|
7774
|
+
}
|
|
7775
|
+
return findMatchingResponse(this.fixture, command);
|
|
7776
|
+
}
|
|
7777
|
+
/**
|
|
7778
|
+
* Cancels current execution.
|
|
7779
|
+
*/
|
|
7780
|
+
cancel() {
|
|
7781
|
+
if (!this.isProcessingCommand && !this.isExecuting) {
|
|
7782
|
+
return false;
|
|
7783
|
+
}
|
|
7784
|
+
this.logger.info("Cancelling mock supervisor execution");
|
|
7785
|
+
this.isCancelled = true;
|
|
7786
|
+
this.isExecuting = false;
|
|
7787
|
+
this.isProcessingCommand = false;
|
|
7788
|
+
if (this.abortController) {
|
|
7789
|
+
this.abortController.abort();
|
|
7790
|
+
}
|
|
7791
|
+
return true;
|
|
7792
|
+
}
|
|
7793
|
+
/**
|
|
7794
|
+
* Check if execution was cancelled.
|
|
7795
|
+
*/
|
|
7796
|
+
wasCancelled() {
|
|
7797
|
+
return this.isCancelled;
|
|
7798
|
+
}
|
|
7799
|
+
/**
|
|
7800
|
+
* Starts command processing.
|
|
7801
|
+
*/
|
|
7802
|
+
startProcessing() {
|
|
7803
|
+
this.abortController = new AbortController();
|
|
7804
|
+
this.isProcessingCommand = true;
|
|
7805
|
+
this.isCancelled = false;
|
|
7806
|
+
return this.abortController;
|
|
7807
|
+
}
|
|
7808
|
+
/**
|
|
7809
|
+
* Checks if processing is active.
|
|
7810
|
+
*/
|
|
7811
|
+
isProcessing() {
|
|
7812
|
+
return this.isProcessingCommand || this.isExecuting;
|
|
7813
|
+
}
|
|
7814
|
+
/**
|
|
7815
|
+
* Ends command processing.
|
|
7816
|
+
*/
|
|
7817
|
+
endProcessing() {
|
|
7818
|
+
this.isProcessingCommand = false;
|
|
7819
|
+
}
|
|
7820
|
+
/**
|
|
7821
|
+
* Clears conversation history.
|
|
7822
|
+
*/
|
|
7823
|
+
clearHistory() {
|
|
7824
|
+
this.conversationHistory = [];
|
|
7825
|
+
this.isCancelled = false;
|
|
7826
|
+
this.logger.info("Mock conversation history cleared");
|
|
7827
|
+
}
|
|
7828
|
+
/**
|
|
7829
|
+
* Resets cancellation state.
|
|
7830
|
+
*/
|
|
7831
|
+
resetCancellationState() {
|
|
7832
|
+
this.isCancelled = false;
|
|
7833
|
+
}
|
|
7834
|
+
/**
|
|
7835
|
+
* Restores conversation history.
|
|
7836
|
+
*/
|
|
7837
|
+
restoreHistory(history) {
|
|
7838
|
+
this.conversationHistory = history.slice(-20);
|
|
7839
|
+
}
|
|
7840
|
+
/**
|
|
7841
|
+
* Gets conversation history.
|
|
7842
|
+
*/
|
|
7843
|
+
getConversationHistory() {
|
|
7844
|
+
return [...this.conversationHistory];
|
|
7845
|
+
}
|
|
7846
|
+
/**
|
|
7847
|
+
* Sleep utility.
|
|
7848
|
+
*/
|
|
7849
|
+
sleep(ms) {
|
|
7850
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
7851
|
+
}
|
|
7852
|
+
};
|
|
7853
|
+
|
|
7854
|
+
// src/infrastructure/mock/mock-agent-session-manager.ts
|
|
7855
|
+
import { EventEmitter as EventEmitter6 } from "events";
|
|
7856
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
7857
|
+
var MockAgentSessionManager = class extends EventEmitter6 {
|
|
7858
|
+
sessions = /* @__PURE__ */ new Map();
|
|
7859
|
+
fixtures = /* @__PURE__ */ new Map();
|
|
7860
|
+
logger;
|
|
7861
|
+
fixturesPath;
|
|
7862
|
+
constructor(config2) {
|
|
7863
|
+
super();
|
|
7864
|
+
this.logger = config2.logger.child({ component: "MockAgentSessionManager" });
|
|
7865
|
+
this.fixturesPath = config2.fixturesPath;
|
|
7866
|
+
this.loadAgentFixtures();
|
|
7867
|
+
this.logger.info("Mock Agent Session Manager initialized");
|
|
7868
|
+
}
|
|
7869
|
+
/**
|
|
7870
|
+
* Pre-load fixtures for all agent types.
|
|
7871
|
+
*/
|
|
7872
|
+
loadAgentFixtures() {
|
|
7873
|
+
const agentTypes = ["cursor", "claude", "opencode"];
|
|
7874
|
+
for (const agentType of agentTypes) {
|
|
7875
|
+
const fixture = loadFixture(agentType, this.fixturesPath);
|
|
7876
|
+
this.fixtures.set(agentType, fixture);
|
|
7877
|
+
if (fixture) {
|
|
7878
|
+
this.logger.debug(
|
|
7879
|
+
{ agentType, scenarios: Object.keys(fixture.scenarios).length },
|
|
7880
|
+
"Loaded fixture for agent type"
|
|
7881
|
+
);
|
|
7882
|
+
}
|
|
7883
|
+
}
|
|
7884
|
+
}
|
|
7885
|
+
/**
|
|
7886
|
+
* Create a new mock agent session.
|
|
7887
|
+
*/
|
|
7888
|
+
createSession(agentType, workingDir, sessionId, agentName) {
|
|
7889
|
+
const id = sessionId ?? `agent-${randomUUID3()}`;
|
|
7890
|
+
const resolvedAgentName = agentName ?? agentType;
|
|
7891
|
+
const state = {
|
|
7892
|
+
sessionId: id,
|
|
7893
|
+
agentType,
|
|
7894
|
+
agentName: resolvedAgentName,
|
|
7895
|
+
workingDir,
|
|
7896
|
+
cliSessionId: `mock-cli-${randomUUID3().slice(0, 8)}`,
|
|
7897
|
+
isExecuting: false,
|
|
7898
|
+
isCancelled: false,
|
|
7899
|
+
messages: [],
|
|
7900
|
+
createdAt: Date.now(),
|
|
7901
|
+
lastActivityAt: Date.now()
|
|
7902
|
+
};
|
|
7903
|
+
this.sessions.set(id, state);
|
|
7904
|
+
this.logger.info(
|
|
7905
|
+
{ sessionId: id, agentType, agentName: resolvedAgentName, workingDir },
|
|
7906
|
+
"Mock agent session created"
|
|
7907
|
+
);
|
|
7908
|
+
this.emit("sessionCreated", state);
|
|
7909
|
+
this.emit("cliSessionIdDiscovered", id, state.cliSessionId);
|
|
7910
|
+
return state;
|
|
7911
|
+
}
|
|
7912
|
+
/**
|
|
7913
|
+
* Execute a command in a mock agent session with simulated streaming.
|
|
7914
|
+
*/
|
|
7915
|
+
async executeCommand(sessionId, prompt) {
|
|
7916
|
+
const state = this.sessions.get(sessionId);
|
|
7917
|
+
if (!state) {
|
|
7918
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
7919
|
+
}
|
|
7920
|
+
if (state.isExecuting) {
|
|
7921
|
+
this.cancelCommand(sessionId);
|
|
7922
|
+
}
|
|
7923
|
+
state.isExecuting = true;
|
|
7924
|
+
state.isCancelled = false;
|
|
7925
|
+
state.lastActivityAt = Date.now();
|
|
7926
|
+
const userMessage = {
|
|
7927
|
+
id: randomUUID3(),
|
|
7928
|
+
timestamp: Date.now(),
|
|
7929
|
+
role: "user",
|
|
7930
|
+
blocks: [createTextBlock(prompt)]
|
|
7931
|
+
};
|
|
7932
|
+
state.messages.push(userMessage);
|
|
7933
|
+
try {
|
|
7934
|
+
const fixture = this.fixtures.get(state.agentType);
|
|
7935
|
+
const response = fixture ? findMatchingResponse(fixture, prompt) : this.getDefaultResponse(state.agentType);
|
|
7936
|
+
await this.sleep(150);
|
|
7937
|
+
const allBlocks = [];
|
|
7938
|
+
await simulateStreaming(
|
|
7939
|
+
response.text,
|
|
7940
|
+
response.delay_ms ?? 30,
|
|
7941
|
+
(blocks, _isComplete) => {
|
|
7942
|
+
if (state.isExecuting && !state.isCancelled) {
|
|
7943
|
+
this.emit("blocks", sessionId, blocks, false);
|
|
7944
|
+
}
|
|
7945
|
+
},
|
|
7946
|
+
() => {
|
|
7947
|
+
}
|
|
7948
|
+
);
|
|
7949
|
+
if (state.isExecuting && !state.isCancelled) {
|
|
7950
|
+
const assistantMessage = {
|
|
7951
|
+
id: randomUUID3(),
|
|
7952
|
+
timestamp: Date.now(),
|
|
7953
|
+
role: "assistant",
|
|
7954
|
+
blocks: [createTextBlock(response.text)]
|
|
7955
|
+
};
|
|
7956
|
+
state.messages.push(assistantMessage);
|
|
7957
|
+
allBlocks.push(createTextBlock(response.text));
|
|
7958
|
+
const completionBlocks = [createStatusBlock("Command completed")];
|
|
7959
|
+
const completionMsg = {
|
|
7960
|
+
id: randomUUID3(),
|
|
7961
|
+
timestamp: Date.now(),
|
|
7962
|
+
role: "system",
|
|
7963
|
+
blocks: completionBlocks
|
|
7964
|
+
};
|
|
7965
|
+
state.messages.push(completionMsg);
|
|
7966
|
+
this.emit("blocks", sessionId, completionBlocks, true);
|
|
7967
|
+
}
|
|
7968
|
+
} catch (error) {
|
|
7969
|
+
if (!state.isCancelled) {
|
|
7970
|
+
this.logger.error({ sessionId, error }, "Mock command execution error");
|
|
7971
|
+
const errorBlocks = [
|
|
7972
|
+
createTextBlock(
|
|
7973
|
+
error instanceof Error ? error.message : "An error occurred"
|
|
7974
|
+
)
|
|
7975
|
+
];
|
|
7976
|
+
this.emit("blocks", sessionId, errorBlocks, true);
|
|
7977
|
+
}
|
|
7978
|
+
} finally {
|
|
7979
|
+
state.isExecuting = false;
|
|
7980
|
+
state.lastActivityAt = Date.now();
|
|
7981
|
+
}
|
|
7982
|
+
}
|
|
7983
|
+
/**
|
|
7984
|
+
* Get default response when no fixture is available.
|
|
7985
|
+
*/
|
|
7986
|
+
getDefaultResponse(agentType) {
|
|
7987
|
+
const responses = {
|
|
7988
|
+
claude: "I'm Claude, an AI assistant. I can help you with coding tasks, answer questions, and assist with various development workflows. What would you like me to help you with?",
|
|
7989
|
+
cursor: "I'm Cursor AI, ready to help you write and edit code. I can assist with code completion, refactoring, and explaining complex code. What can I help you with today?",
|
|
7990
|
+
opencode: "I'm OpenCode, an open-source AI coding assistant. I can help with code generation, debugging, and documentation. How can I assist you?"
|
|
7991
|
+
};
|
|
7992
|
+
return {
|
|
7993
|
+
text: responses[agentType],
|
|
7994
|
+
delay_ms: 30
|
|
7995
|
+
};
|
|
7996
|
+
}
|
|
7997
|
+
/**
|
|
7998
|
+
* Cancel current command execution.
|
|
7999
|
+
*/
|
|
8000
|
+
cancelCommand(sessionId) {
|
|
8001
|
+
const state = this.sessions.get(sessionId);
|
|
8002
|
+
if (!state?.isExecuting) {
|
|
8003
|
+
return;
|
|
8004
|
+
}
|
|
8005
|
+
this.logger.info({ sessionId }, "Cancelling mock command execution");
|
|
8006
|
+
state.isExecuting = false;
|
|
8007
|
+
state.isCancelled = true;
|
|
8008
|
+
state.lastActivityAt = Date.now();
|
|
8009
|
+
}
|
|
8010
|
+
/**
|
|
8011
|
+
* Clear chat history for a session.
|
|
8012
|
+
*/
|
|
8013
|
+
clearHistory(sessionId) {
|
|
8014
|
+
const state = this.sessions.get(sessionId);
|
|
8015
|
+
if (!state) {
|
|
8016
|
+
return;
|
|
8017
|
+
}
|
|
8018
|
+
state.messages = [];
|
|
8019
|
+
this.logger.info({ sessionId }, "Mock session history cleared");
|
|
8020
|
+
}
|
|
8021
|
+
/**
|
|
8022
|
+
* Terminate an agent session.
|
|
8023
|
+
*/
|
|
8024
|
+
terminateSession(sessionId) {
|
|
8025
|
+
this.sessions.delete(sessionId);
|
|
8026
|
+
this.logger.info({ sessionId }, "Mock agent session terminated");
|
|
8027
|
+
this.emit("sessionTerminated", sessionId);
|
|
8028
|
+
}
|
|
8029
|
+
/**
|
|
8030
|
+
* Get session state.
|
|
8031
|
+
*/
|
|
8032
|
+
getSession(sessionId) {
|
|
8033
|
+
return this.sessions.get(sessionId);
|
|
8034
|
+
}
|
|
8035
|
+
/**
|
|
8036
|
+
* List all active sessions.
|
|
8037
|
+
*/
|
|
8038
|
+
listSessions() {
|
|
8039
|
+
return Array.from(this.sessions.values());
|
|
8040
|
+
}
|
|
8041
|
+
/**
|
|
8042
|
+
* Get chat history for a session.
|
|
8043
|
+
*/
|
|
8044
|
+
getMessages(sessionId) {
|
|
8045
|
+
return this.sessions.get(sessionId)?.messages ?? [];
|
|
8046
|
+
}
|
|
8047
|
+
/**
|
|
8048
|
+
* Check if a session is executing.
|
|
8049
|
+
*/
|
|
8050
|
+
isExecuting(sessionId) {
|
|
8051
|
+
return this.sessions.get(sessionId)?.isExecuting ?? false;
|
|
8052
|
+
}
|
|
8053
|
+
/**
|
|
8054
|
+
* Check if a session was cancelled.
|
|
8055
|
+
*/
|
|
8056
|
+
wasCancelled(sessionId) {
|
|
8057
|
+
return this.sessions.get(sessionId)?.isCancelled ?? false;
|
|
8058
|
+
}
|
|
8059
|
+
/**
|
|
8060
|
+
* Cleanup all sessions.
|
|
8061
|
+
*/
|
|
8062
|
+
cleanup() {
|
|
8063
|
+
const sessionIds = Array.from(this.sessions.keys());
|
|
8064
|
+
for (const id of sessionIds) {
|
|
8065
|
+
this.terminateSession(id);
|
|
8066
|
+
}
|
|
8067
|
+
}
|
|
8068
|
+
/**
|
|
8069
|
+
* Sleep utility.
|
|
8070
|
+
*/
|
|
8071
|
+
sleep(ms) {
|
|
8072
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
8073
|
+
}
|
|
8074
|
+
};
|
|
8075
|
+
|
|
6666
8076
|
// src/infrastructure/speech/stt-service.ts
|
|
6667
8077
|
import { writeFile as writeFile2, unlink as unlink2 } from "fs/promises";
|
|
6668
|
-
import { join as
|
|
8078
|
+
import { join as join8 } from "path";
|
|
6669
8079
|
import { tmpdir } from "os";
|
|
6670
|
-
import { randomUUID as
|
|
8080
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
6671
8081
|
var STTService = class {
|
|
6672
8082
|
config;
|
|
6673
8083
|
logger;
|
|
@@ -6708,7 +8118,7 @@ var STTService = class {
|
|
|
6708
8118
|
async transcribeOpenAI(audioBuffer, format, signal) {
|
|
6709
8119
|
const baseUrl = this.config.baseUrl ?? "https://api.openai.com/v1";
|
|
6710
8120
|
const endpoint = `${baseUrl}/audio/transcriptions`;
|
|
6711
|
-
const tempPath =
|
|
8121
|
+
const tempPath = join8(tmpdir(), `stt-${randomUUID4()}.${format}`);
|
|
6712
8122
|
try {
|
|
6713
8123
|
if (signal?.aborted) {
|
|
6714
8124
|
throw new Error("Transcription cancelled");
|
|
@@ -6756,7 +8166,7 @@ var STTService = class {
|
|
|
6756
8166
|
async transcribeElevenLabs(audioBuffer, format, signal) {
|
|
6757
8167
|
const baseUrl = this.config.baseUrl ?? "https://api.elevenlabs.io/v1";
|
|
6758
8168
|
const endpoint = `${baseUrl}/speech-to-text`;
|
|
6759
|
-
const tempPath =
|
|
8169
|
+
const tempPath = join8(tmpdir(), `stt-${randomUUID4()}.${format}`);
|
|
6760
8170
|
try {
|
|
6761
8171
|
if (signal?.aborted) {
|
|
6762
8172
|
throw new Error("Transcription cancelled");
|
|
@@ -7269,13 +8679,60 @@ async function bootstrap() {
|
|
|
7269
8679
|
workspacesRoot: env.WORKSPACES_ROOT
|
|
7270
8680
|
});
|
|
7271
8681
|
const ptyManager = new PtyManager({ logger });
|
|
7272
|
-
const agentSessionManager = new AgentSessionManager(logger);
|
|
8682
|
+
const agentSessionManager = env.MOCK_MODE ? new MockAgentSessionManager({ logger, fixturesPath: env.MOCK_FIXTURES_PATH }) : new AgentSessionManager(logger);
|
|
8683
|
+
if (env.MOCK_MODE) {
|
|
8684
|
+
logger.info(
|
|
8685
|
+
{ fixturesPath: env.MOCK_FIXTURES_PATH ?? "built-in" },
|
|
8686
|
+
"Mock mode enabled - using mock agent session manager"
|
|
8687
|
+
);
|
|
8688
|
+
}
|
|
7273
8689
|
const sessionManager = new InMemorySessionManager({
|
|
7274
8690
|
ptyManager,
|
|
7275
8691
|
agentSessionManager,
|
|
7276
8692
|
workspacesRoot: env.WORKSPACES_ROOT,
|
|
7277
8693
|
logger
|
|
7278
8694
|
});
|
|
8695
|
+
if (env.MOCK_MODE) {
|
|
8696
|
+
const mockAgentManager = agentSessionManager;
|
|
8697
|
+
await sessionManager.createSession({
|
|
8698
|
+
sessionType: "supervisor",
|
|
8699
|
+
workingDir: env.WORKSPACES_ROOT
|
|
8700
|
+
});
|
|
8701
|
+
logger.info("Pre-created supervisor session for screenshots");
|
|
8702
|
+
mockAgentManager.createSession(
|
|
8703
|
+
"claude",
|
|
8704
|
+
`${env.WORKSPACES_ROOT}/work/my-app`,
|
|
8705
|
+
"claude-my-app",
|
|
8706
|
+
"claude"
|
|
8707
|
+
);
|
|
8708
|
+
mockAgentManager.createSession(
|
|
8709
|
+
"cursor",
|
|
8710
|
+
`${env.WORKSPACES_ROOT}/personal/blog`,
|
|
8711
|
+
"cursor-blog",
|
|
8712
|
+
"cursor"
|
|
8713
|
+
);
|
|
8714
|
+
mockAgentManager.createSession(
|
|
8715
|
+
"opencode",
|
|
8716
|
+
`${env.WORKSPACES_ROOT}/work/api-service`,
|
|
8717
|
+
"opencode-api",
|
|
8718
|
+
"opencode"
|
|
8719
|
+
);
|
|
8720
|
+
logger.info("Pre-created 3 mock agent sessions for screenshots");
|
|
8721
|
+
chatHistoryService.seedMockData({
|
|
8722
|
+
claude: {
|
|
8723
|
+
id: "claude-my-app",
|
|
8724
|
+
workingDir: `${env.WORKSPACES_ROOT}/work/my-app`
|
|
8725
|
+
},
|
|
8726
|
+
cursor: {
|
|
8727
|
+
id: "cursor-blog",
|
|
8728
|
+
workingDir: `${env.WORKSPACES_ROOT}/personal/blog`
|
|
8729
|
+
},
|
|
8730
|
+
opencode: {
|
|
8731
|
+
id: "opencode-api",
|
|
8732
|
+
workingDir: `${env.WORKSPACES_ROOT}/work/api-service`
|
|
8733
|
+
}
|
|
8734
|
+
});
|
|
8735
|
+
}
|
|
7279
8736
|
const sttService = createSTTService(env, logger);
|
|
7280
8737
|
if (sttService) {
|
|
7281
8738
|
logger.info(
|
|
@@ -7309,7 +8766,10 @@ async function bootstrap() {
|
|
|
7309
8766
|
const cancelledDuringTranscription = /* @__PURE__ */ new Set();
|
|
7310
8767
|
const expectedAuthKey = new AuthKey(env.WORKSTATION_AUTH_KEY);
|
|
7311
8768
|
let messageBroadcaster = null;
|
|
7312
|
-
const supervisorAgent = new
|
|
8769
|
+
const supervisorAgent = env.MOCK_MODE ? new MockSupervisorAgent({
|
|
8770
|
+
logger,
|
|
8771
|
+
fixturesPath: env.MOCK_FIXTURES_PATH
|
|
8772
|
+
}) : new SupervisorAgent({
|
|
7313
8773
|
sessionManager,
|
|
7314
8774
|
agentSessionManager,
|
|
7315
8775
|
workspaceDiscovery,
|
|
@@ -7318,7 +8778,11 @@ async function bootstrap() {
|
|
|
7318
8778
|
getMessageBroadcaster: () => messageBroadcaster,
|
|
7319
8779
|
getChatHistoryService: () => chatHistoryService
|
|
7320
8780
|
});
|
|
7321
|
-
|
|
8781
|
+
if (env.MOCK_MODE) {
|
|
8782
|
+
logger.info("Mock Supervisor Agent initialized for screenshot automation");
|
|
8783
|
+
} else {
|
|
8784
|
+
logger.info("Supervisor Agent initialized with LangGraph");
|
|
8785
|
+
}
|
|
7322
8786
|
const authenticateClient = new AuthenticateClientUseCase({
|
|
7323
8787
|
clientRegistry,
|
|
7324
8788
|
expectedAuthKey,
|
|
@@ -7851,7 +9315,7 @@ async function bootstrap() {
|
|
|
7851
9315
|
logger.info({ wasCancelled }, "supervisorAgent.cancel() returned");
|
|
7852
9316
|
if (messageBroadcaster) {
|
|
7853
9317
|
const cancelBlock = {
|
|
7854
|
-
id:
|
|
9318
|
+
id: randomUUID5(),
|
|
7855
9319
|
block_type: "cancel",
|
|
7856
9320
|
content: "Cancelled by user"
|
|
7857
9321
|
};
|
|
@@ -8086,6 +9550,22 @@ async function bootstrap() {
|
|
|
8086
9550
|
subscribeMessage.device_id,
|
|
8087
9551
|
JSON.stringify(result)
|
|
8088
9552
|
);
|
|
9553
|
+
if (env.MOCK_MODE) {
|
|
9554
|
+
const session = sessionManager.getSession(new SessionId(sessionId));
|
|
9555
|
+
if (session?.type === "terminal") {
|
|
9556
|
+
setTimeout(() => {
|
|
9557
|
+
const clearAndBanner = `clear && printf '\\033[1;36m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\\033[0m\\n\\033[1;32m Tiflis Code - Remote Development Workstation\\033[0m\\n\\033[1;36m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\\033[0m\\n\\n\\033[1;33m System Information:\\033[0m\\n \u251C\u2500 OS: macOS Sequoia 15.1\\n \u251C\u2500 Shell: zsh 5.9\\n \u251C\u2500 Node: v22.11.0\\n \u2514\u2500 Uptime: 2 days, 14 hours\\n\\n\\033[1;33m Active Sessions:\\033[0m\\n \u251C\u2500 Claude Code \u2500 tiflis/tiflis-code\\n \u251C\u2500 Cursor \u2500 personal/portfolio\\n \u2514\u2500 OpenCode \u2500 tiflis/tiflis-api\\n\\n\\033[1;36m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\\033[0m\\n\\n'\r`;
|
|
9558
|
+
ptyManager.write(
|
|
9559
|
+
session,
|
|
9560
|
+
clearAndBanner
|
|
9561
|
+
);
|
|
9562
|
+
logger.info(
|
|
9563
|
+
{ sessionId },
|
|
9564
|
+
"Mock mode: Generated terminal banner on subscribe"
|
|
9565
|
+
);
|
|
9566
|
+
}, 100);
|
|
9567
|
+
}
|
|
9568
|
+
}
|
|
8089
9569
|
}
|
|
8090
9570
|
}
|
|
8091
9571
|
return Promise.resolve();
|
|
@@ -8383,7 +9863,7 @@ async function bootstrap() {
|
|
|
8383
9863
|
}
|
|
8384
9864
|
if (messageBroadcaster) {
|
|
8385
9865
|
const cancelBlock = {
|
|
8386
|
-
id:
|
|
9866
|
+
id: randomUUID5(),
|
|
8387
9867
|
block_type: "cancel",
|
|
8388
9868
|
content: "Cancelled by user"
|
|
8389
9869
|
};
|
|
@@ -9193,6 +10673,40 @@ async function bootstrap() {
|
|
|
9193
10673
|
);
|
|
9194
10674
|
});
|
|
9195
10675
|
});
|
|
10676
|
+
if (env.MOCK_MODE) {
|
|
10677
|
+
const terminalSession = await sessionManager.createSession({
|
|
10678
|
+
sessionType: "terminal",
|
|
10679
|
+
workingDir: env.WORKSPACES_ROOT,
|
|
10680
|
+
terminalSize: { cols: 80, rows: 24 }
|
|
10681
|
+
});
|
|
10682
|
+
logger.info(
|
|
10683
|
+
{ sessionId: terminalSession.id.value },
|
|
10684
|
+
"Pre-created terminal session for screenshots"
|
|
10685
|
+
);
|
|
10686
|
+
if (terminalSession.type === "terminal") {
|
|
10687
|
+
setTimeout(() => {
|
|
10688
|
+
try {
|
|
10689
|
+
const command = `printf $'\\033[1;36m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\\033[0m\\n\\033[1;32m Tiflis Code - Remote Development Workstation\\033[0m\\n\\033[1;36m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\\033[0m\\n\\n\\033[1;33m System Information:\\033[0m\\n \u251C\u2500 OS: macOS Sequoia 15.1\\n \u251C\u2500 Shell: zsh 5.9\\n \u251C\u2500 Node: v22.11.0\\n \u2514\u2500 Uptime: 2 days, 14 hours\\n\\n\\033[1;33m Active Sessions:\\033[0m\\n \u251C\u2500 Claude Code \u2500 tiflis/tiflis-code\\n \u251C\u2500 Cursor \u2500 personal/portfolio\\n \u2514\u2500 OpenCode \u2500 tiflis/tiflis-api\\n\\n\\033[1;36m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\\033[0m\\n\\n'`;
|
|
10690
|
+
ptyManager.write(terminalSession, command + "\r");
|
|
10691
|
+
logger.info("Ran terminal commands for screenshots");
|
|
10692
|
+
setTimeout(() => {
|
|
10693
|
+
const ts = terminalSession;
|
|
10694
|
+
const history = ts.getOutputHistory();
|
|
10695
|
+
logger.info(
|
|
10696
|
+
{
|
|
10697
|
+
sessionId: ts.id.value,
|
|
10698
|
+
bufferSize: history.length,
|
|
10699
|
+
currentSequence: ts.currentSequence
|
|
10700
|
+
},
|
|
10701
|
+
"Terminal output buffer status after command"
|
|
10702
|
+
);
|
|
10703
|
+
}, 500);
|
|
10704
|
+
} catch (error) {
|
|
10705
|
+
logger.warn({ error }, "Failed to run terminal commands");
|
|
10706
|
+
}
|
|
10707
|
+
}, 100);
|
|
10708
|
+
}
|
|
10709
|
+
}
|
|
9196
10710
|
const app = createApp({ env, logger });
|
|
9197
10711
|
registerHealthRoute(
|
|
9198
10712
|
app,
|
|
@@ -9505,6 +11019,36 @@ bootstrap().catch((error) => {
|
|
|
9505
11019
|
*
|
|
9506
11020
|
* LangGraph-based Supervisor Agent for managing workstation resources.
|
|
9507
11021
|
*/
|
|
11022
|
+
/**
|
|
11023
|
+
* @file fixture-loader.ts
|
|
11024
|
+
* @copyright 2025 Roman Barinov <rbarinov@gmail.com>
|
|
11025
|
+
* @license FSL-1.1-NC
|
|
11026
|
+
*
|
|
11027
|
+
* Loads and parses JSON fixture files for mock mode.
|
|
11028
|
+
*/
|
|
11029
|
+
/**
|
|
11030
|
+
* @file streaming-simulator.ts
|
|
11031
|
+
* @copyright 2025 Roman Barinov <rbarinov@gmail.com>
|
|
11032
|
+
* @license FSL-1.1-NC
|
|
11033
|
+
*
|
|
11034
|
+
* Simulates realistic streaming output for mock responses.
|
|
11035
|
+
*/
|
|
11036
|
+
/**
|
|
11037
|
+
* @file mock-supervisor-agent.ts
|
|
11038
|
+
* @copyright 2025 Roman Barinov <rbarinov@gmail.com>
|
|
11039
|
+
* @license FSL-1.1-NC
|
|
11040
|
+
*
|
|
11041
|
+
* Mock Supervisor Agent for screenshot automation tests.
|
|
11042
|
+
* Returns fixture-based responses with simulated streaming.
|
|
11043
|
+
*/
|
|
11044
|
+
/**
|
|
11045
|
+
* @file mock-agent-session-manager.ts
|
|
11046
|
+
* @copyright 2025 Roman Barinov <rbarinov@gmail.com>
|
|
11047
|
+
* @license FSL-1.1-NC
|
|
11048
|
+
*
|
|
11049
|
+
* Mock Agent Session Manager for screenshot automation tests.
|
|
11050
|
+
* Simulates agent sessions with fixture-based responses and streaming.
|
|
11051
|
+
*/
|
|
9508
11052
|
/**
|
|
9509
11053
|
* @file stt-service.ts
|
|
9510
11054
|
* @copyright 2025 Roman Barinov <rbarinov@gmail.com>
|