diffact 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/cli.mjs +2 -0
  2. package/dist/index-node-bKTmbwGt.mjs +1 -0
  3. package/dist/src-CPKE75x0.mjs +11 -0
  4. package/dist/src-Ceryd8j5.mjs +1 -0
  5. package/package.json +4 -5
  6. package/web/dist/assets/{code-block-37QAKDTI-C97XC0lL.js → code-block-37QAKDTI-yDNOZoY4.js} +1 -1
  7. package/web/dist/assets/{index-DWCfDth4.js → index-BlaXWu6U.js} +30 -30
  8. package/web/dist/assets/index-DMEToi1s.css +1 -0
  9. package/web/dist/index.html +2 -2
  10. package/dist/agent-manager.d.ts +0 -32
  11. package/dist/agent-manager.js +0 -502
  12. package/dist/app-server-client.d.ts +0 -38
  13. package/dist/app-server-client.js +0 -249
  14. package/dist/capabilities.d.ts +0 -2
  15. package/dist/capabilities.js +0 -27
  16. package/dist/cli.d.ts +0 -6
  17. package/dist/cli.js +0 -13
  18. package/dist/command-runner.d.ts +0 -83
  19. package/dist/command-runner.js +0 -427
  20. package/dist/editors.d.ts +0 -26
  21. package/dist/editors.js +0 -144
  22. package/dist/gh.d.ts +0 -61
  23. package/dist/gh.js +0 -185
  24. package/dist/git.d.ts +0 -57
  25. package/dist/git.js +0 -482
  26. package/dist/http.d.ts +0 -7
  27. package/dist/http.js +0 -98
  28. package/dist/index-node.d.ts +0 -5
  29. package/dist/index-node.js +0 -51
  30. package/dist/index.d.ts +0 -6
  31. package/dist/index.js +0 -1011
  32. package/dist/list-directories.d.ts +0 -8
  33. package/dist/list-directories.js +0 -32
  34. package/dist/log.d.ts +0 -2
  35. package/dist/log.js +0 -2
  36. package/dist/open-browser.d.ts +0 -5
  37. package/dist/open-browser.js +0 -23
  38. package/dist/project-commands.d.ts +0 -17
  39. package/dist/project-commands.js +0 -152
  40. package/dist/project-path.d.ts +0 -5
  41. package/dist/project-path.js +0 -33
  42. package/dist/runtime.d.ts +0 -65
  43. package/dist/runtime.js +0 -235
  44. package/dist/static.d.ts +0 -10
  45. package/dist/static.js +0 -127
  46. package/dist/types.d.ts +0 -17
  47. package/dist/types.js +0 -1
  48. package/dist/utils.d.ts +0 -3
  49. package/dist/utils.js +0 -26
  50. package/dist/ws-hub.d.ts +0 -20
  51. package/dist/ws-hub.js +0 -123
  52. package/web/dist/assets/index-CRDz04kv.css +0 -1
