cray-code 1.0.0
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/README.md +316 -0
- package/dist/Tool.d.ts +217 -0
- package/dist/Tool.d.ts.map +1 -0
- package/dist/Tool.js +89 -0
- package/dist/Tool.js.map +1 -0
- package/dist/branding/logo.d.ts +8 -0
- package/dist/branding/logo.d.ts.map +1 -0
- package/dist/branding/logo.js +26 -0
- package/dist/branding/logo.js.map +1 -0
- package/dist/branding/theme.d.ts +27 -0
- package/dist/branding/theme.d.ts.map +1 -0
- package/dist/branding/theme.js +28 -0
- package/dist/branding/theme.js.map +1 -0
- package/dist/commands/registry.d.ts +32 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +759 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/components/MessageView.d.ts +12 -0
- package/dist/components/MessageView.d.ts.map +1 -0
- package/dist/components/MessageView.js +35 -0
- package/dist/components/MessageView.js.map +1 -0
- package/dist/components/PermissionPrompt.d.ts +11 -0
- package/dist/components/PermissionPrompt.d.ts.map +1 -0
- package/dist/components/PermissionPrompt.js +6 -0
- package/dist/components/PermissionPrompt.js.map +1 -0
- package/dist/components/PluginManager.d.ts +27 -0
- package/dist/components/PluginManager.d.ts.map +1 -0
- package/dist/components/PluginManager.js +391 -0
- package/dist/components/PluginManager.js.map +1 -0
- package/dist/components/ThinkingBlock.d.ts +27 -0
- package/dist/components/ThinkingBlock.d.ts.map +1 -0
- package/dist/components/ThinkingBlock.js +29 -0
- package/dist/components/ThinkingBlock.js.map +1 -0
- package/dist/components/ToolCallBlock.d.ts +14 -0
- package/dist/components/ToolCallBlock.d.ts.map +1 -0
- package/dist/components/ToolCallBlock.js +83 -0
- package/dist/components/ToolCallBlock.js.map +1 -0
- package/dist/components/TrustDialog.d.ts +20 -0
- package/dist/components/TrustDialog.d.ts.map +1 -0
- package/dist/components/TrustDialog.js +80 -0
- package/dist/components/TrustDialog.js.map +1 -0
- package/dist/context.d.ts +25 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +268 -0
- package/dist/context.js.map +1 -0
- package/dist/cray.d.ts +114 -0
- package/dist/cray.d.ts.map +1 -0
- package/dist/cray.js +338 -0
- package/dist/cray.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/registry.d.ts +106 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +695 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/query.d.ts +31 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +637 -0
- package/dist/query.js.map +1 -0
- package/dist/queryStream.d.ts +36 -0
- package/dist/queryStream.d.ts.map +1 -0
- package/dist/queryStream.js +704 -0
- package/dist/queryStream.js.map +1 -0
- package/dist/screens/ReplScreen.d.ts +22 -0
- package/dist/screens/ReplScreen.d.ts.map +1 -0
- package/dist/screens/ReplScreen.js +763 -0
- package/dist/screens/ReplScreen.js.map +1 -0
- package/dist/services/agentRunner.d.ts +39 -0
- package/dist/services/agentRunner.d.ts.map +1 -0
- package/dist/services/agentRunner.js +115 -0
- package/dist/services/agentRunner.js.map +1 -0
- package/dist/services/compact.d.ts +34 -0
- package/dist/services/compact.d.ts.map +1 -0
- package/dist/services/compact.js +179 -0
- package/dist/services/compact.js.map +1 -0
- package/dist/services/loadPluginCommands.d.ts +55 -0
- package/dist/services/loadPluginCommands.d.ts.map +1 -0
- package/dist/services/loadPluginCommands.js +219 -0
- package/dist/services/loadPluginCommands.js.map +1 -0
- package/dist/services/mcp/index.d.ts +3 -0
- package/dist/services/mcp/index.d.ts.map +1 -0
- package/dist/services/mcp/index.js +3 -0
- package/dist/services/mcp/index.js.map +1 -0
- package/dist/services/mcp/manager.d.ts +24 -0
- package/dist/services/mcp/manager.d.ts.map +1 -0
- package/dist/services/mcp/manager.js +138 -0
- package/dist/services/mcp/manager.js.map +1 -0
- package/dist/services/mcp/types.d.ts +52 -0
- package/dist/services/mcp/types.d.ts.map +1 -0
- package/dist/services/mcp/types.js +5 -0
- package/dist/services/mcp/types.js.map +1 -0
- package/dist/services/memory.d.ts +38 -0
- package/dist/services/memory.d.ts.map +1 -0
- package/dist/services/memory.js +181 -0
- package/dist/services/memory.js.map +1 -0
- package/dist/services/permissionPrompt.d.ts +38 -0
- package/dist/services/permissionPrompt.d.ts.map +1 -0
- package/dist/services/permissionPrompt.js +83 -0
- package/dist/services/permissionPrompt.js.map +1 -0
- package/dist/services/permissions.d.ts +15 -0
- package/dist/services/permissions.d.ts.map +1 -0
- package/dist/services/permissions.js +237 -0
- package/dist/services/permissions.js.map +1 -0
- package/dist/services/sessionStorage.d.ts +51 -0
- package/dist/services/sessionStorage.d.ts.map +1 -0
- package/dist/services/sessionStorage.js +266 -0
- package/dist/services/sessionStorage.js.map +1 -0
- package/dist/setup.d.ts +22 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +160 -0
- package/dist/setup.js.map +1 -0
- package/dist/skills/bundledSkills.d.ts +18 -0
- package/dist/skills/bundledSkills.d.ts.map +1 -0
- package/dist/skills/bundledSkills.js +277 -0
- package/dist/skills/bundledSkills.js.map +1 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +3 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/loadSkillsDir.d.ts +45 -0
- package/dist/skills/loadSkillsDir.d.ts.map +1 -0
- package/dist/skills/loadSkillsDir.js +233 -0
- package/dist/skills/loadSkillsDir.js.map +1 -0
- package/dist/state/AppState.d.ts +70 -0
- package/dist/state/AppState.d.ts.map +1 -0
- package/dist/state/AppState.js +106 -0
- package/dist/state/AppState.js.map +1 -0
- package/dist/tools/AgentTool.d.ts +62 -0
- package/dist/tools/AgentTool.d.ts.map +1 -0
- package/dist/tools/AgentTool.js +133 -0
- package/dist/tools/AgentTool.js.map +1 -0
- package/dist/tools/AskUserQuestionTool.d.ts +60 -0
- package/dist/tools/AskUserQuestionTool.d.ts.map +1 -0
- package/dist/tools/AskUserQuestionTool.js +52 -0
- package/dist/tools/AskUserQuestionTool.js.map +1 -0
- package/dist/tools/BashTool.d.ts +33 -0
- package/dist/tools/BashTool.d.ts.map +1 -0
- package/dist/tools/BashTool.js +211 -0
- package/dist/tools/BashTool.js.map +1 -0
- package/dist/tools/EditTool.d.ts +24 -0
- package/dist/tools/EditTool.d.ts.map +1 -0
- package/dist/tools/EditTool.js +102 -0
- package/dist/tools/EditTool.js.map +1 -0
- package/dist/tools/GlobTool.d.ts +17 -0
- package/dist/tools/GlobTool.d.ts.map +1 -0
- package/dist/tools/GlobTool.js +65 -0
- package/dist/tools/GlobTool.js.map +1 -0
- package/dist/tools/GrepTool.d.ts +30 -0
- package/dist/tools/GrepTool.d.ts.map +1 -0
- package/dist/tools/GrepTool.js +140 -0
- package/dist/tools/GrepTool.js.map +1 -0
- package/dist/tools/MCPTool.d.ts +24 -0
- package/dist/tools/MCPTool.d.ts.map +1 -0
- package/dist/tools/MCPTool.js +67 -0
- package/dist/tools/MCPTool.js.map +1 -0
- package/dist/tools/NotebookEditTool.d.ts +28 -0
- package/dist/tools/NotebookEditTool.d.ts.map +1 -0
- package/dist/tools/NotebookEditTool.js +213 -0
- package/dist/tools/NotebookEditTool.js.map +1 -0
- package/dist/tools/NotebookReadTool.d.ts +19 -0
- package/dist/tools/NotebookReadTool.d.ts.map +1 -0
- package/dist/tools/NotebookReadTool.js +191 -0
- package/dist/tools/NotebookReadTool.js.map +1 -0
- package/dist/tools/PlanTools.d.ts +17 -0
- package/dist/tools/PlanTools.d.ts.map +1 -0
- package/dist/tools/PlanTools.js +65 -0
- package/dist/tools/PlanTools.js.map +1 -0
- package/dist/tools/ReadTool.d.ts +21 -0
- package/dist/tools/ReadTool.d.ts.map +1 -0
- package/dist/tools/ReadTool.js +202 -0
- package/dist/tools/ReadTool.js.map +1 -0
- package/dist/tools/SkillTool.d.ts +32 -0
- package/dist/tools/SkillTool.d.ts.map +1 -0
- package/dist/tools/SkillTool.js +217 -0
- package/dist/tools/SkillTool.js.map +1 -0
- package/dist/tools/TodoWriteTool.d.ts +35 -0
- package/dist/tools/TodoWriteTool.d.ts.map +1 -0
- package/dist/tools/TodoWriteTool.js +58 -0
- package/dist/tools/TodoWriteTool.js.map +1 -0
- package/dist/tools/WebFetchTool.d.ts +17 -0
- package/dist/tools/WebFetchTool.d.ts.map +1 -0
- package/dist/tools/WebFetchTool.js +97 -0
- package/dist/tools/WebFetchTool.js.map +1 -0
- package/dist/tools/WebSearchTool.d.ts +18 -0
- package/dist/tools/WebSearchTool.d.ts.map +1 -0
- package/dist/tools/WebSearchTool.js +76 -0
- package/dist/tools/WebSearchTool.js.map +1 -0
- package/dist/tools/WriteTool.d.ts +17 -0
- package/dist/tools/WriteTool.d.ts.map +1 -0
- package/dist/tools/WriteTool.js +84 -0
- package/dist/tools/WriteTool.js.map +1 -0
- package/dist/tools/index.d.ts +21 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +20 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools.d.ts +34 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +102 -0
- package/dist/tools.js.map +1 -0
- package/dist/types/events.d.ts +85 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +12 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/message.d.ts +71 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +5 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/permission.d.ts +56 -0
- package/dist/types/permission.d.ts.map +1 -0
- package/dist/types/permission.js +46 -0
- package/dist/types/permission.js.map +1 -0
- package/dist/types/processUserInput.d.ts +18 -0
- package/dist/types/processUserInput.d.ts.map +1 -0
- package/dist/types/processUserInput.js +8 -0
- package/dist/types/processUserInput.js.map +1 -0
- package/dist/types/tool.d.ts +32 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +5 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/utils/compactBoundary.d.ts +11 -0
- package/dist/utils/compactBoundary.d.ts.map +1 -0
- package/dist/utils/compactBoundary.js +26 -0
- package/dist/utils/compactBoundary.js.map +1 -0
- package/dist/utils/configStore.d.ts +41 -0
- package/dist/utils/configStore.d.ts.map +1 -0
- package/dist/utils/configStore.js +111 -0
- package/dist/utils/configStore.js.map +1 -0
- package/dist/utils/forkedAgent.d.ts +40 -0
- package/dist/utils/forkedAgent.d.ts.map +1 -0
- package/dist/utils/forkedAgent.js +231 -0
- package/dist/utils/forkedAgent.js.map +1 -0
- package/dist/utils/messages.d.ts +14 -0
- package/dist/utils/messages.d.ts.map +1 -0
- package/dist/utils/messages.js +29 -0
- package/dist/utils/messages.js.map +1 -0
- package/dist/utils/sandbox.d.ts +22 -0
- package/dist/utils/sandbox.d.ts.map +1 -0
- package/dist/utils/sandbox.js +59 -0
- package/dist/utils/sandbox.js.map +1 -0
- package/dist/utils/sideQuestion.d.ts +29 -0
- package/dist/utils/sideQuestion.d.ts.map +1 -0
- package/dist/utils/sideQuestion.js +81 -0
- package/dist/utils/sideQuestion.js.map +1 -0
- package/install.ps1 +86 -0
- package/install.sh +92 -0
- package/package.json +68 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* forkedAgent.ts — Lightweight forked agent execution.
|
|
3
|
+
*
|
|
4
|
+
* Creates a minimal, tool-free agent call that shares the main
|
|
5
|
+
* conversation's prompt context for cache reuse. Used by /btw side
|
|
6
|
+
* questions and other short-lived, read-only agent forks.
|
|
7
|
+
*/
|
|
8
|
+
import type { ToolUseContext } from '../Tool.js';
|
|
9
|
+
import type { Message, TokenUsage } from '../types/message.js';
|
|
10
|
+
export interface CacheSafeParams {
|
|
11
|
+
systemPrompt: string;
|
|
12
|
+
userContext: string;
|
|
13
|
+
systemContext: string;
|
|
14
|
+
toolUseContext: ToolUseContext;
|
|
15
|
+
forkContextMessages: Message[];
|
|
16
|
+
}
|
|
17
|
+
export declare function getLastCacheSafeParams(): CacheSafeParams | null;
|
|
18
|
+
export declare function setLastCacheSafeParams(params: CacheSafeParams): void;
|
|
19
|
+
export interface ForkedAgentInput {
|
|
20
|
+
promptMessages: Message[];
|
|
21
|
+
cacheSafeParams: CacheSafeParams;
|
|
22
|
+
canUseTool?: (toolName: string) => Promise<{
|
|
23
|
+
behavior: 'allow' | 'deny';
|
|
24
|
+
message?: string;
|
|
25
|
+
}>;
|
|
26
|
+
querySource?: string;
|
|
27
|
+
forkLabel?: string;
|
|
28
|
+
maxTurns?: number;
|
|
29
|
+
skipCacheWrite?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ForkedAgentResult {
|
|
32
|
+
messages: Message[];
|
|
33
|
+
totalUsage: TokenUsage;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Run a forked agent — a lightweight, tool-free agent call that
|
|
37
|
+
* shares the main conversation context for prompt cache reuse.
|
|
38
|
+
*/
|
|
39
|
+
export declare function runForkedAgent(input: ForkedAgentInput): Promise<ForkedAgentResult>;
|
|
40
|
+
//# sourceMappingURL=forkedAgent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forkedAgent.d.ts","sourceRoot":"","sources":["../../src/utils/forkedAgent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAI/D,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,cAAc,CAAC;IAC/B,mBAAmB,EAAE,OAAO,EAAE,CAAC;CAChC;AAID,wBAAgB,sBAAsB,IAAI,eAAe,GAAG,IAAI,CAE/D;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAEpE;AAID,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,OAAO,EAAE,CAAC;IAC1B,eAAe,EAAE,eAAe,CAAC;IACjC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,iBAAiB,CAAC,CAkG5B"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* forkedAgent.ts — Lightweight forked agent execution.
|
|
3
|
+
*
|
|
4
|
+
* Creates a minimal, tool-free agent call that shares the main
|
|
5
|
+
* conversation's prompt context for cache reuse. Used by /btw side
|
|
6
|
+
* questions and other short-lived, read-only agent forks.
|
|
7
|
+
*/
|
|
8
|
+
let lastCacheSafeParams = null;
|
|
9
|
+
export function getLastCacheSafeParams() {
|
|
10
|
+
return lastCacheSafeParams;
|
|
11
|
+
}
|
|
12
|
+
export function setLastCacheSafeParams(params) {
|
|
13
|
+
lastCacheSafeParams = params;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Run a forked agent — a lightweight, tool-free agent call that
|
|
17
|
+
* shares the main conversation context for prompt cache reuse.
|
|
18
|
+
*/
|
|
19
|
+
export async function runForkedAgent(input) {
|
|
20
|
+
const { promptMessages, cacheSafeParams, canUseTool, forkLabel = 'fork', maxTurns = 1, } = input;
|
|
21
|
+
const { toolUseContext, systemPrompt, forkContextMessages } = cacheSafeParams;
|
|
22
|
+
const modelConfig = toolUseContext.modelConfig;
|
|
23
|
+
// Build full prompt from the main conversation's system prompt
|
|
24
|
+
const fullSystemPrompt = [
|
|
25
|
+
systemPrompt,
|
|
26
|
+
`Working directory: ${toolUseContext.cwd}`,
|
|
27
|
+
`Date: ${new Date().toISOString().split('T')[0]}`,
|
|
28
|
+
`You are a Cray Code ${forkLabel} — answer directly without tools, in a single response.`,
|
|
29
|
+
].join('\n');
|
|
30
|
+
const messages = [];
|
|
31
|
+
// Build conversation: context messages first, then the side question
|
|
32
|
+
const conversation = [
|
|
33
|
+
...forkContextMessages.map((m) => ({
|
|
34
|
+
role: m.role,
|
|
35
|
+
content: typeof m.content === 'string'
|
|
36
|
+
? m.content
|
|
37
|
+
: m.content.map((c) => {
|
|
38
|
+
if (c.type === 'text')
|
|
39
|
+
return { type: 'text', text: c.text };
|
|
40
|
+
if (c.type === 'tool_use')
|
|
41
|
+
return { type: 'tool_use', id: c.id, name: c.name, input: c.input };
|
|
42
|
+
if (c.type === 'tool_result')
|
|
43
|
+
return { type: 'tool_result', tool_use_id: c.tool_use_id, content: c.content };
|
|
44
|
+
return { type: 'text', text: JSON.stringify(c) };
|
|
45
|
+
}),
|
|
46
|
+
})),
|
|
47
|
+
// The actual question
|
|
48
|
+
...promptMessages.map((m) => ({
|
|
49
|
+
role: 'user',
|
|
50
|
+
content: typeof m.content === 'string' ? m.content : m.content,
|
|
51
|
+
})),
|
|
52
|
+
];
|
|
53
|
+
const provider = modelConfig.provider;
|
|
54
|
+
const model = modelConfig.model;
|
|
55
|
+
const apiKey = modelConfig.apiKey;
|
|
56
|
+
let totalInputTokens = 0;
|
|
57
|
+
let totalOutputTokens = 0;
|
|
58
|
+
// Single turn — no tool use loop
|
|
59
|
+
try {
|
|
60
|
+
const response = await callLLMForked({
|
|
61
|
+
provider,
|
|
62
|
+
model,
|
|
63
|
+
apiKey,
|
|
64
|
+
baseUrl: modelConfig.baseUrl,
|
|
65
|
+
systemPrompt: fullSystemPrompt,
|
|
66
|
+
messages: conversation,
|
|
67
|
+
maxTokens: modelConfig.maxTokens,
|
|
68
|
+
abortSignal: toolUseContext.abortSignal,
|
|
69
|
+
});
|
|
70
|
+
totalInputTokens += response.usage.inputTokens;
|
|
71
|
+
totalOutputTokens += response.usage.outputTokens;
|
|
72
|
+
const content = [];
|
|
73
|
+
if (response.thinking) {
|
|
74
|
+
content.push({ type: 'thinking', thinking: response.thinking, signature: '' });
|
|
75
|
+
}
|
|
76
|
+
if (response.text) {
|
|
77
|
+
content.push({ type: 'text', text: response.text });
|
|
78
|
+
}
|
|
79
|
+
messages.push({
|
|
80
|
+
role: 'assistant',
|
|
81
|
+
id: `fork-${Date.now()}`,
|
|
82
|
+
timestamp: Date.now(),
|
|
83
|
+
model,
|
|
84
|
+
stopReason: 'end_turn',
|
|
85
|
+
usage: response.usage,
|
|
86
|
+
content,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
messages.push({
|
|
91
|
+
role: 'assistant',
|
|
92
|
+
id: `fork-err-${Date.now()}`,
|
|
93
|
+
timestamp: Date.now(),
|
|
94
|
+
model,
|
|
95
|
+
stopReason: 'end_turn',
|
|
96
|
+
usage: { inputTokens: 0, outputTokens: 0 },
|
|
97
|
+
content: [{ type: 'text', text: `Side question failed: ${err.message}` }],
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
messages,
|
|
102
|
+
totalUsage: { inputTokens: totalInputTokens, outputTokens: totalOutputTokens },
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async function callLLMForked(input) {
|
|
106
|
+
const { provider, model, apiKey, systemPrompt, messages, maxTokens, abortSignal } = input;
|
|
107
|
+
const baseUrl = input.baseUrl || getDefaultBaseUrl(provider);
|
|
108
|
+
// Route to appropriate provider
|
|
109
|
+
if (provider === 'anthropic') {
|
|
110
|
+
return callAnthropicForked({ model, apiKey, systemPrompt, messages, maxTokens, abortSignal });
|
|
111
|
+
}
|
|
112
|
+
// OpenAI-compatible
|
|
113
|
+
return callOpenAIForked({ model, apiKey, baseUrl, systemPrompt, messages, maxTokens, abortSignal });
|
|
114
|
+
}
|
|
115
|
+
function getDefaultBaseUrl(provider) {
|
|
116
|
+
switch (provider) {
|
|
117
|
+
case 'ollama': return 'http://localhost:11434/v1';
|
|
118
|
+
case 'openai': return 'https://api.openai.com/v1';
|
|
119
|
+
case 'openrouter': return 'https://openrouter.ai/api/v1';
|
|
120
|
+
case 'deepseek': return 'https://api.deepseek.com/v1';
|
|
121
|
+
default: return '';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function callAnthropicForked(input) {
|
|
125
|
+
const { model, apiKey, systemPrompt, messages, maxTokens, abortSignal } = input;
|
|
126
|
+
const antMessages = messages.map((m) => {
|
|
127
|
+
const role = m.role === 'assistant' ? 'assistant' : 'user';
|
|
128
|
+
if (typeof m.content === 'string')
|
|
129
|
+
return { role, content: m.content };
|
|
130
|
+
if (Array.isArray(m.content)) {
|
|
131
|
+
return {
|
|
132
|
+
role,
|
|
133
|
+
content: m.content.map((c) => {
|
|
134
|
+
switch (c.type) {
|
|
135
|
+
case 'text': return { type: 'text', text: String(c.text ?? '') };
|
|
136
|
+
case 'tool_use': return { type: 'tool_use', id: String(c.id ?? ''), name: String(c.name ?? ''), input: c.input ?? {} };
|
|
137
|
+
case 'tool_result': return { type: 'tool_result', tool_use_id: String(c.tool_use_id ?? ''), content: String(c.content ?? '') };
|
|
138
|
+
default: return { type: 'text', text: JSON.stringify(c) };
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return { role, content: String(m.content) };
|
|
144
|
+
});
|
|
145
|
+
const body = {
|
|
146
|
+
model,
|
|
147
|
+
max_tokens: maxTokens || 4096,
|
|
148
|
+
system: systemPrompt,
|
|
149
|
+
messages: antMessages,
|
|
150
|
+
};
|
|
151
|
+
// No tools — just text
|
|
152
|
+
const res = await fetch('https://api.anthropic.com/v1/messages', {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
headers: {
|
|
155
|
+
'Content-Type': 'application/json',
|
|
156
|
+
'x-api-key': apiKey,
|
|
157
|
+
'anthropic-version': '2023-06-01',
|
|
158
|
+
},
|
|
159
|
+
body: JSON.stringify(body),
|
|
160
|
+
signal: abortSignal,
|
|
161
|
+
});
|
|
162
|
+
if (!res.ok)
|
|
163
|
+
throw new Error(`API ${res.status}: ${(await res.text()).slice(0, 300)}`);
|
|
164
|
+
const data = await res.json();
|
|
165
|
+
const textParts = [];
|
|
166
|
+
const thinkingParts = [];
|
|
167
|
+
for (const block of data.content) {
|
|
168
|
+
if (block.type === 'text')
|
|
169
|
+
textParts.push(block.text);
|
|
170
|
+
else if (block.type === 'thinking')
|
|
171
|
+
thinkingParts.push(block.thinking);
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
text: textParts.join('') || null,
|
|
175
|
+
thinking: thinkingParts.length > 0 ? thinkingParts.join('\n') : null,
|
|
176
|
+
usage: {
|
|
177
|
+
inputTokens: data.usage?.input_tokens ?? 0,
|
|
178
|
+
outputTokens: data.usage?.output_tokens ?? 0,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
async function callOpenAIForked(input) {
|
|
183
|
+
const { model, apiKey, baseUrl, systemPrompt, messages, maxTokens, abortSignal } = input;
|
|
184
|
+
const url = `${baseUrl.replace(/\/$/, '')}/chat/completions`;
|
|
185
|
+
const oaiMessages = [{ role: 'system', content: systemPrompt }];
|
|
186
|
+
for (const m of messages) {
|
|
187
|
+
if (typeof m.content === 'string') {
|
|
188
|
+
oaiMessages.push({ role: m.role, content: m.content });
|
|
189
|
+
}
|
|
190
|
+
else if (Array.isArray(m.content)) {
|
|
191
|
+
const textParts = [];
|
|
192
|
+
for (const c of m.content) {
|
|
193
|
+
if (c.type === 'text')
|
|
194
|
+
textParts.push(c.text ?? '');
|
|
195
|
+
else if (c.type === 'tool_result') {
|
|
196
|
+
oaiMessages.push({ role: 'tool', tool_call_id: c.tool_use_id, content: c.content });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (textParts.length) {
|
|
200
|
+
oaiMessages.push({ role: m.role, content: textParts.join('') });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const body = {
|
|
205
|
+
model, messages: oaiMessages, max_tokens: maxTokens || 4096, temperature: 0.7,
|
|
206
|
+
};
|
|
207
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
208
|
+
if (baseUrl.includes('openrouter.ai')) {
|
|
209
|
+
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
210
|
+
headers['HTTP-Referer'] = 'https://github.com/cray-code';
|
|
211
|
+
headers['X-Title'] = 'Cray Code';
|
|
212
|
+
}
|
|
213
|
+
else if (apiKey) {
|
|
214
|
+
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
215
|
+
}
|
|
216
|
+
const res = await fetch(url, { method: 'POST', headers, body: JSON.stringify(body), signal: abortSignal });
|
|
217
|
+
if (!res.ok)
|
|
218
|
+
throw new Error(`API ${res.status}: ${(await res.text()).slice(0, 300)}`);
|
|
219
|
+
const data = await res.json();
|
|
220
|
+
const msg = data.choices?.[0]?.message;
|
|
221
|
+
const thinking = msg?.reasoning_content || msg?.reasoning || null;
|
|
222
|
+
return {
|
|
223
|
+
text: msg?.content || null,
|
|
224
|
+
thinking,
|
|
225
|
+
usage: {
|
|
226
|
+
inputTokens: data.usage?.prompt_tokens ?? 0,
|
|
227
|
+
outputTokens: data.usage?.completion_tokens ?? 0,
|
|
228
|
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AG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;IAC3G,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IAEvF,MAAM,IAAI,GAAQ,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;IACvC,MAAM,QAAQ,GAAG,GAAG,EAAE,iBAAiB,IAAI,GAAG,EAAE,SAAS,IAAI,IAAI,CAAC;IAElE,OAAO;QACL,IAAI,EAAE,GAAG,EAAE,OAAO,IAAI,IAAI;QAC1B,QAAQ;QACR,KAAK,EAAE;YACL,WAAW,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,IAAI,CAAC;YAC3C,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,IAAI,CAAC;SACjD;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* messages.ts — Message creation and extraction helpers.
|
|
3
|
+
*/
|
|
4
|
+
import type { Message } from '../types/message.js';
|
|
5
|
+
export declare function createUserMessage({ content }: {
|
|
6
|
+
content: string;
|
|
7
|
+
}): Message;
|
|
8
|
+
export declare function extractTextContent(blocks: any[], separator?: string): string;
|
|
9
|
+
/** Strip in-progress assistant message (no stop_reason yet) from the end */
|
|
10
|
+
export declare function stripInProgressAssistantMessage(messages: Message[]): Message[];
|
|
11
|
+
/** Get messages after the last compact boundary */
|
|
12
|
+
import { getMessagesAfterCompactBoundary } from './compactBoundary.js';
|
|
13
|
+
export { getMessagesAfterCompactBoundary };
|
|
14
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/utils/messages.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,wBAAgB,iBAAiB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAO3E;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,GAAG,EAAE,EACb,SAAS,SAAO,GACf,MAAM,CAKR;AAED,4EAA4E;AAC5E,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAM9E;AAED,mDAAmD;AACnD,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AAEvE,OAAO,EAAE,+BAA+B,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* messages.ts — Message creation and extraction helpers.
|
|
3
|
+
*/
|
|
4
|
+
export function createUserMessage({ content }) {
|
|
5
|
+
return {
|
|
6
|
+
role: 'user',
|
|
7
|
+
id: `u-${Date.now()}`,
|
|
8
|
+
timestamp: Date.now(),
|
|
9
|
+
content,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function extractTextContent(blocks, separator = '\n') {
|
|
13
|
+
return blocks
|
|
14
|
+
.filter((b) => b.type === 'text')
|
|
15
|
+
.map((b) => b.text ?? '')
|
|
16
|
+
.join(separator);
|
|
17
|
+
}
|
|
18
|
+
/** Strip in-progress assistant message (no stop_reason yet) from the end */
|
|
19
|
+
export function stripInProgressAssistantMessage(messages) {
|
|
20
|
+
const last = messages.at(-1);
|
|
21
|
+
if (last?.role === 'assistant' && last.stopReason === null) {
|
|
22
|
+
return messages.slice(0, -1);
|
|
23
|
+
}
|
|
24
|
+
return messages;
|
|
25
|
+
}
|
|
26
|
+
/** Get messages after the last compact boundary */
|
|
27
|
+
import { getMessagesAfterCompactBoundary } from './compactBoundary.js';
|
|
28
|
+
export { getMessagesAfterCompactBoundary };
|
|
29
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/utils/messages.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,UAAU,iBAAiB,CAAC,EAAE,OAAO,EAAuB;IAChE,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,EAAE,EAAE,KAAK,IAAI,CAAC,GAAG,EAAE,EAAE;QACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,OAAO;KACR,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,MAAa,EACb,SAAS,GAAG,IAAI;IAEhB,OAAO,MAAM;SACV,MAAM,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;SACrC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;SAC7B,IAAI,CAAC,SAAS,CAAC,CAAC;AACrB,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,+BAA+B,CAAC,QAAmB;IACjE,MAAM,IAAI,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,IAAI,EAAE,IAAI,KAAK,WAAW,IAAK,IAAY,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QACpE,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,mDAAmD;AACnD,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AAEvE,OAAO,EAAE,+BAA+B,EAAE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox utilities for Cray Code.
|
|
3
|
+
*
|
|
4
|
+
* Provides optional sandboxing for bash commands:
|
|
5
|
+
* - Linux: can use nsjail, firejail, or Docker
|
|
6
|
+
* - macOS: can use sandbox-exec or Docker
|
|
7
|
+
* - Windows: can use Windows Sandbox or Docker
|
|
8
|
+
*
|
|
9
|
+
* Disabled by default — enable via CRAY_SANDBOX env var or settings.
|
|
10
|
+
*/
|
|
11
|
+
/** Check if sandbox is enabled */
|
|
12
|
+
export declare function isSandboxEnabled(): boolean;
|
|
13
|
+
/** Apply sandbox wrapping to a command */
|
|
14
|
+
export declare function applySandbox(command: string, cwd: string): string;
|
|
15
|
+
/** Get security-relevant information about a command */
|
|
16
|
+
export declare function analyzeCommandSecurity(command: string): {
|
|
17
|
+
isDestructive: boolean;
|
|
18
|
+
modifiesFilesystem: boolean;
|
|
19
|
+
requiresNetwork: boolean;
|
|
20
|
+
riskLevel: 'low' | 'medium' | 'high';
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../src/utils/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,kCAAkC;AAClC,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED,0CAA0C;AAC1C,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAqBjE;AAED,wDAAwD;AACxD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG;IACvD,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;CACtC,CAyBA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox utilities for Cray Code.
|
|
3
|
+
*
|
|
4
|
+
* Provides optional sandboxing for bash commands:
|
|
5
|
+
* - Linux: can use nsjail, firejail, or Docker
|
|
6
|
+
* - macOS: can use sandbox-exec or Docker
|
|
7
|
+
* - Windows: can use Windows Sandbox or Docker
|
|
8
|
+
*
|
|
9
|
+
* Disabled by default — enable via CRAY_SANDBOX env var or settings.
|
|
10
|
+
*/
|
|
11
|
+
const SANDBOX_ENABLED = process.env.CRAY_SANDBOX === 'true' || process.env.CRAY_SANDBOX === '1';
|
|
12
|
+
/** Check if sandbox is enabled */
|
|
13
|
+
export function isSandboxEnabled() {
|
|
14
|
+
return SANDBOX_ENABLED;
|
|
15
|
+
}
|
|
16
|
+
/** Apply sandbox wrapping to a command */
|
|
17
|
+
export function applySandbox(command, cwd) {
|
|
18
|
+
if (!SANDBOX_ENABLED)
|
|
19
|
+
return command;
|
|
20
|
+
const platform = process.platform;
|
|
21
|
+
if (platform === 'linux') {
|
|
22
|
+
// Use firejail if available (lightweight, no root needed)
|
|
23
|
+
return `firejail --quiet --noprofile --net=none --read-only=${cwd} --tmpfs=/tmp -- ${command}`;
|
|
24
|
+
}
|
|
25
|
+
if (platform === 'darwin') {
|
|
26
|
+
// macOS: use sandbox-exec with a restrictive profile
|
|
27
|
+
return `sandbox-exec -f "${cwd}/.cray/sandbox.sb" -- ${command}`;
|
|
28
|
+
}
|
|
29
|
+
if (platform === 'win32') {
|
|
30
|
+
// Windows: no built-in sandbox for individual commands
|
|
31
|
+
return command;
|
|
32
|
+
}
|
|
33
|
+
return command;
|
|
34
|
+
}
|
|
35
|
+
/** Get security-relevant information about a command */
|
|
36
|
+
export function analyzeCommandSecurity(command) {
|
|
37
|
+
const destructive = [
|
|
38
|
+
'rm ', 'rmdir', 'del ', 'format', 'dd ', 'mkfs',
|
|
39
|
+
'> /dev/', 'chmod 777', 'chown',
|
|
40
|
+
];
|
|
41
|
+
const filesystem = [
|
|
42
|
+
'touch ', 'mkdir', 'cp ', 'mv ', 'cat >', 'echo >',
|
|
43
|
+
'git add', 'git commit', 'npm install', 'pip install',
|
|
44
|
+
];
|
|
45
|
+
const network = [
|
|
46
|
+
'curl ', 'wget ', 'git clone', 'git fetch', 'git push',
|
|
47
|
+
'npm publish', 'ssh ', 'scp ', 'rsync ',
|
|
48
|
+
];
|
|
49
|
+
const isDestructive = destructive.some((p) => command.includes(p));
|
|
50
|
+
const modifiesFilesystem = filesystem.some((p) => command.includes(p)) || isDestructive;
|
|
51
|
+
const requiresNetwork = network.some((p) => command.includes(p));
|
|
52
|
+
let riskLevel = 'low';
|
|
53
|
+
if (isDestructive)
|
|
54
|
+
riskLevel = 'high';
|
|
55
|
+
else if (modifiesFilesystem && requiresNetwork)
|
|
56
|
+
riskLevel = 'medium';
|
|
57
|
+
return { isDestructive, modifiesFilesystem, requiresNetwork, riskLevel };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../src/utils/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,GAAG,CAAC;AAEhG,kCAAkC;AAClC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,GAAW;IACvD,IAAI,CAAC,eAAe;QAAE,OAAO,OAAO,CAAC;IAErC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAElC,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,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,IAAI,SAAS,GAA8B,KAAK,CAAC;IACjD,IAAI,aAAa;QAAE,SAAS,GAAG,MAAM,CAAC;SACjC,IAAI,kBAAkB,IAAI,eAAe;QAAE,SAAS,GAAG,QAAQ,CAAC;IAErE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sideQuestion.ts — Side Question ("/btw") feature.
|
|
3
|
+
*
|
|
4
|
+
* Allows users to ask quick questions during an active conversation
|
|
5
|
+
* without interrupting the main agent. Uses a forked agent with
|
|
6
|
+
* shared prompt cache for fast, context-aware answers.
|
|
7
|
+
*/
|
|
8
|
+
import type { TokenUsage } from '../types/message.js';
|
|
9
|
+
import { type CacheSafeParams } from './forkedAgent.js';
|
|
10
|
+
export declare function findBtwTriggerPositions(text: string): Array<{
|
|
11
|
+
word: string;
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function isBtwInput(text: string): boolean;
|
|
16
|
+
export declare function extractBtwQuestion(text: string): string;
|
|
17
|
+
export interface SideQuestionResult {
|
|
18
|
+
response: string | null;
|
|
19
|
+
usage: TokenUsage;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Run a side question using a forked agent.
|
|
23
|
+
* Shares the parent's prompt context, blocks all tools, caps at 1 turn.
|
|
24
|
+
*/
|
|
25
|
+
export declare function runSideQuestion({ question, cacheSafeParams, }: {
|
|
26
|
+
question: string;
|
|
27
|
+
cacheSafeParams: CacheSafeParams;
|
|
28
|
+
}): Promise<SideQuestionResult>;
|
|
29
|
+
//# sourceMappingURL=sideQuestion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sideQuestion.d.ts","sourceRoot":"","sources":["../../src/utils/sideQuestion.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAW,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAG/D,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAOxE,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC,CAeD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAID,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,UAAU,CAAC;CACnB;AAID;;;GAGG;AACH,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,eAAe,GAChB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,eAAe,CAAC;CAClC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkC9B"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sideQuestion.ts — Side Question ("/btw") feature.
|
|
3
|
+
*
|
|
4
|
+
* Allows users to ask quick questions during an active conversation
|
|
5
|
+
* without interrupting the main agent. Uses a forked agent with
|
|
6
|
+
* shared prompt cache for fast, context-aware answers.
|
|
7
|
+
*/
|
|
8
|
+
import { createUserMessage, extractTextContent } from './messages.js';
|
|
9
|
+
import { runForkedAgent } from './forkedAgent.js';
|
|
10
|
+
// Pattern to detect "/btw" at start of input (case-insensitive)
|
|
11
|
+
const BTW_PATTERN = /^\/btw\b/gi;
|
|
12
|
+
// ─── Trigger detection ───────────────────────────────────────────────
|
|
13
|
+
export function findBtwTriggerPositions(text) {
|
|
14
|
+
const positions = [];
|
|
15
|
+
const matches = text.matchAll(BTW_PATTERN);
|
|
16
|
+
for (const match of matches) {
|
|
17
|
+
if (match.index !== undefined) {
|
|
18
|
+
positions.push({
|
|
19
|
+
word: match[0],
|
|
20
|
+
start: match.index,
|
|
21
|
+
end: match.index + match[0].length,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return positions;
|
|
26
|
+
}
|
|
27
|
+
export function isBtwInput(text) {
|
|
28
|
+
return BTW_PATTERN.test(text.trimStart());
|
|
29
|
+
}
|
|
30
|
+
export function extractBtwQuestion(text) {
|
|
31
|
+
return text.replace(BTW_PATTERN, '').trim();
|
|
32
|
+
}
|
|
33
|
+
// ─── Side question execution ─────────────────────────────────────────
|
|
34
|
+
/**
|
|
35
|
+
* Run a side question using a forked agent.
|
|
36
|
+
* Shares the parent's prompt context, blocks all tools, caps at 1 turn.
|
|
37
|
+
*/
|
|
38
|
+
export async function runSideQuestion({ question, cacheSafeParams, }) {
|
|
39
|
+
// Wrap the question with instructions to answer without tools
|
|
40
|
+
const wrappedQuestion = [
|
|
41
|
+
'<system-reminder>',
|
|
42
|
+
'This is a side question from the user. Answer directly in one response.',
|
|
43
|
+
'',
|
|
44
|
+
'CRITICAL CONSTRAINTS:',
|
|
45
|
+
'- You have NO tools available - you cannot read files, run commands, search, or take any actions',
|
|
46
|
+
'- This is a one-off response - there will be no follow-up turns',
|
|
47
|
+
'- NEVER say things like "Let me try..." or "Let me check..." or promise to take any action',
|
|
48
|
+
'- If you don\'t know the answer, say so directly',
|
|
49
|
+
'',
|
|
50
|
+
'Simply answer the question with the information you have.',
|
|
51
|
+
'</system-reminder>',
|
|
52
|
+
'',
|
|
53
|
+
question,
|
|
54
|
+
].join('\n');
|
|
55
|
+
const agentResult = await runForkedAgent({
|
|
56
|
+
promptMessages: [createUserMessage({ content: wrappedQuestion })],
|
|
57
|
+
cacheSafeParams,
|
|
58
|
+
canUseTool: async () => ({
|
|
59
|
+
behavior: 'deny',
|
|
60
|
+
message: 'Side questions cannot use tools',
|
|
61
|
+
}),
|
|
62
|
+
forkLabel: 'side_question',
|
|
63
|
+
maxTurns: 1,
|
|
64
|
+
skipCacheWrite: true,
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
response: extractSideQuestionResponse(agentResult.messages),
|
|
68
|
+
usage: agentResult.totalUsage,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
// ─── Response extraction ─────────────────────────────────────────────
|
|
72
|
+
function extractSideQuestionResponse(messages) {
|
|
73
|
+
const assistantBlocks = messages.flatMap((m) => m.role === 'assistant' ? m.content : []);
|
|
74
|
+
if (assistantBlocks.length > 0) {
|
|
75
|
+
const text = extractTextContent(assistantBlocks).trim();
|
|
76
|
+
if (text)
|
|
77
|
+
return text;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=sideQuestion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sideQuestion.js","sourceRoot":"","sources":["../../src/utils/sideQuestion.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,cAAc,EAAwB,MAAM,kBAAkB,CAAC;AAExE,gEAAgE;AAChE,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC,wEAAwE;AAExE,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAKlD,MAAM,SAAS,GAAwD,EAAE,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAE3C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC9B,SAAS,CAAC,IAAI,CAAC;gBACb,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;gBACd,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,GAAG,EAAE,KAAK,CAAC,KAAK,GAAG,KAA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AmB;IACtD,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAC7C,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAE,CAAC,CAAC,OAAiB,CAAC,CAAC,CAAC,EAAE,CACnD,CAAC;IAEF,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,CAAC;QACxD,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;IACxB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/install.ps1
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Cray Code — One-line installer for Windows (PowerShell)
|
|
2
|
+
#
|
|
3
|
+
# Usage:
|
|
4
|
+
# iwr -useb https://cdn.craycode.dev/install.ps1 | iex
|
|
5
|
+
#
|
|
6
|
+
# # or with options:
|
|
7
|
+
# iwr -useb ... | iex -args "-Version 1.2.3"
|
|
8
|
+
|
|
9
|
+
param(
|
|
10
|
+
[string]$Version = "latest",
|
|
11
|
+
[string]$InstallDir = ""
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
$ErrorActionPreference = "Stop"
|
|
15
|
+
|
|
16
|
+
# ─── Colors ────────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
function Write-Color {
|
|
19
|
+
param([string]$Text, [string]$Color = "White")
|
|
20
|
+
Write-Host $Text -ForegroundColor $Color
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# ─── Banner ────────────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
Write-Color "🦀 Cray Code Installer" "Blue"
|
|
26
|
+
Write-Host ""
|
|
27
|
+
|
|
28
|
+
# ─── Check prerequisites ───────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
# Node.js
|
|
31
|
+
try {
|
|
32
|
+
$nodeVersion = (node -v) 2>$null
|
|
33
|
+
if (-not $nodeVersion) {
|
|
34
|
+
Write-Color "Error: Node.js >= 18 is required." "Red"
|
|
35
|
+
Write-Host "Install from: https://nodejs.org/"
|
|
36
|
+
exit 1
|
|
37
|
+
}
|
|
38
|
+
$major = [int]($nodeVersion -replace 'v','' -replace '\..*','')
|
|
39
|
+
if ($major -lt 18) {
|
|
40
|
+
Write-Color "Error: Node.js >= 18 required. Current: $nodeVersion" "Red"
|
|
41
|
+
exit 1
|
|
42
|
+
}
|
|
43
|
+
Write-Color " Node.js: $nodeVersion" "Green"
|
|
44
|
+
} catch {
|
|
45
|
+
Write-Color "Error: Node.js not found. Install from https://nodejs.org/" "Red"
|
|
46
|
+
exit 1
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# npm
|
|
50
|
+
try {
|
|
51
|
+
$npmVersion = (npm -v) 2>$null
|
|
52
|
+
Write-Color " npm: $npmVersion" "Green"
|
|
53
|
+
} catch {
|
|
54
|
+
Write-Color "Error: npm not found." "Red"
|
|
55
|
+
exit 1
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Write-Host ""
|
|
59
|
+
|
|
60
|
+
# ─── Install ───────────────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
$spec = "cray-code"
|
|
63
|
+
if ($Version -ne "latest") { $spec = "cray-code@$Version" }
|
|
64
|
+
|
|
65
|
+
Write-Host " Installing $spec..."
|
|
66
|
+
Write-Host ""
|
|
67
|
+
|
|
68
|
+
$result = npm install -g $spec 2>&1
|
|
69
|
+
if ($LASTEXITCODE -eq 0) {
|
|
70
|
+
Write-Color "╔══════════════════════════════════════╗" "Green"
|
|
71
|
+
Write-Color "║ Cray Code installed successfully! ║" "Green"
|
|
72
|
+
Write-Color "╚══════════════════════════════════════╝" "Green"
|
|
73
|
+
Write-Host ""
|
|
74
|
+
Write-Host " Run it:"
|
|
75
|
+
Write-Color " cray" "Yellow"
|
|
76
|
+
Write-Host ""
|
|
77
|
+
Write-Host " First time? Run setup:"
|
|
78
|
+
Write-Color " cray --setup" "Yellow"
|
|
79
|
+
Write-Host ""
|
|
80
|
+
} else {
|
|
81
|
+
Write-Host ""
|
|
82
|
+
Write-Color "Installation failed. Try manual install:" "Red"
|
|
83
|
+
Write-Host " npm install -g cray-code"
|
|
84
|
+
Write-Host " or visit: https://github.com/WYH/cray-code"
|
|
85
|
+
exit 1
|
|
86
|
+
}
|