toolcraft 0.0.85 → 0.0.86

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/dist/cli.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ import "./node-require-shim.js";
1
2
  import { configureTheme } from "toolcraft-design";
2
3
  import type { Group, LogLevel, RuntimeLoggerInput } from "./index.js";
3
4
  import { type ErrorReportsOption } from "./error-report.js";
4
- import type { HumanInLoopRuntimeOptions } from "./human-in-loop/index.js";
5
+ import type { HumanInLoopRuntimeOptions } from "./human-in-loop/types.js";
5
6
  export { configureTheme };
6
7
  type Casing = "kebab" | "snake";
7
8
  export interface CLIControls {
package/dist/cli.js CHANGED
@@ -1,13 +1,11 @@
1
+ import "./node-require-shim.js";
1
2
  import { access, lstat, readFile, rename, unlink, writeFile } from "node:fs/promises";
2
3
  import path from "node:path";
3
4
  import { Command as CommanderCommand, CommanderError, InvalidArgumentError, Option } from "commander";
4
5
  import { cancel, configureTheme, confirm, createLogger, formatCommandList, formatOptionList, getTheme, helpFormatterPlain, isCancel, note, promptText, renderTable, resetOutputFormatCache, select, text } from "toolcraft-design";
5
- import { ApprovalDeclinedError, UserError, assertCommandRequirements, getCommandSourcePath, resolveCommandSecrets } from "./index.js";
6
+ import { ApprovalDeclinedError, UserError, assertCommandRequirements, getCommandSourcePath, hasMcpProxyConfig, resolveCommandSecrets } from "./index.js";
6
7
  import { hasOwnErrorCode } from "./error-codes.js";
7
- import { mergeApprovalsGroup } from "./human-in-loop/approvals-commands.js";
8
8
  import { writeErrorReport } from "./error-report.js";
9
- import { invokeWithHumanInLoop } from "./human-in-loop/index.js";
10
- import { resolveMcpProxies } from "./mcp-proxy.js";
11
9
  import { getExpectedNumberDescription, isValidNumberSchemaValue } from "./number-schema.js";
12
10
  import { findEntrypointPackageMetadata } from "./package-metadata.js";
13
11
  import { redactHttpBody, redactHttpHeaderValue } from "./redaction.js";
@@ -33,6 +31,14 @@ const RESERVED_SERVICE_NAMES = new Set([
33
31
  ]);
34
32
  const RESERVED_SERVICE_NAMES_MESSAGE = "Available reserved names: params, secrets, fetch, fs, env, diagnostics, progress, runtimeOptions, root.";
35
33
  const NULL_OPTION_VALUE = Symbol("toolcraft.cli.null");
34
+ const optionalModulePaths = {
35
+ approvals: "./human-in-loop/approvals-commands.js",
36
+ humanInLoop: "./human-in-loop/gate.js",
37
+ mcpProxy: "./mcp-proxy.js"
38
+ };
39
+ function importOptionalModule(specifier) {
40
+ return import(specifier);
41
+ }
36
42
  function inferProgramName(argv) {
37
43
  const entrypoint = argv[1];
38
44
  if (typeof entrypoint !== "string" || entrypoint.length === 0) {
@@ -2875,7 +2881,9 @@ async function executeCommand(state, services, requirementOptions, runtimeFetch,
2875
2881
  throw new UserError("Operation cancelled.");
2876
2882
  }
2877
2883
  }
2878
- const result = await invokeWithHumanInLoop(state.command, context, runtimeOptions, state.commandPath);
2884
+ const result = state.command.humanInLoop
2885
+ ? await (await importOptionalModule(optionalModulePaths.humanInLoop)).invokeWithHumanInLoop(state.command, context, runtimeOptions, state.commandPath)
2886
+ : await state.command.handler(context);
2879
2887
  if (output === "rich" && runtime.isFixture) {
2880
2888
  writeRichHeader(`${state.command.name} (fixture)`);
2881
2889
  }
@@ -3419,8 +3427,12 @@ export async function runCLI(roots, options = {}) {
3419
3427
  let errorReportContext;
3420
3428
  try {
3421
3429
  const normalizedRoot = normalizeRoots(roots, argv);
3422
- const root = options.approvals === true ? mergeApprovalsGroup(normalizedRoot) : normalizedRoot;
3423
- await resolveMcpProxies(root, { projectRoot: options.projectRoot });
3430
+ const root = options.approvals === true
3431
+ ? (await importOptionalModule(optionalModulePaths.approvals)).mergeApprovalsGroup(normalizedRoot)
3432
+ : normalizedRoot;
3433
+ if (hasMcpProxyConfig(root)) {
3434
+ await (await importOptionalModule(optionalModulePaths.mcpProxy)).resolveMcpProxies(root, { projectRoot: options.projectRoot });
3435
+ }
3424
3436
  const casing = options.casing ?? "kebab";
3425
3437
  const services = (options.services ?? {});
3426
3438
  const runtimeOptions = options.humanInLoop ?? {};
@@ -4,8 +4,8 @@ import os from "node:os";
4
4
  import path from "node:path";
5
5
  import { CommanderError } from "commander";
6
6
  import { ApprovalDeclinedError } from "./human-in-loop/types.js";
7
- import { findProjectRoot } from "./mcp-proxy.js";
8
7
  import { findPackageMetadata } from "./package-metadata.js";
8
+ import { findProjectRoot } from "./project-root.js";
9
9
  import { isSensitiveName, redactHttpBody, redactHttpHeaderValue } from "./redaction.js";
10
10
  import { UserError } from "./user-error.js";
11
11
  const ERROR_REPORTS_ENV = "TOOLCRAFT_ERROR_REPORTS";
package/dist/index.d.ts CHANGED
@@ -200,6 +200,7 @@ export declare function defineGroup<TServices extends object = EmptyServices, TN
200
200
  humanInLoop?: TOwnHumanInLoop;
201
201
  }): Group<TServices> & TypedGroupMetadata<TServices, TName, TChildren, TOwnScope, ResolveOwnHumanInLoopMode<TOwnHumanInLoop>>;
202
202
  export declare function getCommandSourcePath(command: Command<any, any, any, any>): string | undefined;
203
+ export declare function hasMcpProxyConfig(group: Group<any>): boolean;
203
204
  export { S, toJsonSchema } from "toolcraft-schema";
204
205
  export { AuthenticationError, BadRequestError, ClientError, ConflictError, HttpError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, ServerError, ServiceUnavailableError, UnprocessableEntityError, createHttpError } from "./http-errors.js";
205
206
  export type { HttpErrorRequest, HttpErrorResponse } from "./http-errors.js";
package/dist/index.js CHANGED
@@ -469,6 +469,17 @@ export function defineGroup(config) {
469
469
  export function getCommandSourcePath(command) {
470
470
  return command[commandSourcePathSymbol];
471
471
  }
472
+ export function hasMcpProxyConfig(group) {
473
+ const configSymbol = Object.getOwnPropertySymbols(group).find((candidate) => candidate.description === groupConfigSymbol.description);
474
+ const config = configSymbol === undefined
475
+ ? undefined
476
+ : group[configSymbol];
477
+ if (config?.mcp !== undefined) {
478
+ return true;
479
+ }
480
+ const children = config?.children ?? group.children;
481
+ return children.some((child) => child.kind === "group" && hasMcpProxyConfig(child));
482
+ }
472
483
  export { S, toJsonSchema } from "toolcraft-schema";
473
484
  export { AuthenticationError, BadRequestError, ClientError, ConflictError, HttpError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, ServerError, ServiceUnavailableError, UnprocessableEntityError, createHttpError } from "./http-errors.js";
474
485
  export { ApprovalDeclinedError, ToolcraftBugError, UserError };
@@ -1,11 +1,11 @@
1
1
  import type { McpServerConfig } from "@poe-code/agent-mcp-config";
2
2
  import { McpClient } from "tiny-mcp-client";
3
3
  import type { Group } from "./index.js";
4
+ export { findProjectRoot } from "./project-root.js";
4
5
  export interface ResolveMcpProxyOptions {
5
6
  projectRoot?: string;
6
7
  }
7
8
  export declare function hasMcpProxyGroups(root: Group<any>): boolean;
8
- export declare function findProjectRoot(from?: string): string | undefined;
9
9
  export declare function resolveCachePath(name: string, projectRoot?: string): string;
10
10
  export declare function parseRefreshEnv(value: string | undefined): "all" | Set<string> | undefined;
11
11
  export declare function dialUpstream(name: string, config: McpServerConfig): Promise<McpClient>;
package/dist/mcp-proxy.js CHANGED
@@ -1,4 +1,3 @@
1
- import { existsSync } from "node:fs";
2
1
  import { lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
3
2
  import path from "node:path";
4
3
  import { createHash, randomUUID } from "node:crypto";
@@ -6,6 +5,8 @@ import { createLogger } from "toolcraft-design";
6
5
  import { HttpTransport, McpClient, StdioTransport } from "tiny-mcp-client";
7
6
  import { hasOwnErrorCode } from "./error-codes.js";
8
7
  import { convertJsonSchema } from "./json-schema-converter.js";
8
+ import { findProjectRoot } from "./project-root.js";
9
+ export { findProjectRoot } from "./project-root.js";
9
10
  const GROUP_CONFIG_SYMBOL_DESCRIPTION = "toolcraft.group.config";
10
11
  const MCP_PROXY_SCHEMA_URL = "https://poe-platform.github.io/poe-code/schemas/toolcraft/mcp-proxy.schema.json";
11
12
  const DEFAULT_CLIENT_INFO = {
@@ -400,22 +401,6 @@ function collectProxyGroups(root) {
400
401
  export function hasMcpProxyGroups(root) {
401
402
  return collectProxyGroups(root).length > 0;
402
403
  }
403
- export function findProjectRoot(from = process.cwd()) {
404
- let current = process.cwd();
405
- if (from !== current) {
406
- current = path.resolve(from);
407
- }
408
- while (true) {
409
- if (existsSync(path.join(current, "package.json"))) {
410
- return current;
411
- }
412
- const parent = path.dirname(current);
413
- if (parent === current) {
414
- return undefined;
415
- }
416
- current = parent;
417
- }
418
- }
419
404
  export function resolveCachePath(name, projectRoot) {
420
405
  const resolvedProjectRoot = projectRoot ?? findProjectRoot();
421
406
  if (resolvedProjectRoot === undefined) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { createRequire } from "node:module";
2
+ import path from "node:path";
3
+ const globalWithRequire = globalThis;
4
+ globalWithRequire.require ??= createRequire(path.join(process.cwd(), "package.json"));
@@ -0,0 +1 @@
1
+ export declare function findProjectRoot(from?: string): string | undefined;
@@ -0,0 +1,15 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ export function findProjectRoot(from = process.cwd()) {
4
+ let current = from === process.cwd() ? process.cwd() : path.resolve(from);
5
+ while (true) {
6
+ if (existsSync(path.join(current, "package.json"))) {
7
+ return current;
8
+ }
9
+ const parent = path.dirname(current);
10
+ if (parent === current) {
11
+ return undefined;
12
+ }
13
+ current = parent;
14
+ }
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft",
3
- "version": "0.0.85",
3
+ "version": "0.0.86",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -55,7 +55,7 @@
55
55
  "postpack": "node ../../scripts/manage-bundled-workspace-deps.mjs cleanup . toolcraft-design @poe-code/frontmatter @poe-code/agent-mcp-config @poe-code/agent-human-in-loop @poe-code/task-list @poe-code/agent-defs @poe-code/config-mutations @poe-code/process-runner tiny-mcp-client mcp-oauth auth-store"
56
56
  },
57
57
  "dependencies": {
58
- "toolcraft-schema": "0.0.85",
58
+ "toolcraft-schema": "0.0.86",
59
59
  "commander": "^13.1.0",
60
60
  "fast-string-width": "^3.0.2",
61
61
  "fast-wrap-ansi": "^0.2.0",