@pixelbyte-software/pixcode 1.54.11 → 1.55.1

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.
Files changed (165) hide show
  1. package/dist/assets/{index-Bcqs_1vc.js → index-B-ySsQqi.js} +147 -147
  2. package/dist/assets/index-CWO38aJI.css +32 -0
  3. package/dist/index.html +2 -2
  4. package/dist-server/server/claude-sdk.js +1 -1
  5. package/dist-server/server/claude-sdk.js.map +1 -1
  6. package/dist-server/server/index.js +6 -11
  7. package/dist-server/server/index.js.map +1 -1
  8. package/dist-server/server/modules/security/permission-policy.js.map +1 -0
  9. package/dist-server/server/services/control-room.js +9 -1
  10. package/dist-server/server/services/control-room.js.map +1 -1
  11. package/dist-server/server/services/public-api-manifest.js +5 -5
  12. package/dist-server/server/services/public-api-manifest.js.map +1 -1
  13. package/dist-server/server/services/telegram/control-center.js +10 -10
  14. package/dist-server/server/services/telegram/control-center.js.map +1 -1
  15. package/dist-server/server/services/telegram/telegram-gateway.js +2 -2
  16. package/dist-server/server/services/telegram/telegram-gateway.js.map +1 -1
  17. package/dist-server/server/services/telegram/translations.js +5 -5
  18. package/dist-server/server/services/telegram/translations.js.map +1 -1
  19. package/package.json +1 -1
  20. package/server/claude-sdk.js +1 -1
  21. package/server/index.js +6 -23
  22. package/server/services/control-room.js +10 -1
  23. package/server/services/public-api-manifest.js +5 -5
  24. package/server/services/telegram/control-center.js +10 -10
  25. package/server/services/telegram/telegram-gateway.js +2 -2
  26. package/server/services/telegram/translations.js +5 -5
  27. package/dist/assets/index-Dz1luE0u.css +0 -32
  28. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js +0 -73
  29. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js.map +0 -1
  30. package/dist-server/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js +0 -17
  31. package/dist-server/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js.map +0 -1
  32. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js +0 -236
  33. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js.map +0 -1
  34. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js +0 -202
  35. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js.map +0 -1
  36. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js +0 -205
  37. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js.map +0 -1
  38. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js +0 -205
  39. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js.map +0 -1
  40. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.js +0 -84
  41. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.js.map +0 -1
  42. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.test.js +0 -43
  43. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.test.js.map +0 -1
  44. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js +0 -205
  45. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js.map +0 -1
  46. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js +0 -205
  47. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js.map +0 -1
  48. package/dist-server/server/modules/orchestration/a2a/agent-card.js +0 -50
  49. package/dist-server/server/modules/orchestration/a2a/agent-card.js.map +0 -1
  50. package/dist-server/server/modules/orchestration/a2a/auth.middleware.js +0 -25
  51. package/dist-server/server/modules/orchestration/a2a/auth.middleware.js.map +0 -1
  52. package/dist-server/server/modules/orchestration/a2a/bus.js +0 -34
  53. package/dist-server/server/modules/orchestration/a2a/bus.js.map +0 -1
  54. package/dist-server/server/modules/orchestration/a2a/routes.js +0 -502
  55. package/dist-server/server/modules/orchestration/a2a/routes.js.map +0 -1
  56. package/dist-server/server/modules/orchestration/a2a/task-dispatcher.js +0 -295
  57. package/dist-server/server/modules/orchestration/a2a/task-dispatcher.js.map +0 -1
  58. package/dist-server/server/modules/orchestration/a2a/task-store.js +0 -144
  59. package/dist-server/server/modules/orchestration/a2a/task-store.js.map +0 -1
  60. package/dist-server/server/modules/orchestration/a2a/types.js +0 -6
  61. package/dist-server/server/modules/orchestration/a2a/types.js.map +0 -1
  62. package/dist-server/server/modules/orchestration/a2a/validator.js +0 -101
  63. package/dist-server/server/modules/orchestration/a2a/validator.js.map +0 -1
  64. package/dist-server/server/modules/orchestration/index.js +0 -27
  65. package/dist-server/server/modules/orchestration/index.js.map +0 -1
  66. package/dist-server/server/modules/orchestration/preview/port-watcher.js +0 -90
  67. package/dist-server/server/modules/orchestration/preview/port-watcher.js.map +0 -1
  68. package/dist-server/server/modules/orchestration/preview/preview-proxy.js +0 -58
  69. package/dist-server/server/modules/orchestration/preview/preview-proxy.js.map +0 -1
  70. package/dist-server/server/modules/orchestration/preview/types.js +0 -2
  71. package/dist-server/server/modules/orchestration/preview/types.js.map +0 -1
  72. package/dist-server/server/modules/orchestration/security/permission-policy.js.map +0 -1
  73. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js +0 -34
  74. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js.map +0 -1
  75. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js +0 -70
  76. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js.map +0 -1
  77. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js +0 -181
  78. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js.map +0 -1
  79. package/dist-server/server/modules/orchestration/tasks/orchestration-task.types.js +0 -2
  80. package/dist-server/server/modules/orchestration/tasks/orchestration-task.types.js.map +0 -1
  81. package/dist-server/server/modules/orchestration/tasks/task-run-graph.js +0 -100
  82. package/dist-server/server/modules/orchestration/tasks/task-run-graph.js.map +0 -1
  83. package/dist-server/server/modules/orchestration/workflows/approval-queue.js +0 -72
  84. package/dist-server/server/modules/orchestration/workflows/approval-queue.js.map +0 -1
  85. package/dist-server/server/modules/orchestration/workflows/built-in-workflows.js +0 -126
  86. package/dist-server/server/modules/orchestration/workflows/built-in-workflows.js.map +0 -1
  87. package/dist-server/server/modules/orchestration/workflows/context-packet.js +0 -89
  88. package/dist-server/server/modules/orchestration/workflows/context-packet.js.map +0 -1
  89. package/dist-server/server/modules/orchestration/workflows/handoff-artifact.js +0 -123
  90. package/dist-server/server/modules/orchestration/workflows/handoff-artifact.js.map +0 -1
  91. package/dist-server/server/modules/orchestration/workflows/workflow-fallback-policy.js +0 -114
  92. package/dist-server/server/modules/orchestration/workflows/workflow-fallback-policy.js.map +0 -1
  93. package/dist-server/server/modules/orchestration/workflows/workflow-replay.js +0 -177
  94. package/dist-server/server/modules/orchestration/workflows/workflow-replay.js.map +0 -1
  95. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js +0 -1718
  96. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js.map +0 -1
  97. package/dist-server/server/modules/orchestration/workflows/workflow-store.js +0 -76
  98. package/dist-server/server/modules/orchestration/workflows/workflow-store.js.map +0 -1
  99. package/dist-server/server/modules/orchestration/workflows/workflow-templates.js +0 -242
  100. package/dist-server/server/modules/orchestration/workflows/workflow-templates.js.map +0 -1
  101. package/dist-server/server/modules/orchestration/workflows/workflow-trace.js +0 -388
  102. package/dist-server/server/modules/orchestration/workflows/workflow-trace.js.map +0 -1
  103. package/dist-server/server/modules/orchestration/workflows/workflow.routes.js +0 -508
  104. package/dist-server/server/modules/orchestration/workflows/workflow.routes.js.map +0 -1
  105. package/dist-server/server/modules/orchestration/workflows/workflow.types.js +0 -2
  106. package/dist-server/server/modules/orchestration/workflows/workflow.types.js.map +0 -1
  107. package/dist-server/server/modules/orchestration/workflows/workspace-target.js +0 -100
  108. package/dist-server/server/modules/orchestration/workflows/workspace-target.js.map +0 -1
  109. package/dist-server/server/modules/orchestration/workspace/docker-workspace.js +0 -123
  110. package/dist-server/server/modules/orchestration/workspace/docker-workspace.js.map +0 -1
  111. package/dist-server/server/modules/orchestration/workspace/path-safety.js +0 -48
  112. package/dist-server/server/modules/orchestration/workspace/path-safety.js.map +0 -1
  113. package/dist-server/server/modules/orchestration/workspace/types.js +0 -11
  114. package/dist-server/server/modules/orchestration/workspace/types.js.map +0 -1
  115. package/dist-server/server/modules/orchestration/workspace/workspace-manager.js +0 -84
  116. package/dist-server/server/modules/orchestration/workspace/workspace-manager.js.map +0 -1
  117. package/dist-server/server/modules/orchestration/workspace/worktree-workspace.js +0 -97
  118. package/dist-server/server/modules/orchestration/workspace/worktree-workspace.js.map +0 -1
  119. package/server/modules/orchestration/a2a/adapter-registry.ts +0 -108
  120. package/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.ts +0 -63
  121. package/server/modules/orchestration/a2a/adapters/claude-code.adapter.ts +0 -286
  122. package/server/modules/orchestration/a2a/adapters/codex.adapter.ts +0 -244
  123. package/server/modules/orchestration/a2a/adapters/cursor.adapter.ts +0 -249
  124. package/server/modules/orchestration/a2a/adapters/gemini.adapter.ts +0 -248
  125. package/server/modules/orchestration/a2a/adapters/json-event.adapter.test.ts +0 -60
  126. package/server/modules/orchestration/a2a/adapters/json-event.adapter.ts +0 -101
  127. package/server/modules/orchestration/a2a/adapters/opencode.adapter.ts +0 -248
  128. package/server/modules/orchestration/a2a/adapters/qwen.adapter.ts +0 -248
  129. package/server/modules/orchestration/a2a/agent-card.ts +0 -55
  130. package/server/modules/orchestration/a2a/auth.middleware.ts +0 -29
  131. package/server/modules/orchestration/a2a/bus.ts +0 -46
  132. package/server/modules/orchestration/a2a/routes.ts +0 -586
  133. package/server/modules/orchestration/a2a/task-dispatcher.ts +0 -345
  134. package/server/modules/orchestration/a2a/task-store.ts +0 -178
  135. package/server/modules/orchestration/a2a/types.ts +0 -126
  136. package/server/modules/orchestration/a2a/validator.ts +0 -113
  137. package/server/modules/orchestration/index.ts +0 -99
  138. package/server/modules/orchestration/preview/port-watcher.ts +0 -112
  139. package/server/modules/orchestration/preview/preview-proxy.ts +0 -60
  140. package/server/modules/orchestration/preview/types.ts +0 -19
  141. package/server/modules/orchestration/tasks/orchestration-task-store.ts +0 -41
  142. package/server/modules/orchestration/tasks/orchestration-task.routes.ts +0 -81
  143. package/server/modules/orchestration/tasks/orchestration-task.service.ts +0 -201
  144. package/server/modules/orchestration/tasks/orchestration-task.types.ts +0 -40
  145. package/server/modules/orchestration/tasks/task-run-graph.ts +0 -155
  146. package/server/modules/orchestration/workflows/approval-queue.ts +0 -106
  147. package/server/modules/orchestration/workflows/built-in-workflows.ts +0 -127
  148. package/server/modules/orchestration/workflows/context-packet.ts +0 -186
  149. package/server/modules/orchestration/workflows/handoff-artifact.ts +0 -175
  150. package/server/modules/orchestration/workflows/workflow-fallback-policy.ts +0 -161
  151. package/server/modules/orchestration/workflows/workflow-replay.ts +0 -254
  152. package/server/modules/orchestration/workflows/workflow-runner.ts +0 -2062
  153. package/server/modules/orchestration/workflows/workflow-store.ts +0 -97
  154. package/server/modules/orchestration/workflows/workflow-templates.ts +0 -272
  155. package/server/modules/orchestration/workflows/workflow-trace.ts +0 -424
  156. package/server/modules/orchestration/workflows/workflow.routes.ts +0 -586
  157. package/server/modules/orchestration/workflows/workflow.types.ts +0 -111
  158. package/server/modules/orchestration/workflows/workspace-target.ts +0 -122
  159. package/server/modules/orchestration/workspace/docker-workspace.ts +0 -136
  160. package/server/modules/orchestration/workspace/path-safety.ts +0 -55
  161. package/server/modules/orchestration/workspace/types.ts +0 -52
  162. package/server/modules/orchestration/workspace/workspace-manager.ts +0 -102
  163. package/server/modules/orchestration/workspace/worktree-workspace.ts +0 -126
  164. /package/dist-server/server/modules/{orchestration/security → security}/permission-policy.js +0 -0
  165. /package/server/modules/{orchestration/security → security}/permission-policy.ts +0 -0
