@howaboua/pi-codex-conversion 1.0.6 → 1.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-codex-conversion",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Codex-oriented tool and prompt adapter for pi coding agent",
5
5
  "type": "module",
6
6
  "repository": {
@@ -8,20 +8,17 @@ export function normalizePatchPath({ path }: { path: string }): string {
8
8
  return withoutAt.replace(/^['"]|['"]$/g, "");
9
9
  }
10
10
 
11
- // Patch paths are intentionally confined to ctx.cwd so the adapter cannot write
12
- // outside the active workspace even if the incoming patch text is malicious.
11
+ // Relative patch paths stay anchored to ctx.cwd. Absolute patch paths are
12
+ // accepted as-is so the adapter can match Codex-style path usage.
13
13
  export function resolvePatchPath({ cwd, patchPath }: { cwd: string; patchPath: string }): string {
14
14
  const normalized = normalizePatchPath({ path: patchPath });
15
15
  if (!normalized) {
16
16
  throw new DiffError("Patch path cannot be empty");
17
17
  }
18
- if (isAbsolute(normalized)) {
19
- throw new DiffError("We do not support absolute paths.");
20
- }
21
18
 
22
- const absolutePath = resolve(cwd, normalized);
19
+ const absolutePath = isAbsolute(normalized) ? normalized : resolve(cwd, normalized);
23
20
  const rel = relative(cwd, absolutePath);
24
- if (rel.startsWith("..") || isAbsolute(rel)) {
21
+ if (!isAbsolute(normalized) && (rel.startsWith("..") || isAbsolute(rel))) {
25
22
  throw new DiffError(`Path escapes working directory: ${normalized}`);
26
23
  }
27
24
  return absolutePath;
@@ -65,7 +65,7 @@ export interface ExecSessionManager {
65
65
  }
66
66
 
67
67
  const DEFAULT_EXEC_YIELD_TIME_MS = 10_000;
68
- const DEFAULT_WRITE_YIELD_TIME_MS = 250;
68
+ const DEFAULT_WRITE_YIELD_TIME_MS = 10_000;
69
69
  const DEFAULT_MAX_OUTPUT_TOKENS = 10_000;
70
70
  const MIN_YIELD_TIME_MS = 250;
71
71
  const MAX_YIELD_TIME_MS = 30_000;
@@ -292,18 +292,24 @@ export function createExecSessionManager(): ExecSessionManager {
292
292
  notify(session);
293
293
  }
294
294
 
295
- function waitForActivity(session: ExecSession, yieldTimeMs: number): Promise<number> {
296
- if (session.buffer !== session.emittedBuffer || session.exitCode !== undefined && session.exitCode !== null) {
295
+ function waitForExitOrTimeout(session: ExecSession, yieldTimeMs: number): Promise<number> {
296
+ if (session.exitCode !== undefined && session.exitCode !== null) {
297
297
  return Promise.resolve(0);
298
298
  }
299
299
 
300
300
  const startedAt = Date.now();
301
301
  return new Promise((resolvePromise) => {
302
302
  const onWake = () => {
303
+ if (session.exitCode === undefined || session.exitCode === null) {
304
+ return;
305
+ }
303
306
  cleanup();
304
307
  resolvePromise(Date.now() - startedAt);
305
308
  };
306
- const timeout = setTimeout(onWake, yieldTimeMs);
309
+ const timeout = setTimeout(() => {
310
+ cleanup();
311
+ resolvePromise(Date.now() - startedAt);
312
+ }, yieldTimeMs);
307
313
  const cleanup = () => {
308
314
  clearTimeout(timeout);
309
315
  session.listeners.delete(onWake);
@@ -432,7 +438,7 @@ export function createExecSessionManager(): ExecSessionManager {
432
438
  sessions.set(session.id, session);
433
439
  rememberCommand(session.id, session.command);
434
440
 
435
- const waitedMs = await waitForActivity(session, clampYieldTime(input.yield_time_ms, DEFAULT_EXEC_YIELD_TIME_MS));
441
+ const waitedMs = await waitForExitOrTimeout(session, clampYieldTime(input.yield_time_ms, DEFAULT_EXEC_YIELD_TIME_MS));
436
442
  return makeResult(session, waitedMs, input.max_output_tokens);
437
443
  },
438
444
  write: async (input) => {
@@ -450,7 +456,7 @@ export function createExecSessionManager(): ExecSessionManager {
450
456
  }
451
457
  const waitedMs =
452
458
  session.exitCode === undefined
453
- ? await waitForActivity(session, clampYieldTime(input.yield_time_ms, DEFAULT_WRITE_YIELD_TIME_MS))
459
+ ? await waitForExitOrTimeout(session, clampYieldTime(input.yield_time_ms, DEFAULT_WRITE_YIELD_TIME_MS))
454
460
  : 0;
455
461
  return makeResult(session, waitedMs, input.max_output_tokens);
456
462
  },