@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.
Files changed (217) hide show
  1. package/dist/__tests__/adapter/context-builder.test.d.ts +1 -0
  2. package/dist/__tests__/adapter/plugin-helper.test.d.ts +1 -0
  3. package/dist/__tests__/adapter/registration-integration.test.d.ts +1 -0
  4. package/dist/__tests__/adapter/scoped-store.test.d.ts +1 -0
  5. package/dist/__tests__/plugins/conversation.test.d.ts +1 -0
  6. package/dist/__tests__/testing/createMockContext.test.d.ts +1 -0
  7. package/dist/adapter/context-builder.d.ts +0 -9
  8. package/dist/adapter/index.d.ts +0 -1
  9. package/dist/adapter/plugin-helper.d.ts +0 -7
  10. package/dist/adapter/scoped-store.d.ts +0 -10
  11. package/dist/adapter/types.d.ts +0 -7
  12. package/dist/agent/resolver.d.ts +0 -13
  13. package/dist/boxing/box-storage.interface.d.ts +0 -4
  14. package/dist/boxing/box.service.d.ts +0 -4
  15. package/dist/boxing/box.types.d.ts +0 -4
  16. package/dist/boxing/context-builder.d.ts +0 -4
  17. package/dist/client/CrewxClient.d.ts +0 -32
  18. package/dist/client/index.d.ts +0 -1
  19. package/dist/client/index.js +1 -6
  20. package/dist/config/loader.browser.d.ts +0 -8
  21. package/dist/config/loader.d.ts +0 -12
  22. package/dist/conversation/__tests__/sqlite-provider.test.d.ts +1 -0
  23. package/dist/conversation/__tests__/to-task-reader.test.d.ts +1 -0
  24. package/dist/conversation/index.d.ts +0 -1
  25. package/dist/conversation/sqlite-provider.d.ts +0 -9
  26. package/dist/conversation/to-task-reader.d.ts +0 -11
  27. package/dist/conversation/to-template-messages.d.ts +0 -13
  28. package/dist/conversation/types.d.ts +0 -58
  29. package/dist/esm/client/index.js +1 -0
  30. package/dist/esm/hooks/index.js +7 -0
  31. package/dist/esm/index.js +79 -0
  32. package/dist/esm/plugins/index.js +52 -0
  33. package/dist/esm/testing/index.js +1 -0
  34. package/dist/esm/tools/node/index.js +36 -0
  35. package/dist/events/TypedEventEmitter.d.ts +0 -24
  36. package/dist/events/types.d.ts +0 -43
  37. package/dist/facade/Crewx.browser.d.ts +0 -40
  38. package/dist/facade/Crewx.d.ts +0 -163
  39. package/dist/hooks/define.d.ts +0 -1
  40. package/dist/hooks/dispatch.d.ts +0 -12
  41. package/dist/hooks/index.d.ts +0 -1
  42. package/dist/hooks/index.js +7 -24
  43. package/dist/hooks/observer.d.ts +0 -1
  44. package/dist/hooks/plugin.d.ts +0 -1
  45. package/dist/hooks/tool-normalize.d.ts +0 -26
  46. package/dist/hooks/types.d.ts +0 -1
  47. package/dist/hooks/yaml-plugin.d.ts +0 -1
  48. package/dist/index.browser.d.ts +0 -7
  49. package/dist/index.browser.js +2 -25
  50. package/dist/index.d.ts +0 -4
  51. package/dist/index.js +79 -151
  52. package/dist/layout/loader.d.ts +0 -20
  53. package/dist/layout/props-validator.d.ts +0 -6
  54. package/dist/layout/renderer.d.ts +0 -24
  55. package/dist/layout/types.d.ts +0 -42
  56. package/dist/parallel/agent-runtime.d.ts +0 -11
  57. package/dist/parallel/helpers.d.ts +0 -1
  58. package/dist/parallel/index.d.ts +0 -1
  59. package/dist/parallel/parallel-runner.d.ts +0 -8
  60. package/dist/parallel/types.d.ts +0 -24
  61. package/dist/parsers/agent-call.util.d.ts +0 -3
  62. package/dist/parsers/claude.parser.d.ts +0 -8
  63. package/dist/parsers/codex.parser.d.ts +0 -8
  64. package/dist/parsers/copilot.parser.d.ts +0 -9
  65. package/dist/parsers/gemini.parser.d.ts +0 -10
  66. package/dist/parsers/opencode.parser.d.ts +0 -10
  67. package/dist/parsers/router.d.ts +0 -5
  68. package/dist/paths.d.ts +1 -0
  69. package/dist/platform/BrowserFsAdapter.d.ts +0 -20
  70. package/dist/platform/IFsAdapter.d.ts +0 -23
  71. package/dist/platform/NodeFsAdapter.d.ts +0 -8
  72. package/dist/plugin/plugin-provider.d.ts +0 -22
  73. package/dist/plugin/types.d.ts +0 -31
  74. package/dist/plugin.d.ts +0 -27
  75. package/dist/plugins/conversation.d.ts +0 -2
  76. package/dist/plugins/file-logger.d.ts +0 -13
  77. package/dist/plugins/index.d.ts +0 -10
  78. package/dist/plugins/index.js +52 -19
  79. package/dist/plugins/sqlite-tracing.d.ts +0 -13
  80. package/dist/plugins/sqlite-tracing.spec.d.ts +1 -0
  81. package/dist/provider/bridge.browser.d.ts +0 -20
  82. package/dist/provider/bridge.d.ts +0 -47
  83. package/dist/provider/parse-usage.d.ts +0 -14
  84. package/dist/provider/register-api.d.ts +0 -7
  85. package/dist/provider/vercel-runtime.d.ts +0 -29
  86. package/dist/remote/index.d.ts +0 -6
  87. package/dist/remote/remote-agent-manager.d.ts +0 -31
  88. package/dist/remote/remote-provider.d.ts +0 -15
  89. package/dist/remote/remote-transport.d.ts +0 -17
  90. package/dist/remote/types.d.ts +0 -59
  91. package/dist/server/auth.d.ts +0 -16
  92. package/dist/server/handler.d.ts +0 -17
  93. package/dist/server/index.d.ts +0 -4
  94. package/dist/server/tool-adapter.d.ts +0 -16
  95. package/dist/template/engine.d.ts +0 -19
  96. package/dist/template/helpers/exec.browser.d.ts +0 -7
  97. package/dist/template/helpers/exec.d.ts +0 -45
  98. package/dist/template/helpers/fenced_code.d.ts +0 -16
  99. package/dist/template/helpers/format-conversation.d.ts +0 -22
  100. package/dist/template/helpers/include.d.ts +0 -15
  101. package/dist/template/helpers/p1p2.d.ts +0 -32
  102. package/dist/template/loader/DocumentLoader.d.ts +0 -30
  103. package/dist/template/types.d.ts +0 -30
  104. package/dist/testing/index.d.ts +0 -1
  105. package/dist/testing/index.js +1 -16
  106. package/dist/testing/mock-audit.d.ts +0 -1
  107. package/dist/testing/mock-context.d.ts +0 -1
  108. package/dist/testing/mock-logger.d.ts +0 -1
  109. package/dist/testing/mock-router.d.ts +0 -1
  110. package/dist/testing/mock-storage.d.ts +0 -1
  111. package/dist/testing/mock-store.d.ts +0 -1
  112. package/dist/tools/delegate.d.ts +0 -7
  113. package/dist/tools/index.d.ts +0 -4
  114. package/dist/tools/node/builtin.d.ts +0 -16
  115. package/dist/tools/node/index.d.ts +0 -20
  116. package/dist/tools/node/index.js +36 -59
  117. package/dist/types/index.d.ts +0 -20
  118. package/dist/types/task-log.types.d.ts +0 -4
  119. package/dist/utils/env-defaults.d.ts +0 -16
  120. package/dist/utils/glob-match.d.ts +0 -16
  121. package/dist/utils/id.d.ts +0 -15
  122. package/dist/utils/timestamp.d.ts +0 -1
  123. package/dist/utils/workspace.d.ts +0 -4
  124. package/package.json +24 -25
  125. package/dist/adapter/context-builder.js +0 -87
  126. package/dist/adapter/index.js +0 -21
  127. package/dist/adapter/plugin-helper.js +0 -45
  128. package/dist/adapter/scoped-store.js +0 -43
  129. package/dist/adapter/types.js +0 -23
  130. package/dist/agent/resolver.js +0 -46
  131. package/dist/boxing/box-storage.interface.js +0 -6
  132. package/dist/boxing/box.service.js +0 -73
  133. package/dist/boxing/box.types.js +0 -6
  134. package/dist/boxing/context-builder.js +0 -79
  135. package/dist/client/CrewxClient.js +0 -86
  136. package/dist/config/loader.browser.js +0 -59
  137. package/dist/config/loader.js +0 -95
  138. package/dist/conversation/index.js +0 -25
  139. package/dist/conversation/sqlite-provider.js +0 -178
  140. package/dist/conversation/to-task-reader.js +0 -28
  141. package/dist/conversation/to-template-messages.js +0 -34
  142. package/dist/conversation/types.js +0 -10
  143. package/dist/events/TypedEventEmitter.js +0 -65
  144. package/dist/events/types.js +0 -9
  145. package/dist/facade/Crewx.browser.js +0 -314
  146. package/dist/facade/Crewx.js +0 -1299
  147. package/dist/hooks/define.js +0 -13
  148. package/dist/hooks/dispatch.js +0 -147
  149. package/dist/hooks/observer.js +0 -60
  150. package/dist/hooks/plugin.js +0 -17
  151. package/dist/hooks/tool-normalize.js +0 -110
  152. package/dist/hooks/types.js +0 -12
  153. package/dist/hooks/yaml-plugin.js +0 -356
  154. package/dist/layout/loader.js +0 -305
  155. package/dist/layout/props-validator.js +0 -301
  156. package/dist/layout/renderer.js +0 -193
  157. package/dist/layout/types.js +0 -36
  158. package/dist/parallel/agent-runtime.js +0 -25
  159. package/dist/parallel/helpers.js +0 -219
  160. package/dist/parallel/index.js +0 -13
  161. package/dist/parallel/parallel-runner.js +0 -226
  162. package/dist/parallel/types.js +0 -6
  163. package/dist/parsers/agent-call.util.js +0 -19
  164. package/dist/parsers/claude.parser.js +0 -67
  165. package/dist/parsers/codex.parser.js +0 -100
  166. package/dist/parsers/copilot.parser.js +0 -66
  167. package/dist/parsers/gemini.parser.js +0 -46
  168. package/dist/parsers/opencode.parser.js +0 -76
  169. package/dist/parsers/router.js +0 -56
  170. package/dist/platform/BrowserFsAdapter.js +0 -84
  171. package/dist/platform/IFsAdapter.js +0 -3
  172. package/dist/platform/NodeFsAdapter.js +0 -38
  173. package/dist/plugin/plugin-provider.js +0 -207
  174. package/dist/plugin/types.js +0 -9
  175. package/dist/plugin.js +0 -29
  176. package/dist/plugins/conversation.js +0 -59
  177. package/dist/plugins/file-logger.js +0 -87
  178. package/dist/plugins/sqlite-tracing.js +0 -112
  179. package/dist/provider/bridge.browser.js +0 -49
  180. package/dist/provider/bridge.js +0 -381
  181. package/dist/provider/parse-usage.js +0 -83
  182. package/dist/provider/register-api.js +0 -24
  183. package/dist/provider/vercel-runtime.js +0 -347
  184. package/dist/remote/index.js +0 -32
  185. package/dist/remote/remote-agent-manager.js +0 -198
  186. package/dist/remote/remote-provider.js +0 -141
  187. package/dist/remote/remote-transport.js +0 -83
  188. package/dist/remote/types.js +0 -9
  189. package/dist/server/auth.js +0 -35
  190. package/dist/server/handler.js +0 -75
  191. package/dist/server/index.js +0 -9
  192. package/dist/server/tool-adapter.js +0 -95
  193. package/dist/template/engine.js +0 -137
  194. package/dist/template/helpers/exec.browser.js +0 -41
  195. package/dist/template/helpers/exec.js +0 -230
  196. package/dist/template/helpers/fenced_code.js +0 -20
  197. package/dist/template/helpers/format-conversation.js +0 -53
  198. package/dist/template/helpers/include.js +0 -23
  199. package/dist/template/helpers/p1p2.js +0 -90
  200. package/dist/template/loader/DocumentLoader.js +0 -128
  201. package/dist/template/types.js +0 -6
  202. package/dist/testing/mock-audit.js +0 -13
  203. package/dist/testing/mock-context.js +0 -68
  204. package/dist/testing/mock-logger.js +0 -27
  205. package/dist/testing/mock-router.js +0 -67
  206. package/dist/testing/mock-storage.js +0 -21
  207. package/dist/testing/mock-store.js +0 -8
  208. package/dist/tools/delegate.js +0 -60
  209. package/dist/tools/index.js +0 -9
  210. package/dist/tools/node/builtin.js +0 -547
  211. package/dist/types/index.js +0 -32
  212. package/dist/types/task-log.types.js +0 -6
  213. package/dist/utils/env-defaults.js +0 -27
  214. package/dist/utils/glob-match.js +0 -42
  215. package/dist/utils/id.js +0 -50
  216. package/dist/utils/timestamp.js +0 -13
  217. package/dist/utils/workspace.js +0 -58