@@ -1,122 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { dirname, resolve } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- export type WorkspaceTargetKind = 'selected_project' | 'pixcode_app' | 'custom';
6
-
7
- export type ResolvedWorkspaceTarget = {
8
- kind: WorkspaceTargetKind;
9
- label: string;
10
- projectPath: string;
11
- selectedProjectPath?: string;
12
- selectedProjectName?: string;
13
- appRoot: string;
14
- };
15
-
16
- const pixcodePackageName = '@pixelbyte-software/pixcode';
17
-
18
- function readRecord(value: unknown): Record<string, unknown> | undefined {
19
- return value && typeof value === 'object' ? value as Record<string, unknown> : undefined;
20
- }
21
-
22
- function readString(value: unknown): string | undefined {
23
- return typeof value === 'string' && value.trim() ? value.trim() : undefined;
24
- }
25
-
26
- function readTargetKind(value: unknown): WorkspaceTargetKind | undefined {
27
- return value === 'selected_project' || value === 'pixcode_app' || value === 'custom'
28
- ? value
29
- : undefined;
30
- }
31
-
32
- export function findPixcodeAppRoot(): string {
33
- let currentDir = dirname(fileURLToPath(import.meta.url));
34
-
35
- for (let depth = 0; depth < 10; depth += 1) {
36
- try {
37
- const packagePath = resolve(currentDir, 'package.json');
38
- const pkg = JSON.parse(readFileSync(packagePath, 'utf8')) as { name?: string };
39
- if (pkg.name === pixcodePackageName) {
40
- return currentDir;
41
- }
42
- } catch {
43
- // Walk upward until the Pixcode package root is found.
44
- }
45
-
46
- const parent = dirname(currentDir);
47
- if (parent === currentDir) break;
48
- currentDir = parent;
49
- }
50
-
51
- return process.cwd();
52
- }
53
-
54
- export function resolveWorkflowWorkspace(metadata?: Record<string, unknown>): ResolvedWorkspaceTarget {
55
- const target = readRecord(metadata?.workspaceTarget);
56
- const appRoot = findPixcodeAppRoot();
57
- const selectedProjectPath = readString(metadata?.selectedProjectPath) ?? readString(metadata?.projectPath);
58
- const selectedProjectName = readString(metadata?.projectName) ?? readString(metadata?.projectId);
59
- const kind = readTargetKind(target?.kind) ?? 'selected_project';
60
- const customPath = readString(target?.projectPath);
61
-
62
- if (kind === 'pixcode_app') {
63
- return {
64
- kind,
65
- label: 'Pixcode app',
66
- projectPath: appRoot,
67
- selectedProjectPath,
68
- selectedProjectName,
69
- appRoot,
70
- };
71
- }
72
-
73
- if (kind === 'custom') {
74
- return {
75
- kind,
76
- label: readString(target?.label) ?? 'Custom workspace',
77
- projectPath: customPath ?? selectedProjectPath ?? appRoot,
78
- selectedProjectPath,
79
- selectedProjectName,
80
- appRoot,
81
- };
82
- }
83
-
84
- return {
85
- kind: 'selected_project',
86
- label: selectedProjectName ?? 'Selected project',
87
- projectPath: selectedProjectPath ?? appRoot,
88
- selectedProjectPath,
89
- selectedProjectName,
90
- appRoot,
91
- };
92
- }
93
-
94
- export function workspaceTargetMetadata(target: ResolvedWorkspaceTarget): Record<string, unknown> {
95
- return {
96
- kind: target.kind,
97
- label: target.label,
98
- projectPath: target.projectPath,
99
- selectedProjectPath: target.selectedProjectPath,
100
- selectedProjectName: target.selectedProjectName,
101
- appRoot: target.appRoot,
102
- };
103
- }
104
-
105
- export function workspaceContextPrompt(target: ResolvedWorkspaceTarget): string {
106
- return [
107
- 'Pixcode orchestration execution context:',
108
- `- Target workspace: ${target.label}`,
109
- `- Working directory for this agent: ${target.projectPath}`,
110
- target.selectedProjectName ? `- Selected UI project: ${target.selectedProjectName}` : '',
111
- target.selectedProjectPath ? `- Selected UI project path: ${target.selectedProjectPath}` : '',
112
- `- Pixcode app root: ${target.appRoot}`,
113
- '',
114
- 'Rules:',
115
- '- Treat the working directory above as the authoritative project/application for this task.',
116
- '- Do not guess another repository path unless the user explicitly asks for it.',
117
- '- Do not access parent directories, sibling projects, or broad external globs outside the working directory unless the user explicitly asks.',
118
- '- If the user asks to analyze or modify Pixcode/orchestration itself, the target workspace must be the Pixcode app root.',
119
- '- Before running package-manager commands, inspect the package files in the working directory.',
120
- '- If a tool reports a permission denial, summarize the limitation and continue from the provided context instead of retrying the same external path.',
121
- ].filter(Boolean).join('\n');
122
- }
@@ -1,136 +0,0 @@
1
- import { WorkspaceError } from '@/modules/orchestration/workspace/types.js';
2
- import type {
3
- ExecResult,
4
- WorkspaceHandle,
5
- WorkspaceRequest,
6
- } from '@/modules/orchestration/workspace/types.js';
7
-
8
- async function run(
9
- command: string,
10
- args: string[],
11
- ): Promise<ExecResult> {
12
- try {
13
- const { execFile } = await import('node:child_process');
14
- const { promisify } = await import('node:util');
15
- const execFileAsync = promisify(execFile);
16
- const { stdout, stderr } = await execFileAsync(command, args, {
17
- maxBuffer: 20 * 1024 * 1024,
18
- });
19
- return { stdout: String(stdout), stderr: String(stderr), exitCode: 0 };
20
- } catch (error) {
21
- const err = error as Error & { stdout?: string; stderr?: string; code?: number };
22
- return {
23
- stdout: String(err.stdout ?? ''),
24
- stderr: String(err.stderr ?? err.message),
25
- exitCode: typeof err.code === 'number' ? err.code : 1,
26
- };
27
- }
28
- }
29
-
30
- export class DockerWorkspace implements WorkspaceHandle {
31
- readonly kind = 'docker' as const;
32
- readonly id: string;
33
- readonly path: string;
34
- readonly baseRef: string;
35
- readonly metadata: Record<string, unknown>;
36
- private containerId?: string;
37
- private readonly worktreePath: string;
38
-
39
- constructor(request: WorkspaceRequest) {
40
- this.id = `docker_${request.taskId}`;
41
- this.path = '/workspace';
42
- this.baseRef = request.baseRef ?? 'HEAD';
43
- this.worktreePath = request.projectPath;
44
- this.metadata = {
45
- ...request.metadata,
46
- image: request.metadata?.image ?? 'node:22-slim',
47
- containerId: undefined,
48
- exposedPorts: [],
49
- };
50
- }
51
-
52
- private async ensureStarted(): Promise<void> {
53
- if (this.containerId) return;
54
- const image = String(this.metadata.image ?? 'node:22-slim');
55
- const pullResult = await run('docker', ['pull', image]);
56
- if (pullResult.exitCode !== 0) {
57
- throw new WorkspaceError('WORKSPACE_DOCKER_PULL_FAILED', pullResult.stderr || pullResult.stdout, {
58
- image,
59
- workspaceId: this.id,
60
- });
61
- }
62
- const createResult = await run('docker', [
63
- 'create',
64
- '--rm',
65
- '-v', `${this.worktreePath}:/workspace`,
66
- '-w', '/workspace',
67
- image,
68
- 'tail', '-f', '/dev/null',
69
- ]);
70
- if (createResult.exitCode !== 0 || !createResult.stdout.trim()) {
71
- throw new WorkspaceError('WORKSPACE_DOCKER_CREATE_FAILED', createResult.stderr || createResult.stdout, {
72
- image,
73
- workspaceId: this.id,
74
- });
75
- }
76
- this.containerId = createResult.stdout.trim();
77
- const startResult = await run('docker', ['start', this.containerId]);
78
- if (startResult.exitCode !== 0) {
79
- await this.cleanupContainer();
80
- throw new WorkspaceError('WORKSPACE_DOCKER_START_FAILED', startResult.stderr || startResult.stdout, {
81
- containerId: this.containerId,
82
- workspaceId: this.id,
83
- });
84
- }
85
- this.metadata.containerId = this.containerId;
86
- }
87
-
88
- private async cleanupContainer(): Promise<void> {
89
- if (!this.containerId) return;
90
- await run('docker', ['rm', '-f', this.containerId]).catch(() => {});
91
- this.containerId = undefined;
92
- }
93
-
94
- async exec(command: string, args: string[] = []): Promise<ExecResult> {
95
- await this.ensureStarted();
96
- return run('docker', ['exec', this.containerId!, command, ...args]);
97
- }
98
-
99
- async readFile(relativePath: string): Promise<string> {
100
- await this.ensureStarted();
101
- const result = await run('docker', ['exec', this.containerId!, 'cat', relativePath]);
102
- if (result.exitCode !== 0) {
103
- throw new WorkspaceError('WORKSPACE_READ_FAILED', result.stderr, { path: relativePath });
104
- }
105
- return result.stdout;
106
- }
107
-
108
- async writeFile(relativePath: string, content: string): Promise<void> {
109
- await this.ensureStarted();
110
- const result = await run('docker', ['exec', this.containerId!, 'sh', '-c', `cat > ${relativePath}`]);
111
- if (result.exitCode !== 0) {
112
- throw new WorkspaceError('WORKSPACE_WRITE_FAILED', result.stderr, { path: relativePath });
113
- }
114
- }
115
-
116
- async diff(): Promise<string> {
117
- const { execFile } = await import('node:child_process');
118
- const { promisify } = await import('node:util');
119
- const execFileAsync = promisify(execFile);
120
- try {
121
- const { stdout } = await execFileAsync('git', ['diff', `${this.baseRef}...HEAD`], {
122
- cwd: this.worktreePath,
123
- maxBuffer: 20 * 1024 * 1024,
124
- });
125
- return String(stdout);
126
- } catch (error) {
127
- const err = error as Error & { stderr?: string };
128
- const output = String(err.stderr ?? err.message);
129
- return /not a git repository|usage: git diff --no-index/i.test(output) ? '' : output;
130
- }
131
- }
132
-
133
- async destroy(): Promise<void> {
134
- await this.cleanupContainer();
135
- }
136
- }
@@ -1,55 +0,0 @@
1
- import fs from 'node:fs';
2
- import os from 'node:os';
3
- import path from 'node:path';
4
-
5
- import { WorkspaceError } from '@/modules/orchestration/workspace/types.js';
6
-
7
- const SAFE_ID = /^[a-zA-Z0-9_-]+$/;
8
-
9
- export function getWorktreesRoot(): string {
10
- return process.env.PIXCODE_WORKTREES_ROOT ?? path.join(os.homedir(), '.pixcode', 'worktrees');
11
- }
12
-
13
- export function assertSafeId(value: string, label: string): string {
14
- if (!SAFE_ID.test(value) || value.includes('..')) {
15
- throw new WorkspaceError('UNSAFE_WORKSPACE_ID', `Unsafe ${label}: ${value}`, { value, label });
16
- }
17
- return value;
18
- }
19
-
20
- export function ensureDirectory(dir: string): void {
21
- fs.mkdirSync(dir, { recursive: true });
22
- }
23
-
24
- export function safeWorkspacePath(workspaceId: string): string {
25
- assertSafeId(workspaceId, 'workspace id');
26
- const root = getWorktreesRoot();
27
- ensureDirectory(root);
28
- const resolvedRoot = fs.realpathSync.native(root);
29
- const target = path.resolve(resolvedRoot, workspaceId);
30
- if (!target.startsWith(`${resolvedRoot}${path.sep}`)) {
31
- throw new WorkspaceError('WORKSPACE_PATH_TRAVERSAL', 'Workspace path escaped root', {
32
- root: resolvedRoot,
33
- target,
34
- });
35
- }
36
- return target;
37
- }
38
-
39
- export function safeJoin(root: string, relativePath: string): string {
40
- if (path.isAbsolute(relativePath) || relativePath.includes('\0')) {
41
- throw new WorkspaceError('WORKSPACE_PATH_TRAVERSAL', 'Workspace file path must be relative', {
42
- relativePath,
43
- });
44
- }
45
-
46
- const target = path.resolve(root, relativePath);
47
- const resolvedRoot = fs.existsSync(root) ? fs.realpathSync.native(root) : path.resolve(root);
48
- if (!target.startsWith(`${resolvedRoot}${path.sep}`) && target !== resolvedRoot) {
49
- throw new WorkspaceError('WORKSPACE_PATH_TRAVERSAL', 'Workspace file path escaped root', {
50
- root: resolvedRoot,
51
- target,
52
- });
53
- }
54
- return target;
55
- }
@@ -1,52 +0,0 @@
1
- import type { ExecFileOptions } from 'node:child_process';
2
-
3
- export type WorkspaceKind = 'host' | 'worktree' | 'docker';
4
-
5
- export interface ExecResult {
6
- stdout: string;
7
- stderr: string;
8
- exitCode: number;
9
- }
10
-
11
- export interface WorkspaceHandle {
12
- id: string;
13
- kind: WorkspaceKind;
14
- path: string;
15
- baseRef: string;
16
- branchName?: string;
17
- metadata: Record<string, unknown>;
18
- exec(command: string, args?: string[], options?: ExecFileOptions): Promise<ExecResult>;
19
- readFile(relativePath: string): Promise<string>;
20
- writeFile(relativePath: string, content: string): Promise<void>;
21
- diff(): Promise<string>;
22
- destroy(): Promise<void>;
23
- }
24
-
25
- export interface WorkspaceRequest {
26
- taskId: string;
27
- projectPath: string;
28
- kind?: WorkspaceKind;
29
- baseRef?: string;
30
- keepAfterCompletion?: boolean;
31
- metadata?: Record<string, unknown>;
32
- }
33
-
34
- export interface WorkspaceMetadata {
35
- id: string;
36
- kind: WorkspaceKind;
37
- path: string;
38
- baseRef: string;
39
- branchName?: string;
40
- keepAfterCompletion?: boolean;
41
- }
42
-
43
- export class WorkspaceError extends Error {
44
- constructor(
45
- public readonly code: string,
46
- message: string,
47
- public readonly details: Record<string, unknown> = {},
48
- ) {
49
- super(message);
50
- this.name = 'WorkspaceError';
51
- }
52
- }
@@ -1,102 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- import { DockerWorkspace } from '@/modules/orchestration/workspace/docker-workspace.js';
5
- import { safeJoin } from '@/modules/orchestration/workspace/path-safety.js';
6
- import type {
7
- ExecResult,
8
- WorkspaceHandle,
9
- WorkspaceKind,
10
- WorkspaceRequest,
11
- } from '@/modules/orchestration/workspace/types.js';
12
- import { WorktreeWorkspace } from '@/modules/orchestration/workspace/worktree-workspace.js';
13
-
14
- class HostWorkspace implements WorkspaceHandle {
15
- readonly kind = 'host' as const;
16
- readonly id: string;
17
- readonly path: string;
18
- readonly baseRef: string;
19
- readonly metadata: Record<string, unknown>;
20
-
21
- constructor(request: WorkspaceRequest) {
22
- this.id = `host_${request.taskId}`;
23
- this.path = request.projectPath;
24
- this.baseRef = request.baseRef ?? 'HEAD';
25
- this.metadata = { ...request.metadata, keepAfterCompletion: true };
26
- }
27
-
28
- async exec(command: string, args: string[] = []): Promise<ExecResult> {
29
- const { execFile } = await import('node:child_process');
30
- const { promisify } = await import('node:util');
31
- const execFileAsync = promisify(execFile);
32
- try {
33
- const { stdout, stderr } = await execFileAsync(command, args, {
34
- cwd: this.path,
35
- maxBuffer: 20 * 1024 * 1024,
36
- });
37
- return { stdout: String(stdout), stderr: String(stderr), exitCode: 0 };
38
- } catch (error) {
39
- const err = error as Error & { stdout?: string; stderr?: string; code?: number };
40
- return {
41
- stdout: String(err.stdout ?? ''),
42
- stderr: String(err.stderr ?? err.message),
43
- exitCode: typeof err.code === 'number' ? err.code : 1,
44
- };
45
- }
46
- }
47
-
48
- async readFile(relativePath: string): Promise<string> {
49
- return fs.promises.readFile(safeJoin(this.path, relativePath), 'utf8');
50
- }
51
-
52
- async writeFile(relativePath: string, content: string): Promise<void> {
53
- const target = safeJoin(this.path, relativePath);
54
- await fs.promises.mkdir(path.dirname(target), { recursive: true });
55
- await fs.promises.writeFile(target, content, 'utf8');
56
- }
57
-
58
- async diff(): Promise<string> {
59
- const insideWorkTree = await this.exec('git', ['rev-parse', '--is-inside-work-tree']);
60
- if (insideWorkTree.exitCode !== 0 || insideWorkTree.stdout.trim() !== 'true') {
61
- return '';
62
- }
63
-
64
- const result = await this.exec('git', ['diff', `${this.baseRef}...HEAD`]);
65
- return result.exitCode === 0 ? result.stdout : result.stderr || result.stdout;
66
- }
67
-
68
- destroy(): Promise<void> {
69
- return Promise.resolve();
70
- }
71
- }
72
-
73
- function readKind(value: unknown): WorkspaceKind {
74
- return value === 'host' || value === 'docker' || value === 'worktree' ? value : 'worktree';
75
- }
76
-
77
- class WorkspaceManager {
78
- async create(request: WorkspaceRequest): Promise<WorkspaceHandle> {
79
- const kind = readKind(request.kind);
80
- if (kind === 'host') {
81
- return new HostWorkspace(request);
82
- }
83
- if (kind === 'docker') {
84
- return new DockerWorkspace(request);
85
- }
86
- return WorktreeWorkspace.create(request);
87
- }
88
-
89
- recover(request: WorkspaceRequest): WorkspaceHandle {
90
- return new HostWorkspace({
91
- ...request,
92
- kind: 'host',
93
- metadata: {
94
- ...request.metadata,
95
- recovered: true,
96
- },
97
- });
98
- }
99
- }
100
-
101
- export const workspaceManager = new WorkspaceManager();
102
- export type { WorkspaceManager };
@@ -1,126 +0,0 @@
1
- import { execFile } from 'node:child_process';
2
- import fs from 'node:fs/promises';
3
- import path from 'node:path';
4
- import { promisify } from 'node:util';
5
-
6
- import { assertSafeId, safeJoin, safeWorkspacePath } from '@/modules/orchestration/workspace/path-safety.js';
7
- import type {
8
- ExecResult,
9
- WorkspaceHandle,
10
- WorkspaceRequest,
11
- } from '@/modules/orchestration/workspace/types.js';
12
- import { WorkspaceError } from '@/modules/orchestration/workspace/types.js';
13
-
14
- const execFileAsync = promisify(execFile);
15
-
16
- async function run(
17
- command: string,
18
- args: string[],
19
- cwd: string,
20
- ): Promise<ExecResult> {
21
- try {
22
- const { stdout, stderr } = await execFileAsync(command, args, {
23
- cwd,
24
- maxBuffer: 20 * 1024 * 1024,
25
- });
26
- return {
27
- stdout: String(stdout),
28
- stderr: String(stderr),
29
- exitCode: 0,
30
- };
31
- } catch (error) {
32
- const err = error as Error & {
33
- stdout?: string | Buffer;
34
- stderr?: string | Buffer;
35
- code?: number;
36
- };
37
- return {
38
- stdout: String(err.stdout ?? ''),
39
- stderr: String(err.stderr ?? err.message),
40
- exitCode: typeof err.code === 'number' ? err.code : 1,
41
- };
42
- }
43
- }
44
-
45
- export class WorktreeWorkspace implements WorkspaceHandle {
46
- readonly kind = 'worktree' as const;
47
- readonly id: string;
48
- readonly path: string;
49
- readonly baseRef: string;
50
- readonly branchName: string;
51
- readonly metadata: Record<string, unknown>;
52
- private readonly projectPath: string;
53
-
54
- private constructor(request: WorkspaceRequest, workspaceId: string, branchName: string) {
55
- this.id = workspaceId;
56
- this.path = safeWorkspacePath(workspaceId);
57
- this.baseRef = request.baseRef ?? 'HEAD';
58
- this.branchName = branchName;
59
- this.projectPath = request.projectPath;
60
- this.metadata = {
61
- ...request.metadata,
62
- keepAfterCompletion: request.keepAfterCompletion === true,
63
- };
64
- }
65
-
66
- static async create(request: WorkspaceRequest): Promise<WorktreeWorkspace> {
67
- assertSafeId(request.taskId, 'task id');
68
- const workspaceId = `ws_${request.taskId}`;
69
- const branchName = `pixcode/task_${request.taskId}`;
70
- const workspace = new WorktreeWorkspace(request, workspaceId, branchName);
71
-
72
- const existingBranch = await run('git', ['rev-parse', '--verify', branchName], request.projectPath);
73
- if (existingBranch.exitCode === 0) {
74
- throw new WorkspaceError('WORKSPACE_EXISTS', `Workspace branch already exists: ${branchName}`, {
75
- branchName,
76
- });
77
- }
78
-
79
- const result = await run(
80
- 'git',
81
- ['worktree', 'add', workspace.path, '-b', branchName, workspace.baseRef],
82
- request.projectPath,
83
- );
84
- if (result.exitCode !== 0) {
85
- throw new WorkspaceError('WORKSPACE_CREATE_FAILED', result.stderr || result.stdout, {
86
- stdout: result.stdout,
87
- stderr: result.stderr,
88
- baseRef: workspace.baseRef,
89
- });
90
- }
91
-
92
- return workspace;
93
- }
94
-
95
- exec(command: string, args: string[] = []): Promise<ExecResult> {
96
- return run(command, args, this.path);
97
- }
98
-
99
- async readFile(relativePath: string): Promise<string> {
100
- return fs.readFile(safeJoin(this.path, relativePath), 'utf8');
101
- }
102
-
103
- async writeFile(relativePath: string, content: string): Promise<void> {
104
- const target = safeJoin(this.path, relativePath);
105
- await fs.mkdir(path.dirname(target), { recursive: true });
106
- await fs.writeFile(target, content, 'utf8');
107
- }
108
-
109
- async diff(): Promise<string> {
110
- const result = await run('git', ['diff', `${this.baseRef}...HEAD`], this.path);
111
- if (result.exitCode !== 0) {
112
- const output = result.stderr || result.stdout;
113
- return /not a git repository|usage: git diff --no-index/i.test(output) ? '' : output;
114
- }
115
- return result.stdout;
116
- }
117
-
118
- async destroy(): Promise<void> {
119
- const result = await run('git', ['worktree', 'remove', '--force', this.path], this.projectPath);
120
- if (result.exitCode !== 0) {
121
- throw new WorkspaceError('WORKSPACE_DESTROY_FAILED', result.stderr || result.stdout, {
122
- workspacePath: this.path,
123
- });
124
- }
125
- }
126
- }