toolcraft 0.0.164 → 0.0.165

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/composition.json CHANGED
@@ -98,7 +98,7 @@
98
98
  },
99
99
  {
100
100
  "name": "tiny-http-mcp-server",
101
- "version": "0.1.7",
101
+ "version": "0.1.8",
102
102
  "license": "MIT"
103
103
  },
104
104
  {
@@ -113,7 +113,7 @@
113
113
  },
114
114
  {
115
115
  "name": "toolcraft",
116
- "version": "0.0.164",
116
+ "version": "0.0.165",
117
117
  "license": "MIT"
118
118
  },
119
119
  {
@@ -123,7 +123,7 @@
123
123
  },
124
124
  {
125
125
  "name": "toolcraft-schema",
126
- "version": "0.0.164",
126
+ "version": "0.0.165",
127
127
  "license": "MIT"
128
128
  },
129
129
  {
@@ -98,7 +98,7 @@
98
98
  },
99
99
  {
100
100
  "name": "tiny-http-mcp-server",
101
- "version": "0.1.7",
101
+ "version": "0.1.8",
102
102
  "license": "MIT"
103
103
  },
104
104
  {
@@ -113,7 +113,7 @@
113
113
  },
114
114
  {
115
115
  "name": "toolcraft",
116
- "version": "0.0.164",
116
+ "version": "0.0.165",
117
117
  "license": "MIT"
118
118
  },
119
119
  {
@@ -123,7 +123,7 @@
123
123
  },
124
124
  {
125
125
  "name": "toolcraft-schema",
126
- "version": "0.0.164",
126
+ "version": "0.0.165",
127
127
  "license": "MIT"
128
128
  },
129
129
  {
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import path from "node:path";
3
3
  import { renderTemplate } from "toolcraft-design";
4
+ import { isConfigObject } from "../types.js";
4
5
  import { getConfigFormat, detectFormat } from "../formats/index.js";
5
6
  import { cloneConfigObject, setConfigEntry } from "../formats/object.js";
6
7
  import { resolvePath } from "./path-utils.js";
@@ -187,9 +188,6 @@ function pruneKeysByPrefix(table, prefix) {
187
188
  }
188
189
  return result;
189
190
  }
