terminal-pilot 0.0.22 → 0.0.23

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.
@@ -1,5 +1,6 @@
1
1
  import { fileMutation, runMutations, templateMutation } from "@poe-code/config-mutations";
2
2
  import { resolveAgentSupport } from "./configs.js";
3
+ import { hasOwnErrorCode } from "./error-codes.js";
3
4
  import { createTemplateLoader } from "./templates.js";
4
5
  export class UnsupportedAgentError extends Error {
5
6
  constructor(agentId) {
@@ -23,10 +24,7 @@ async function pathExists(fs, targetPath) {
23
24
  return true;
24
25
  }
25
26
  catch (error) {
26
- if (typeof error === "object" &&
27
- error !== null &&
28
- Object.prototype.hasOwnProperty.call(error, "code") &&
29
- error.code === "ENOENT") {
27
+ if (hasOwnErrorCode(error, "ENOENT")) {
30
28
  return false;
31
29
  }
32
30
  throw error;
@@ -2,21 +2,19 @@ import * as fs from "node:fs";
2
2
  import { createHash, randomUUID } from "node:crypto";
3
3
  import path from "node:path";
4
4
  import { getAgentConfig, resolveAgentSupport, resolveSkillDir, supportedAgents } from "./configs.js";
5
+ import { hasOwnErrorCode } from "./error-codes.js";
5
6
  import { appendExcludeBlock, removeExcludeBlock } from "./git-exclude.js";
6
7
  import { resolveSkillReference } from "./resolve-skill-reference.js";
7
8
  const activeTargets = new Map();
8
9
  const manifestStates = new WeakMap();
9
10
  const ownershipFileName = ".poe-code-bridge-owner";
10
- function isNodeError(error) {
11
- return error instanceof Error && Object.prototype.hasOwnProperty.call(error, "code");
12
- }
13
11
  function pathExists(targetPath) {
14
12
  try {
15
13
  fs.statSync(targetPath);
16
14
  return true;
17
15
  }
18
16
  catch (error) {
19
- if (isNodeError(error) && error.code === "ENOENT") {
17
+ if (hasOwnErrorCode(error, "ENOENT")) {
20
18
  return false;
21
19
  }
22
20
  throw error;
@@ -36,7 +34,7 @@ function assertNoSymbolicLink(targetPath) {
36
34
  }
37
35
  }
38
36
  catch (error) {
39
- if (isNodeError(error) && error.code === "ENOENT") {
37
+ if (hasOwnErrorCode(error, "ENOENT")) {
40
38
  return;
41
39
  }
42
40
  throw error;
@@ -48,7 +46,7 @@ function isDirectory(targetPath) {
48
46
  return fs.statSync(targetPath).isDirectory();
49
47
  }
50
48
  catch (error) {
51
- if (isNodeError(error) && error.code === "ENOENT") {
49
+ if (hasOwnErrorCode(error, "ENOENT")) {
52
50
  return false;
53
51
  }
54
52
  throw error;
@@ -137,7 +135,7 @@ function hasOwnershipToken(targetPath, token) {
137
135
  return fs.readFileSync(ownershipPath(targetPath), "utf8") === token;
138
136
  }
139
137
  catch (error) {
140
- if (isNodeError(error) && error.code === "ENOENT") {
138
+ if (hasOwnErrorCode(error, "ENOENT")) {
141
139
  return false;
142
140
  }
143
141
  throw error;
@@ -161,8 +159,9 @@ function removeDirectoryIfEmpty(targetPath) {
161
159
  fs.rmdirSync(targetPath);
162
160
  }
163
161
  catch (error) {
164
- if (isNodeError(error) &&
165
- (error.code === "ENOENT" || error.code === "ENOTEMPTY" || error.code === "EEXIST")) {
162
+ if (hasOwnErrorCode(error, "ENOENT") ||
163
+ hasOwnErrorCode(error, "ENOTEMPTY") ||
164
+ hasOwnErrorCode(error, "EEXIST")) {
166
165
  return;
167
166
  }
168
167
  throw error;
@@ -0,0 +1 @@
1
+ export declare function hasOwnErrorCode(error: unknown, code: string): boolean;
@@ -0,0 +1,5 @@
1
+ export function hasOwnErrorCode(error, code) {
2
+ return (error instanceof Error &&
3
+ Object.prototype.hasOwnProperty.call(error, "code") &&
4
+ error.code === code);
5
+ }
@@ -2,6 +2,7 @@ import { execFileSync } from "node:child_process";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import * as fs from "node:fs";
4
4
  import path from "node:path";
5
+ import { hasOwnErrorCode } from "./error-codes.js";
5
6
  const defaultMarkerPrefix = "poe-code-spawn-skills";
6
7
  function defaultGitDirRunner(cwd) {
7
8
  try {
@@ -46,17 +47,14 @@ function readExcludeFile(excludePath) {
46
47
  return fs.readFileSync(excludePath, "utf8");
47
48
  }
48
49
  catch (error) {
49
- if (isNodeError(error) && error.code === "ENOENT") {
50
+ if (hasOwnErrorCode(error, "ENOENT")) {
50
51
  return undefined;
51
52
  }
52
53
  throw error;
53
54
  }
54
55
  }
55
- function isNodeError(error) {
56
- return error instanceof Error && Object.prototype.hasOwnProperty.call(error, "code");
57
- }
58
56
  function isAlreadyExistsError(error) {
59
- return isNodeError(error) && error.code === "EEXIST";
57
+ return hasOwnErrorCode(error, "EEXIST");
60
58
  }
61
59
  function assertNoSymbolicLink(targetPath) {
62
60
  const parsed = path.parse(path.resolve(targetPath));
@@ -72,7 +70,7 @@ function assertNoSymbolicLink(targetPath) {
72
70
  }
73
71
  }
74
72
  catch (error) {
75
- if (isNodeError(error) && error.code === "ENOENT") {
73
+ if (hasOwnErrorCode(error, "ENOENT")) {
76
74
  return;
77
75
  }
78
76
  throw error;
@@ -1,6 +1,7 @@
1
1
  import { readFile, stat } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
+ import { hasOwnErrorCode } from "./error-codes.js";
4
5
  const TEMPLATE_IDS = ["poe-generate.md", "terminal-pilot.md"];
5
6
  const cache = new Map();
6
7
  async function pathExists(target) {
@@ -9,10 +10,7 @@ async function pathExists(target) {
9
10
  return true;
10
11
  }
11
12
  catch (error) {
12
- if (error &&
13
- typeof error === "object" &&
14
- Object.prototype.hasOwnProperty.call(error, "code") &&
15
- error.code === "ENOENT") {
13
+ if (hasOwnErrorCode(error, "ENOENT")) {
16
14
  return false;
17
15
  }
18
16
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terminal-pilot",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "Playwright-like SDK and CLI for automating interactive CLI apps through a real PTY",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",