@@ -1,249 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { log } from "./log.js";
3
- const APP_SERVER_LOG_PREFIX = "[app-server]";
4
- const logAppServer = (event, detail) => {
5
- if (detail) {
6
- log.info({ detail }, `${APP_SERVER_LOG_PREFIX} ${event}`);
7
- return;
8
- }
9
- log.info(`${APP_SERVER_LOG_PREFIX} ${event}`);
10
- };
11
- export class AppServerClient {
12
- #command;
13
- #args;
14
- #process = null;
15
- #pending = new Map();
16
- #nextId = 1;
17
- #connectPromise = null;
18
- #initializePromise = null;
19
- #onNotification;
20
- #onRequest;
21
- #onClose;
22
- #initialized = false;
23
- #stdoutBuffer = "";
24
- constructor(options) {
25
- this.#command = options.command ?? "codex";
26
- this.#args = options.args ?? ["app-server"];
27
- this.#onNotification = options.onNotification;
28
- this.#onRequest = options.onRequest;
29
- this.#onClose = options.onClose;
30
- }
31
- async connect() {
32
- if (this.#connectPromise) {
33
- return this.#connectPromise;
34
- }
35
- this.#connectPromise = new Promise((resolve, reject) => {
36
- logAppServer("connect:start", { command: this.#command });
37
- const child = spawn(this.#command, this.#args, {
38
- stdio: ["pipe", "pipe", "pipe"],
39
- });
40
- this.#process = child;
41
- let settled = false;
42
- const cleanup = () => {
43
- child.removeListener("spawn", onSpawn);
44
- child.removeListener("error", onError);
45
- };
46
- const onSpawn = () => {
47
- if (settled) {
48
- return;
49
- }
50
- settled = true;
51
- cleanup();
52
- logAppServer("connect:ready");
53
- resolve();
54
- };
55
- const onError = () => {
56
- if (settled) {
57
- return;
58
- }
59
- settled = true;
60
- cleanup();
61
- const error = new Error("app_server_spawn_failed");
62
- this.#connectPromise = null;
63
- this.#process = null;
64
- logAppServer("connect:error", { error: error.message });
65
- reject(error);
66
- if (this.#onClose) {
67
- this.#onClose(error);
68
- }
69
- };
70
- child.on("spawn", onSpawn);
71
- child.on("error", onError);
72
- child.stdout.on("data", (chunk) => {
73
- this.#handleStdout(chunk);
74
- });
75
- child.stderr.on("data", () => { });
76
- child.on("exit", (code, signal) => {
77
- const error = new Error("app_server_closed");
78
- for (const pending of this.#pending.values()) {
79
- pending.reject(error);
80
- }
81
- this.#pending.clear();
82
- this.#connectPromise = null;
83
- this.#initializePromise = null;
84
- this.#initialized = false;
85
- this.#stdoutBuffer = "";
86
- this.#process = null;
87
- logAppServer("connect:closed", { code, signal });
88
- if (this.#onClose) {
89
- this.#onClose(error);
90
- }
91
- });
92
- });
93
- return this.#connectPromise;
94
- }
95
- async initialize(params) {
96
- if (this.#initialized) {
97
- return;
98
- }
99
- if (this.#initializePromise) {
100
- return this.#initializePromise;
101
- }
102
- this.#initializePromise = (async () => {
103
- await this.connect();
104
- logAppServer("initialize:start");
105
- await this.request("initialize", {
106
- clientInfo: {
107
- name: params.name,
108
- title: params.title ?? null,
109
- version: params.version,
110
- },
111
- });
112
- this.notify("initialized");
113
- this.#initialized = true;
114
- logAppServer("initialize:done");
115
- })();
116
- try {
117
- await this.#initializePromise;
118
- }
119
- finally {
120
- this.#initializePromise = null;
121
- }
122
- }
123
- async request(method, params) {
124
- await this.connect();
125
- const id = this.#nextId++;
126
- const payload = { id, method, params };
127
- const stdin = this.#process?.stdin;
128
- if (!stdin || !stdin.writable) {
129
- throw new Error("app_server_not_connected");
130
- }
131
- const result = new Promise((resolve, reject) => {
132
- this.#pending.set(id, { method, resolve, reject });
133
- logAppServer("request:out", { id, method });
134
- stdin.write(`${JSON.stringify(payload)}\n`);
135
- });
136
- return result;
137
- }
138
- notify(method, params) {
139
- const stdin = this.#process?.stdin;
140
- if (!stdin || !stdin.writable) {
141
- return;
142
- }
143
- const payload = { method, params };
144
- logAppServer("notify:out", { method });
145
- stdin.write(`${JSON.stringify(payload)}\n`);
146
- }
147
- close() {
148
- if (this.#process) {
149
- this.#process.kill();
150
- }
151
- }
152
- async #handleMessage(message) {
153
- if (message.method) {
154
- if (message.id !== undefined) {
155
- logAppServer("request:in", {
156
- id: message.id,
157
- method: message.method,
158
- });
159
- const request = {
160
- id: message.id,
161
- method: message.method,
162
- params: message.params,
163
- };
164
- let result = null;
165
- if (this.#onRequest) {
166
- result = await this.#onRequest(request);
167
- }
168
- logAppServer("response:out", {
169
- id: request.id,
170
- method: request.method,
171
- });
172
- this.#sendResponse(request.id, result);
173
- return;
174
- }
175
- if (this.#onNotification) {
176
- logAppServer("notification:in", { message });
177
- this.#onNotification({
178
- method: message.method,
179
- params: message.params,
180
- });
181
- }
182
- return;
183
- }
184
- if (message.id === undefined) {
185
- return;
186
- }
187
- const pending = this.#pending.get(message.id);
188
- if (!pending) {
189
- return;
190
- }
191
- this.#pending.delete(message.id);
192
- if (message.error) {
193
- logAppServer("response:error", {
194
- id: message.id,
195
- method: pending.method,
196
- });
197
- const messageError = message.error &&
198
- typeof message.error === "object" &&
199
- "message" in message.error
200
- ? message.error.message
201
- : null;
202
- pending.reject(new Error(typeof messageError === "string" ? messageError : "app_server_error"));
203
- return;
204
- }
205
- if (message.result !== undefined) {
206
- logAppServer("response:in", {
207
- id: message.id,
208
- method: pending.method,
209
- });
210
- pending.resolve(message.result);
211
- return;
212
- }
213
- logAppServer("response:in", { id: message.id, method: pending.method });
214
- pending.resolve(message);
215
- }
216
- #sendResponse(id, result) {
217
- const stdin = this.#process?.stdin;
218
- if (!stdin || !stdin.writable) {
219
- return;
220
- }
221
- stdin.write(`${JSON.stringify({ id, result })}\n`);
222
- }
223
- #handleStdout(chunk) {
224
- this.#stdoutBuffer += chunk.toString("utf8");
225
- let newlineIndex = this.#stdoutBuffer.indexOf("\n");
226
- while (newlineIndex !== -1) {
227
- const line = this.#stdoutBuffer.slice(0, newlineIndex).trim();
228
- this.#stdoutBuffer = this.#stdoutBuffer.slice(newlineIndex + 1);
229
- if (!line) {
230
- newlineIndex = this.#stdoutBuffer.indexOf("\n");
231
- continue;
232
- }
233
- let parsed = null;
234
- try {
235
- parsed = JSON.parse(line);
236
- }
237
- catch {
238
- newlineIndex = this.#stdoutBuffer.indexOf("\n");
239
- continue;
240
- }
241
- if (!parsed || typeof parsed !== "object") {
242
- newlineIndex = this.#stdoutBuffer.indexOf("\n");
243
- continue;
244
- }
245
- void this.#handleMessage(parsed);
246
- newlineIndex = this.#stdoutBuffer.indexOf("\n");
247
- }
248
- }
249
- }
@@ -1,2 +0,0 @@
1
- import type { CapabilityInfo } from "./types.js";
2
- export declare function computeCapabilities(projectPath?: string | null): Promise<CapabilityInfo>;
@@ -1,27 +0,0 @@
1
- import { resolveProjectRoot } from "./project-path.js";
2
- import { runtime } from "./runtime.js";
3
- async function detectGithubAuth() {
4
- const ghPath = runtime.which("gh");
5
- if (!ghPath) {
6
- return false;
7
- }
8
- try {
9
- const proc = runtime.spawn([ghPath, "auth", "status", "--hostname", "github.com"], {});
10
- const exitCode = await proc.exited;
11
- return exitCode === 0;
12
- }
13
- catch {
14
- return false;
15
- }
16
- }
17
- export async function computeCapabilities(projectPath) {
18
- const project = projectPath
19
- ? await resolveProjectRoot(projectPath).catch(() => null)
20
- : null;
21
- const github = await detectGithubAuth();
22
- return {
23
- diffReview: true,
24
- git: project ? project.isGit : false,
25
- github,
26
- };
27
- }
package/dist/cli.d.ts DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * CLI entry point for diffact.
4
- * Auto-detects runtime (Bun/Node) and starts the appropriate server.
5
- */
6
- export {};
package/dist/cli.js DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * CLI entry point for diffact.
4
- * Auto-detects runtime (Bun/Node) and starts the appropriate server.
5
- */
6
- const isBun = typeof globalThis.Bun !== "undefined";
7
- if (isBun) {
8
- await import("./index.js");
9
- }
10
- else {
11
- await import("./index-node.js");
12
- }
13
- export {};
@@ -1,83 +0,0 @@
1
- import type { CommandExecutionPlan, CommandSource } from "./project-commands.js";
2
- import { type RuntimeTerminal, type SpawnedProcess } from "./runtime.js";
3
- export type CommandRunStatus = "running" | "completed" | "failed" | "stopped";
4
- export type CommandRunStream = "stdout" | "stderr";
5
- export type CommandDescriptor = {
6
- id: string;
7
- name: string;
8
- label: string;
9
- source: CommandSource;
10
- };
11
- export type CommandRunOutput = {
12
- stdout: string;
13
- stderr: string;
14
- combined: string;
15
- };
16
- export type CommandRunRecord = {
17
- id: string;
18
- command: CommandDescriptor;
19
- projectRoot: string;
20
- terminalId: string;
21
- status: CommandRunStatus;
22
- exitCode: number | null;
23
- signal: string | null;
24
- startedAt: string;
25
- completedAt?: string;
26
- output: CommandRunOutput;
27
- process: CommandRunProcess;
28
- stdoutPath?: string;
29
- stderrPath?: string;
30
- };
31
- export type CommandRunResult = {
32
- status: CommandRunStatus;
33
- runId: string | null;
34
- exitCode: number | null;
35
- signal: string | null;
36
- error?: string;
37
- };
38
- export type CommandRunSummary = {
39
- runId: string;
40
- projectPath: string;
41
- terminalId: string;
42
- commandId: string;
43
- commandName: string;
44
- commandLabel: string;
45
- commandSource: CommandSource;
46
- status: CommandRunStatus;
47
- exitCode: number | null;
48
- signal: string | null;
49
- startedAt: string;
50
- completedAt: string | null;
51
- stdout?: string;
52
- stderr?: string;
53
- };
54
- export type CommandRunListener = {
55
- onStatus?: (record: CommandRunRecord) => void;
56
- onOutput?: (event: {
57
- runId: string;
58
- stream: CommandRunStream;
59
- data: string;
60
- }) => void;
61
- };
62
- type CommandRunProcess = SpawnedProcess & {
63
- terminal?: RuntimeTerminal;
64
- };
65
- export declare const startCommandRun: (params: {
66
- command: CommandDescriptor;
67
- projectRoot: string;
68
- plan: CommandExecutionPlan;
69
- terminal?: {
70
- cols: number;
71
- rows: number;
72
- };
73
- listener?: CommandRunListener;
74
- }) => Promise<CommandRunResult>;
75
- export declare const getCommandRun: (runId: string) => CommandRunRecord | null;
76
- export declare const listCommandRuns: (projectRoot: string) => CommandRunRecord[];
77
- export declare const getCommandRunOutput: (runId: string) => {
78
- stdout: string;
79
- stderr: string;
80
- combined: string;
81
- } | null;
82
- export declare const stopCommandRun: (runId: string) => CommandRunRecord | null;
83
- export {};