@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createAdapterContext — builds an AdapterContext for an adapter instance.
|
|
3
|
-
*
|
|
4
|
-
* M1: respondSync uses AsyncLocalStorage to bind the current HTTP response.
|
|
5
|
-
* When called inside a registerRoute handler (sync window), respondSync writes
|
|
6
|
-
* to the HTTP res. When called outside the sync window, it performs graceful
|
|
7
|
-
* degradation: logs a warning instead of throwing (PoC correction #3).
|
|
8
|
-
*/
|
|
9
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
10
2
|
import type { AdapterContext, AdapterCapability, AdapterStore, AgentRunner, AuditSink, BlobStorage, EventResolution, HttpRouter, InboundEvent, InboundMessage, Logger, OutboundMessage, RawResponse, ResolvedUser, RouteResolution } from './types';
|
|
11
3
|
export interface SyncWindow {
|
|
@@ -32,4 +24,3 @@ export interface AdapterContextOptions<TConfig = unknown> {
|
|
|
32
24
|
logger?: Logger;
|
|
33
25
|
}
|
|
34
26
|
export declare function createAdapterContext<TConfig = unknown>(opts: AdapterContextOptions<TConfig>): AdapterContext<TConfig>;
|
|
35
|
-
//# sourceMappingURL=context-builder.d.ts.map
|
package/dist/adapter/index.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin helpers for defining channel adapters.
|
|
3
|
-
*
|
|
4
|
-
* defineChannelAdapter — type-safe identity function for IChannelAdapter.
|
|
5
|
-
* defineChannelAdapterPlugin — wraps an adapter as a CrewxPlugin (§3.3).
|
|
6
|
-
*/
|
|
7
1
|
import type { IChannelAdapter } from './types';
|
|
8
2
|
import type { CrewxPlugin } from '../plugin';
|
|
9
3
|
export declare function defineChannelAdapter<TConfig = unknown>(spec: IChannelAdapter<TConfig>): IChannelAdapter<TConfig>;
|
|
@@ -16,4 +10,3 @@ export interface ChannelAdapterPluginSpec<TConfig = unknown> {
|
|
|
16
10
|
readonly onDetach?: (crewx: unknown) => void | Promise<void>;
|
|
17
11
|
}
|
|
18
12
|
export declare function defineChannelAdapterPlugin<TConfig = unknown>(spec: ChannelAdapterPluginSpec<TConfig>): CrewxPlugin;
|
|
19
|
-
//# sourceMappingURL=plugin-helper.d.ts.map
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ScopedAdapterStore — adapter key-value store with mandatory instanceId prefix.
|
|
3
|
-
*
|
|
4
|
-
* Security: Uses Map closure pattern (RT-1 defense).
|
|
5
|
-
* The internal Map is captured in a function closure — no public or private
|
|
6
|
-
* property on the returned AdapterStore object holds the raw Map reference.
|
|
7
|
-
* Reflect / Object.getPrototypeOf / (ctx.db as any)['_rawStore'] all fail
|
|
8
|
-
* because the Map only exists in the createScopedAdapterStore function scope.
|
|
9
|
-
*/
|
|
10
1
|
import type { AdapterStore } from './types';
|
|
11
2
|
export declare function createScopedAdapterStore(instanceId: string): AdapterStore;
|
|
12
|
-
//# sourceMappingURL=scoped-store.d.ts.map
|
package/dist/adapter/types.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapter Platform v0.4 — core types.
|
|
3
|
-
* PoC corrections applied:
|
|
4
|
-
* 1. AdapterError: class only (interface removed)
|
|
5
|
-
* 2. kind: added 'config' for configuration errors
|
|
6
|
-
*/
|
|
7
1
|
export type AdapterCapability = 'send' | 'receive' | 'threads' | 'attachments' | 'interactive' | 'markdown' | 'edit' | 'delete' | 'reaction' | 'mention' | 'rich_cards' | 'sync_reply' | 'typing' | 'ephemeral' | 'proactive' | 'commands' | 'presence';
|
|
8
2
|
export interface AdapterManifest {
|
|
9
3
|
readonly id: string;
|
|
@@ -261,4 +255,3 @@ export interface ChannelAdapterRegistration<TConfig = unknown> {
|
|
|
261
255
|
readonly defaultAgent?: string;
|
|
262
256
|
readonly onInbound?: (msg: InboundMessage) => Promise<RouteResolution>;
|
|
263
257
|
}
|
|
264
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/agent/resolver.d.ts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent resolver: looks up an agent from a list by ref.
|
|
3
|
-
* Supports both bare id ('claude') and @mention format ('@claude').
|
|
4
|
-
* Falls back to built-in provider shorthands (claude, gemini, copilot, codex).
|
|
5
|
-
*/
|
|
6
1
|
import type { AgentConfig } from '../types';
|
|
7
2
|
export declare class AgentNotFoundError extends Error {
|
|
8
3
|
constructor(agentRef: string, availableIds: string[]);
|
|
9
4
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Resolve an agent by reference.
|
|
12
|
-
* @param agentRef - Agent reference: '@claude', 'claude', '@my_agent', etc.
|
|
13
|
-
* @param agents - List of available agent configs.
|
|
14
|
-
* @returns The matching AgentConfig.
|
|
15
|
-
* @throws AgentNotFoundError when no match is found.
|
|
16
|
-
*/
|
|
17
5
|
export declare function resolveAgent(agentRef: string, agents: AgentConfig[]): AgentConfig;
|
|
18
|
-
//# sourceMappingURL=resolver.d.ts.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Box storage interfaces — used by SdkBoxService and buildContext.
|
|
3
|
-
*/
|
|
4
1
|
import type { BoxRow, InsertBoxData, ThreadMessage } from './box.types';
|
|
5
2
|
export interface IBoxStorage {
|
|
6
3
|
listBoxes(threadId: string): BoxRow[];
|
|
@@ -22,4 +19,3 @@ export interface IBoxServiceReader {
|
|
|
22
19
|
};
|
|
23
20
|
getBox(threadId: string, boxId: string): BoxResponse | null;
|
|
24
21
|
}
|
|
25
|
-
//# sourceMappingURL=box-storage.interface.d.ts.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SdkBoxService — manages box creation, retrieval, and listing.
|
|
3
|
-
*/
|
|
4
1
|
import type { IBoxStorage } from './box-storage.interface';
|
|
5
2
|
import type { BoxResponse, CreateBoxParams } from './box.types';
|
|
6
3
|
export declare class SdkBoxService {
|
|
@@ -16,4 +13,3 @@ export declare class SdkBoxService {
|
|
|
16
13
|
private validateId;
|
|
17
14
|
private generateBoxId;
|
|
18
15
|
}
|
|
19
|
-
//# sourceMappingURL=box.service.d.ts.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Boxing domain types — Box/Thread/Context types for SDK boxing module.
|
|
3
|
-
*/
|
|
4
1
|
export interface BoxRow {
|
|
5
2
|
id: string;
|
|
6
3
|
thread_id: string;
|
|
@@ -87,4 +84,3 @@ export interface CreateBoxParams {
|
|
|
87
84
|
sourceTokens: number;
|
|
88
85
|
summaryTokens?: number | null;
|
|
89
86
|
}
|
|
90
|
-
//# sourceMappingURL=box.types.d.ts.map
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* buildContext() — builds hot/warm context windows from thread messages and box summaries.
|
|
3
|
-
*/
|
|
4
1
|
import type { IBoxServiceReader, ITaskReader, ITokenizer } from './box-storage.interface';
|
|
5
2
|
import type { ContextBuildParams, ContextBuildResponse } from './box.types';
|
|
6
3
|
export declare function buildContext(threadId: string, taskReader: ITaskReader, boxService: IBoxServiceReader, params: ContextBuildParams, tokenizer: ITokenizer): ContextBuildResponse;
|
|
7
|
-
//# sourceMappingURL=context-builder.d.ts.map
|
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CrewxClient — Browser client for CrewX SDK.
|
|
3
|
-
*
|
|
4
|
-
* Communicates with a server running CrewX SDK via HTTP.
|
|
5
|
-
* Handles the Client-Intercept pattern automatically:
|
|
6
|
-
* registerTool() + query() — that's it.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { CrewxClient } from '@crewx/sdk/client';
|
|
11
|
-
*
|
|
12
|
-
* const crewx = new CrewxClient('http://localhost:3000');
|
|
13
|
-
* crewx.registerTool('browser_storage_read', {
|
|
14
|
-
* execute: async ({ key }) => localStorage.getItem(key),
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* const result = await crewx.query('assistant', 'read my settings');
|
|
18
|
-
* console.log(result.data);
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
1
|
export interface ClientToolDefinition {
|
|
22
2
|
description?: string;
|
|
23
3
|
parameters?: Record<string, unknown>;
|
|
24
4
|
execute: (args: Record<string, unknown>) => Promise<unknown>;
|
|
25
5
|
}
|
|
26
6
|
export interface QueryCallbacks {
|
|
27
|
-
/** Called when the agent invokes a client tool. */
|
|
28
7
|
onToolCall?: (call: {
|
|
29
8
|
toolCallId: string;
|
|
30
9
|
toolName: string;
|
|
@@ -48,18 +27,7 @@ export declare class CrewxClient {
|
|
|
48
27
|
private readonly baseUrl;
|
|
49
28
|
private readonly tools;
|
|
50
29
|
constructor(baseUrl: string);
|
|
51
|
-
/**
|
|
52
|
-
* Register a browser-side tool.
|
|
53
|
-
* When the server agent calls a tool with this name (and no server-side execute),
|
|
54
|
-
* CrewxClient automatically runs it locally and sends the result back.
|
|
55
|
-
*/
|
|
56
30
|
registerTool(name: string, definition: ClientToolDefinition): void;
|
|
57
|
-
/**
|
|
58
|
-
* Send a message to an agent.
|
|
59
|
-
* The requires_action loop is handled automatically — if the agent calls a
|
|
60
|
-
* client tool, CrewxClient executes it locally and continues the conversation.
|
|
61
|
-
*/
|
|
62
31
|
query(agent: string, message: string, callbacks?: QueryCallbacks): Promise<QueryResponse>;
|
|
63
32
|
private _post;
|
|
64
33
|
}
|
|
65
|
-
//# sourceMappingURL=CrewxClient.d.ts.map
|
package/dist/client/index.d.ts
CHANGED
package/dist/client/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CrewxClient = void 0;
|
|
4
|
-
var CrewxClient_js_1 = require("./CrewxClient.js");
|
|
5
|
-
Object.defineProperty(exports, "CrewxClient", { enumerable: true, get: function () { return CrewxClient_js_1.CrewxClient; } });
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict';var a=class{baseUrl;tools=new Map;constructor(t){this.baseUrl=t.replace(/\/$/,"");}registerTool(t,r){this.tools.set(t,r);}async query(t,r,o){let n=await this._post("/api/chat",{agent:t,message:r});for(;n.status==="requires_action";){let{toolCall:e,threadId:c}=n;if(!e)break;let l=this.tools.get(e.toolName);o?.onToolCall&&o.onToolCall(e);let i;if(l?.execute)try{let s=await l.execute(e.args);i=typeof s=="string"?s:JSON.stringify(s);}catch(s){i=`Error: ${s.message}`;}else i=`Error: No client handler for tool "${e.toolName}"`;n=await this._post("/api/chat/continue",{threadId:c,toolCallId:e.toolCallId,result:i});}return n}async _post(t,r){let o=await fetch(`${this.baseUrl}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP ${o.status}`);return o.json()}};exports.CrewxClient=a;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser-safe YAML config loader.
|
|
3
|
-
* Only parseYamlContent — no file I/O.
|
|
4
|
-
*/
|
|
5
1
|
import type { CrewxProjectConfig } from '../types/index.js';
|
|
6
2
|
export declare class ConfigLoadError extends Error {
|
|
7
3
|
readonly cause?: unknown | undefined;
|
|
8
4
|
constructor(message: string, cause?: unknown | undefined);
|
|
9
5
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Parse YAML string into a validated CrewxProjectConfig.
|
|
12
|
-
*/
|
|
13
6
|
export declare function parseYamlContent(yamlString: string): CrewxProjectConfig;
|
|
14
|
-
//# sourceMappingURL=loader.browser.d.ts.map
|
package/dist/config/loader.d.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* YAML configuration loader for CrewX projects.
|
|
3
|
-
* Reads crewx.yaml and validates it with Zod schema.
|
|
4
|
-
*/
|
|
5
1
|
import type { CrewxProjectConfig } from '../types';
|
|
6
2
|
export declare class ConfigLoadError extends Error {
|
|
7
3
|
readonly cause?: unknown | undefined;
|
|
8
4
|
constructor(message: string, cause?: unknown | undefined);
|
|
9
5
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Parse YAML string into a validated CrewxProjectConfig.
|
|
12
|
-
* Converts the agents record (keyed by id) into an array.
|
|
13
|
-
*/
|
|
14
6
|
export declare function parseYamlContent(yamlString: string): CrewxProjectConfig;
|
|
15
|
-
/**
|
|
16
|
-
* Load and parse crewx.yaml from a file path.
|
|
17
|
-
*/
|
|
18
7
|
export declare function loadYamlFile(filePath: string): CrewxProjectConfig;
|
|
19
|
-
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SqliteConversationProvider — reads/writes conversation history from ~/.crewx/crewx.db.
|
|
3
|
-
*
|
|
4
|
-
* Security:
|
|
5
|
-
* - SEC-1: SELECT columns are explicitly whitelisted (no rendered_prompt, command, logs, metadata).
|
|
6
|
-
* - SEC-2: All queries use parameterized bindings (? placeholders).
|
|
7
|
-
* - Writes target `threads` table ONLY — `tasks` table writes are owned by SqliteTracingPlugin.
|
|
8
|
-
*/
|
|
9
1
|
import type { ConversationThread, FetchHistoryOptions, IConversationHistoryProvider, Platform } from './types';
|
|
10
2
|
export declare class SqliteConversationProvider implements IConversationHistoryProvider {
|
|
11
3
|
private db;
|
|
@@ -18,4 +10,3 @@ export declare class SqliteConversationProvider implements IConversationHistoryP
|
|
|
18
10
|
close(): void;
|
|
19
11
|
private rowsToMessages;
|
|
20
12
|
}
|
|
21
|
-
//# sourceMappingURL=sqlite-provider.d.ts.map
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* toTaskReader — adapter from ConversationThread to boxing ITaskReader.
|
|
3
|
-
*
|
|
4
|
-
* SQ3 invariant:
|
|
5
|
-
* The returned ThreadMessage[] is structured as [user, assistant, user, assistant, ...]
|
|
6
|
-
* where each task produces exactly 2 consecutive elements (user first, then assistant).
|
|
7
|
-
* context-builder.ts:31~42 pairs messages as [i, i+1], so violating this invariant
|
|
8
|
-
* would corrupt context. Tasks without assistants (failed/running) are already
|
|
9
|
-
* filtered by fetchHistory — this adapter performs no additional filtering.
|
|
10
|
-
*/
|
|
11
1
|
import type { ConversationThread } from './types';
|
|
12
2
|
import type { ITaskReader } from '../boxing/box-storage.interface';
|
|
13
3
|
export declare function toTaskReader(thread: ConversationThread): ITaskReader;
|
|
14
|
-
//# sourceMappingURL=to-task-reader.d.ts.map
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* toTemplateMessages — maps ConversationThread messages to TemplateMessage[]
|
|
3
|
-
* for consumption by the formatConversation block helper.
|
|
4
|
-
*
|
|
5
|
-
* Includes SEC-M1 sanitization at the provider boundary:
|
|
6
|
-
* <, > are entity-escaped to prevent XML structure tag injection in the
|
|
7
|
-
* <conversation_history> block.
|
|
8
|
-
*/
|
|
9
1
|
import type { ConversationThread, TemplateMessage } from './types';
|
|
10
|
-
/**
|
|
11
|
-
* Convert a ConversationThread to a TemplateMessage array suitable for
|
|
12
|
-
* formatConversation block helper consumption.
|
|
13
|
-
*/
|
|
14
2
|
export declare function toTemplateMessages(thread: ConversationThread): TemplateMessage[];
|
|
15
|
-
//# sourceMappingURL=to-template-messages.d.ts.map
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conversation history types — SDK public API for reading/writing thread history.
|
|
3
|
-
*
|
|
4
|
-
* **Security (SEC-3):** history content is untrusted user input.
|
|
5
|
-
* Consumers (e.g. Phase 2 CLI wiring) MUST delimit history from system prompts
|
|
6
|
-
* using structured blocks (e.g. `[HISTORY START]...[HISTORY END]`).
|
|
7
|
-
*/
|
|
8
1
|
export interface ConversationMessage {
|
|
9
2
|
id: string;
|
|
10
3
|
userId?: string;
|
|
@@ -16,7 +9,6 @@ export interface ConversationMessage {
|
|
|
16
9
|
export type Platform = 'cli' | 'web' | 'api' | `channel/${string}`;
|
|
17
10
|
export interface ConversationThread {
|
|
18
11
|
threadId: string;
|
|
19
|
-
/** Immutable after ensureThread — reusing a 'cli' thread as 'channel/slack' is forbidden (P1-6). */
|
|
20
12
|
platform: Platform;
|
|
21
13
|
messages: ConversationMessage[];
|
|
22
14
|
metadata?: {
|
|
@@ -27,10 +19,6 @@ export interface ConversationThread {
|
|
|
27
19
|
updatedAt?: number;
|
|
28
20
|
};
|
|
29
21
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Template-friendly message shape consumed by formatConversation block helper.
|
|
32
|
-
* Matches default.yaml L292~303 expected structure.
|
|
33
|
-
*/
|
|
34
22
|
export interface TemplateMessage {
|
|
35
23
|
text: string;
|
|
36
24
|
isAssistant: boolean;
|
|
@@ -44,58 +32,12 @@ export interface TemplateMessage {
|
|
|
44
32
|
export interface FetchHistoryOptions {
|
|
45
33
|
limit?: number;
|
|
46
34
|
maxContextLength?: number;
|
|
47
|
-
/**
|
|
48
|
-
* Trace ID of the currently running task — excluded from history
|
|
49
|
-
* to avoid including in-progress turns (SQ2).
|
|
50
|
-
*/
|
|
51
35
|
currentTraceId?: string;
|
|
52
36
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Provider interface for reading/writing conversation history.
|
|
55
|
-
*
|
|
56
|
-
* **Security (SEC-3):** history content is untrusted user input.
|
|
57
|
-
* Consumers (Phase 2 CLI wiring) MUST delimit history from system prompts
|
|
58
|
-
* using structured blocks (e.g. `[HISTORY START]...[HISTORY END]`).
|
|
59
|
-
*/
|
|
60
37
|
export interface IConversationHistoryProvider {
|
|
61
|
-
/**
|
|
62
|
-
* Ensure a thread row exists in the threads table.
|
|
63
|
-
* @param threadId - Recommended: unguessable value (UUID/nanoid).
|
|
64
|
-
* WI-C2 Slack environments MUST enforce userId/channelId-based namespace
|
|
65
|
-
* isolation in threadId generation policy.
|
|
66
|
-
*/
|
|
67
38
|
ensureThread(threadId: string, platform: Platform, workspaceId?: string): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Fetch conversation history from the tasks table.
|
|
70
|
-
*
|
|
71
|
-
* Filter rules (SQ2, aligned with server thread.service.ts:373):
|
|
72
|
-
* - WHERE thread_id = ?
|
|
73
|
-
* - AND parent_task_id IS NULL (exclude chain child tasks)
|
|
74
|
-
* - AND (status IN ('done','completed') OR status IS NULL) (exclude failed/running)
|
|
75
|
-
* - AND (if options.currentTraceId) trace_id != currentTraceId
|
|
76
|
-
* - ORDER BY started_at ASC
|
|
77
|
-
* - LIMIT options.limit ?? 100
|
|
78
|
-
*/
|
|
79
39
|
fetchHistory(threadId: string, options?: FetchHistoryOptions): Promise<ConversationThread>;
|
|
80
|
-
/**
|
|
81
|
-
* Phase 1: update threads metadata only (updated_at, last_message, message_count).
|
|
82
|
-
* User content is written by SqliteTracingPlugin to tasks.prompt.
|
|
83
|
-
* userId parameter is a WI-C2 (Slack) extension point.
|
|
84
|
-
*
|
|
85
|
-
* **⛔ (SEC-5)** Do NOT pass credentials, env vars, or API keys in metadata —
|
|
86
|
-
* this data is persisted as JSON in the threads table.
|
|
87
|
-
*/
|
|
88
40
|
saveUserMessage(threadId: string, text: string, userId?: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* Phase 1: update threads metadata only.
|
|
91
|
-
* Assistant content is written by SqliteTracingPlugin to tasks.result.
|
|
92
|
-
* agentId parameter enriches threads metadata only.
|
|
93
|
-
*
|
|
94
|
-
* **⛔ (SEC-5)** Do NOT pass credentials, env vars, or API keys in metadata —
|
|
95
|
-
* this data is persisted as JSON in the threads table.
|
|
96
|
-
*/
|
|
97
41
|
saveAssistantMessage(threadId: string, text: string, agentId: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
98
|
-
/** Optional — prevent connection leaks in long-running server/test environments. */
|
|
99
42
|
close?(): void;
|
|
100
43
|
}
|
|
101
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=class{baseUrl;tools=new Map;constructor(t){this.baseUrl=t.replace(/\/$/,"");}registerTool(t,r){this.tools.set(t,r);}async query(t,r,o){let n=await this._post("/api/chat",{agent:t,message:r});for(;n.status==="requires_action";){let{toolCall:e,threadId:c}=n;if(!e)break;let l=this.tools.get(e.toolName);o?.onToolCall&&o.onToolCall(e);let i;if(l?.execute)try{let s=await l.execute(e.args);i=typeof s=="string"?s:JSON.stringify(s);}catch(s){i=`Error: ${s.message}`;}else i=`Error: No client handler for tool "${e.toolName}"`;n=await this._post("/api/chat/continue",{threadId:c,toolCallId:e.toolCallId,result:i});}return n}async _post(t,r){let o=await fetch(`${this.baseUrl}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP ${o.status}`);return o.json()}};export{a as CrewxClient};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {createHash}from'crypto';import {resolve,relative,dirname,join}from'path';import {homedir}from'os';import {appendFileSync,existsSync,readFileSync,mkdirSync,writeFileSync,statSync}from'fs';var D=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var g=class{detach(e){}};var f=class extends g{unsubs=[];attach(e){if(this.on.beforeTool){let t=e.on("tool:observed:before",async o=>{if(!this.matchesTool(this.on.beforeTool,o.tool.name))return;let r=this.buildContext("beforeTool",o);await this.run(r);});this.unsubs.push(t);}if(this.on.afterTool){let t=e.on("tool:observed:after",async o=>{if(!this.matchesTool(this.on.afterTool,o.tool.name))return;let r=this.buildContext("afterTool",o);await this.run(r);});this.unsubs.push(t);}}async detach(e){for(let t of this.unsubs)t();this.unsubs=[];}matchesTool(e,t){return e===true?true:e.includes(t)}buildContext(e,t){return {event:e,traceId:t.traceId,agent:{id:t.agentId||t.agentRef,role:"",team:""},provider:t.provider,thread:{id:t.threadId||""},tool:{name:t.tool.name,rawName:t.tool.rawName,input:"input"in t.tool?t.tool.input:void 0},cwd:process.cwd(),sessionId:t.sessionId||"",pass:()=>({type:"pass"})}}};var d=class{capabilities={required:[]}};function j(n){return new class extends d{name=n.name;version=n.version;capabilities=n.capabilities??{required:[]};run=n.run}}function M(n){return new class extends f{name=n.name;version=n.version;on=n.on;run=n.run}}function A(n){let e=r=>r.replace(/[.+^${}()|[\]\\]/g,"\\$&"),o=n.split("/").map(r=>r==="**"?".*":r.split("*").map(e).join("[^/]*"));return new RegExp(`^${o.join("\\/")}$`)}function y(n,e){try{return A(e).test(n)}catch{return false}}var i={FileRead:"file.read",FileWrite:"file.write",FileEdit:"file.edit",Shell:"shell",Search:"search",Other:"other"};var z={Read:i.FileRead,Write:i.FileWrite,Edit:i.FileEdit,MultiEdit:i.FileEdit,NotebookEdit:i.FileEdit,Bash:i.Shell,Grep:i.Search,Glob:i.Search},W={read_file:i.FileRead,write_file:i.FileWrite,replace:i.FileEdit,edit:i.FileEdit,run_shell_command:i.Shell,search_file_content:i.Search,glob:i.Search},L={read:i.FileRead,write:i.FileWrite,edit:i.FileEdit,shell:i.Shell,bash:i.Shell,search:i.Search,grep:i.Search},$={"file.read":i.FileRead,"file.write":i.FileWrite,"file.edit":i.FileEdit,read:i.FileRead,write:i.FileWrite,edit:i.FileEdit,bash:i.Shell,shell:i.Shell,grep:i.Search,glob:i.Search},G={Bash:i.Shell,bash:i.Shell},X={claude:z,codex:G,gemini:W,copilot:L,opencode:$};function x(n,e){let t=B(e);if(t){let o=X[t][n];if(o)return o}return Object.values(i).includes(n)?n:i.Other}function B(n){let e=n.toLowerCase();return e.includes("claude")?"claude":e.includes("codex")?"codex":e.includes("gemini")?"gemini":e.includes("copilot")?"copilot":e.includes("opencode")?"opencode":null}var H=200,R=2e3;function w(n){let e=n.replace(/[\x00-\x1f\x7f\u2028\u2029]/g,"");return e.length<=H?e:e.slice(0,H-11)+" [redacted]"}function h(n){let e=n.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f\u2028\u2029]/g,"");return e.length<=R?e:e.slice(0,R-11)+" [redacted]"}function q(n,e){let t=resolve(n),o=resolve(e);return !(relative(o,t).startsWith("..")||resolve(t).startsWith("/etc/")||resolve(t).startsWith("/usr/")||t.includes("node_modules"))}function J(n){return n==="codex"?"codex":"claude"}function C(n,e,t){return n==="codex"?{hookSpecificOutput:{hookEventName:e,permissionDecision:"allow",systemMessage:t}}:{hookSpecificOutput:{hookEventName:e,permissionDecision:"allow",additionalContext:t}}}function O(n,e,t){return {hookSpecificOutput:{hookEventName:e,permissionDecision:"deny",permissionDecisionReason:t}}}function S(n,e,t="cli/claude"){let o=t||process.env.CREWX_PROVIDER||"cli/claude";return {event:"beforeTool",traceId:n.tool_use_id||"",agent:{id:process.env.CREWX_AGENT_ID||"",role:process.env.CREWX_AGENT_ROLE||"",team:process.env.CREWX_AGENT_TEAM||""},provider:o,thread:{id:process.env.CREWX_THREAD_ID||""},tool:{name:x(n.tool_name,o),rawName:n.tool_name,input:n.tool_input},cwd:e||n.cwd,sessionId:n.session_id||process.env.CREWX_SESSION_ID||"",pass:()=>({type:"pass"}),deny:r=>({type:"deny",reason:r}),inject:r=>({type:"inject",message:r}),modify:r=>({type:"modify",patch:r})}}async function K(n,e,t,o="cli/claude"){let r=S(e,t,o),s=await n.run(r),c=J(o),a={hookSpecificOutput:{hookEventName:e.hook_event_name,permissionDecision:"allow"}};switch(s.type){case "pass":return {exitCode:0,stdout:a,injected:false};case "deny":{let p=w(s.reason);return {exitCode:2,stdout:O(c,e.hook_event_name,p),injected:false}}case "inject":{let p=h(s.message);return {exitCode:0,stdout:C(c,e.hook_event_name,p),injected:true}}case "modify":return console.error(`[crewx] Hook result type '${s.type}' is not supported in Phase 0. Plugin: ${n.name}. Treating as pass.`),{exitCode:0,stdout:a,injected:false};default:return {exitCode:0,stdout:a,injected:false}}}var oe=10*1024*1024,re={b:1,kb:1024,mb:1024*1024,gb:1024*1024*1024};function b(n,e){return n===void 0?true:Array.isArray(n)?n.includes(e):n===e}function ie(n,e){return n===void 0?true:Array.isArray(n)?n.some(t=>e.includes(t)):e.includes(n)}function P(n){if(typeof n=="number")return n;let e=n.match(/^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)?$/i);if(!e)return 0;let t=parseFloat(e[1]),o=(e[2]??"b").toLowerCase();return Math.floor(t*(re[o]??1))}function T(n){return typeof n=="string"}function _(n){try{let e=statSync(n);return e.size>oe?(process.stderr.write(`[YamlHookPlugin] File too large for line count: ${n} (${e.size} bytes)
|
|
2
|
+
`),null):readFileSync(n,"utf8").split(`
|
|
3
|
+
`).length}catch{return null}}function N(n){try{return statSync(n).size}catch{return null}}function se(n,e,t){if(!n)return true;let o=e,r=o?.path??o?.file_path??o?.filePath??o?.filename;if(typeof r!="string")return false;if(y(r,n))return true;if(t&&r.startsWith("/")){let{relative:s,isAbsolute:c}=D("path");if(c(r)){let a=s(t,r);if(a&&!a.startsWith("..")&&y(a,n))return true}}return false}function ae(n,e){return n?JSON.stringify(e).includes(n):true}function ue(n,e){if(!n)return true;try{let t=new RegExp(n),o=JSON.stringify(e);return t.test(o)}catch{return false}}function le(n,e){if(!n)return true;try{let t=new RegExp(n),o=JSON.stringify(e);return t.test(o)}catch{return false}}function ce(n,e){if(n.pathSizeMin===void 0&&n.pathSizeMax===void 0)return true;let t=e,o=t?.path??t?.file_path??t?.filePath??t?.filename;if(typeof o!="string")return false;if(n.pathSizeMin!==void 0)if(T(n.pathSizeMin)){let r=N(o);if(r===null||r<P(n.pathSizeMin))return false}else {let r=_(o);if(r===null||r<n.pathSizeMin)return false}if(n.pathSizeMax!==void 0)if(T(n.pathSizeMax)){let r=N(o);if(r===null||r>P(n.pathSizeMax))return false}else {let r=_(o);if(r===null||r>n.pathSizeMax)return false}return true}function de(n){let e=[],t=[];for(let o=0;o<n.length;o++){let r=n[o];if(!r||typeof r!="object"){t.push(`Hook at index ${o}: not an object, skipping`);continue}let s=r;if(typeof s.name!="string"||!s.name){t.push(`Hook at index ${o}: missing or invalid "name", skipping`);continue}let c=s.guide&&typeof s.guide=="object",a=s.deny&&typeof s.deny=="object",p=typeof s.plugin=="string";if(!c&&!a&&!p){t.push(`Hook "${s.name}": missing guide/deny/plugin, skipping`);continue}if(c&&typeof s.guide.say!="string"){t.push(`Hook "${s.name}": guide.say is required and must be string, skipping`);continue}if(a&&typeof s.deny.reason!="string"){t.push(`Hook "${s.name}": deny.reason is required and must be string, skipping`);continue}e.push(s);}return {valid:e,warnings:t}}var v=class extends d{name="@crewx/yaml-hook-plugin";version="0.1.0";capabilities={required:["inject"]};hooks;agentMap;constructor(e){super(),this.hooks=e.hooks,this.agentMap=new Map((e.agents??[]).map(t=>[t.id,t]));}async run(e){let t=[],o=process.env.CREWX_TASK_LOG_PATH,r=process.env.CREWX_HOOK_LOG_VERBOSE==="1";for(let s of this.hooks)if(this.matchEntryLevel(s,e)&&s.guide){if(!this.matchRuleLevel(s.guide,e)){r&&o&&this.appendHookLog(o,{rule:s.name,action:"pass",once:s.guide.once??false,ctx:e,matched:false});continue}s.guide.once&&this.hasFired(e.sessionId,s.name)||(s.guide.once&&this.markFired(e.sessionId,s.name),t.push(s.guide.say),o&&this.appendHookLog(o,{rule:s.name,action:"inject",once:s.guide.once??false,ctx:e,matched:true,message:s.guide.say}));}return t.length?e.inject(t.join(`
|
|
4
|
+
|
|
5
|
+
`)):e.pass()}appendHookLog(e,t){try{let o={rule:t.rule,action:t.action,once:t.once,sessionId:t.ctx.sessionId,provider:t.ctx.provider,agent:t.ctx.agent.id,toolName:t.ctx.tool.name,rawToolName:t.ctx.tool.rawName};t.message&&(o.chars=t.message.length,process.env.CREWX_HOOK_LOG_VERBOSE==="1"&&(o.message=h(t.message).slice(0,500)));let r=`[${new Date().toISOString()}] HOOK: ${JSON.stringify(o)}
|
|
6
|
+
`;appendFileSync(e,r,{encoding:"utf8",mode:384});}catch{}}matchEntryLevel(e,t){if(e.provider!==void 0){let o=t.provider.replace(/^cli\//,"");if(!b(e.provider,o))return false}if(e.team!==void 0){let r=this.agentMap.get(t.agent.id)?.team??t.agent.team;if(!b(e.team,r))return false}if(e.role!==void 0){let r=this.agentMap.get(t.agent.id)?.role??t.agent.role;if(!b(e.role,r))return false}if(e.tag!==void 0){let r=this.agentMap.get(t.agent.id)?.tags??[];if(!ie(e.tag,r))return false}return !(e.agents!==void 0&&!e.agents.includes(t.agent.id))}matchRuleLevel(e,t){return !(e.when!==void 0&&e.when.length>0&&!e.when.includes(t.tool.name)&&!e.when.includes(t.tool.rawName)||!ae(e.pattern,t.tool.input)||!ue(e.regex,t.tool.input)||!se(e.pathPattern,t.tool.input,t.cwd)||!ce(e,t.tool.input)||!le(e.whenInputRegex,t.tool.input))}hasFired(e,t){try{let o=this.firedFilePath(e);if(!existsSync(o))return !1;let r=JSON.parse(readFileSync(o,"utf8"));return Array.isArray(r.fired)&&r.fired.includes(t)}catch{return false}}markFired(e,t){try{let o=this.firedFilePath(e);mkdirSync(dirname(o),{recursive:!0,mode:448});let r=existsSync(o)?JSON.parse(readFileSync(o,"utf8")):{fired:[]};Array.isArray(r.fired)||(r.fired=[]),r.fired.includes(t)||(r.fired.push(t),writeFileSync(o,JSON.stringify(r),{mode:384}));}catch(o){process.stderr.write(`[YamlHookPlugin] once state write failed: ${o}
|
|
7
|
+
`);}}firedFilePath(e){let t=createHash("sha1").update(e).digest("hex");return join(homedir(),".crewx","sessions",t,"fired-rules.json")}};export{d as HookPlugin,f as ToolObserverPlugin,i as Tools,v as YamlHookPlugin,S as buildHookContext,j as defineHookPlugin,M as definePlugin,K as evaluateHook,O as formatDenyOutput,C as formatInjectOutput,q as isPathSafe,w as sanitizeDenyReason,h as sanitizeInjectMessage,de as validateHooksSchema};
|