190
- function isConfigObject(value) {
191
- return typeof value === "object" && value !== null && !Array.isArray(value);
192
- }
193
191
  function mergeWithPruneByPrefix(base, patch, pruneByPrefix) {
194
192
  const result = cloneConfigObject(base);
195
193
  const prefixMap = pruneByPrefix ?? {};
@@ -1,8 +1,6 @@
1
1
  import * as jsonc from "jsonc-parser";
2
+ import { isConfigObject } from "../types.js";
2
3
  import { cloneConfigObject, hasConfigEntry, setConfigEntry } from "./object.js";
3
- function isConfigObject(value) {
4
- return typeof value === "object" && value !== null && !Array.isArray(value);
5
- }
6
4
  function detectIndent(content) {
7
5
  const match = content.match(/^[\t ]+/m);
8
6
  if (match) {
@@ -1,8 +1,6 @@
1
1
  import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
2
+ import { isConfigObject } from "../types.js";
2
3
  import { cloneConfigObject, hasConfigEntry, setConfigEntry } from "./object.js";
3
- function isConfigObject(value) {
4
- return typeof value === "object" && value !== null && !Array.isArray(value);
5
- }
6
4
  function parse(content) {
7
5
  if (!content || content.trim() === "") {
8
6
  return {};
@@ -1,8 +1,6 @@
1
1
  import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
2
+ import { isConfigObject } from "../types.js";
2
3
  import { cloneConfigObject, hasConfigEntry, setConfigEntry } from "./object.js";
3
- function isConfigObject(value) {
4
- return typeof value === "object" && value !== null && !Array.isArray(value);
5
- }
6
4
  function parse(content) {
7
5
  if (!content || content.trim() === "") {
8
6
  return {};
@@ -2,5 +2,5 @@
2
2
  // Config Object Types
3
3
  // ============================================================================
4
4
  export function isConfigObject(value) {
5
- return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ return (typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date));
6
6
  }
@@ -1,5 +1,7 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import path from "node:path";
3
+ const LOCK_WAIT_MS = 30_000;
4
+ const LOCK_RETRY_MS = 10;
3
5
  export function compareCreated(left, right) {
4
6
  const leftCreated = typeof left.raw.created === "string" ? left.raw.created : "";
5
7
  const rightCreated = typeof right.raw.created === "string" ? right.raw.created : "";
@@ -10,7 +12,14 @@ export function compareCreated(left, right) {
10
12
  return 1;
11
13
  if (rightCreated === "")
12
14
  return -1;
13
- return leftCreated.localeCompare(rightCreated);
15
+ const leftTimestamp = Date.parse(leftCreated);
16
+ const rightTimestamp = Date.parse(rightCreated);
17
+ if (Number.isNaN(leftTimestamp)) {
18
+ return Number.isNaN(rightTimestamp) ? leftCreated.localeCompare(rightCreated) : 1;
19
+ }
20
+ if (Number.isNaN(rightTimestamp))
21
+ return -1;
22
+ return leftTimestamp - rightTimestamp;
14
23
  }
15
24
  export function applyOrder(entries, order) {
16
25
  if (order === "alphabetical") {
@@ -123,62 +132,48 @@ export async function writeAtomically(fs, filePath, content) {
123
132
  }
124
133
  }
125
134
  export async function withFileLock(fs, lockPath, operation) {
135
+ await rejectSymbolicLinkComponents(fs, lockPath);
126
136
  await fs.mkdir(path.dirname(lockPath), { recursive: true });
137
+ const ownerPath = path.join(lockPath, `${process.pid}-${randomUUID()}`);
138
+ const deadline = Date.now() + LOCK_WAIT_MS;
127
139
  for (;;) {
140
+ await rejectSymbolicLinkComponents(fs, lockPath);
128
141
  try {
129
- await fs.writeFile(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
142
+ await fs.mkdir(lockPath);
130
143
  break;
131
144
  }
132
145
  catch (error) {
133
146
  if (!hasErrorCode(error, "EEXIST")) {
134
- await fs.unlink(lockPath).catch(() => undefined);
135
147
  throw error;
136
148
  }
137
- if (await removeAbandonedLock(fs, lockPath)) {
138
- continue;
149
+ if (Date.now() >= deadline) {
150
+ throw new Error(`Timed out waiting for task-list lock: ${lockPath}. ` +
151
+ "An abandoned or legacy lock must only be removed after confirming all task-list operations have stopped.");
139
152
  }
140
- await Promise.resolve();
153
+ await new Promise((done) => setTimeout(done, LOCK_RETRY_MS));
141
154
  }
142
155
  }
156
+ await rejectSymbolicLinkComponents(fs, ownerPath);
157
+ await fs.mkdir(ownerPath);
158
+ let outcome;
143
159
  try {
144
- return await operation();
145
- }
146
- finally {
147
- await fs.unlink(lockPath);
148
- }
149
- }
150
- async function removeAbandonedLock(fs, lockPath) {
151
- let content;
152
- try {
153
- content = await fs.readFile(lockPath, "utf8");
160
+ outcome = { result: await operation() };
154
161
  }
155
162
  catch (error) {
156
- if (hasErrorCode(error, "ENOENT")) {
157
- return true;
158
- }
159
- throw error;
160
- }
161
- const owner = Number(content);
162
- if (Number.isInteger(owner) && owner > 0 && isProcessRunning(owner)) {
163
- return false;
163
+ outcome = { error };
164
164
  }
165
165
  try {
166
- await fs.unlink(lockPath);
167
- return true;
166
+ await rejectSymbolicLinkComponents(fs, ownerPath);
167
+ await fs.rmdir(ownerPath);
168
+ await fs.rmdir(lockPath);
168
169
  }
169
170
  catch (error) {
170
- if (hasErrorCode(error, "ENOENT")) {
171
- return true;
171
+ if ("error" in outcome) {
172
+ throw new AggregateError([outcome.error, error], "Task-list operation and lock release failed");
172
173
  }
173
174
  throw error;
174
175
  }
175
- }
176
- function isProcessRunning(pid) {
177
- try {
178
- process.kill(pid, 0);
179
- return true;
180
- }
181
- catch (error) {
182
- return !hasErrorCode(error, "ESRCH");
183
- }
176
+ if ("error" in outcome)
177
+ throw outcome.error;
178
+ return outcome.result;
184
179
  }
@@ -73,6 +73,7 @@ export interface TaskListFs {
73
73
  readFile(path: string, encoding: BufferEncoding): Promise<string>;
74
74
  readdir(path: string): Promise<string[]>;
75
75
  rename(fromPath: string, toPath: string): Promise<void>;
76
+ rmdir(path: string): Promise<void>;
76
77
  stat(path: string): Promise<{
77
78
  isDirectory(): boolean;
78
79
  isFile(): boolean;
@@ -19,6 +19,9 @@ export class MigratingSecretStore {
19
19
  await this.mutate(async () => {
20
20
  if (await this.store.get() === null) {
21
21
  try {
22
+ if (await this.legacyStore?.get() !== legacyValue) {
23
+ return;
24
+ }
22
25
  await this.store.set(legacyValue);
23
26
  }
24
27
  catch {
@@ -18,7 +18,7 @@
18
18
  },
19
19
  {
20
20
  "name": "tiny-http-mcp-server",
21
- "version": "0.1.7",
21
+ "version": "0.1.8",
22
22
  "license": "MIT"
23
23
  },
24
24
  {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-http-mcp-server",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Minimal MCP server over HTTP built on tiny-stdio-mcp-server",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,7 +8,7 @@
8
8
  },
9
9
  {
10
10
  "name": "toolcraft-schema",
11
- "version": "0.0.164",
11
+ "version": "0.0.165",
12
12
  "license": "MIT"
13
13
  }
14
14
  ]
@@ -48,7 +48,7 @@ export declare class Prompt<Value> extends EventEmitter {
48
48
  get cursor(): number;
49
49
  prompt(): Promise<Value | typeof CANCEL>;
50
50
  protected promptNonTty(): Promise<Value | typeof CANCEL>;
51
- protected readNonTtyLine(): Promise<string>;
51
+ protected readNonTtyLine(): Promise<string | typeof CANCEL>;
52
52
  protected setValue(value: Value | undefined): void;
53
53
  protected setError(message: string): void;
54
54
  protected setUserInput(value: string): void;
@@ -117,11 +117,20 @@ export class Prompt extends EventEmitter {
117
117
  return;
118
118
  }
119
119
  settled = true;
120
+ this.signal?.removeEventListener("abort", onAbort);
120
121
  rl.close();
121
122
  resolve(value);
122
123
  };
124
+ const onAbort = () => {
125
+ this.state = "cancel";
126
+ settle(CANCEL);
127
+ };
123
128
  rl.once("line", settle);
124
129
  rl.once("close", () => settle(rl.line));
130
+ this.signal?.addEventListener("abort", onAbort, { once: true });
131
+ if (this.signal?.aborted) {
132
+ onAbort();
133
+ }
125
134
  });
126
135
  }
127
136
  setValue(value) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.164",
3
+ "version": "0.0.165",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft",
3
- "version": "0.0.164",
3
+ "version": "0.0.165",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -158,7 +158,7 @@
158
158
  "yaml"
159
159
  ],
160
160
  "optionalDependencies": {
161
- "toolcraft-schema": "0.0.164",
161
+ "toolcraft-schema": "0.0.165",
162
162
  "toolcraft-design": "*",
163
163
  "@poe-code/frontmatter": "*",
164
164
  "@poe-code/agent-mcp-config": "*",