@@ -1,230 +0,0 @@
1
- "use strict";
2
- /**
3
- * exec Handlebars helper — 5-stage security implementation.
4
- *
5
- * Ports the security logic from packages/cli-bak/src/utils/template-processor.ts
6
- * without using shell-quote or minimatch (not in allowed library list).
7
- *
8
- * Stages:
9
- * 1. Recursion depth check (fail-closed on NaN)
10
- * 2. Shell metacharacter validation
11
- * 3. Allow-list enforcement (deny > builtin > allow > reject)
12
- * 4. Environment isolation (strip sensitive keys)
13
- * 5. Result capture (execFileSync with timeout + maxBuffer, wrapped in tags)
14
- */
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.getSanitizedEnv = getSanitizedEnv;
17
- exports.validateCommand = validateCommand;
18
- exports.isBuiltinAllowed = isBuiltinAllowed;
19
- exports.validateAllowPattern = validateAllowPattern;
20
- exports.isAllowed = isAllowed;
21
- exports.setAuditVerbose = setAuditVerbose;
22
- exports.logExecAudit = logExecAudit;
23
- exports.executeCommand = executeCommand;
24
- const child_process_1 = require("child_process");
25
- const glob_match_1 = require("../../utils/glob-match");
26
- // Sensitive env key patterns — removed from exec child processes
27
- const SENSITIVE_ENV_PATTERNS = [
28
- /^ANTHROPIC_/i, /^OPENAI_/i, /^AWS_SECRET/i, /^SLACK_/i,
29
- /^GITHUB_TOKEN$/i, /^CREWX_MCP_KEY$/i, /^DATABASE_/i,
30
- /^AWS_ACCESS_KEY/i, /^AWS_SESSION_TOKEN$/i,
31
- /^GH_TOKEN$/i, /^GH_APP_/i,
32
- /^NPM_TOKEN$/i, /^NPM_AUTH/i,
33
- /^GOOGLE_APPLICATION/i, /^GCLOUD_/i,
34
- /^AZURE_/i, /^ARM_/i,
35
- /^DOCKER_PASSWORD$/i, /^DOCKER_AUTH/i,
36
- /^SSH_PRIVATE/i, /^SSH_AUTH_SOCK$/i,
37
- /^CI_JOB_TOKEN$/i, /^ACTIONS_RUNTIME_TOKEN$/i,
38
- /^VAULT_TOKEN$/i, /^SONAR_TOKEN$/i, /^CODECOV_TOKEN$/i,
39
- /TOKEN$/i, /SECRET$/i, /PASSWORD$/i, /API_KEY$/i,
40
- ];
41
- // Shell metacharacter pattern — blocks command injection
42
- const SHELL_METACHAR = /[;|&`$(){}!><\n\r]/;
43
- // Max recursion depth for exec helper
44
- const MAX_EXEC_DEPTH = 2;
45
- // Overly broad patterns that must be rejected in allow/deny lists
46
- const DANGEROUS_PATTERNS = ['*', '**', '*:*', '* *', '**/*'];
47
- // ─────────────────────────────────────────────────────────────────────────────
48
- // Stage 4: Environment isolation
49
- // ─────────────────────────────────────────────────────────────────────────────
50
- /**
51
- * Returns a copy of process.env with all sensitive keys removed.
52
- */
53
- function getSanitizedEnv() {
54
- const env = {};
55
- for (const [key, value] of Object.entries(process.env)) {
56
- if (value === undefined)
57
- continue;
58
- if (SENSITIVE_ENV_PATTERNS.some(p => p.test(key)))
59
- continue;
60
- env[key] = value;
61
- }
62
- return env;
63
- }
64
- // ─────────────────────────────────────────────────────────────────────────────
65
- // Stage 1: Shell metacharacter validation
66
- // ─────────────────────────────────────────────────────────────────────────────
67
- /**
68
- * Validates a command string for shell metacharacter injection.
69
- * @throws Error if shell metacharacters are detected.
70
- */
71
- function validateCommand(command) {
72
- if (SHELL_METACHAR.test(command)) {
73
- throw new Error(`exec blocked: shell metacharacter detected in "${command}"`);
74
- }
75
- }
76
- // ─────────────────────────────────────────────────────────────────────────────
77
- // Stage 2: Allow-list enforcement
78
- // ─────────────────────────────────────────────────────────────────────────────
79
- /**
80
- * Checks if a command matches the builtin allowed pattern.
81
- * Only npx @crewx/<package> scope is allowed by default.
82
- */
83
- function isBuiltinAllowed(command) {
84
- return /^npx\s+@crewx\/[\w-]+/.test(command);
85
- }
86
- /**
87
- * Validates allow/deny patterns — rejects overly broad wildcards.
88
- * @throws Error if pattern is too broad or malformed.
89
- */
90
- function validateAllowPattern(pattern) {
91
- // Trim only for dangerous-pattern check (exact match list)
92
- if (DANGEROUS_PATTERNS.includes(pattern.trim())) {
93
- throw new Error(`exec config error: overly broad pattern "${pattern}" is not allowed`);
94
- }
95
- // Start-character check uses original pattern (space prefix → rejected)
96
- if (!/^[\w./@-]/.test(pattern)) {
97
- throw new Error(`exec config error: pattern must start with a command name`);
98
- }
99
- }
100
- /**
101
- * Checks if a command is allowed by the exec policy.
102
- * Priority: deny > builtin(@crewx) > allow > reject
103
- */
104
- function isAllowed(command, policy) {
105
- const allow = policy.allow ?? [];
106
- const deny = policy.deny ?? [];
107
- // Validate patterns
108
- for (const p of [...allow, ...deny]) {
109
- validateAllowPattern(p);
110
- }
111
- // Step 1: deny takes highest priority
112
- if (deny.some(pattern => (0, glob_match_1.matchesPattern)(command, pattern)))
113
- return false;
114
- // Step 2: builtin allowed (@crewx/* scope only)
115
- if (isBuiltinAllowed(command))
116
- return true;
117
- // Step 3: explicit allow patterns
118
- return allow.some(pattern => (0, glob_match_1.matchesPattern)(command, pattern));
119
- }
120
- // ─────────────────────────────────────────────────────────────────────────────
121
- // Audit log
122
- // ─────────────────────────────────────────────────────────────────────────────
123
- /** When false (default), audit logs are suppressed. Set true via setAuditVerbose(). */
124
- let _verboseAudit = false;
125
- /**
126
- * Enable or disable exec audit log output to stderr.
127
- * Call with true to show span JSON (verbose mode); false to suppress (default).
128
- */
129
- function setAuditVerbose(enabled) {
130
- _verboseAudit = enabled;
131
- }
132
- /**
133
- * Emits a structured audit log entry to stderr.
134
- * Only writes when verbose audit mode is enabled via setAuditVerbose(true).
135
- */
136
- function logExecAudit(entry) {
137
- if (!_verboseAudit)
138
- return;
139
- const log = JSON.stringify({ span: 'template_exec', ...entry, timestamp: new Date().toISOString() });
140
- console.error(log);
141
- }
142
- // ─────────────────────────────────────────────────────────────────────────────
143
- // Simple shell argument parser (replaces shell-quote)
144
- // ─────────────────────────────────────────────────────────────────────────────
145
- /**
146
- * Parses a command string into an array of arguments.
147
- * Handles single and double quoted strings.
148
- */
149
- function parseShellArgs(command) {
150
- const tokens = [];
151
- let current = '';
152
- let inSingle = false;
153
- let inDouble = false;
154
- for (let i = 0; i < command.length; i++) {
155
- const ch = command[i];
156
- if (ch === "'" && !inDouble) {
157
- inSingle = !inSingle;
158
- }
159
- else if (ch === '"' && !inSingle) {
160
- inDouble = !inDouble;
161
- }
162
- else if (ch === ' ' && !inSingle && !inDouble) {
163
- if (current.length > 0) {
164
- tokens.push(current);
165
- current = '';
166
- }
167
- }
168
- else {
169
- current += ch;
170
- }
171
- }
172
- if (current.length > 0)
173
- tokens.push(current);
174
- return tokens;
175
- }
176
- // ─────────────────────────────────────────────────────────────────────────────
177
- // Stage 3 + 5: Execute command with timeout and result capture
178
- // ─────────────────────────────────────────────────────────────────────────────
179
- /**
180
- * Executes a command and returns the output wrapped in exec-output tags.
181
- * Implements all 5 security stages.
182
- */
183
- function executeCommand(command, policy) {
184
- const startMs = Date.now();
185
- // Stage 1: Recursion depth check (NaN fail-closed)
186
- const execDepth = parseInt(process.env.CREWX_EXEC_DEPTH ?? '0', 10);
187
- if (isNaN(execDepth) || execDepth >= MAX_EXEC_DEPTH) {
188
- logExecAudit({ command, status: 'denied', reason: 'invalid or max recursion depth' });
189
- return '(exec blocked: max recursion depth reached)';
190
- }
191
- // Stage 2a: Shell metacharacter validation
192
- try {
193
- validateCommand(command);
194
- }
195
- catch {
196
- logExecAudit({ command, status: 'denied', reason: 'shell metacharacter detected' });
197
- return `(exec blocked: shell metacharacter detected in "${command}")`;
198
- }
199
- // Stage 2b/c: Allow-list enforcement (deny > builtin > allow > reject)
200
- if (!isAllowed(command, policy)) {
201
- logExecAudit({ command, status: 'denied', reason: 'not in allow list' });
202
- return `(exec blocked: ${command})`;
203
- }
204
- // Stage 3 + 4 + 5: Execute with timeout, env isolation, and result capture
205
- try {
206
- const parsed = parseShellArgs(command);
207
- const [bin, ...args] = parsed;
208
- if (!bin)
209
- return `(exec failed: ${command})`;
210
- // Stage 4: Environment isolation
211
- const sanitizedEnv = getSanitizedEnv();
212
- // Stage 3: Timeout + Stage 5: Result capture
213
- const result = (0, child_process_1.execFileSync)(bin, args, {
214
- timeout: policy.timeout ?? 5000,
215
- maxBuffer: 64 * 1024, // 64KB — OOM prevention
216
- encoding: 'utf-8',
217
- env: { ...sanitizedEnv, CREWX_EXEC_DEPTH: String(execDepth + 1) },
218
- stdio: ['pipe', 'pipe', 'pipe'],
219
- });
220
- const durationMs = Date.now() - startMs;
221
- logExecAudit({ command, status: 'allowed', allowed_by: 'policy', duration_ms: durationMs });
222
- // Stage 5: Wrap result in structured tags
223
- return `<exec-output cmd="${command}">\n${result.trim()}\n</exec-output>`;
224
- }
225
- catch {
226
- logExecAudit({ command, status: 'error', reason: 'execution failed' });
227
- return `(exec failed: ${command})`;
228
- }
229
- }
230
- //# sourceMappingURL=exec.js.map
@@ -1,20 +0,0 @@
1
- "use strict";
2
- /**
3
- * fenced_code Handlebars helper — wraps content in a Markdown fenced code block.
4
- *
5
- * Usage in templates:
6
- * {{fenced_code myCode lang="typescript"}}
7
- * {{fenced_code myCode}} ← no language specified
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.fencedCodeHelper = fencedCodeHelper;
11
- /**
12
- * Wraps content in a Markdown fenced code block.
13
- * @param content - The code content to wrap.
14
- * @param options - Handlebars options object (may contain hash.lang).
15
- */
16
- function fencedCodeHelper(content, options) {
17
- const lang = options?.hash?.lang ?? '';
18
- return `\`\`\`${lang}\n${content ?? ''}\n\`\`\``;
19
- }
20
- //# sourceMappingURL=fenced_code.js.map
@@ -1,53 +0,0 @@
1
- "use strict";
2
- /**
3
- * formatConversation Handlebars block helper.
4
- *
5
- * Ported from packages/sdk-bak/src/services/layout-renderer.service.ts:230~297.
6
- * Block mode only — the default.yaml template uses block mode exclusively.
7
- * Inline/fallback template file read is excluded (environment-independence concern).
8
- *
9
- * Unlike exec/shell-quote (which were excluded for RCE risk), formatConversation
10
- * is pure string manipulation with no code execution — RCE is not a concern.
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.formatConversationHelper = formatConversationHelper;
14
- /**
15
- * Extract unique assistant agent IDs from messages.
16
- * An assistant message with metadata.agent_id is considered an agent turn.
17
- */
18
- function extractAgentIds(messages) {
19
- return Array.from(new Set(messages
20
- .filter((msg) => msg?.isAssistant && msg?.metadata?.agent_id)
21
- .map((msg) => String(msg.metadata.agent_id))));
22
- }
23
- /**
24
- * Handlebars block helper for conversation history formatting.
25
- *
26
- * Usage in template:
27
- * {{#formatConversation messages platform}}
28
- * ...block content with {{messages}}, {{platform}}, {{messagesCount}},
29
- * {{agentIds}}, {{primaryAgentId}}...
30
- * {{/formatConversation}}
31
- *
32
- * Returns '' for empty/non-array messages.
33
- */
34
- function formatConversationHelper(messages, platform, options) {
35
- if (!Array.isArray(messages) || messages.length === 0) {
36
- return '';
37
- }
38
- const isBlockHelper = options && typeof options.fn === 'function';
39
- if (!isBlockHelper) {
40
- return '';
41
- }
42
- const assistantAgentIds = extractAgentIds(messages);
43
- const primaryAgentId = assistantAgentIds.length > 0 ? assistantAgentIds[0] : '';
44
- const context = {
45
- messages,
46
- platform: typeof platform === 'string' ? platform : '',
47
- messagesCount: messages.length,
48
- agentIds: assistantAgentIds,
49
- primaryAgentId,
50
- };
51
- return options.fn(context);
52
- }
53
- //# sourceMappingURL=format-conversation.js.map
@@ -1,23 +0,0 @@
1
- "use strict";
2
- /**
3
- * include Handlebars helper — returns inline string content as-is.
4
- *
5
- * Usage in templates:
6
- * {{{include someVariable}}}
7
- * {{{include "literal string"}}}
8
- *
9
- * Note: File-path based document loading is handled in SDK-006 (DocumentLoader).
10
- * This helper supports only inline string content (already in context).
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.includeHelper = includeHelper;
14
- /**
15
- * Returns the given string content unchanged.
16
- * Returns empty string for null/undefined.
17
- */
18
- function includeHelper(content) {
19
- if (content === null || content === undefined)
20
- return '';
21
- return String(content);
22
- }
23
- //# sourceMappingURL=include.js.map
@@ -1,90 +0,0 @@
1
- "use strict";
2
- /**
3
- * P1/P2 Handlebars helper implementations.
4
- *
5
- * P1: truncate, length, escapeHandlebars
6
- * P2: formatFileSize, formatTimestamp
7
- *
8
- * Ported from packages/cli-bak/src/utils/template-processor.ts.
9
- * formatConversation is intentionally excluded (user confirmed).
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.truncateHelper = truncateHelper;
13
- exports.lengthHelper = lengthHelper;
14
- exports.escapeHandlebarsHelper = escapeHandlebarsHelper;
15
- exports.formatFileSizeHelper = formatFileSizeHelper;
16
- exports.formatTimestampHelper = formatTimestampHelper;
17
- // ── P1 Helpers ────────────────────────────────────────────────────────────────
18
- /**
19
- * Truncate text to maxLength, appending remaining char count if truncated.
20
- * {{truncate text 500}} or {{{truncate text 500}}}
21
- */
22
- function truncateHelper(text, maxLength) {
23
- if (!text)
24
- return '';
25
- if (text.length <= maxLength)
26
- return text;
27
- const remaining = text.length - maxLength;
28
- return `${text.substring(0, maxLength)} (...+${remaining} chars)`;
29
- }
30
- /**
31
- * Return the length of an array or string.
32
- * {{length array}} / {{length string}}
33
- */
34
- function lengthHelper(value) {
35
- if (Array.isArray(value))
36
- return value.length;
37
- if (typeof value === 'string')
38
- return value.length;
39
- return 0;
40
- }
41
- /**
42
- * Escape Handlebars delimiters in user-provided content.
43
- * Prevents secondary template compilation of user content.
44
- * {{{escapeHandlebars text}}}
45
- */
46
- function escapeHandlebarsHelper(text) {
47
- if (typeof text !== 'string')
48
- return '';
49
- return text.replace(/\{\{/g, '&#123;&#123;').replace(/\}\}/g, '&#125;&#125;');
50
- }
51
- // ── P2 Helpers ────────────────────────────────────────────────────────────────
52
- const FILE_SIZE_UNITS = ['B', 'KB', 'MB', 'GB'];
53
- /**
54
- * Format a byte count as a human-readable file size string.
55
- * {{formatFileSize bytes}}
56
- */
57
- function formatFileSizeHelper(bytes) {
58
- if (bytes === 0)
59
- return '0 B';
60
- const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), FILE_SIZE_UNITS.length - 1);
61
- const value = Math.round((bytes / Math.pow(1024, i)) * 100) / 100;
62
- return `${value} ${FILE_SIZE_UNITS[i]}`;
63
- }
64
- /**
65
- * Format a Date or ISO timestamp string into a locale-aware display string.
66
- * Returns empty string for invalid or falsy input.
67
- * {{formatTimestamp timestamp}}
68
- */
69
- function formatTimestampHelper(timestamp) {
70
- if (!timestamp)
71
- return '';
72
- try {
73
- const date = timestamp instanceof Date ? timestamp : new Date(timestamp);
74
- if (isNaN(date.getTime()))
75
- return '';
76
- return date.toLocaleString('ko-KR', {
77
- year: 'numeric',
78
- month: '2-digit',
79
- day: '2-digit',
80
- hour: '2-digit',
81
- minute: '2-digit',
82
- second: '2-digit',
83
- hour12: false,
84
- });
85
- }
86
- catch {
87
- return '';
88
- }
89
- }
90
- //# sourceMappingURL=p1p2.js.map
@@ -1,128 +0,0 @@
1
- "use strict";
2
- /**
3
- * DocumentLoader — loads documents from crewx.yaml `documents:` section.
4
- *
5
- * Supports:
6
- * - Inline string: `notice: "Some text"`
7
- * - Inline object: `notice: { content: "Some text" }`
8
- * - File path (relative): `guide: { path: "docs/guide.md" }`
9
- * - File path (absolute): `guide: { path: "/abs/docs/guide.md" }`
10
- *
11
- * File I/O is delegated to IFsAdapter for testability and future WEB compat.
12
- */
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.DocumentLoader = void 0;
15
- const NodeFsAdapter_1 = require("../../platform/NodeFsAdapter");
16
- // ── DocumentLoader ──────────────────────────────────────────────────────────
17
- class DocumentLoader {
18
- docs = new Map();
19
- fs;
20
- constructor(fsAdapter) {
21
- this.fs = fsAdapter ?? NodeFsAdapter_1.defaultFsAdapter;
22
- }
23
- /**
24
- * Load all documents from the `documents:` section of crewx.yaml.
25
- *
26
- * @param sources - Record of document name → source (string, {path}, or {content})
27
- * @param projectRoot - Base directory for resolving relative file paths
28
- */
29
- async load(sources, projectRoot) {
30
- if (!sources)
31
- return;
32
- for (const [name, rawSource] of Object.entries(sources)) {
33
- const source = rawSource;
34
- if (typeof source === 'string') {
35
- // Case 1: inline string
36
- this.docs.set(name, { content: source });
37
- }
38
- else if (source && typeof source === 'object') {
39
- const src = source;
40
- if ('content' in src && typeof src['content'] === 'string') {
41
- // Case 2: inline object with content field
42
- this.docs.set(name, { content: src['content'] });
43
- }
44
- else if ('path' in src && typeof src['path'] === 'string') {
45
- // Case 3: file path
46
- await this.loadFromFile(name, src['path'], projectRoot);
47
- }
48
- else {
49
- console.warn(`[DocumentLoader] Skipping '${name}': unsupported format`);
50
- }
51
- }
52
- else {
53
- console.warn(`[DocumentLoader] Skipping '${name}': unsupported format`);
54
- }
55
- }
56
- }
57
- /** Get document text content by name. Returns undefined if not loaded. */
58
- async getContent(name) {
59
- return this.docs.get(name)?.content;
60
- }
61
- /**
62
- * Get a simple TOC (table of contents) for a markdown document.
63
- * Extracts headings (lines starting with `#`) and returns them as an indented list.
64
- * Returns undefined if there are no headings.
65
- */
66
- async getToc(name) {
67
- const doc = this.docs.get(name);
68
- if (!doc)
69
- return undefined;
70
- const headings = [];
71
- for (const line of doc.content.split('\n')) {
72
- const match = /^(#{1,6})\s+(.+)$/.exec(line.trim());
73
- if (match) {
74
- headings.push({ depth: match[1].length, text: match[2].trim() });
75
- }
76
- }
77
- if (headings.length === 0)
78
- return undefined;
79
- return headings
80
- .map(({ depth, text }) => `${' '.repeat(depth - 1)}- ${text}`)
81
- .join('\n');
82
- }
83
- /** Get the resolved absolute file path for a file-based document. */
84
- getPath(name) {
85
- return this.docs.get(name)?.path;
86
- }
87
- /** Get all loaded document names. */
88
- getNames() {
89
- return Array.from(this.docs.keys());
90
- }
91
- /**
92
- * Build a documents context object suitable for Handlebars template rendering.
93
- * Returns `{ docName: { content, toc, path? }, ... }`.
94
- */
95
- async buildContext() {
96
- const ctx = {};
97
- for (const name of this.docs.keys()) {
98
- const content = await this.getContent(name) ?? '';
99
- const toc = await this.getToc(name);
100
- const path = this.getPath(name);
101
- ctx[name] = { content, toc, ...(path ? { path } : {}) };
102
- }
103
- return ctx;
104
- }
105
- // ── Private ───────────────────────────────────────────────────────────────
106
- async loadFromFile(name, filePath, projectRoot) {
107
- try {
108
- const resolvedPath = this.resolve(filePath, projectRoot);
109
- const content = await this.fs.readFile(resolvedPath);
110
- this.docs.set(name, { content, path: resolvedPath });
111
- }
112
- catch (err) {
113
- const msg = err instanceof Error ? err.message : String(err);
114
- console.warn(`[DocumentLoader] Failed to load '${name}' from '${filePath}': ${msg}`);
115
- }
116
- }
117
- resolve(filePath, projectRoot) {
118
- if (this.fs.isAbsolute(filePath)) {
119
- return filePath;
120
- }
121
- if (projectRoot) {
122
- return this.fs.resolvePath(projectRoot, filePath);
123
- }
124
- return this.fs.resolvePath(filePath);
125
- }
126
- }
127
- exports.DocumentLoader = DocumentLoader;
128
- //# sourceMappingURL=DocumentLoader.js.map
@@ -1,6 +0,0 @@
1
- "use strict";
2
- /**
3
- * Type definitions for the CrewX template engine.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- //# sourceMappingURL=types.js.map
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMockAudit = createMockAudit;
4
- function createMockAudit() {
5
- const events = [];
6
- return {
7
- events,
8
- async log(event, payload) {
9
- events.push({ event, payload });
10
- },
11
- };
12
- }
13
- //# sourceMappingURL=mock-audit.js.map
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMockContext = createMockContext;
4
- const mock_audit_1 = require("./mock-audit");
5
- const mock_logger_1 = require("./mock-logger");
6
- const mock_router_1 = require("./mock-router");
7
- const mock_store_1 = require("./mock-store");
8
- const mock_storage_1 = require("./mock-storage");
9
- function createMockContext(opts) {
10
- const instanceId = opts.instanceId ?? 'mock-instance';
11
- const audit = (0, mock_audit_1.createMockAudit)();
12
- const log = (0, mock_logger_1.createMockLogger)();
13
- const router = (0, mock_router_1.createMockRouter)();
14
- const db = (0, mock_store_1.createMockStore)(instanceId);
15
- const storage = (0, mock_storage_1.createMockStorage)();
16
- const inboundCalls = [];
17
- const emittedEvents = [];
18
- const sentMessages = [];
19
- const agentRunner = {
20
- run: async () => ({ output: '' }),
21
- ...opts.agentRunner,
22
- };
23
- const abortController = new AbortController();
24
- const inbound = async (msg) => {
25
- inboundCalls.push(msg);
26
- return { accepted: true };
27
- };
28
- const emitEvent = async (event) => {
29
- emittedEvents.push(event);
30
- return { accepted: true };
31
- };
32
- const updateMessage = async (messageId, patch) => {
33
- sentMessages.push({ messageId, patch });
34
- };
35
- const resolveUser = async (userId) => ({
36
- userId,
37
- displayName: userId,
38
- });
39
- const respondSync = async () => { };
40
- const proactive = async () => ({
41
- messageId: 'mock-proactive',
42
- sentAt: Date.now(),
43
- });
44
- return {
45
- instanceId,
46
- installationId: opts.installationId,
47
- config: opts.config,
48
- capabilities: new Set(opts.capabilities ?? []),
49
- log,
50
- agentRunner,
51
- db,
52
- storage,
53
- audit,
54
- abortSignal: opts.abortSignal ?? abortController.signal,
55
- httpRouter: router,
56
- router,
57
- inbound,
58
- emitEvent,
59
- updateMessage,
60
- resolveUser,
61
- respondSync,
62
- proactive,
63
- inboundCalls,
64
- emittedEvents,
65
- sentMessages,
66
- };
67
- }
68
- //# sourceMappingURL=mock-context.js.map
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMockLogger = createMockLogger;
4
- function createMockLogger() {
5
- const entries = {
6
- debug: [],
7
- info: [],
8
- warn: [],
9
- error: [],
10
- };
11
- return {
12
- entries,
13
- debug(msg, meta) {
14
- entries.debug.push({ msg, meta });
15
- },
16
- info(msg, meta) {
17
- entries.info.push({ msg, meta });
18
- },
19
- warn(msg, meta) {
20
- entries.warn.push({ msg, meta });
21
- },
22
- error(msg, meta) {
23
- entries.error.push({ msg, meta });
24
- },
25
- };
26
- }
27
- //# sourceMappingURL=mock-logger.js.map