@crewx/sdk 0.8.0-rc.80 → 0.8.0-rc.82
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/__tests__/adapter/context-builder.test.d.ts +1 -0
- package/dist/__tests__/adapter/plugin-helper.test.d.ts +1 -0
- package/dist/__tests__/adapter/registration-integration.test.d.ts +1 -0
- package/dist/__tests__/adapter/scoped-store.test.d.ts +1 -0
- package/dist/__tests__/plugins/conversation.test.d.ts +1 -0
- package/dist/__tests__/testing/createMockContext.test.d.ts +1 -0
- package/dist/adapter/context-builder.d.ts +0 -9
- package/dist/adapter/index.d.ts +0 -1
- package/dist/adapter/plugin-helper.d.ts +0 -7
- package/dist/adapter/scoped-store.d.ts +0 -10
- package/dist/adapter/types.d.ts +0 -7
- package/dist/agent/resolver.d.ts +0 -13
- package/dist/boxing/box-storage.interface.d.ts +0 -4
- package/dist/boxing/box.service.d.ts +0 -4
- package/dist/boxing/box.types.d.ts +0 -4
- package/dist/boxing/context-builder.d.ts +0 -4
- package/dist/client/CrewxClient.d.ts +0 -32
- package/dist/client/index.d.ts +0 -1
- package/dist/client/index.js +1 -6
- package/dist/config/loader.browser.d.ts +0 -8
- package/dist/config/loader.d.ts +0 -12
- package/dist/conversation/__tests__/sqlite-provider.test.d.ts +1 -0
- package/dist/conversation/__tests__/to-task-reader.test.d.ts +1 -0
- package/dist/conversation/index.d.ts +0 -1
- package/dist/conversation/sqlite-provider.d.ts +0 -9
- package/dist/conversation/to-task-reader.d.ts +0 -11
- package/dist/conversation/to-template-messages.d.ts +0 -13
- package/dist/conversation/types.d.ts +0 -58
- package/dist/esm/client/index.js +1 -0
- package/dist/esm/hooks/index.js +7 -0
- package/dist/esm/index.js +79 -0
- package/dist/esm/plugins/index.js +52 -0
- package/dist/esm/testing/index.js +1 -0
- package/dist/esm/tools/node/index.js +36 -0
- package/dist/events/TypedEventEmitter.d.ts +0 -24
- package/dist/events/types.d.ts +0 -43
- package/dist/facade/Crewx.browser.d.ts +0 -40
- package/dist/facade/Crewx.d.ts +0 -163
- package/dist/hooks/define.d.ts +0 -1
- package/dist/hooks/dispatch.d.ts +0 -12
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +7 -24
- package/dist/hooks/observer.d.ts +0 -1
- package/dist/hooks/plugin.d.ts +0 -1
- package/dist/hooks/tool-normalize.d.ts +0 -26
- package/dist/hooks/types.d.ts +0 -1
- package/dist/hooks/yaml-plugin.d.ts +0 -1
- package/dist/index.browser.d.ts +0 -7
- package/dist/index.browser.js +2 -25
- package/dist/index.d.ts +0 -4
- package/dist/index.js +79 -151
- package/dist/layout/loader.d.ts +0 -20
- package/dist/layout/props-validator.d.ts +0 -6
- package/dist/layout/renderer.d.ts +0 -24
- package/dist/layout/types.d.ts +0 -42
- package/dist/parallel/agent-runtime.d.ts +0 -11
- package/dist/parallel/helpers.d.ts +0 -1
- package/dist/parallel/index.d.ts +0 -1
- package/dist/parallel/parallel-runner.d.ts +0 -8
- package/dist/parallel/types.d.ts +0 -24
- package/dist/parsers/agent-call.util.d.ts +0 -3
- package/dist/parsers/claude.parser.d.ts +0 -8
- package/dist/parsers/codex.parser.d.ts +0 -8
- package/dist/parsers/copilot.parser.d.ts +0 -9
- package/dist/parsers/gemini.parser.d.ts +0 -10
- package/dist/parsers/opencode.parser.d.ts +0 -10
- package/dist/parsers/router.d.ts +0 -5
- package/dist/paths.d.ts +1 -0
- package/dist/platform/BrowserFsAdapter.d.ts +0 -20
- package/dist/platform/IFsAdapter.d.ts +0 -23
- package/dist/platform/NodeFsAdapter.d.ts +0 -8
- package/dist/plugin/plugin-provider.d.ts +0 -22
- package/dist/plugin/types.d.ts +0 -31
- package/dist/plugin.d.ts +0 -27
- package/dist/plugins/conversation.d.ts +0 -2
- package/dist/plugins/file-logger.d.ts +0 -13
- package/dist/plugins/index.d.ts +0 -10
- package/dist/plugins/index.js +52 -19
- package/dist/plugins/sqlite-tracing.d.ts +0 -13
- package/dist/plugins/sqlite-tracing.spec.d.ts +1 -0
- package/dist/provider/bridge.browser.d.ts +0 -20
- package/dist/provider/bridge.d.ts +0 -47
- package/dist/provider/parse-usage.d.ts +0 -14
- package/dist/provider/register-api.d.ts +0 -7
- package/dist/provider/vercel-runtime.d.ts +0 -29
- package/dist/remote/index.d.ts +0 -6
- package/dist/remote/remote-agent-manager.d.ts +0 -31
- package/dist/remote/remote-provider.d.ts +0 -15
- package/dist/remote/remote-transport.d.ts +0 -17
- package/dist/remote/types.d.ts +0 -59
- package/dist/server/auth.d.ts +0 -16
- package/dist/server/handler.d.ts +0 -17
- package/dist/server/index.d.ts +0 -4
- package/dist/server/tool-adapter.d.ts +0 -16
- package/dist/template/engine.d.ts +0 -19
- package/dist/template/helpers/exec.browser.d.ts +0 -7
- package/dist/template/helpers/exec.d.ts +0 -45
- package/dist/template/helpers/fenced_code.d.ts +0 -16
- package/dist/template/helpers/format-conversation.d.ts +0 -22
- package/dist/template/helpers/include.d.ts +0 -15
- package/dist/template/helpers/p1p2.d.ts +0 -32
- package/dist/template/loader/DocumentLoader.d.ts +0 -30
- package/dist/template/types.d.ts +0 -30
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +1 -16
- package/dist/testing/mock-audit.d.ts +0 -1
- package/dist/testing/mock-context.d.ts +0 -1
- package/dist/testing/mock-logger.d.ts +0 -1
- package/dist/testing/mock-router.d.ts +0 -1
- package/dist/testing/mock-storage.d.ts +0 -1
- package/dist/testing/mock-store.d.ts +0 -1
- package/dist/tools/delegate.d.ts +0 -7
- package/dist/tools/index.d.ts +0 -4
- package/dist/tools/node/builtin.d.ts +0 -16
- package/dist/tools/node/index.d.ts +0 -20
- package/dist/tools/node/index.js +36 -59
- package/dist/types/index.d.ts +0 -20
- package/dist/types/task-log.types.d.ts +0 -4
- package/dist/utils/env-defaults.d.ts +0 -16
- package/dist/utils/glob-match.d.ts +0 -16
- package/dist/utils/id.d.ts +0 -15
- package/dist/utils/timestamp.d.ts +0 -1
- package/dist/utils/workspace.d.ts +0 -4
- package/package.json +24 -25
- package/dist/adapter/context-builder.js +0 -87
- package/dist/adapter/index.js +0 -21
- package/dist/adapter/plugin-helper.js +0 -45
- package/dist/adapter/scoped-store.js +0 -43
- package/dist/adapter/types.js +0 -23
- package/dist/agent/resolver.js +0 -46
- package/dist/boxing/box-storage.interface.js +0 -6
- package/dist/boxing/box.service.js +0 -73
- package/dist/boxing/box.types.js +0 -6
- package/dist/boxing/context-builder.js +0 -79
- package/dist/client/CrewxClient.js +0 -86
- package/dist/config/loader.browser.js +0 -59
- package/dist/config/loader.js +0 -95
- package/dist/conversation/index.js +0 -25
- package/dist/conversation/sqlite-provider.js +0 -178
- package/dist/conversation/to-task-reader.js +0 -28
- package/dist/conversation/to-template-messages.js +0 -34
- package/dist/conversation/types.js +0 -10
- package/dist/events/TypedEventEmitter.js +0 -65
- package/dist/events/types.js +0 -9
- package/dist/facade/Crewx.browser.js +0 -314
- package/dist/facade/Crewx.js +0 -1299
- package/dist/hooks/define.js +0 -13
- package/dist/hooks/dispatch.js +0 -147
- package/dist/hooks/observer.js +0 -60
- package/dist/hooks/plugin.js +0 -17
- package/dist/hooks/tool-normalize.js +0 -110
- package/dist/hooks/types.js +0 -12
- package/dist/hooks/yaml-plugin.js +0 -356
- package/dist/layout/loader.js +0 -305
- package/dist/layout/props-validator.js +0 -301
- package/dist/layout/renderer.js +0 -193
- package/dist/layout/types.js +0 -36
- package/dist/parallel/agent-runtime.js +0 -25
- package/dist/parallel/helpers.js +0 -219
- package/dist/parallel/index.js +0 -13
- package/dist/parallel/parallel-runner.js +0 -226
- package/dist/parallel/types.js +0 -6
- package/dist/parsers/agent-call.util.js +0 -19
- package/dist/parsers/claude.parser.js +0 -67
- package/dist/parsers/codex.parser.js +0 -100
- package/dist/parsers/copilot.parser.js +0 -66
- package/dist/parsers/gemini.parser.js +0 -46
- package/dist/parsers/opencode.parser.js +0 -76
- package/dist/parsers/router.js +0 -56
- package/dist/platform/BrowserFsAdapter.js +0 -84
- package/dist/platform/IFsAdapter.js +0 -3
- package/dist/platform/NodeFsAdapter.js +0 -38
- package/dist/plugin/plugin-provider.js +0 -207
- package/dist/plugin/types.js +0 -9
- package/dist/plugin.js +0 -29
- package/dist/plugins/conversation.js +0 -59
- package/dist/plugins/file-logger.js +0 -87
- package/dist/plugins/sqlite-tracing.js +0 -112
- package/dist/provider/bridge.browser.js +0 -49
- package/dist/provider/bridge.js +0 -381
- package/dist/provider/parse-usage.js +0 -83
- package/dist/provider/register-api.js +0 -24
- package/dist/provider/vercel-runtime.js +0 -347
- package/dist/remote/index.js +0 -32
- package/dist/remote/remote-agent-manager.js +0 -198
- package/dist/remote/remote-provider.js +0 -141
- package/dist/remote/remote-transport.js +0 -83
- package/dist/remote/types.js +0 -9
- package/dist/server/auth.js +0 -35
- package/dist/server/handler.js +0 -75
- package/dist/server/index.js +0 -9
- package/dist/server/tool-adapter.js +0 -95
- package/dist/template/engine.js +0 -137
- package/dist/template/helpers/exec.browser.js +0 -41
- package/dist/template/helpers/exec.js +0 -230
- package/dist/template/helpers/fenced_code.js +0 -20
- package/dist/template/helpers/format-conversation.js +0 -53
- package/dist/template/helpers/include.js +0 -23
- package/dist/template/helpers/p1p2.js +0 -90
- package/dist/template/loader/DocumentLoader.js +0 -128
- package/dist/template/types.js +0 -6
- package/dist/testing/mock-audit.js +0 -13
- package/dist/testing/mock-context.js +0 -68
- package/dist/testing/mock-logger.js +0 -27
- package/dist/testing/mock-router.js +0 -67
- package/dist/testing/mock-storage.js +0 -21
- package/dist/testing/mock-store.js +0 -8
- package/dist/tools/delegate.js +0 -60
- package/dist/tools/index.js +0 -9
- package/dist/tools/node/builtin.js +0 -547
- package/dist/types/index.js +0 -32
- package/dist/types/task-log.types.js +0 -6
- package/dist/utils/env-defaults.js +0 -27
- package/dist/utils/glob-match.js +0 -42
- package/dist/utils/id.js +0 -50
- package/dist/utils/timestamp.js +0 -13
- package/dist/utils/workspace.js +0 -58
package/dist/server/handler.d.ts
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* crewx.handler() — Framework-independent MCP HTTP handler.
|
|
3
|
-
*
|
|
4
|
-
* Returns a Web Standard `(req: Request) => Promise<Response>` handler
|
|
5
|
-
* that can be mounted on Express, Next.js, Hono, Bun, etc.
|
|
6
|
-
*/
|
|
7
1
|
import type { Crewx } from '../facade/Crewx';
|
|
8
2
|
export interface HandlerOptions {
|
|
9
|
-
/** Agent IDs to expose via MCP. Required — explicit selection for security. */
|
|
10
3
|
agents: string[];
|
|
11
|
-
/** Custom auth callback. Return false to reject the request. */
|
|
12
4
|
auth?: (req: Request) => Promise<boolean>;
|
|
13
5
|
}
|
|
14
|
-
/** The Web Standard handler type returned by crewx.handler(). */
|
|
15
6
|
export type CrewxHandler = (req: Request) => Promise<Response>;
|
|
16
|
-
/**
|
|
17
|
-
* Create an MCP handler bound to the given Crewx instance.
|
|
18
|
-
*
|
|
19
|
-
* @param crewx - Crewx facade instance
|
|
20
|
-
* @param options - Handler configuration (agents list required)
|
|
21
|
-
* @returns Web Standard request handler
|
|
22
|
-
*/
|
|
23
7
|
export declare function createHandler(crewx: Crewx, options: HandlerOptions): CrewxHandler;
|
|
24
|
-
//# sourceMappingURL=handler.d.ts.map
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @crewx/sdk server module — MCP HTTP handler for exposing agents.
|
|
3
|
-
*/
|
|
4
1
|
export { createHandler } from './handler';
|
|
5
2
|
export type { HandlerOptions, CrewxHandler } from './handler';
|
|
6
3
|
export type { AuthOptions } from './auth';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP tool adapter — 범용 MCP 도구 3개를 McpServer에 등록한다.
|
|
3
|
-
*
|
|
4
|
-
* 도구:
|
|
5
|
-
* crewx_queryAgent(agentId, query, context?, thread?)
|
|
6
|
-
* crewx_executeAgent(agentId, task, context?, thread?)
|
|
7
|
-
* crewx_listAgents()
|
|
8
|
-
*/
|
|
9
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
10
2
|
import type { Crewx } from '../facade/Crewx';
|
|
11
|
-
/**
|
|
12
|
-
* Register the 3 universal tools on the given McpServer.
|
|
13
|
-
*
|
|
14
|
-
* @param server - McpServer instance
|
|
15
|
-
* @param crewx - Crewx facade instance
|
|
16
|
-
* @param allowedAgents - Set of agent IDs exposed via handler
|
|
17
|
-
*/
|
|
18
3
|
export declare function registerCrewxTools(server: McpServer, crewx: Crewx, allowedAgents: Set<string>): void;
|
|
19
|
-
//# sourceMappingURL=tool-adapter.d.ts.map
|
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CrewX template engine — Handlebars-based rendering with P0 helpers.
|
|
3
|
-
*
|
|
4
|
-
* P0 helpers implemented here:
|
|
5
|
-
* - exec : shell command execution (5-stage security)
|
|
6
|
-
* - include : inline string content passthrough
|
|
7
|
-
* - fenced_code : Markdown fenced code block wrapper
|
|
8
|
-
* - eq, ne, and, or, not, json (condition helpers)
|
|
9
|
-
*/
|
|
10
1
|
import type { TemplateContext, TemplateEngineOptions } from './types';
|
|
11
2
|
export declare class TemplateEngine {
|
|
12
3
|
private readonly hbs;
|
|
13
4
|
private readonly execPolicy;
|
|
14
5
|
private readonly execEnabled;
|
|
15
6
|
constructor(options?: TemplateEngineOptions);
|
|
16
|
-
/**
|
|
17
|
-
* Register all P0 helpers onto this engine's Handlebars instance.
|
|
18
|
-
*/
|
|
19
7
|
private registerHelpers;
|
|
20
|
-
/**
|
|
21
|
-
* Render a Handlebars template string with the given context.
|
|
22
|
-
* @param template - Handlebars template string
|
|
23
|
-
* @param context - Template context (documents, env, agent, etc.)
|
|
24
|
-
* @returns Rendered string
|
|
25
|
-
*/
|
|
26
8
|
render(template: string, context?: TemplateContext): Promise<string>;
|
|
27
9
|
}
|
|
28
|
-
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser stub for the exec helper.
|
|
3
|
-
*
|
|
4
|
-
* Replaces the Node.js exec helper in browser bundles (via package.json "browser" field).
|
|
5
|
-
* All functions are no-ops or return safe defaults — child_process is not available in browsers.
|
|
6
|
-
*/
|
|
7
1
|
import type { ExecPolicy } from '../types';
|
|
8
2
|
export declare function getSanitizedEnv(): Record<string, string>;
|
|
9
3
|
export declare function validateCommand(_command: string): void;
|
|
@@ -19,4 +13,3 @@ export declare function logExecAudit(_entry: {
|
|
|
19
13
|
duration_ms?: number;
|
|
20
14
|
}): void;
|
|
21
15
|
export declare function executeCommand(_command: string, _policy: ExecPolicy): string;
|
|
22
|
-
//# sourceMappingURL=exec.browser.d.ts.map
|
|
@@ -1,50 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* exec Handlebars helper — 5-stage security implementation.
|
|
3
|
-
*
|
|
4
|
-
* Ports the security logic from packages/cli-bak/src/utils/template-processor.ts
|
|
5
|
-
* without using shell-quote or minimatch (not in allowed library list).
|
|
6
|
-
*
|
|
7
|
-
* Stages:
|
|
8
|
-
* 1. Recursion depth check (fail-closed on NaN)
|
|
9
|
-
* 2. Shell metacharacter validation
|
|
10
|
-
* 3. Allow-list enforcement (deny > builtin > allow > reject)
|
|
11
|
-
* 4. Environment isolation (strip sensitive keys)
|
|
12
|
-
* 5. Result capture (execFileSync with timeout + maxBuffer, wrapped in tags)
|
|
13
|
-
*/
|
|
14
1
|
import type { ExecPolicy } from '../types';
|
|
15
|
-
/**
|
|
16
|
-
* Returns a copy of process.env with all sensitive keys removed.
|
|
17
|
-
*/
|
|
18
2
|
export declare function getSanitizedEnv(): Record<string, string>;
|
|
19
|
-
/**
|
|
20
|
-
* Validates a command string for shell metacharacter injection.
|
|
21
|
-
* @throws Error if shell metacharacters are detected.
|
|
22
|
-
*/
|
|
23
3
|
export declare function validateCommand(command: string): void;
|
|
24
|
-
/**
|
|
25
|
-
* Checks if a command matches the builtin allowed pattern.
|
|
26
|
-
* Only npx @crewx/<package> scope is allowed by default.
|
|
27
|
-
*/
|
|
28
4
|
export declare function isBuiltinAllowed(command: string): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Validates allow/deny patterns — rejects overly broad wildcards.
|
|
31
|
-
* @throws Error if pattern is too broad or malformed.
|
|
32
|
-
*/
|
|
33
5
|
export declare function validateAllowPattern(pattern: string): void;
|
|
34
|
-
/**
|
|
35
|
-
* Checks if a command is allowed by the exec policy.
|
|
36
|
-
* Priority: deny > builtin(@crewx) > allow > reject
|
|
37
|
-
*/
|
|
38
6
|
export declare function isAllowed(command: string, policy: ExecPolicy): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Enable or disable exec audit log output to stderr.
|
|
41
|
-
* Call with true to show span JSON (verbose mode); false to suppress (default).
|
|
42
|
-
*/
|
|
43
7
|
export declare function setAuditVerbose(enabled: boolean): void;
|
|
44
|
-
/**
|
|
45
|
-
* Emits a structured audit log entry to stderr.
|
|
46
|
-
* Only writes when verbose audit mode is enabled via setAuditVerbose(true).
|
|
47
|
-
*/
|
|
48
8
|
export declare function logExecAudit(entry: {
|
|
49
9
|
command: string;
|
|
50
10
|
status: 'allowed' | 'denied' | 'error';
|
|
@@ -52,9 +12,4 @@ export declare function logExecAudit(entry: {
|
|
|
52
12
|
reason?: string;
|
|
53
13
|
duration_ms?: number;
|
|
54
14
|
}): void;
|
|
55
|
-
/**
|
|
56
|
-
* Executes a command and returns the output wrapped in exec-output tags.
|
|
57
|
-
* Implements all 5 security stages.
|
|
58
|
-
*/
|
|
59
15
|
export declare function executeCommand(command: string, policy: ExecPolicy): string;
|
|
60
|
-
//# sourceMappingURL=exec.d.ts.map
|
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* fenced_code Handlebars helper — wraps content in a Markdown fenced code block.
|
|
3
|
-
*
|
|
4
|
-
* Usage in templates:
|
|
5
|
-
* {{fenced_code myCode lang="typescript"}}
|
|
6
|
-
* {{fenced_code myCode}} ← no language specified
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Options hash passed by Handlebars for the fenced_code helper.
|
|
10
|
-
*/
|
|
11
1
|
export interface FencedCodeOptions {
|
|
12
2
|
hash?: {
|
|
13
3
|
lang?: string;
|
|
14
4
|
};
|
|
15
5
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Wraps content in a Markdown fenced code block.
|
|
18
|
-
* @param content - The code content to wrap.
|
|
19
|
-
* @param options - Handlebars options object (may contain hash.lang).
|
|
20
|
-
*/
|
|
21
6
|
export declare function fencedCodeHelper(content: string, options: FencedCodeOptions): string;
|
|
22
|
-
//# sourceMappingURL=fenced_code.d.ts.map
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* formatConversation Handlebars block helper.
|
|
3
|
-
*
|
|
4
|
-
* Ported from packages/sdk-bak/src/services/layout-renderer.service.ts:230~297.
|
|
5
|
-
* Block mode only — the default.yaml template uses block mode exclusively.
|
|
6
|
-
* Inline/fallback template file read is excluded (environment-independence concern).
|
|
7
|
-
*
|
|
8
|
-
* Unlike exec/shell-quote (which were excluded for RCE risk), formatConversation
|
|
9
|
-
* is pure string manipulation with no code execution — RCE is not a concern.
|
|
10
|
-
*/
|
|
11
1
|
export interface FormatConversationBlockContext {
|
|
12
2
|
messages: any[];
|
|
13
3
|
platform: string;
|
|
@@ -15,16 +5,4 @@ export interface FormatConversationBlockContext {
|
|
|
15
5
|
agentIds: string[];
|
|
16
6
|
primaryAgentId: string;
|
|
17
7
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Handlebars block helper for conversation history formatting.
|
|
20
|
-
*
|
|
21
|
-
* Usage in template:
|
|
22
|
-
* {{#formatConversation messages platform}}
|
|
23
|
-
* ...block content with {{messages}}, {{platform}}, {{messagesCount}},
|
|
24
|
-
* {{agentIds}}, {{primaryAgentId}}...
|
|
25
|
-
* {{/formatConversation}}
|
|
26
|
-
*
|
|
27
|
-
* Returns '' for empty/non-array messages.
|
|
28
|
-
*/
|
|
29
8
|
export declare function formatConversationHelper(this: any, messages: any, platform: any, options?: any): string;
|
|
30
|
-
//# sourceMappingURL=format-conversation.d.ts.map
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* include Handlebars helper — returns inline string content as-is.
|
|
3
|
-
*
|
|
4
|
-
* Usage in templates:
|
|
5
|
-
* {{{include someVariable}}}
|
|
6
|
-
* {{{include "literal string"}}}
|
|
7
|
-
*
|
|
8
|
-
* Note: File-path based document loading is handled in SDK-006 (DocumentLoader).
|
|
9
|
-
* This helper supports only inline string content (already in context).
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Returns the given string content unchanged.
|
|
13
|
-
* Returns empty string for null/undefined.
|
|
14
|
-
*/
|
|
15
1
|
export declare function includeHelper(content: string): string;
|
|
16
|
-
//# sourceMappingURL=include.d.ts.map
|
|
@@ -1,37 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* P1/P2 Handlebars helper implementations.
|
|
3
|
-
*
|
|
4
|
-
* P1: truncate, length, escapeHandlebars
|
|
5
|
-
* P2: formatFileSize, formatTimestamp
|
|
6
|
-
*
|
|
7
|
-
* Ported from packages/cli-bak/src/utils/template-processor.ts.
|
|
8
|
-
* formatConversation is intentionally excluded (user confirmed).
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Truncate text to maxLength, appending remaining char count if truncated.
|
|
12
|
-
* {{truncate text 500}} or {{{truncate text 500}}}
|
|
13
|
-
*/
|
|
14
1
|
export declare function truncateHelper(text: string, maxLength: number): string;
|
|
15
|
-
/**
|
|
16
|
-
* Return the length of an array or string.
|
|
17
|
-
* {{length array}} / {{length string}}
|
|
18
|
-
*/
|
|
19
2
|
export declare function lengthHelper(value: unknown): number;
|
|
20
|
-
/**
|
|
21
|
-
* Escape Handlebars delimiters in user-provided content.
|
|
22
|
-
* Prevents secondary template compilation of user content.
|
|
23
|
-
* {{{escapeHandlebars text}}}
|
|
24
|
-
*/
|
|
25
3
|
export declare function escapeHandlebarsHelper(text: string): string;
|
|
26
|
-
/**
|
|
27
|
-
* Format a byte count as a human-readable file size string.
|
|
28
|
-
* {{formatFileSize bytes}}
|
|
29
|
-
*/
|
|
30
4
|
export declare function formatFileSizeHelper(bytes: number): string;
|
|
31
|
-
/**
|
|
32
|
-
* Format a Date or ISO timestamp string into a locale-aware display string.
|
|
33
|
-
* Returns empty string for invalid or falsy input.
|
|
34
|
-
* {{formatTimestamp timestamp}}
|
|
35
|
-
*/
|
|
36
5
|
export declare function formatTimestampHelper(timestamp: Date | string | null | undefined): string;
|
|
37
|
-
//# sourceMappingURL=p1p2.d.ts.map
|
|
@@ -1,42 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DocumentLoader — loads documents from crewx.yaml `documents:` section.
|
|
3
|
-
*
|
|
4
|
-
* Supports:
|
|
5
|
-
* - Inline string: `notice: "Some text"`
|
|
6
|
-
* - Inline object: `notice: { content: "Some text" }`
|
|
7
|
-
* - File path (relative): `guide: { path: "docs/guide.md" }`
|
|
8
|
-
* - File path (absolute): `guide: { path: "/abs/docs/guide.md" }`
|
|
9
|
-
*
|
|
10
|
-
* File I/O is delegated to IFsAdapter for testability and future WEB compat.
|
|
11
|
-
*/
|
|
12
1
|
import type { IFsAdapter } from '../../platform/IFsAdapter';
|
|
13
2
|
export declare class DocumentLoader {
|
|
14
3
|
private readonly docs;
|
|
15
4
|
private readonly fs;
|
|
16
5
|
constructor(fsAdapter?: IFsAdapter);
|
|
17
|
-
/**
|
|
18
|
-
* Load all documents from the `documents:` section of crewx.yaml.
|
|
19
|
-
*
|
|
20
|
-
* @param sources - Record of document name → source (string, {path}, or {content})
|
|
21
|
-
* @param projectRoot - Base directory for resolving relative file paths
|
|
22
|
-
*/
|
|
23
6
|
load(sources?: Record<string, unknown>, projectRoot?: string): Promise<void>;
|
|
24
|
-
/** Get document text content by name. Returns undefined if not loaded. */
|
|
25
7
|
getContent(name: string): Promise<string | undefined>;
|
|
26
|
-
/**
|
|
27
|
-
* Get a simple TOC (table of contents) for a markdown document.
|
|
28
|
-
* Extracts headings (lines starting with `#`) and returns them as an indented list.
|
|
29
|
-
* Returns undefined if there are no headings.
|
|
30
|
-
*/
|
|
31
8
|
getToc(name: string): Promise<string | undefined>;
|
|
32
|
-
/** Get the resolved absolute file path for a file-based document. */
|
|
33
9
|
getPath(name: string): string | undefined;
|
|
34
|
-
/** Get all loaded document names. */
|
|
35
10
|
getNames(): string[];
|
|
36
|
-
/**
|
|
37
|
-
* Build a documents context object suitable for Handlebars template rendering.
|
|
38
|
-
* Returns `{ docName: { content, toc, path? }, ... }`.
|
|
39
|
-
*/
|
|
40
11
|
buildContext(): Promise<Record<string, {
|
|
41
12
|
content: string;
|
|
42
13
|
toc?: string;
|
|
@@ -45,4 +16,3 @@ export declare class DocumentLoader {
|
|
|
45
16
|
private loadFromFile;
|
|
46
17
|
private resolve;
|
|
47
18
|
}
|
|
48
|
-
//# sourceMappingURL=DocumentLoader.d.ts.map
|
package/dist/template/types.d.ts
CHANGED
|
@@ -1,51 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for the CrewX template engine.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Exec helper policy — controls which shell commands may be executed
|
|
6
|
-
* by the {{exec "..."}} Handlebars helper.
|
|
7
|
-
*
|
|
8
|
-
* Priority: deny > builtin(@crewx) > allow > reject
|
|
9
|
-
*/
|
|
10
1
|
export interface ExecPolicy {
|
|
11
|
-
/** Glob patterns for commands that are explicitly allowed (after deny check). */
|
|
12
2
|
allow?: string[];
|
|
13
|
-
/** Glob patterns for commands that are always denied (highest priority). */
|
|
14
3
|
deny?: string[];
|
|
15
|
-
/** Execution timeout in milliseconds (default: 5000). */
|
|
16
4
|
timeout?: number;
|
|
17
5
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Context object passed to renderPrompt() / TemplateEngine.render().
|
|
20
|
-
*
|
|
21
|
-
* Loosely typed to support arbitrary Handlebars context keys while providing
|
|
22
|
-
* structured types for the well-known properties.
|
|
23
|
-
*/
|
|
24
6
|
export interface TemplateContext {
|
|
25
|
-
/** Pre-loaded documents keyed by document name. */
|
|
26
7
|
documents?: Record<string, {
|
|
27
8
|
content?: string;
|
|
28
9
|
toc?: string;
|
|
29
10
|
summary?: string;
|
|
30
11
|
}>;
|
|
31
|
-
/** Environment variables (subset). */
|
|
32
12
|
env?: Record<string, string>;
|
|
33
|
-
/** Agent metadata. */
|
|
34
13
|
agent?: Record<string, unknown>;
|
|
35
|
-
/** Current platform. */
|
|
36
14
|
platform?: string;
|
|
37
|
-
/** Execution mode. */
|
|
38
15
|
mode?: string;
|
|
39
|
-
/** Arbitrary additional context. */
|
|
40
16
|
[key: string]: unknown;
|
|
41
17
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Options for the TemplateEngine constructor.
|
|
44
|
-
*/
|
|
45
18
|
export interface TemplateEngineOptions {
|
|
46
|
-
/** Exec policy. If omitted, exec helper is disabled (all commands blocked). */
|
|
47
19
|
execPolicy?: ExecPolicy;
|
|
48
|
-
/** Whether the exec helper is enabled. Default: true. Set to false for browser environments. */
|
|
49
20
|
execEnabled?: boolean;
|
|
50
21
|
}
|
|
51
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/testing/index.d.ts
CHANGED
package/dist/testing/index.js
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createMockRouter = exports.createMockAudit = exports.createMockStorage = exports.createMockStore = exports.createMockLogger = exports.createMockContext = void 0;
|
|
4
|
-
var mock_context_1 = require("./mock-context");
|
|
5
|
-
Object.defineProperty(exports, "createMockContext", { enumerable: true, get: function () { return mock_context_1.createMockContext; } });
|
|
6
|
-
var mock_logger_1 = require("./mock-logger");
|
|
7
|
-
Object.defineProperty(exports, "createMockLogger", { enumerable: true, get: function () { return mock_logger_1.createMockLogger; } });
|
|
8
|
-
var mock_store_1 = require("./mock-store");
|
|
9
|
-
Object.defineProperty(exports, "createMockStore", { enumerable: true, get: function () { return mock_store_1.createMockStore; } });
|
|
10
|
-
var mock_storage_1 = require("./mock-storage");
|
|
11
|
-
Object.defineProperty(exports, "createMockStorage", { enumerable: true, get: function () { return mock_storage_1.createMockStorage; } });
|
|
12
|
-
var mock_audit_1 = require("./mock-audit");
|
|
13
|
-
Object.defineProperty(exports, "createMockAudit", { enumerable: true, get: function () { return mock_audit_1.createMockAudit; } });
|
|
14
|
-
var mock_router_1 = require("./mock-router");
|
|
15
|
-
Object.defineProperty(exports, "createMockRouter", { enumerable: true, get: function () { return mock_router_1.createMockRouter; } });
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict';function m(){let e=[];return {events:e,async log(t,r){e.push({event:t,payload:r});}}}function y(){let e={debug:[],info:[],warn:[],error:[]};return {entries:e,debug(t,r){e.debug.push({msg:t,meta:r});},info(t,r){e.info.push({msg:t,meta:r});},warn(t,r){e.warn.push({msg:t,meta:r});},error(t,r){e.error.push({msg:t,meta:r});}}}function h(){let e=200,t,r,n={},o={status(s){return e=s,o},set(s,i){return n[s]=i,o},send(s){return r=s,o},json(s){return t=s,o},end(){return o},getStatusCode:()=>e,getJsonBody:()=>t,getSentBody:()=>r,getHeaders:()=>({...n})};return o}function R(){let e=[];return {routes:e,registerRoute(r,n,o){e.push({path:r,handler:n,opts:o});},async simulate(r,n,o=Buffer.alloc(0),s={},i={},d={}){let c=e.find(f=>f.path===n);if(!c)return {status:404,body:{error:"Not found"},headers:{}};let p={method:r,url:n,headers:s,body:o,params:i,query:d},u=h();return await c.handler(p,u),{status:u.getStatusCode(),body:u.getJsonBody()??u.getSentBody(),headers:u.getHeaders()}}}}function M(e){let t=new Map,r=n=>n.startsWith(`${e}::`)?n:`${e}::${n}`;return {async get(n){let o=t.get(r(n));return o?o.value:void 0},async set(n,o){t.set(r(n),{value:o});},async delete(n){return t.delete(r(n))},async list(n){let o=n?r(n):`${e}::`,s=[];for(let i of t.keys())i.startsWith(o)&&s.push(i.slice(e.length+2));return s}}}function k(e){return M(e)}function l(){let e=new Map;return {blobs:e,async put(t,r,n){return e.set(t,{data:r,contentType:n}),t},async get(t){let r=e.get(t);return r?r.data:void 0},async delete(t){return e.delete(t)}}}function E(e){let t=e.instanceId??"mock-instance",r=m(),n=y(),o=R(),s=k(t),i=l(),d=[],c=[],p=[],u={run:async()=>({output:""}),...e.agentRunner},f=new AbortController,b=async a=>(d.push(a),{accepted:true}),x=async a=>(c.push(a),{accepted:true}),S=async(a,C)=>{p.push({messageId:a,patch:C});},w=async a=>({userId:a,displayName:a}),A=async()=>{},v=async()=>({messageId:"mock-proactive",sentAt:Date.now()});return {instanceId:t,installationId:e.installationId,config:e.config,capabilities:new Set(e.capabilities??[]),log:n,agentRunner:u,db:s,storage:i,audit:r,abortSignal:e.abortSignal??f.signal,httpRouter:o,router:o,inbound:b,emitEvent:x,updateMessage:S,resolveUser:w,respondSync:A,proactive:v,inboundCalls:d,emittedEvents:c,sentMessages:p}}exports.createMockAudit=m;exports.createMockContext=E;exports.createMockLogger=y;exports.createMockRouter=R;exports.createMockStorage=l;exports.createMockStore=k;
|
package/dist/tools/delegate.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* delegate_to_agent — 다른 에이전트에게 작업을 위임하는 빌트인 tool.
|
|
3
|
-
*
|
|
4
|
-
* PM → Dev처럼 에이전트 간 자동 위임을 가능하게 한다.
|
|
5
|
-
* crewx 인스턴스를 클로저로 캡처하여 내부에서 query/execute 호출.
|
|
6
|
-
*/
|
|
7
1
|
import type { ToolDefinition } from '../facade/Crewx';
|
|
8
2
|
import type { Crewx } from '../facade/Crewx';
|
|
9
3
|
export declare function createDelegateTool(crewx: Crewx): ToolDefinition;
|
|
10
|
-
//# sourceMappingURL=delegate.d.ts.map
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Built-in tool definitions for api/* provider agents.
|
|
3
|
-
*
|
|
4
|
-
* Adapted from packages/sdk-bak/src/tools/.
|
|
5
|
-
* Uses only Node.js built-ins — no external dependencies.
|
|
6
|
-
*
|
|
7
|
-
* Each entry in BUILTIN_TOOL_REGISTRY matches Omit<ToolDefinition, 'name'>.
|
|
8
|
-
* Register via crewx.registerTool(name, BUILTIN_TOOL_REGISTRY[name]).
|
|
9
|
-
*/
|
|
10
1
|
type BuiltinTool = {
|
|
11
2
|
description: string;
|
|
12
3
|
parameters?: Record<string, unknown>;
|
|
13
4
|
execute: (args: Record<string, unknown>) => Promise<unknown>;
|
|
14
5
|
};
|
|
15
|
-
/**
|
|
16
|
-
* All available built-in tools, keyed by tool name.
|
|
17
|
-
*
|
|
18
|
-
* Listed tools are registered via crewx.registerTool() when their name appears
|
|
19
|
-
* in crewx.yaml `tools.builtin` for an agent using an api/* provider.
|
|
20
|
-
*/
|
|
21
6
|
export declare const BUILTIN_TOOL_REGISTRY: Record<string, BuiltinTool>;
|
|
22
7
|
export {};
|
|
23
|
-
//# sourceMappingURL=builtin.d.ts.map
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @crewx/sdk/tools/node — Node.js built-in tools.
|
|
3
|
-
*
|
|
4
|
-
* Provides file system, shell, and search tools for api/* providers.
|
|
5
|
-
* Import this only in Node.js environments (CLI, Express server).
|
|
6
|
-
* Do NOT import in browser builds.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* import { registerBuiltinTools } from '@crewx/sdk/tools/node';
|
|
10
|
-
* const crewx = await Crewx.loadYaml('./crewx.yaml');
|
|
11
|
-
* registerBuiltinTools(crewx);
|
|
12
|
-
*/
|
|
13
1
|
import type { Crewx } from '../../facade/Crewx';
|
|
14
|
-
/**
|
|
15
|
-
* Register built-in Node.js tools based on agent configs in crewx.yaml.
|
|
16
|
-
*
|
|
17
|
-
* Scans all agents using api/* providers, collects tool names from
|
|
18
|
-
* options.query.tools and options.execute.tools, then registers
|
|
19
|
-
* only the matching built-in tools via crewx.registerTool().
|
|
20
|
-
*/
|
|
21
2
|
export declare function registerBuiltinTools(crewx: Crewx): void;
|
|
22
3
|
export { BUILTIN_TOOL_REGISTRY } from './builtin';
|
|
23
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/tools/node/index.js
CHANGED
|
@@ -1,59 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!isApiProvider)
|
|
38
|
-
continue;
|
|
39
|
-
const opts = agent.options;
|
|
40
|
-
if (Array.isArray(opts?.query?.tools)) {
|
|
41
|
-
for (const name of opts.query.tools)
|
|
42
|
-
neededTools.add(name);
|
|
43
|
-
}
|
|
44
|
-
if (Array.isArray(opts?.execute?.tools)) {
|
|
45
|
-
for (const name of opts.execute.tools)
|
|
46
|
-
neededTools.add(name);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
// Register only the needed built-in tools
|
|
50
|
-
for (const name of neededTools) {
|
|
51
|
-
const toolDef = builtin_1.BUILTIN_TOOL_REGISTRY[name];
|
|
52
|
-
if (toolDef) {
|
|
53
|
-
crewx.registerTool(name, toolDef);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
var builtin_2 = require("./builtin");
|
|
58
|
-
Object.defineProperty(exports, "BUILTIN_TOOL_REGISTRY", { enumerable: true, get: function () { return builtin_2.BUILTIN_TOOL_REGISTRY; } });
|
|
59
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict';var p=require('path'),u=require('fs/promises'),child_process=require('child_process'),util=require('util');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var p__default=/*#__PURE__*/_interopDefault(p);var u__default=/*#__PURE__*/_interopDefault(u);var S=util.promisify(child_process.exec),g=new Set(["node_modules",".git","dist","build",".next"]);async function $(r,s,o=5,t=0){if(t>=o)return [`${p__default.default.relative(s,r)}/ (max depth reached)`];let e=[],n;try{n=await u__default.default.readdir(r,{withFileTypes:!0});}catch{return [`${p__default.default.relative(s,r)}/ (permission denied)`]}for(let c of n){let i=p__default.default.join(r,c.name),a=p__default.default.relative(s,i);if(c.isDirectory()){e.push(`${a}/`);let l=await $(i,s,o,t+1);e.push(...l);}else {let l=await u__default.default.stat(i);e.push(`${a} (${l.size} bytes)`);}}return e}async function x(r,s){let{currentDepth:o,maxDepth:t}=s,e=" ".repeat(o),n;try{n=await u__default.default.readdir(r,{withFileTypes:!0});}catch(i){let a=i.code??"unknown";return [`${e}(error: ${a})`]}n.sort((i,a)=>i.isDirectory()&&!a.isDirectory()?-1:!i.isDirectory()&&a.isDirectory()?1:i.name.localeCompare(a.name));let c=[];for(let i of n){let a=p__default.default.join(r,i.name);if(i.isDirectory())if(c.push(`${e}[DIR] ${i.name}/`),o<t){let l=await x(a,{currentDepth:o+1,maxDepth:t});c.push(...l);}else c.push(`${" ".repeat(o+1)}(max depth reached)`);else try{let l=await u__default.default.stat(a);c.push(`${e}[FILE] ${i.name} (${l.size} bytes)`);}catch{c.push(`${e}[FILE] ${i.name} (stat error)`);}}return c}async function h(r,s,o){try{let e=(await u__default.default.readFile(r,"utf-8")).split(`
|
|
2
|
+
`),n=p__default.default.relative(o,r);return e.flatMap((c,i)=>s.test(c)?[`${n}:${i+1}: ${c}`]:[])}catch{return []}}async function b(r,s,o,t=10,e=0){if(e>=t)return [];let n=[],c;try{c=await u__default.default.readdir(r,{withFileTypes:!0});}catch{return []}for(let i of c){let a=p__default.default.join(r,i.name);if(i.isDirectory()){if(!g.has(i.name)){let l=await b(a,s,o,t,e+1);n.push(...l);}}else {let l=await h(a,s,o);n.push(...l);}}return n}function F(r,s,o){let t=o?r:r.toLowerCase(),n=(o?s:s.toLowerCase()).replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${n}$`).test(t)}async function T(r,s,o,t,e,n=0){if(t.length>=e||n>10)return;let c;try{c=await u__default.default.readdir(r,{withFileTypes:!0});}catch{return}for(let i of c){if(t.length>=e)break;let a=p__default.default.join(r,i.name);i.isDirectory()?g.has(i.name)||await T(a,s,o,t,e,n+1):F(i.name,s,o)&&t.push(a);}}function j(r,s){let o=r.replace(/\\/g,"/"),e=s.replace(/\\/g,"/").replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*\//g,"\xA7\xA7\xA7").replace(/\*\*/g,"\xA7\xA7\xA7").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]").replace(/§§§/g,".*");return new RegExp(`^${e}$`).test(o)}async function v(r,s,o,t,e,n=0){if(t.length>=e||n>15)return;let c;try{c=await u__default.default.readdir(r,{withFileTypes:!0});}catch{return}for(let i of c){if(t.length>=e)break;let a=p__default.default.join(r,i.name);if(i.isDirectory())g.has(i.name)||await v(a,s,o,t,e,n+1);else {let l=p__default.default.relative(o,a).replace(/\\/g,"/");j(l,s)&&t.push(a);}}}var L={description:"Reads and returns the content of a specified file. Use offset/limit to paginate large text files.",parameters:{type:"object",properties:{file_path:{type:"string",description:"Path to the file to read."},offset:{type:"integer",description:"Optional 0-based line number to start reading from."},limit:{type:"integer",description:"Optional maximum number of lines to read."}},required:["file_path"]},execute:async r=>{let s=r.file_path,o=r.offset,t=r.limit;if(!s.trim())throw new Error("The 'file_path' parameter must be non-empty.");let e=p__default.default.resolve(s),n=await u__default.default.readFile(e,"utf-8");if(o!==void 0||t!==void 0){let c=n.split(`
|
|
3
|
+
`),i=o??0,a=t!==void 0?i+t:c.length,l=c.slice(i,a),d=a<c.length,f=l.join(`
|
|
4
|
+
`);return d?`IMPORTANT: Content truncated. Showing lines ${i}-${a-1} of ${c.length}.
|
|
5
|
+
|
|
6
|
+
${f}`:f}return n}},P={description:"Creates a new file or overwrites an existing file with the provided content.",parameters:{type:"object",properties:{file_path:{type:"string",description:"Path to the file to create or overwrite."},content:{type:"string",description:"The content to write to the file."}},required:["file_path","content"]},execute:async r=>{let s=r.file_path,o=r.content;if(!s.trim())throw new Error("The 'file_path' parameter must be non-empty.");let t=p__default.default.resolve(s);await u__default.default.mkdir(p__default.default.dirname(t),{recursive:true});let e=false;try{await u__default.default.access(t),e=!0;}catch{}await u__default.default.writeFile(t,o,"utf-8");let n=Buffer.byteLength(o,"utf-8");return `${e?"Updated":"Created"} file: ${s} (${n} bytes)`}},I={description:"Replaces a range of lines in a file with new text. Line numbers are 1-based.",parameters:{type:"object",properties:{file_path:{type:"string",description:"Path to the file to modify."},start_line:{type:"integer",description:"Starting line number (1-based, inclusive)."},end_line:{type:"integer",description:"Ending line number (1-based, inclusive)."},new_text:{type:"string",description:"New text to insert in place of the specified lines."}},required:["file_path","start_line","end_line","new_text"]},execute:async r=>{let s=r.file_path,o=r.start_line,t=r.end_line,e=r.new_text;if(!s.trim())throw new Error("The 'file_path' parameter must be non-empty.");if(o>t)throw new Error(`start_line (${o}) must be <= end_line (${t}).`);let n=p__default.default.resolve(s),i=(await u__default.default.readFile(n,"utf-8")).split(`
|
|
7
|
+
`);if(o<1||o>i.length)throw new Error(`start_line (${o}) out of range. File has ${i.length} lines.`);if(t>i.length)throw new Error(`end_line (${t}) out of range. File has ${i.length} lines.`);let a=e.split(`
|
|
8
|
+
`);return i.splice(o-1,t-o+1,...a),await u__default.default.writeFile(n,i.join(`
|
|
9
|
+
`),"utf-8"),`Successfully replaced lines ${o}-${t} in ${s}`}},B={description:"Lists contents of a directory. Shows file sizes and marks directories with trailing slashes.",parameters:{type:"object",properties:{path:{type:"string",description:"Directory path to list (default: current directory)."},recursive:{type:"boolean",description:"List contents recursively (default: false)."}}},execute:async r=>{let s=r.path??".",o=r.recursive??false,t=p__default.default.resolve(s);if(!(await u__default.default.stat(t)).isDirectory())throw new Error(`Path is not a directory: ${s}`);let n=`Directory listing: ${s}
|
|
10
|
+
|
|
11
|
+
`;if(o){let c=await $(t,t);n+=c.join(`
|
|
12
|
+
`);}else {let c=await u__default.default.readdir(t,{withFileTypes:true}),i=[];for(let a of c)if(a.isDirectory())i.push(`${a.name}/`);else {let l=await u__default.default.stat(p__default.default.join(t,a.name));i.push(`${a.name} (${l.size} bytes)`);}n+=i.join(`
|
|
13
|
+
`);}return n||"Directory is empty"}},k={description:"Displays a directory tree with [DIR]/[FILE] labels up to max_depth levels.",parameters:{type:"object",properties:{path:{type:"string",description:"Directory to inspect (default: current directory)."},max_depth:{type:"integer",description:"Maximum depth to traverse (default: 3)."}}},execute:async r=>{let s=r.path??".",o=r.max_depth??3,t=p__default.default.resolve(s);if(!(await u__default.default.stat(t)).isDirectory())throw new Error(`Path is not a directory: ${s}`);let n=p__default.default.relative(process.cwd(),t),c=n===""?".":n,i=[`Tree for ${c} (max depth: ${o})`,`[DIR] ${c}/`],a=await x(t,{currentDepth:1,maxDepth:o});return i.push(...a),i.join(`
|
|
14
|
+
`)}},C={description:"Searches for a regex pattern in files. Returns matching lines with file paths and line numbers.",parameters:{type:"object",properties:{pattern:{type:"string",description:"Regular expression pattern to search for."},path:{type:"string",description:"File or directory path to search in (default: current directory)."},recursive:{type:"boolean",description:"Search recursively through subdirectories (default: true)."}},required:["pattern"]},execute:async r=>{let s=r.pattern,o=r.path??".",t=r.recursive??true;if(!s.trim())throw new Error("The 'pattern' parameter must be non-empty.");let e;try{e=new RegExp(s);}catch(m){throw new Error(`Invalid regular expression: ${m.message}`)}let n=p__default.default.resolve(o),c=await u__default.default.stat(n),i=c.isDirectory()?n:p__default.default.dirname(n),a=[];if(c.isDirectory())if(t)a=await b(n,e,i);else {let m=await u__default.default.readdir(n,{withFileTypes:true});for(let w of m)if(!w.isDirectory()){let _=await h(p__default.default.join(n,w.name),e,i);a.push(..._);}}else a=await h(n,e,i);if(a.length===0)return `No matches found for pattern: ${s}`;let l=100,d=a.slice(0,l),f=`Found ${a.length} match(es) for pattern: ${s}
|
|
15
|
+
|
|
16
|
+
${d.join(`
|
|
17
|
+
`)}`;return a.length>l&&(f+=`
|
|
18
|
+
|
|
19
|
+
... and ${a.length-l} more (output truncated)`),f}},O={description:"Searches for files by filename pattern. Supports * and ? wildcards.",parameters:{type:"object",properties:{pattern:{type:"string",description:"Filename pattern. Supports * and ? wildcards."},dir_path:{type:"string",description:"Directory to search in (default: current directory)."},case_sensitive:{type:"boolean",description:"Case-sensitive matching (default: false)."},max_results:{type:"integer",description:"Maximum results to return (default: 50)."}},required:["pattern"]},execute:async r=>{let s=r.pattern,o=r.dir_path??".",t=r.case_sensitive??false,e=r.max_results??50,n=p__default.default.resolve(o),c=[];if(await T(n,s,t,c,e),c.length===0)return `No files found matching pattern: ${s}
|
|
20
|
+
Searched in: ${n}`;let i=c.map((l,d)=>` ${d+1}. ${p__default.default.relative(process.cwd(),l)}`),a=c.length>=e?`
|
|
21
|
+
(Limited to ${e} results)`:"";return `Found ${c.length} file(s) matching "${s}":
|
|
22
|
+
${i.join(`
|
|
23
|
+
`)}${a}`}},q={description:'Finds files matching glob patterns (e.g., "**/*.ts", "src/**/*.yaml"). Returns file paths.',parameters:{type:"object",properties:{pattern:{type:"string",description:"Glob pattern to match files against."},dir_path:{type:"string",description:"Directory to search in (default: current directory)."},max_results:{type:"integer",description:"Maximum results to return (default: 100)."}},required:["pattern"]},execute:async r=>{let s=r.pattern,o=r.dir_path??".",t=r.max_results??100,e=p__default.default.resolve(o),n=[];if(await v(e,s,e,n,t),n.length===0)return `No files found matching pattern: ${s}
|
|
24
|
+
Searched in: ${e}`;let c=n.map((a,l)=>` ${l+1}. ${p__default.default.relative(process.cwd(),a)}`),i=n.length>=t?`
|
|
25
|
+
(Limited to ${t} results)`:"";return `Found ${n.length} file(s) matching "${s}":
|
|
26
|
+
${c.join(`
|
|
27
|
+
`)}${i}`}},A={description:"Executes a shell command and returns its output (stdout and stderr). Use with caution.",parameters:{type:"object",properties:{command:{type:"string",description:"The shell command to execute."},timeout_seconds:{type:"integer",description:"Maximum execution time in seconds (default: 30)."}},required:["command"]},execute:async r=>{let s=r.command,o=r.timeout_seconds??30;if(!s.trim())throw new Error("The 'command' parameter must be non-empty.");try{let{stdout:t,stderr:e}=await S(s,{timeout:o*1e3,maxBuffer:10485760,cwd:process.cwd()}),n="";return t&&(n+=`STDOUT:
|
|
28
|
+
${t}`),e&&(n+=(t?`
|
|
29
|
+
|
|
30
|
+
`:"")+`STDERR:
|
|
31
|
+
${e}`),n||"Command executed successfully (no output)"}catch(t){let e=t;if(e.killed&&e.signal==="SIGTERM")throw new Error(`Command timed out after ${o} seconds`);let n=`Command failed: ${s}`;throw e.stdout&&(n+=`
|
|
32
|
+
STDOUT:
|
|
33
|
+
${e.stdout}`),e.stderr&&(n+=`
|
|
34
|
+
STDERR:
|
|
35
|
+
${e.stderr}`),e.code!==void 0&&(n+=`
|
|
36
|
+
Exit code: ${e.code}`),new Error(n)}}},y={read_file:L,write_file:P,replace:I,ls:B,tree:k,grep:C,find:O,glob:q,run_shell_command:A};function W(r){let s=r.config;if(!s)return;let o=s.agents??[],t=new Set;for(let e of o){if(!(Array.isArray(e.provider)?e.provider:[e.provider]).some(a=>typeof a=="string"&&a.startsWith("api/")))continue;let i=e.options;if(Array.isArray(i?.query?.tools))for(let a of i.query.tools)t.add(a);if(Array.isArray(i?.execute?.tools))for(let a of i.execute.tools)t.add(a);}for(let e of t){let n=y[e];n&&r.registerTool(e,n);}}exports.BUILTIN_TOOL_REGISTRY=y;exports.registerBuiltinTools=W;
|