@polka-codes/cli 0.10.23 → 0.10.25
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/bin.cjs +143854 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9201 -9195
- package/dist/program.d.ts +3 -0
- package/dist/program.d.ts.map +1 -0
- package/package.json +6 -7
- package/cli.mjs +0 -2
- package/dist/ApiProviderConfig.js +0 -57
- package/dist/ApiProviderConfig.js.map +0 -1
- package/dist/ApiProviderConfig.test.js +0 -278
- package/dist/ApiProviderConfig.test.js.map +0 -1
- package/dist/agent/advanced-discovery.js +0 -604
- package/dist/agent/advanced-discovery.js.map +0 -1
- package/dist/agent/config.js +0 -139
- package/dist/agent/config.js.map +0 -1
- package/dist/agent/config.test.js +0 -140
- package/dist/agent/config.test.js.map +0 -1
- package/dist/agent/constants.js +0 -172
- package/dist/agent/constants.js.map +0 -1
- package/dist/agent/constants.test.js +0 -132
- package/dist/agent/constants.test.js.map +0 -1
- package/dist/agent/debug-logger.js +0 -281
- package/dist/agent/debug-logger.js.map +0 -1
- package/dist/agent/debug-logger.test.js +0 -294
- package/dist/agent/debug-logger.test.js.map +0 -1
- package/dist/agent/error-handling.js +0 -114
- package/dist/agent/error-handling.js.map +0 -1
- package/dist/agent/error-handling.test.js +0 -191
- package/dist/agent/error-handling.test.js.map +0 -1
- package/dist/agent/errors.js +0 -301
- package/dist/agent/errors.js.map +0 -1
- package/dist/agent/executor.js +0 -206
- package/dist/agent/executor.js.map +0 -1
- package/dist/agent/executor.test.js +0 -228
- package/dist/agent/executor.test.js.map +0 -1
- package/dist/agent/goal-decomposer.js +0 -281
- package/dist/agent/goal-decomposer.js.map +0 -1
- package/dist/agent/goal-decomposer.test.js +0 -225
- package/dist/agent/goal-decomposer.test.js.map +0 -1
- package/dist/agent/health-monitor.js +0 -89
- package/dist/agent/health-monitor.js.map +0 -1
- package/dist/agent/improvement-loop.js +0 -177
- package/dist/agent/improvement-loop.js.map +0 -1
- package/dist/agent/index.js +0 -38
- package/dist/agent/index.js.map +0 -1
- package/dist/agent/metrics.js +0 -158
- package/dist/agent/metrics.js.map +0 -1
- package/dist/agent/metrics.test.js +0 -311
- package/dist/agent/metrics.test.js.map +0 -1
- package/dist/agent/orchestrator.js +0 -438
- package/dist/agent/orchestrator.js.map +0 -1
- package/dist/agent/planner.js +0 -199
- package/dist/agent/planner.js.map +0 -1
- package/dist/agent/planner.test.js +0 -135
- package/dist/agent/planner.test.js.map +0 -1
- package/dist/agent/progress.js +0 -298
- package/dist/agent/progress.js.map +0 -1
- package/dist/agent/progress.test.js +0 -255
- package/dist/agent/progress.test.js.map +0 -1
- package/dist/agent/resource-monitor.js +0 -114
- package/dist/agent/resource-monitor.js.map +0 -1
- package/dist/agent/safety/approval.js +0 -178
- package/dist/agent/safety/approval.js.map +0 -1
- package/dist/agent/safety/approval.test.js +0 -142
- package/dist/agent/safety/approval.test.js.map +0 -1
- package/dist/agent/safety/checks.js +0 -152
- package/dist/agent/safety/checks.js.map +0 -1
- package/dist/agent/safety/checks.test.js +0 -89
- package/dist/agent/safety/checks.test.js.map +0 -1
- package/dist/agent/safety/interrupt.js +0 -92
- package/dist/agent/safety/interrupt.js.map +0 -1
- package/dist/agent/safety/interrupt.test.js +0 -53
- package/dist/agent/safety/interrupt.test.js.map +0 -1
- package/dist/agent/session.js +0 -117
- package/dist/agent/session.js.map +0 -1
- package/dist/agent/session.test.js +0 -213
- package/dist/agent/session.test.js.map +0 -1
- package/dist/agent/state-manager.js +0 -287
- package/dist/agent/state-manager.js.map +0 -1
- package/dist/agent/task-discovery.js +0 -433
- package/dist/agent/task-discovery.js.map +0 -1
- package/dist/agent/task-discovery.test.js +0 -40
- package/dist/agent/task-discovery.test.js.map +0 -1
- package/dist/agent/task-history.js +0 -128
- package/dist/agent/task-history.js.map +0 -1
- package/dist/agent/task-prioritizer.js +0 -286
- package/dist/agent/task-prioritizer.js.map +0 -1
- package/dist/agent/test-fixtures.js +0 -112
- package/dist/agent/test-fixtures.js.map +0 -1
- package/dist/agent/types.js +0 -15
- package/dist/agent/types.js.map +0 -1
- package/dist/agent/workflow-adapter.js +0 -219
- package/dist/agent/workflow-adapter.js.map +0 -1
- package/dist/agent/workflow-adapter.test.js +0 -11
- package/dist/agent/workflow-adapter.test.js.map +0 -1
- package/dist/agent/working-dir-discovery.js +0 -54
- package/dist/agent/working-dir-discovery.js.map +0 -1
- package/dist/agent/working-space.js +0 -484
- package/dist/agent/working-space.js.map +0 -1
- package/dist/agent/working-space.test.js +0 -436
- package/dist/agent/working-space.test.js.map +0 -1
- package/dist/api.js +0 -279
- package/dist/api.js.map +0 -1
- package/dist/builtin-commands.js +0 -20
- package/dist/builtin-commands.js.map +0 -1
- package/dist/commandSummarizer.js +0 -96
- package/dist/commandSummarizer.js.map +0 -1
- package/dist/commands/__tests__/command-detection.integration.test.js +0 -238
- package/dist/commands/__tests__/command-detection.integration.test.js.map +0 -1
- package/dist/commands/__tests__/script-generator.integration.test.js +0 -271
- package/dist/commands/__tests__/script-generator.integration.test.js.map +0 -1
- package/dist/commands/agent.js +0 -218
- package/dist/commands/agent.js.map +0 -1
- package/dist/commands/code.js +0 -102
- package/dist/commands/code.js.map +0 -1
- package/dist/commands/command.constants.js +0 -13
- package/dist/commands/command.constants.js.map +0 -1
- package/dist/commands/commit.js +0 -17
- package/dist/commands/commit.js.map +0 -1
- package/dist/commands/fix.js +0 -17
- package/dist/commands/fix.js.map +0 -1
- package/dist/commands/init.js +0 -501
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/mcp-server.js +0 -122
- package/dist/commands/mcp-server.js.map +0 -1
- package/dist/commands/memory.js +0 -410
- package/dist/commands/memory.js.map +0 -1
- package/dist/commands/memory.test.js +0 -453
- package/dist/commands/memory.test.js.map +0 -1
- package/dist/commands/meta.js +0 -142
- package/dist/commands/meta.js.map +0 -1
- package/dist/commands/plan.js +0 -39
- package/dist/commands/plan.js.map +0 -1
- package/dist/commands/pr.js +0 -14
- package/dist/commands/pr.js.map +0 -1
- package/dist/commands/review-json.test.js +0 -33
- package/dist/commands/review-json.test.js.map +0 -1
- package/dist/commands/review.js +0 -137
- package/dist/commands/review.js.map +0 -1
- package/dist/commands/review.usage.test.js +0 -41
- package/dist/commands/review.usage.test.js.map +0 -1
- package/dist/commands/run.js +0 -107
- package/dist/commands/run.js.map +0 -1
- package/dist/commands/skills.js +0 -175
- package/dist/commands/skills.js.map +0 -1
- package/dist/commands/task.js +0 -34
- package/dist/commands/task.js.map +0 -1
- package/dist/commands/workflow.js +0 -117
- package/dist/commands/workflow.js.map +0 -1
- package/dist/configPrompt.js +0 -39
- package/dist/configPrompt.js.map +0 -1
- package/dist/env.js +0 -22
- package/dist/env.js.map +0 -1
- package/dist/errors.js +0 -132
- package/dist/errors.js.map +0 -1
- package/dist/errors.test.js +0 -21
- package/dist/errors.test.js.map +0 -1
- package/dist/file-attachments.js +0 -77
- package/dist/file-attachments.js.map +0 -1
- package/dist/file-attachments.test.js +0 -214
- package/dist/file-attachments.test.js.map +0 -1
- package/dist/getModel.js +0 -229
- package/dist/getModel.js.map +0 -1
- package/dist/getModel.test.js +0 -67
- package/dist/getModel.test.js.map +0 -1
- package/dist/getProviderOptions.js +0 -58
- package/dist/getProviderOptions.js.map +0 -1
- package/dist/git-operations.js +0 -363
- package/dist/git-operations.js.map +0 -1
- package/dist/git-operations.test.js +0 -81
- package/dist/git-operations.test.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger.js +0 -41
- package/dist/logger.js.map +0 -1
- package/dist/mcp/client.js +0 -11
- package/dist/mcp/client.js.map +0 -1
- package/dist/mcp/error-scenarios.test.js +0 -206
- package/dist/mcp/error-scenarios.test.js.map +0 -1
- package/dist/mcp/errors.js +0 -63
- package/dist/mcp/errors.js.map +0 -1
- package/dist/mcp/index.js +0 -9
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/manager.js +0 -231
- package/dist/mcp/manager.js.map +0 -1
- package/dist/mcp/manager.test.js +0 -40
- package/dist/mcp/manager.test.js.map +0 -1
- package/dist/mcp/sdk-client.js +0 -166
- package/dist/mcp/sdk-client.js.map +0 -1
- package/dist/mcp/shared-types.js +0 -3
- package/dist/mcp/shared-types.js.map +0 -1
- package/dist/mcp/tools-integration.test.js +0 -198
- package/dist/mcp/tools-integration.test.js.map +0 -1
- package/dist/mcp/tools.js +0 -60
- package/dist/mcp/tools.js.map +0 -1
- package/dist/mcp/transport.js +0 -257
- package/dist/mcp/transport.js.map +0 -1
- package/dist/mcp/types.js +0 -3
- package/dist/mcp/types.js.map +0 -1
- package/dist/mcp-server/index.js +0 -5
- package/dist/mcp-server/index.js.map +0 -1
- package/dist/mcp-server/plan-formatting.test.js +0 -74
- package/dist/mcp-server/plan-formatting.test.js.map +0 -1
- package/dist/mcp-server/sdk-server.js +0 -102
- package/dist/mcp-server/sdk-server.js.map +0 -1
- package/dist/mcp-server/sdk-server.test.js +0 -363
- package/dist/mcp-server/sdk-server.test.js.map +0 -1
- package/dist/mcp-server/tools.js +0 -785
- package/dist/mcp-server/tools.js.map +0 -1
- package/dist/mcp-server/types.js +0 -3
- package/dist/mcp-server/types.js.map +0 -1
- package/dist/options.js +0 -85
- package/dist/options.js.map +0 -1
- package/dist/options.test.js +0 -177
- package/dist/options.test.js.map +0 -1
- package/dist/prices.js +0 -61
- package/dist/prices.js.map +0 -1
- package/dist/prices.test.js +0 -148
- package/dist/prices.test.js.map +0 -1
- package/dist/runWorkflow.js +0 -313
- package/dist/runWorkflow.js.map +0 -1
- package/dist/script/__tests__/execution.integration.test.js +0 -274
- package/dist/script/__tests__/execution.integration.test.js.map +0 -1
- package/dist/script/__tests__/runner.test.js +0 -176
- package/dist/script/__tests__/runner.test.js.map +0 -1
- package/dist/script/__tests__/validator.test.js +0 -180
- package/dist/script/__tests__/validator.test.js.map +0 -1
- package/dist/script/executor.js +0 -127
- package/dist/script/executor.js.map +0 -1
- package/dist/script/index.js +0 -4
- package/dist/script/index.js.map +0 -1
- package/dist/script/runner.js +0 -258
- package/dist/script/runner.js.map +0 -1
- package/dist/skillIntegration.js +0 -46
- package/dist/skillIntegration.js.map +0 -1
- package/dist/skillIntegration.test.js +0 -128
- package/dist/skillIntegration.test.js.map +0 -1
- package/dist/test/utils.js +0 -200
- package/dist/test/utils.js.map +0 -1
- package/dist/test/workflow-fixtures.js +0 -120
- package/dist/test/workflow-fixtures.js.map +0 -1
- package/dist/tool-implementations.js +0 -521
- package/dist/tool-implementations.js.map +0 -1
- package/dist/tool-implementations.skill-tools.test.js +0 -106
- package/dist/tool-implementations.skill-tools.test.js.map +0 -1
- package/dist/tools/getTodoItem.js +0 -33
- package/dist/tools/getTodoItem.js.map +0 -1
- package/dist/tools/gitDiff.js +0 -108
- package/dist/tools/gitDiff.js.map +0 -1
- package/dist/tools/index.js +0 -8
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/listMemoryTopics.js +0 -24
- package/dist/tools/listMemoryTopics.js.map +0 -1
- package/dist/tools/listTodoItems.js +0 -35
- package/dist/tools/listTodoItems.js.map +0 -1
- package/dist/tools/listTodoItems.test.js +0 -89
- package/dist/tools/listTodoItems.test.js.map +0 -1
- package/dist/tools/readMemory.js +0 -33
- package/dist/tools/readMemory.js.map +0 -1
- package/dist/tools/updateMemory.js +0 -62
- package/dist/tools/updateMemory.js.map +0 -1
- package/dist/tools/updateMemory.test.js +0 -109
- package/dist/tools/updateMemory.test.js.map +0 -1
- package/dist/tools/updateTodoItem.js +0 -31
- package/dist/tools/updateTodoItem.js.map +0 -1
- package/dist/tools/utils/diffLineNumbers.js +0 -178
- package/dist/tools/utils/diffLineNumbers.js.map +0 -1
- package/dist/utils/cacheControl.js +0 -59
- package/dist/utils/cacheControl.js.map +0 -1
- package/dist/utils/cacheControl.test.js +0 -128
- package/dist/utils/cacheControl.test.js.map +0 -1
- package/dist/utils/command.js +0 -50
- package/dist/utils/command.js.map +0 -1
- package/dist/utils/shell.js +0 -56
- package/dist/utils/shell.js.map +0 -1
- package/dist/utils/userInput.js +0 -47
- package/dist/utils/userInput.js.map +0 -1
- package/dist/workflow-tools.js +0 -21
- package/dist/workflow-tools.js.map +0 -1
- package/dist/workflows/agent-builder.js +0 -90
- package/dist/workflows/agent-builder.js.map +0 -1
- package/dist/workflows/agent-builder.test.js +0 -115
- package/dist/workflows/agent-builder.test.js.map +0 -1
- package/dist/workflows/code.workflow.js +0 -145
- package/dist/workflows/code.workflow.js.map +0 -1
- package/dist/workflows/commit.workflow.js +0 -111
- package/dist/workflows/commit.workflow.js.map +0 -1
- package/dist/workflows/commit.workflow.test.js +0 -141
- package/dist/workflows/commit.workflow.test.js.map +0 -1
- package/dist/workflows/fix.workflow.js +0 -172
- package/dist/workflows/fix.workflow.js.map +0 -1
- package/dist/workflows/fix.workflow.test.js +0 -137
- package/dist/workflows/fix.workflow.test.js.map +0 -1
- package/dist/workflows/git-file-tools.js +0 -408
- package/dist/workflows/git-file-tools.js.map +0 -1
- package/dist/workflows/index.js +0 -12
- package/dist/workflows/index.js.map +0 -1
- package/dist/workflows/init-interactive.workflow.js +0 -198
- package/dist/workflows/init-interactive.workflow.js.map +0 -1
- package/dist/workflows/init.workflow.js +0 -41
- package/dist/workflows/init.workflow.js.map +0 -1
- package/dist/workflows/meta.workflow.js +0 -107
- package/dist/workflows/meta.workflow.js.map +0 -1
- package/dist/workflows/plan.workflow.js +0 -275
- package/dist/workflows/plan.workflow.js.map +0 -1
- package/dist/workflows/plan.workflow.test.js +0 -419
- package/dist/workflows/plan.workflow.test.js.map +0 -1
- package/dist/workflows/pr.workflow.js +0 -54
- package/dist/workflows/pr.workflow.js.map +0 -1
- package/dist/workflows/pr.workflow.test.js +0 -98
- package/dist/workflows/pr.workflow.test.js.map +0 -1
- package/dist/workflows/prompts/coder.js +0 -85
- package/dist/workflows/prompts/coder.js.map +0 -1
- package/dist/workflows/prompts/commit.js +0 -16
- package/dist/workflows/prompts/commit.js.map +0 -1
- package/dist/workflows/prompts/fix.js +0 -44
- package/dist/workflows/prompts/fix.js.map +0 -1
- package/dist/workflows/prompts/index.js +0 -10
- package/dist/workflows/prompts/index.js.map +0 -1
- package/dist/workflows/prompts/init.js +0 -48
- package/dist/workflows/prompts/init.js.map +0 -1
- package/dist/workflows/prompts/meta.js +0 -17
- package/dist/workflows/prompts/meta.js.map +0 -1
- package/dist/workflows/prompts/plan.js +0 -212
- package/dist/workflows/prompts/plan.js.map +0 -1
- package/dist/workflows/prompts/pr.js +0 -15
- package/dist/workflows/prompts/pr.js.map +0 -1
- package/dist/workflows/prompts/review.js +0 -145
- package/dist/workflows/prompts/review.js.map +0 -1
- package/dist/workflows/prompts/shared.js +0 -93
- package/dist/workflows/prompts/shared.js.map +0 -1
- package/dist/workflows/review.workflow.js +0 -357
- package/dist/workflows/review.workflow.js.map +0 -1
- package/dist/workflows/task.workflow.js +0 -47
- package/dist/workflows/task.workflow.js.map +0 -1
- package/dist/workflows/testing/helper.js +0 -41
- package/dist/workflows/testing/helper.js.map +0 -1
- package/dist/workflows/workflow.utils.js +0 -351
- package/dist/workflows/workflow.utils.js.map +0 -1
- package/dist/workflows/workflow.utils.test.js +0 -45
- package/dist/workflows/workflow.utils.test.js.map +0 -1
package/dist/script/runner.js
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
// generated by polka.codes
|
|
2
|
-
/**
|
|
3
|
-
* Script execution runtime for custom TypeScript scripts
|
|
4
|
-
*
|
|
5
|
-
* Provides in-process execution of TypeScript scripts with:
|
|
6
|
-
* - Dynamic module loading
|
|
7
|
-
* - Timeout enforcement
|
|
8
|
-
* - Error handling with stack traces
|
|
9
|
-
* - Security validation
|
|
10
|
-
*
|
|
11
|
-
* **IMPORTANT: Memory Limitation**
|
|
12
|
-
* This runner uses cache busting (?t=timestamp) to ensure scripts are reloaded
|
|
13
|
-
* on each execution. This creates a new module entry in Bun's module cache
|
|
14
|
-
* every time a script runs. For CLI commands (which exit after one run),
|
|
15
|
-
* this is acceptable. However, in long-running processes (watch mode,
|
|
16
|
-
* daemon, server), this will cause memory leaks as each execution creates
|
|
17
|
-
* new uncached module entries. Do NOT use this runner in long-running
|
|
18
|
-
* processes (like packages/runner) without implementing a proper cache
|
|
19
|
-
* management strategy.
|
|
20
|
-
*/
|
|
21
|
-
import { existsSync } from 'node:fs';
|
|
22
|
-
import { relative, resolve } from 'node:path';
|
|
23
|
-
import { pathToFileURL } from 'node:url';
|
|
24
|
-
import { createErrorClass } from '@polka-codes/core';
|
|
25
|
-
/**
|
|
26
|
-
* Error thrown when script validation fails
|
|
27
|
-
*/
|
|
28
|
-
export const ScriptValidationError = createErrorClass('ScriptValidationError', ([message]) => `Script validation failed: ${message}`);
|
|
29
|
-
/**
|
|
30
|
-
* Error thrown when script execution times out
|
|
31
|
-
*/
|
|
32
|
-
export const ScriptTimeoutError = createErrorClass('ScriptTimeoutError', ([scriptPath, timeout]) => `Script execution timeout: ${scriptPath} exceeded ${timeout}ms`);
|
|
33
|
-
/**
|
|
34
|
-
* Error thrown when script execution fails
|
|
35
|
-
*/
|
|
36
|
-
export const ScriptExecutionError = createErrorClass('ScriptExecutionError', (args) => `Script execution failed: ${args[0]}`);
|
|
37
|
-
/**
|
|
38
|
-
* Validates that a script path is safe to execute
|
|
39
|
-
*
|
|
40
|
-
* @param scriptPath - Path to the script file
|
|
41
|
-
* @param projectRoot - Root directory of the project (defaults to cwd)
|
|
42
|
-
* @throws {ScriptValidationError} if validation fails
|
|
43
|
-
*/
|
|
44
|
-
export function validateScriptPath(scriptPath, projectRoot = process.cwd()) {
|
|
45
|
-
// Normalize and resolve to absolute paths
|
|
46
|
-
const normalizedRoot = resolve(projectRoot);
|
|
47
|
-
const normalizedScript = resolve(projectRoot, scriptPath);
|
|
48
|
-
// Check if path is within project directory (prevent path traversal)
|
|
49
|
-
const relativePath = relative(normalizedRoot, normalizedScript);
|
|
50
|
-
// Check for path traversal attempts (.. segments at start or in path components)
|
|
51
|
-
if (relativePath.startsWith('..')) {
|
|
52
|
-
throw new ScriptValidationError(`Script path '${scriptPath}' is outside project directory`);
|
|
53
|
-
}
|
|
54
|
-
// Check if file exists
|
|
55
|
-
if (!existsSync(normalizedScript)) {
|
|
56
|
-
throw new ScriptValidationError(`Script file not found: ${scriptPath}`);
|
|
57
|
-
}
|
|
58
|
-
// Check file extension (Bun supports .ts, .js, .mjs, .cjs)
|
|
59
|
-
const validExtensions = ['.ts', '.js', '.mjs', '.cjs'];
|
|
60
|
-
const hasValidExtension = validExtensions.some((ext) => normalizedScript.endsWith(ext));
|
|
61
|
-
if (!hasValidExtension) {
|
|
62
|
-
throw new ScriptValidationError(`Script must be a .ts, .js, .mjs, or .cjs file: ${scriptPath}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Validates script permissions based on security configuration
|
|
67
|
-
*
|
|
68
|
-
* IMPORTANT: TypeScript scripts currently run with full process permissions.
|
|
69
|
-
* Permission declarations in the config are ADVISORY ONLY for future sandboxing.
|
|
70
|
-
* Scripts can access filesystem, network, and subprocesses regardless of declared permissions.
|
|
71
|
-
*
|
|
72
|
-
* @param script - Script configuration
|
|
73
|
-
* @throws {ScriptValidationError} if permissions are invalid
|
|
74
|
-
*/
|
|
75
|
-
export function validateScriptPermissions(script, logger) {
|
|
76
|
-
if (typeof script === 'string' || 'command' in script || 'workflow' in script) {
|
|
77
|
-
// These types don't have permission checks
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if ('script' in script && script.permissions) {
|
|
81
|
-
// Warn user that permissions are advisory only
|
|
82
|
-
logger?.warn('Script permissions are currently advisory only. Scripts run with full process permissions.');
|
|
83
|
-
// Validate permission values
|
|
84
|
-
const { fs, network, subprocess } = script.permissions;
|
|
85
|
-
if (fs && !['read', 'write', 'none'].includes(fs)) {
|
|
86
|
-
throw new ScriptValidationError(`Invalid fs permission: ${fs}. Must be 'read', 'write', or 'none'`);
|
|
87
|
-
}
|
|
88
|
-
if (typeof network !== 'boolean' && network !== undefined) {
|
|
89
|
-
throw new ScriptValidationError(`Invalid network permission: must be true or false`);
|
|
90
|
-
}
|
|
91
|
-
if (typeof subprocess !== 'boolean' && subprocess !== undefined) {
|
|
92
|
-
throw new ScriptValidationError(`Invalid subprocess permission: must be true or false`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* In-process script runner for TypeScript files
|
|
98
|
-
*
|
|
99
|
-
* Executes TypeScript scripts by dynamically importing them as modules.
|
|
100
|
-
* Scripts should export a `main(args: string[], context: ScriptContext)` function.
|
|
101
|
-
*
|
|
102
|
-
* **Important Limitations:**
|
|
103
|
-
*
|
|
104
|
-
* 1. **Synchronous Blocking**: The timeout mechanism uses `Promise.race()` which only
|
|
105
|
-
* handles timeouts for asynchronous operations. If a script performs a synchronous
|
|
106
|
-
* blocking operation (e.g., `while(true) {}`), the timeout will not trigger and the
|
|
107
|
-
* process will hang indefinitely. This is a known limitation of in-process script
|
|
108
|
-
* execution without using Worker threads or child processes.
|
|
109
|
-
*
|
|
110
|
-
* 2. **Path Resolution**: Script paths are resolved relative to `process.cwd()`. If the
|
|
111
|
-
* CLI is run from a subdirectory, script paths from config may not resolve correctly.
|
|
112
|
-
* The caller should ensure paths are absolute or relative to the correct working directory.
|
|
113
|
-
*
|
|
114
|
-
* 3. **Memory Leak Warning**: Cache busting via timestamp query parameters (`?t=...`)
|
|
115
|
-
* only invalidates the entry point script. If a script imports other local modules,
|
|
116
|
-
* those dependencies remain cached across executions. This is acceptable for CLI
|
|
117
|
-
* commands that run once and exit, but **will cause memory leaks in long-running
|
|
118
|
-
* processes**. Do NOT use this ScriptRunner in the `packages/runner` service or
|
|
119
|
-
* other long-lived contexts without implementing proper module cache clearing
|
|
120
|
-
* strategies (e.g., using a custom VM context or Worker threads).
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```typescript
|
|
124
|
-
* // Script file (scripts/deploy.ts):
|
|
125
|
-
* export async function main(args: string[], context: ScriptContext) {
|
|
126
|
-
* const { logger, projectRoot } = context
|
|
127
|
-
* logger.info('Deploying...')
|
|
128
|
-
* // Use logger and projectRoot as needed
|
|
129
|
-
* }
|
|
130
|
-
*
|
|
131
|
-
* // Execution:
|
|
132
|
-
* const runner = new ScriptRunner()
|
|
133
|
-
* const result = await runner.execute({
|
|
134
|
-
* scriptPath: './scripts/deploy.ts',
|
|
135
|
-
* args: ['--production'],
|
|
136
|
-
* context: { projectRoot: '/path/to/project' },
|
|
137
|
-
* logger: createLogger({ verbose: 1 }),
|
|
138
|
-
* timeout: 60000
|
|
139
|
-
* })
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
export class ScriptRunner {
|
|
143
|
-
/**
|
|
144
|
-
* Execute a TypeScript script
|
|
145
|
-
*
|
|
146
|
-
* @param options - Script execution options
|
|
147
|
-
* @returns Promise<ScriptExecutionResult>
|
|
148
|
-
* @throws {ScriptValidationError} if validation fails
|
|
149
|
-
* @throws {ScriptTimeoutError} if execution times out
|
|
150
|
-
* @throws {ScriptExecutionError} if execution fails
|
|
151
|
-
*/
|
|
152
|
-
async execute(options) {
|
|
153
|
-
const { scriptPath, args, logger, timeout = 300000, context } = options;
|
|
154
|
-
// Validate script path
|
|
155
|
-
validateScriptPath(scriptPath);
|
|
156
|
-
// Log execution start
|
|
157
|
-
logger.debug(`Executing script: ${scriptPath}`);
|
|
158
|
-
logger.debug(`Arguments: ${args.join(' ')}`);
|
|
159
|
-
logger.debug(`Timeout: ${timeout}ms`);
|
|
160
|
-
try {
|
|
161
|
-
// Execute with timeout
|
|
162
|
-
const returnValue = await this.withTimeout(timeout, async () => {
|
|
163
|
-
// Resolve script path relative to project root (where config was loaded)
|
|
164
|
-
const projectRoot = context.projectRoot || process.cwd();
|
|
165
|
-
const absolutePath = resolve(projectRoot, scriptPath);
|
|
166
|
-
// Cache busting ensures we reload the script on each execution
|
|
167
|
-
// WARNING: This creates a new module entry in the cache on each execution.
|
|
168
|
-
// For CLI commands that run once and exit, this is acceptable and ensures
|
|
169
|
-
// scripts are reloaded without process restart. However, in long-running
|
|
170
|
-
// processes (watch mode, daemon), this will cause memory leaks as each unique
|
|
171
|
-
// URL creates an uncached module entry. If used in long-running processes,
|
|
172
|
-
// implement explicit cache clearing or use a different strategy.
|
|
173
|
-
const cacheBustUrl = `${pathToFileURL(absolutePath).href}?t=${Date.now()}`;
|
|
174
|
-
// Dynamic import of the script module
|
|
175
|
-
const scriptModule = await import(cacheBustUrl);
|
|
176
|
-
// Check if script exports a main function
|
|
177
|
-
if (typeof scriptModule.main !== 'function') {
|
|
178
|
-
throw new ScriptExecutionError(scriptPath, new Error(`Script must export a 'main(args: string[], context: ScriptContext)' function`));
|
|
179
|
-
}
|
|
180
|
-
// Build script context with logger and project root
|
|
181
|
-
const scriptContext = {
|
|
182
|
-
logger,
|
|
183
|
-
projectRoot,
|
|
184
|
-
...context, // Spread additional context (config, etc.)
|
|
185
|
-
};
|
|
186
|
-
// Execute the main function with args and context
|
|
187
|
-
return await scriptModule.main(args, scriptContext);
|
|
188
|
-
});
|
|
189
|
-
logger.debug(`Script completed successfully: ${scriptPath}`);
|
|
190
|
-
return {
|
|
191
|
-
success: true,
|
|
192
|
-
returnValue,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
const executionError = error instanceof Error ? error : new Error(String(error));
|
|
197
|
-
// Check if it's a timeout
|
|
198
|
-
if (executionError.name === 'ScriptTimeoutError') {
|
|
199
|
-
throw executionError;
|
|
200
|
-
}
|
|
201
|
-
logger.error(`Script execution failed: ${scriptPath}`);
|
|
202
|
-
logger.error(executionError.message);
|
|
203
|
-
// Show stack trace in debug mode
|
|
204
|
-
if (executionError.stack) {
|
|
205
|
-
logger.debug('Stack trace:');
|
|
206
|
-
logger.debug(executionError.stack);
|
|
207
|
-
}
|
|
208
|
-
// Show helpful hint for debugging
|
|
209
|
-
logger.info(`💡 Tip: Run with --verbose=1 for more details`);
|
|
210
|
-
return {
|
|
211
|
-
success: false,
|
|
212
|
-
error: executionError,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Execute a function with a timeout
|
|
218
|
-
*
|
|
219
|
-
* @param ms - Timeout in milliseconds
|
|
220
|
-
* @param fn - Function to execute
|
|
221
|
-
* @returns Promise<T>
|
|
222
|
-
* @throws {ScriptTimeoutError} if timeout is exceeded
|
|
223
|
-
*/
|
|
224
|
-
withTimeout(ms, fn) {
|
|
225
|
-
let timeoutHandle;
|
|
226
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
227
|
-
timeoutHandle = setTimeout(() => reject(new ScriptTimeoutError('script', ms)), ms);
|
|
228
|
-
});
|
|
229
|
-
return Promise.race([fn(), timeoutPromise]).then((result) => {
|
|
230
|
-
if (timeoutHandle)
|
|
231
|
-
clearTimeout(timeoutHandle);
|
|
232
|
-
return result;
|
|
233
|
-
}, (error) => {
|
|
234
|
-
if (timeoutHandle)
|
|
235
|
-
clearTimeout(timeoutHandle);
|
|
236
|
-
throw error;
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Check if a script is a TypeScript file
|
|
241
|
-
*/
|
|
242
|
-
isTypeScriptScript(script) {
|
|
243
|
-
return typeof script !== 'string' && 'script' in script;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Check if a script is a workflow YAML
|
|
247
|
-
*/
|
|
248
|
-
isWorkflowScript(script) {
|
|
249
|
-
return typeof script !== 'string' && 'workflow' in script;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Check if a script is a shell command
|
|
253
|
-
*/
|
|
254
|
-
isShellCommand(script) {
|
|
255
|
-
return typeof script === 'string' || (typeof script !== 'string' && 'command' in script);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
//# sourceMappingURL=runner.js.map
|
|
@@ -1 +0,0 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AM,KAAK,QAAQ,IAAI,SAAS,IAAI,MAAM,CAAC,CAAA;IAC1F,CAAC;CACF"}
|
package/dist/skillIntegration.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Skill integration utilities
|
|
3
|
-
*
|
|
4
|
-
* Provides functionality to integrate Agent Skills with the agent workflow:
|
|
5
|
-
* - Generate system prompts with skill metadata
|
|
6
|
-
* - Create skill context for agent execution
|
|
7
|
-
* - Manage skill loading during agent operations
|
|
8
|
-
*
|
|
9
|
-
* Generated by polka.codes
|
|
10
|
-
*/
|
|
11
|
-
import { SkillDiscoveryService, SOURCE_ICONS } from '@polka-codes/core';
|
|
12
|
-
/**
|
|
13
|
-
* Generate a system prompt section describing available skills
|
|
14
|
-
*/
|
|
15
|
-
export function generateSkillsSystemPrompt(skills) {
|
|
16
|
-
if (skills.length === 0) {
|
|
17
|
-
return '';
|
|
18
|
-
}
|
|
19
|
-
let prompt = '\n## Available Skills\n\n';
|
|
20
|
-
prompt += 'You have access to the following Agent Skills that provide specialized capabilities:\n\n';
|
|
21
|
-
for (const skill of skills) {
|
|
22
|
-
const icon = SOURCE_ICONS[skill.source];
|
|
23
|
-
const sourceLabel = `${icon} ${skill.source.charAt(0).toUpperCase() + skill.source.slice(1)}`;
|
|
24
|
-
prompt += `### ${skill.metadata.name}\n`;
|
|
25
|
-
prompt += `${sourceLabel} - ${skill.metadata.description}\n\n`;
|
|
26
|
-
if (skill.metadata.allowedTools && skill.metadata.allowedTools.length > 0) {
|
|
27
|
-
prompt += `**Allowed Tools:** ${skill.metadata.allowedTools.join(', ')}\n\n`;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
prompt += `**Using Skills:**
|
|
31
|
-
- Use the \`loadSkill\` tool to access a skill's detailed instructions and supporting files
|
|
32
|
-
- When a skill is loaded, follow its instructions carefully to complete specialized tasks
|
|
33
|
-
- Skills provide domain-specific guidance for tasks like testing, deployment, or framework-specific operations
|
|
34
|
-
- Use the \`listSkills\` tool to discover available skills matching your current task
|
|
35
|
-
|
|
36
|
-
`;
|
|
37
|
-
return prompt;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Create an initial skill context for agent execution
|
|
41
|
-
*/
|
|
42
|
-
export async function createSkillContext(cwd) {
|
|
43
|
-
const service = new SkillDiscoveryService({ cwd: cwd || process.cwd() });
|
|
44
|
-
return await service.createContext();
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=skillIntegration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skillIntegration.js","sourceRoot":"","sources":["../src/skillIntegration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEvE;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAwB;IACjE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,MAAM,GAAG,2BAA2B,CAAA;IACxC,MAAM,IAAI,0FAA0F,CAAA;IAEpG,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACvC,MAAM,WAAW,GAAG,GAAG,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;QAC7F,MAAM,IAAI,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAA;QACxC,MAAM,IAAI,GAAG,WAAW,MAAM,KAAK,CAAC,QAAQ,CAAC,WAAW,MAAM,CAAA;QAE9D,IAAI,KAAK,CAAC,QAAQ,CAAC,YAAY,IAAI,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1E,MAAM,IAAI,sBAAsB,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAA;QAC9E,CAAC;IACH,CAAC;IAED,MAAM,IAAI;;;;;;CAMX,CAAA;IAEC,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,GAAY;IACnD,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACxE,OAAO,MAAM,OAAO,CAAC,aAAa,EAAE,CAAA;AACtC,CAAC"}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
// generated by polka.codes
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
|
3
|
-
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { createSkillContext, generateSkillsSystemPrompt } from './skillIntegration';
|
|
7
|
-
describe('skillIntegration', () => {
|
|
8
|
-
const testDir = join(tmpdir(), `polka-test-skill-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`);
|
|
9
|
-
const skillsDir = join(testDir, '.claude', 'skills');
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
mkdirSync(skillsDir, { recursive: true });
|
|
12
|
-
});
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
15
|
-
});
|
|
16
|
-
function createTestSkill(name, description, content) {
|
|
17
|
-
const skillDir = join(skillsDir, name);
|
|
18
|
-
mkdirSync(skillDir, { recursive: true });
|
|
19
|
-
const fullContent = `---
|
|
20
|
-
name: ${name}
|
|
21
|
-
description: ${description}
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
${content || '# Test Skill'}
|
|
25
|
-
`;
|
|
26
|
-
writeFileSync(join(skillDir, 'SKILL.md'), fullContent);
|
|
27
|
-
return skillDir;
|
|
28
|
-
}
|
|
29
|
-
describe('generateSkillsSystemPrompt', () => {
|
|
30
|
-
function createMockSkill(name, description, source, allowedTools) {
|
|
31
|
-
return {
|
|
32
|
-
metadata: { name, description, allowedTools },
|
|
33
|
-
source,
|
|
34
|
-
content: '# Test',
|
|
35
|
-
files: new Map(),
|
|
36
|
-
path: '/test',
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
it('should return empty string when no skills provided', () => {
|
|
40
|
-
const result = generateSkillsSystemPrompt([]);
|
|
41
|
-
expect(result).toBe('');
|
|
42
|
-
});
|
|
43
|
-
it('should generate prompt with project skills', () => {
|
|
44
|
-
const skills = [createMockSkill('test-skill', 'A test skill', 'project')];
|
|
45
|
-
const result = generateSkillsSystemPrompt(skills);
|
|
46
|
-
expect(result).toContain('## Available Skills');
|
|
47
|
-
expect(result).toContain('### test-skill');
|
|
48
|
-
expect(result).toContain('📁 Project');
|
|
49
|
-
expect(result).toContain('A test skill');
|
|
50
|
-
});
|
|
51
|
-
it('should generate prompt with personal skills', () => {
|
|
52
|
-
const skills = [createMockSkill('personal-skill', 'A personal skill', 'personal')];
|
|
53
|
-
const result = generateSkillsSystemPrompt(skills);
|
|
54
|
-
expect(result).toContain('🏠 Personal');
|
|
55
|
-
expect(result).toContain('personal-skill');
|
|
56
|
-
});
|
|
57
|
-
it('should generate prompt with plugin skills', () => {
|
|
58
|
-
const skills = [createMockSkill('plugin-skill', 'A plugin skill', 'plugin')];
|
|
59
|
-
const result = generateSkillsSystemPrompt(skills);
|
|
60
|
-
expect(result).toContain('🔌 Plugin');
|
|
61
|
-
expect(result).toContain('plugin-skill');
|
|
62
|
-
});
|
|
63
|
-
it('should include allowed tools in prompt', () => {
|
|
64
|
-
const skills = [createMockSkill('test-skill', 'A test skill', 'project', ['readFile', 'writeToFile'])];
|
|
65
|
-
const result = generateSkillsSystemPrompt(skills);
|
|
66
|
-
expect(result).toContain('**Allowed Tools:**');
|
|
67
|
-
expect(result).toContain('readFile, writeToFile');
|
|
68
|
-
});
|
|
69
|
-
it('should include multiple skills', () => {
|
|
70
|
-
const skills = [createMockSkill('skill-one', 'First skill', 'project'), createMockSkill('skill-two', 'Second skill', 'personal')];
|
|
71
|
-
const result = generateSkillsSystemPrompt(skills);
|
|
72
|
-
expect(result).toContain('### skill-one');
|
|
73
|
-
expect(result).toContain('### skill-two');
|
|
74
|
-
expect(result).toContain('First skill');
|
|
75
|
-
expect(result).toContain('Second skill');
|
|
76
|
-
});
|
|
77
|
-
it('should include usage instructions', () => {
|
|
78
|
-
const skills = [createMockSkill('test-skill', 'A test skill', 'project')];
|
|
79
|
-
const result = generateSkillsSystemPrompt(skills);
|
|
80
|
-
expect(result).toContain('**Using Skills:**');
|
|
81
|
-
expect(result).toContain('`loadSkill`');
|
|
82
|
-
expect(result).toContain('`listSkills`');
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
describe('createSkillContext', () => {
|
|
86
|
-
it('should create context with discovered skills', async () => {
|
|
87
|
-
createTestSkill('skill-one', 'First skill');
|
|
88
|
-
createTestSkill('skill-two', 'Second skill');
|
|
89
|
-
const context = await createSkillContext(testDir);
|
|
90
|
-
// Check that our test skills are included (may also include personal/plugin skills)
|
|
91
|
-
const skillNames = context.availableSkills.map((s) => s.metadata.name);
|
|
92
|
-
expect(skillNames).toContain('skill-one');
|
|
93
|
-
expect(skillNames).toContain('skill-two');
|
|
94
|
-
// Verify test skills are from project source
|
|
95
|
-
const testSkills = context.availableSkills.filter((s) => s.metadata.name === 'skill-one' || s.metadata.name === 'skill-two');
|
|
96
|
-
expect(testSkills).toHaveLength(2);
|
|
97
|
-
expect(testSkills.every((s) => s.source === 'project')).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
it('should create context with empty skills when none exist', async () => {
|
|
100
|
-
const context = await createSkillContext(testDir);
|
|
101
|
-
// Should not have any project skills (may still have personal/plugin skills)
|
|
102
|
-
const projectSkills = context.availableSkills.filter((s) => s.source === 'project');
|
|
103
|
-
expect(projectSkills).toHaveLength(0);
|
|
104
|
-
expect(context.activeSkill).toBeNull();
|
|
105
|
-
});
|
|
106
|
-
it('should use process.cwd() when no cwd provided', async () => {
|
|
107
|
-
createTestSkill('test-skill', 'A test skill');
|
|
108
|
-
// This will discover skills in the actual test directory
|
|
109
|
-
const context = await createSkillContext();
|
|
110
|
-
// Just verify it returns a valid context structure
|
|
111
|
-
expect(context).toBeDefined();
|
|
112
|
-
expect(context.availableSkills).toBeArray();
|
|
113
|
-
expect(context.activeSkill).toBeNull();
|
|
114
|
-
expect(context.skillLoadingHistory).toBeArray();
|
|
115
|
-
});
|
|
116
|
-
it('should initialize with null active skill', async () => {
|
|
117
|
-
createTestSkill('test-skill', 'A test skill');
|
|
118
|
-
const context = await createSkillContext(testDir);
|
|
119
|
-
expect(context.activeSkill).toBeNull();
|
|
120
|
-
});
|
|
121
|
-
it('should initialize with empty loading history', async () => {
|
|
122
|
-
createTestSkill('test-skill', 'A test skill');
|
|
123
|
-
const context = await createSkillContext(testDir);
|
|
124
|
-
expect(context.skillLoadingHistory).toHaveLength(0);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
//# sourceMappingURL=skillIntegration.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skillIntegration.test.js","sourceRoot":"","sources":["../src/skillIntegration.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA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AO,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAA;YAEjD,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAA;QACxC,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;YAC5D,eAAe,CAAC,YAAY,EAAE,cAAc,CAAC,CAAA;YAE7C,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAA;YAEjD,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;QACrD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/test/utils.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Testing Utilities and Fixtures
|
|
3
|
-
*
|
|
4
|
-
* Provides reusable test fixtures and utilities to reduce duplication
|
|
5
|
-
* and improve test maintainability across the codebase.
|
|
6
|
-
*/
|
|
7
|
-
import { mock } from 'bun:test';
|
|
8
|
-
import { randomUUID } from 'node:crypto';
|
|
9
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
10
|
-
import { tmpdir } from 'node:os';
|
|
11
|
-
import { join } from 'node:path';
|
|
12
|
-
/**
|
|
13
|
-
* Temporary directory fixture for isolated test environments
|
|
14
|
-
*
|
|
15
|
-
* Creates a unique temp directory for each test and ensures proper cleanup.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* describe('MyTest', () => {
|
|
20
|
-
* let fixture: TempDirectoryFixture
|
|
21
|
-
*
|
|
22
|
-
* beforeEach(async () => {
|
|
23
|
-
* fixture = new TempDirectoryFixture()
|
|
24
|
-
* const dir = await fixture.setup()
|
|
25
|
-
* })
|
|
26
|
-
*
|
|
27
|
-
* afterEach(async () => {
|
|
28
|
-
* await fixture.teardown()
|
|
29
|
-
* })
|
|
30
|
-
* })
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export class TempDirectoryFixture {
|
|
34
|
-
dir = null;
|
|
35
|
-
/**
|
|
36
|
-
* Create a unique temporary directory
|
|
37
|
-
* @returns Path to the created directory
|
|
38
|
-
*/
|
|
39
|
-
async setup() {
|
|
40
|
-
this.dir = mkdtempSync(join(tmpdir(), 'test-'));
|
|
41
|
-
return this.dir;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Clean up the temporary directory
|
|
45
|
-
* Logs cleanup failures for debugging
|
|
46
|
-
*/
|
|
47
|
-
async teardown() {
|
|
48
|
-
if (this.dir) {
|
|
49
|
-
try {
|
|
50
|
-
rmSync(this.dir, { recursive: true, force: true });
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
console.error(`[TempDirectoryFixture] Failed to cleanup: ${this.dir}`, error);
|
|
54
|
-
}
|
|
55
|
-
this.dir = null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Get a path within the temp directory
|
|
60
|
-
* @param segments - Path segments to join
|
|
61
|
-
* @returns Full path to the file/directory
|
|
62
|
-
* @throws Error if setup() hasn't been called
|
|
63
|
-
*/
|
|
64
|
-
getPath(...segments) {
|
|
65
|
-
if (!this.dir) {
|
|
66
|
-
throw new Error('TempDirectoryFixture not initialized. Call setup() first.');
|
|
67
|
-
}
|
|
68
|
-
return join(this.dir, ...segments);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Check if the fixture has been initialized
|
|
72
|
-
*/
|
|
73
|
-
isInitialized() {
|
|
74
|
-
return this.dir !== null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Mock helpers for creating typed mocks
|
|
79
|
-
*
|
|
80
|
-
* These helpers reduce the need for 'any' type assertions in tests
|
|
81
|
-
*/
|
|
82
|
-
/**
|
|
83
|
-
* Create a mock function with proper type safety
|
|
84
|
-
* @returns A mock function that can be configured
|
|
85
|
-
*/
|
|
86
|
-
export function createMockFunction(implementation) {
|
|
87
|
-
const mockFn = mock(implementation);
|
|
88
|
-
return mockFn;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Helper to create a partial mock (only mock specific methods)
|
|
92
|
-
* @param obj - Object to create partial mock of
|
|
93
|
-
* @param mockedMethods - Methods to mock
|
|
94
|
-
* @returns Partial mock with specified methods mocked
|
|
95
|
-
*/
|
|
96
|
-
export function createPartialMock(obj, mockedMethods) {
|
|
97
|
-
const result = {};
|
|
98
|
-
for (const key in obj) {
|
|
99
|
-
if (mockedMethods.includes(key)) {
|
|
100
|
-
result[key] = mock();
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
result[key] = obj[key];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Snapshot testing helpers
|
|
110
|
-
*/
|
|
111
|
-
/**
|
|
112
|
-
* Fields that should be redacted from snapshots
|
|
113
|
-
* These are typically unstable or environment-specific
|
|
114
|
-
*/
|
|
115
|
-
export const SNAPSHOT_REDACT_FIELDS = [
|
|
116
|
-
'id',
|
|
117
|
-
'timestamp',
|
|
118
|
-
'date',
|
|
119
|
-
'created_at',
|
|
120
|
-
'updated_at',
|
|
121
|
-
'last_accessed',
|
|
122
|
-
'filePath',
|
|
123
|
-
'absolutePath',
|
|
124
|
-
];
|
|
125
|
-
/**
|
|
126
|
-
* Redact unstable fields from an object for snapshot testing
|
|
127
|
-
* @param obj - Object to redact fields from
|
|
128
|
-
* @param fields - Fields to redact (defaults to SNAPSHOT_REDACT_FIELDS)
|
|
129
|
-
* @returns Object with unstable fields replaced with matchers
|
|
130
|
-
*/
|
|
131
|
-
export function redactUnstableFields(obj, fields = SNAPSHOT_REDACT_FIELDS) {
|
|
132
|
-
const result = { ...obj };
|
|
133
|
-
for (const field of fields) {
|
|
134
|
-
if (field in result) {
|
|
135
|
-
// Use a placeholder for unstable fields - actual replacement done in tests
|
|
136
|
-
result[field] = '[REDACTED]';
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Async test helpers
|
|
143
|
-
*/
|
|
144
|
-
/**
|
|
145
|
-
* Run an async test with timeout
|
|
146
|
-
* @param fn - Test function to run
|
|
147
|
-
* @param timeoutMs - Timeout in milliseconds (default: 5000)
|
|
148
|
-
* @returns Promise that rejects if timeout
|
|
149
|
-
*/
|
|
150
|
-
export function withTimeout(fn, timeoutMs = 5000) {
|
|
151
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
152
|
-
setTimeout(() => reject(new Error(`Test timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
153
|
-
});
|
|
154
|
-
return Promise.race([fn(), timeoutPromise]);
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Database test helpers
|
|
158
|
-
*/
|
|
159
|
-
/**
|
|
160
|
-
* Generate a unique database name for testing
|
|
161
|
-
* @returns Unique database name
|
|
162
|
-
*/
|
|
163
|
-
export function generateTestDbName() {
|
|
164
|
-
return `test-${randomUUID().slice(0, 8)}.sqlite`;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Memory test helpers
|
|
168
|
-
*/
|
|
169
|
-
/**
|
|
170
|
-
* Create a test memory entry with required fields
|
|
171
|
-
* @param overrides - Fields to override from defaults
|
|
172
|
-
* @returns Test memory entry
|
|
173
|
-
*/
|
|
174
|
-
export function createTestMemoryEntry(overrides = {}) {
|
|
175
|
-
const now = Date.now();
|
|
176
|
-
return {
|
|
177
|
-
name: `test-entry-${randomUUID().slice(0, 8)}`,
|
|
178
|
-
content: 'Test content',
|
|
179
|
-
entry_type: 'note',
|
|
180
|
-
status: 'active',
|
|
181
|
-
priority: 'medium',
|
|
182
|
-
tags: '',
|
|
183
|
-
created_at: now,
|
|
184
|
-
updated_at: now,
|
|
185
|
-
last_accessed: now,
|
|
186
|
-
...overrides,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Assert helpers (deprecated - use expect() directly in tests)
|
|
191
|
-
*/
|
|
192
|
-
// Note: These helper functions are not used. Use expect() directly in tests.
|
|
193
|
-
// export function expectToRejectWithMessage(fn: () => Promise<any>, errorMessage: string): Promise<void> {
|
|
194
|
-
// return expect(fn()).rejects.toThrow(errorMessage)
|
|
195
|
-
// }
|
|
196
|
-
//
|
|
197
|
-
// export function expectToThrowWithType<T extends Error>(fn: () => any, errorType: new (...args: any[]) => T): Promise<void> {
|
|
198
|
-
// return expect(fn()).toThrow(errorType)
|
|
199
|
-
// }
|
|
200
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/test/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAa,IAAI,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,oBAAoB;IACvB,GAAG,GAAkB,IAAI,CAAA;IAEjC;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAC,GAAG,CAAA;IACjB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,IAAI,CAA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