@phuetz/code-buddy 0.1.18 → 0.1.19
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/agent/background-tasks.d.ts +49 -0
- package/dist/agent/background-tasks.js +153 -0
- package/dist/agent/background-tasks.js.map +1 -0
- package/dist/agent/definitions/agent-definition-loader.d.ts +21 -0
- package/dist/agent/definitions/agent-definition-loader.js +161 -0
- package/dist/agent/definitions/agent-definition-loader.js.map +1 -0
- package/dist/agent/definitions/index.d.ts +1 -0
- package/dist/agent/definitions/index.js +2 -0
- package/dist/agent/definitions/index.js.map +1 -0
- package/dist/agent/extended-thinking.d.ts +64 -0
- package/dist/agent/extended-thinking.js +103 -0
- package/dist/agent/extended-thinking.js.map +1 -0
- package/dist/agent/prompt-suggestions.d.ts +55 -0
- package/dist/agent/prompt-suggestions.js +125 -0
- package/dist/agent/prompt-suggestions.js.map +1 -0
- package/dist/agent/rewind-manager.d.ts +59 -0
- package/dist/agent/rewind-manager.js +124 -0
- package/dist/agent/rewind-manager.js.map +1 -0
- package/dist/agent/teams/agent-team.d.ts +54 -0
- package/dist/agent/teams/agent-team.js +114 -0
- package/dist/agent/teams/agent-team.js.map +1 -0
- package/dist/agent/teams/index.d.ts +1 -0
- package/dist/agent/teams/index.js +2 -0
- package/dist/agent/teams/index.js.map +1 -0
- package/dist/agent/teams/team-v2.d.ts +166 -0
- package/dist/agent/teams/team-v2.js +376 -0
- package/dist/agent/teams/team-v2.js.map +1 -0
- package/dist/channels/imessage/index.d.ts +40 -0
- package/dist/channels/imessage/index.js +69 -0
- package/dist/channels/imessage/index.js.map +1 -0
- package/dist/channels/line/index.d.ts +36 -0
- package/dist/channels/line/index.js +71 -0
- package/dist/channels/line/index.js.map +1 -0
- package/dist/channels/mattermost/index.d.ts +34 -0
- package/dist/channels/mattermost/index.js +56 -0
- package/dist/channels/mattermost/index.js.map +1 -0
- package/dist/channels/nextcloud-talk/index.d.ts +37 -0
- package/dist/channels/nextcloud-talk/index.js +67 -0
- package/dist/channels/nextcloud-talk/index.js.map +1 -0
- package/dist/channels/niche-channels.d.ts +61 -0
- package/dist/channels/niche-channels.js +131 -0
- package/dist/channels/niche-channels.js.map +1 -0
- package/dist/channels/nostr/index.d.ts +30 -0
- package/dist/channels/nostr/index.js +68 -0
- package/dist/channels/nostr/index.js.map +1 -0
- package/dist/channels/twilio-voice/index.d.ts +37 -0
- package/dist/channels/twilio-voice/index.js +76 -0
- package/dist/channels/twilio-voice/index.js.map +1 -0
- package/dist/channels/whatsapp/index.js +0 -1
- package/dist/channels/whatsapp/index.js.map +1 -1
- package/dist/channels/zalo/index.d.ts +28 -0
- package/dist/channels/zalo/index.js +53 -0
- package/dist/channels/zalo/index.js.map +1 -0
- package/dist/cloud/cloud-sessions.d.ts +56 -0
- package/dist/cloud/cloud-sessions.js +187 -0
- package/dist/cloud/cloud-sessions.js.map +1 -0
- package/dist/codebuddy/tool-definitions/advanced-tools.d.ts +1 -0
- package/dist/codebuddy/tool-definitions/advanced-tools.js +24 -0
- package/dist/codebuddy/tool-definitions/advanced-tools.js.map +1 -1
- package/dist/codebuddy/tool-definitions/index.d.ts +1 -1
- package/dist/codebuddy/tool-definitions/index.js +1 -1
- package/dist/codebuddy/tool-definitions/index.js.map +1 -1
- package/dist/commands/handlers/auth-handler.d.ts +32 -0
- package/dist/commands/handlers/auth-handler.js +137 -0
- package/dist/commands/handlers/auth-handler.js.map +1 -0
- package/dist/commands/handlers/context-handler.d.ts +46 -0
- package/dist/commands/handlers/context-handler.js +102 -0
- package/dist/commands/handlers/context-handler.js.map +1 -0
- package/dist/commands/handlers/keybindings-handler.d.ts +30 -0
- package/dist/commands/handlers/keybindings-handler.js +124 -0
- package/dist/commands/handlers/keybindings-handler.js.map +1 -0
- package/dist/commands/handlers/session-commands.d.ts +17 -0
- package/dist/commands/handlers/session-commands.js +119 -0
- package/dist/commands/handlers/session-commands.js.map +1 -0
- package/dist/commands/slash/builtin-commands.js +1 -1
- package/dist/commands/slash/builtin-commands.js.map +1 -1
- package/dist/config/admin-config.d.ts +54 -0
- package/dist/config/admin-config.js +144 -0
- package/dist/config/admin-config.js.map +1 -0
- package/dist/config/advanced-config.d.ts +118 -0
- package/dist/config/advanced-config.js +364 -0
- package/dist/config/advanced-config.js.map +1 -0
- package/dist/config/managed-policies.d.ts +50 -0
- package/dist/config/managed-policies.js +120 -0
- package/dist/config/managed-policies.js.map +1 -0
- package/dist/config/settings-hierarchy.d.ts +59 -0
- package/dist/config/settings-hierarchy.js +188 -0
- package/dist/config/settings-hierarchy.js.map +1 -0
- package/dist/config/tool-profiles.d.ts +37 -0
- package/dist/config/tool-profiles.js +150 -0
- package/dist/config/tool-profiles.js.map +1 -0
- package/dist/config/user-settings.d.ts +31 -0
- package/dist/config/user-settings.js +66 -0
- package/dist/config/user-settings.js.map +1 -0
- package/dist/context/context-files.d.ts +1 -1
- package/dist/context/context-files.js +2 -2
- package/dist/context/context-files.js.map +1 -1
- package/dist/context/partial-summarizer.d.ts +32 -0
- package/dist/context/partial-summarizer.js +144 -0
- package/dist/context/partial-summarizer.js.map +1 -0
- package/dist/desktop/desktop-app.d.ts +44 -0
- package/dist/desktop/desktop-app.js +136 -0
- package/dist/desktop/desktop-app.js.map +1 -0
- package/dist/git/worktree-sessions.d.ts +24 -0
- package/dist/git/worktree-sessions.js +93 -0
- package/dist/git/worktree-sessions.js.map +1 -0
- package/dist/hooks/advanced-hooks.d.ts +110 -0
- package/dist/hooks/advanced-hooks.js +256 -0
- package/dist/hooks/advanced-hooks.js.map +1 -0
- package/dist/hooks/async-hooks.d.ts +73 -0
- package/dist/hooks/async-hooks.js +213 -0
- package/dist/hooks/async-hooks.js.map +1 -0
- package/dist/hooks/env-persistence.d.ts +58 -0
- package/dist/hooks/env-persistence.js +195 -0
- package/dist/hooks/env-persistence.js.map +1 -0
- package/dist/hooks/hook-events.d.ts +36 -0
- package/dist/hooks/hook-events.js +55 -0
- package/dist/hooks/hook-events.js.map +1 -0
- package/dist/hooks/smart-hooks.d.ts +85 -0
- package/dist/hooks/smart-hooks.js +199 -0
- package/dist/hooks/smart-hooks.js.map +1 -0
- package/dist/ide/jetbrains-plugin.d.ts +55 -0
- package/dist/ide/jetbrains-plugin.js +156 -0
- package/dist/ide/jetbrains-plugin.js.map +1 -0
- package/dist/ide/vscode-extension.d.ts +94 -0
- package/dist/ide/vscode-extension.js +229 -0
- package/dist/ide/vscode-extension.js.map +1 -0
- package/dist/index.js +77 -3
- package/dist/index.js.map +1 -1
- package/dist/input/file-autocomplete.d.ts +42 -0
- package/dist/input/file-autocomplete.js +154 -0
- package/dist/input/file-autocomplete.js.map +1 -0
- package/dist/integrations/chrome-bridge.d.ts +90 -0
- package/dist/integrations/chrome-bridge.js +151 -0
- package/dist/integrations/chrome-bridge.js.map +1 -0
- package/dist/integrations/github-action-runner.d.ts +40 -0
- package/dist/integrations/github-action-runner.js +163 -0
- package/dist/integrations/github-action-runner.js.map +1 -0
- package/dist/integrations/gitlab-ci-runner.d.ts +34 -0
- package/dist/integrations/gitlab-ci-runner.js +104 -0
- package/dist/integrations/gitlab-ci-runner.js.map +1 -0
- package/dist/integrations/pr-session-linker.d.ts +44 -0
- package/dist/integrations/pr-session-linker.js +103 -0
- package/dist/integrations/pr-session-linker.js.map +1 -0
- package/dist/integrations/tailscale.d.ts +36 -0
- package/dist/integrations/tailscale.js +101 -0
- package/dist/integrations/tailscale.js.map +1 -0
- package/dist/lsp/lsp-client.d.ts +68 -0
- package/dist/lsp/lsp-client.js +182 -0
- package/dist/lsp/lsp-client.js.map +1 -0
- package/dist/mcp/connectors.d.ts +28 -0
- package/dist/mcp/connectors.js +148 -0
- package/dist/mcp/connectors.js.map +1 -0
- package/dist/mcp/index.d.ts +7 -4
- package/dist/mcp/index.js +7 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/mcp-auto-discovery.d.ts +49 -0
- package/dist/mcp/mcp-auto-discovery.js +104 -0
- package/dist/mcp/mcp-auto-discovery.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +70 -0
- package/dist/mcp/mcp-server.js +374 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/memory/auto-memory.d.ts +53 -0
- package/dist/memory/auto-memory.js +250 -0
- package/dist/memory/auto-memory.js.map +1 -0
- package/dist/memory/hybrid-search.d.ts +51 -0
- package/dist/memory/hybrid-search.js +199 -0
- package/dist/memory/hybrid-search.js.map +1 -0
- package/dist/memory/memory-flush.d.ts +51 -0
- package/dist/memory/memory-flush.js +102 -0
- package/dist/memory/memory-flush.js.map +1 -0
- package/dist/memory/subagent-memory.d.ts +73 -0
- package/dist/memory/subagent-memory.js +172 -0
- package/dist/memory/subagent-memory.js.map +1 -0
- package/dist/nodes/device-node.d.ts +40 -0
- package/dist/nodes/device-node.js +117 -0
- package/dist/nodes/device-node.js.map +1 -0
- package/dist/output/json-schema-output.d.ts +67 -0
- package/dist/output/json-schema-output.js +273 -0
- package/dist/output/json-schema-output.js.map +1 -0
- package/dist/persistence/session-picker.d.ts +22 -0
- package/dist/persistence/session-picker.js +47 -0
- package/dist/persistence/session-picker.js.map +1 -0
- package/dist/persistence/session-store.d.ts +11 -0
- package/dist/persistence/session-store.js +17 -0
- package/dist/persistence/session-store.js.map +1 -1
- package/dist/plugins/git-pinned-marketplace.d.ts +39 -0
- package/dist/plugins/git-pinned-marketplace.js +152 -0
- package/dist/plugins/git-pinned-marketplace.js.map +1 -0
- package/dist/plugins/plugin-manifest.d.ts +116 -0
- package/dist/plugins/plugin-manifest.js +283 -0
- package/dist/plugins/plugin-manifest.js.map +1 -0
- package/dist/sandbox/os-sandbox.d.ts +49 -1
- package/dist/sandbox/os-sandbox.js +347 -6
- package/dist/sandbox/os-sandbox.js.map +1 -1
- package/dist/sdk/agent-sdk.d.ts +61 -0
- package/dist/sdk/agent-sdk.js +90 -0
- package/dist/sdk/agent-sdk.js.map +1 -0
- package/dist/security/permission-modes.d.ts +76 -0
- package/dist/security/permission-modes.js +195 -0
- package/dist/security/permission-modes.js.map +1 -0
- package/dist/security/permission-patterns.d.ts +61 -0
- package/dist/security/permission-patterns.js +171 -0
- package/dist/security/permission-patterns.js.map +1 -0
- package/dist/security/safe-binaries.d.ts +23 -0
- package/dist/security/safe-binaries.js +96 -0
- package/dist/security/safe-binaries.js.map +1 -0
- package/dist/security/sender-policies.d.ts +46 -0
- package/dist/security/sender-policies.js +90 -0
- package/dist/security/sender-policies.js.map +1 -0
- package/dist/server/dashboard.d.ts +53 -0
- package/dist/server/dashboard.js +93 -0
- package/dist/server/dashboard.js.map +1 -0
- package/dist/services/system-prompt-override.d.ts +34 -0
- package/dist/services/system-prompt-override.js +64 -0
- package/dist/services/system-prompt-override.js.map +1 -0
- package/dist/skills/skill-enhancements.d.ts +37 -0
- package/dist/skills/skill-enhancements.js +69 -0
- package/dist/skills/skill-enhancements.js.map +1 -0
- package/dist/telemetry/otel-tracer.d.ts +98 -0
- package/dist/telemetry/otel-tracer.js +245 -0
- package/dist/telemetry/otel-tracer.js.map +1 -0
- package/dist/tools/browser-stub.d.ts +61 -0
- package/dist/tools/browser-stub.js +184 -0
- package/dist/tools/browser-stub.js.map +1 -0
- package/dist/tools/gateway-tool.d.ts +43 -0
- package/dist/tools/gateway-tool.js +92 -0
- package/dist/tools/gateway-tool.js.map +1 -0
- package/dist/tools/image-stub.d.ts +32 -0
- package/dist/tools/image-stub.js +97 -0
- package/dist/tools/image-stub.js.map +1 -0
- package/dist/tools/js-repl.d.ts +78 -0
- package/dist/tools/js-repl.js +280 -0
- package/dist/tools/js-repl.js.map +1 -0
- package/dist/tools/message-tool.d.ts +42 -0
- package/dist/tools/message-tool.js +113 -0
- package/dist/tools/message-tool.js.map +1 -0
- package/dist/ui/cli-enhancements.d.ts +178 -0
- package/dist/ui/cli-enhancements.js +430 -0
- package/dist/ui/cli-enhancements.js.map +1 -0
- package/dist/ui/status-line.d.ts +90 -0
- package/dist/ui/status-line.js +160 -0
- package/dist/ui/status-line.js.map +1 -0
- package/dist/ui/terminal-enhancements.d.ts +34 -0
- package/dist/ui/terminal-enhancements.js +97 -0
- package/dist/ui/terminal-enhancements.js.map +1 -0
- package/dist/ui/ui-enhancements.d.ts +38 -0
- package/dist/ui/ui-enhancements.js +116 -0
- package/dist/ui/ui-enhancements.js.map +1 -0
- package/dist/utils/custom-instructions.js +4 -1
- package/dist/utils/custom-instructions.js.map +1 -1
- package/dist/utils/init-project.d.ts +1 -1
- package/dist/utils/init-project.js +20 -20
- package/dist/utils/init-project.js.map +1 -1
- package/dist/utils/output-schema-validator.d.ts +40 -0
- package/dist/utils/output-schema-validator.js +137 -0
- package/dist/utils/output-schema-validator.js.map +1 -0
- package/dist/utils/safety-misc.d.ts +24 -0
- package/dist/utils/safety-misc.js +91 -0
- package/dist/utils/safety-misc.js.map +1 -0
- package/dist/utils/session-enhancements.d.ts +40 -0
- package/dist/utils/session-enhancements.js +118 -0
- package/dist/utils/session-enhancements.js.map +1 -0
- package/dist/utils/shell-snapshot.d.ts +38 -0
- package/dist/utils/shell-snapshot.js +323 -0
- package/dist/utils/shell-snapshot.js.map +1 -0
- package/dist/utils/stream-json-formatter.d.ts +77 -0
- package/dist/utils/stream-json-formatter.js +61 -0
- package/dist/utils/stream-json-formatter.js.map +1 -0
- package/dist/workflows/lobster-engine.d.ts +43 -0
- package/dist/workflows/lobster-engine.js +167 -0
- package/dist/workflows/lobster-engine.js.map +1 -0
- package/package.json +3 -6
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Environment Snapshots
|
|
3
|
+
*
|
|
4
|
+
* Captures the user's shell environment for better context awareness.
|
|
5
|
+
* Includes shell type, env vars (filtered for safety), aliases, rc files,
|
|
6
|
+
* and common tool versions.
|
|
7
|
+
*
|
|
8
|
+
* Can be injected into the system prompt to help the agent understand
|
|
9
|
+
* the user's development environment.
|
|
10
|
+
*/
|
|
11
|
+
export interface ShellSnapshot {
|
|
12
|
+
/** Detected shell (bash, zsh, fish, sh) */
|
|
13
|
+
shell: string;
|
|
14
|
+
/** Filtered environment variables (safe ones only) */
|
|
15
|
+
env: Record<string, string>;
|
|
16
|
+
/** Parsed aliases from rc files */
|
|
17
|
+
aliases: string[];
|
|
18
|
+
/** Shell function names */
|
|
19
|
+
functions: string[];
|
|
20
|
+
/** Which rc files exist */
|
|
21
|
+
rcFiles: string[];
|
|
22
|
+
/** Node.js version */
|
|
23
|
+
nodeVersion?: string;
|
|
24
|
+
/** npm version */
|
|
25
|
+
npmVersion?: string;
|
|
26
|
+
/** Git version */
|
|
27
|
+
gitVersion?: string;
|
|
28
|
+
/** Python version */
|
|
29
|
+
pythonVersion?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Capture a snapshot of the current shell environment.
|
|
33
|
+
*/
|
|
34
|
+
export declare function captureShellSnapshot(): Promise<ShellSnapshot>;
|
|
35
|
+
/**
|
|
36
|
+
* Format a shell snapshot as a concise prompt string for system prompt injection.
|
|
37
|
+
*/
|
|
38
|
+
export declare function formatSnapshotForPrompt(snapshot: ShellSnapshot): string;
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Environment Snapshots
|
|
3
|
+
*
|
|
4
|
+
* Captures the user's shell environment for better context awareness.
|
|
5
|
+
* Includes shell type, env vars (filtered for safety), aliases, rc files,
|
|
6
|
+
* and common tool versions.
|
|
7
|
+
*
|
|
8
|
+
* Can be injected into the system prompt to help the agent understand
|
|
9
|
+
* the user's development environment.
|
|
10
|
+
*/
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import { execSync } from 'child_process';
|
|
14
|
+
import os from 'os';
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Constants
|
|
17
|
+
// ============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* Environment variables that are safe and useful to include.
|
|
20
|
+
* Explicitly listed to avoid leaking secrets.
|
|
21
|
+
*/
|
|
22
|
+
const SAFE_ENV_VARS = new Set([
|
|
23
|
+
'SHELL',
|
|
24
|
+
'HOME',
|
|
25
|
+
'USER',
|
|
26
|
+
'LOGNAME',
|
|
27
|
+
'PATH',
|
|
28
|
+
'EDITOR',
|
|
29
|
+
'VISUAL',
|
|
30
|
+
'TERM',
|
|
31
|
+
'LANG',
|
|
32
|
+
'LC_ALL',
|
|
33
|
+
'COLORTERM',
|
|
34
|
+
'TERM_PROGRAM',
|
|
35
|
+
'PWD',
|
|
36
|
+
'OLDPWD',
|
|
37
|
+
'HOSTNAME',
|
|
38
|
+
'XDG_CONFIG_HOME',
|
|
39
|
+
'XDG_DATA_HOME',
|
|
40
|
+
'XDG_CACHE_HOME',
|
|
41
|
+
'XDG_RUNTIME_DIR',
|
|
42
|
+
'NODE_ENV',
|
|
43
|
+
'NPM_CONFIG_PREFIX',
|
|
44
|
+
'GOPATH',
|
|
45
|
+
'GOROOT',
|
|
46
|
+
'CARGO_HOME',
|
|
47
|
+
'RUSTUP_HOME',
|
|
48
|
+
'JAVA_HOME',
|
|
49
|
+
'VIRTUAL_ENV',
|
|
50
|
+
'CONDA_DEFAULT_ENV',
|
|
51
|
+
'PYENV_ROOT',
|
|
52
|
+
'NVM_DIR',
|
|
53
|
+
'FNM_DIR',
|
|
54
|
+
'VOLTA_HOME',
|
|
55
|
+
'PNPM_HOME',
|
|
56
|
+
'BUN_INSTALL',
|
|
57
|
+
'DOCKER_HOST',
|
|
58
|
+
'KUBECONFIG',
|
|
59
|
+
'WSL_DISTRO_NAME',
|
|
60
|
+
'DISPLAY',
|
|
61
|
+
'WAYLAND_DISPLAY',
|
|
62
|
+
'SSH_AUTH_SOCK',
|
|
63
|
+
]);
|
|
64
|
+
/**
|
|
65
|
+
* Patterns that indicate a secret - never include these.
|
|
66
|
+
*/
|
|
67
|
+
const SECRET_PATTERNS = [
|
|
68
|
+
/api[_-]?key/i,
|
|
69
|
+
/secret/i,
|
|
70
|
+
/token/i,
|
|
71
|
+
/password/i,
|
|
72
|
+
/credential/i,
|
|
73
|
+
/private[_-]?key/i,
|
|
74
|
+
/auth/i,
|
|
75
|
+
/access[_-]?key/i,
|
|
76
|
+
];
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// Helpers
|
|
79
|
+
// ============================================================================
|
|
80
|
+
function execSafe(command, timeoutMs = 3000) {
|
|
81
|
+
try {
|
|
82
|
+
return execSync(command, {
|
|
83
|
+
encoding: 'utf-8',
|
|
84
|
+
timeout: timeoutMs,
|
|
85
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
86
|
+
}).trim();
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function fileExists(filePath) {
|
|
93
|
+
try {
|
|
94
|
+
return fs.existsSync(filePath);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function readFileSafe(filePath) {
|
|
101
|
+
try {
|
|
102
|
+
if (!fileExists(filePath)) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const stat = fs.statSync(filePath);
|
|
106
|
+
// Skip files larger than 100KB to avoid loading huge rc files
|
|
107
|
+
if (stat.size > 100 * 1024) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function isSafeEnvVar(key) {
|
|
117
|
+
if (SAFE_ENV_VARS.has(key)) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
// Reject anything matching secret patterns
|
|
121
|
+
for (const pattern of SECRET_PATTERNS) {
|
|
122
|
+
if (pattern.test(key)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
// ============================================================================
|
|
129
|
+
// Alias Parsing
|
|
130
|
+
// ============================================================================
|
|
131
|
+
function parseAliasesFromContent(content) {
|
|
132
|
+
const aliases = [];
|
|
133
|
+
const aliasRegex = /^\s*alias\s+([^\s=]+)=['"]?([^'"]*?)['"]?\s*$/gm;
|
|
134
|
+
let match;
|
|
135
|
+
while ((match = aliasRegex.exec(content)) !== null) {
|
|
136
|
+
aliases.push(`${match[1]}=${match[2]}`);
|
|
137
|
+
}
|
|
138
|
+
return aliases;
|
|
139
|
+
}
|
|
140
|
+
function parseFunctionsFromContent(content) {
|
|
141
|
+
const functions = [];
|
|
142
|
+
// Match bash/zsh function declarations
|
|
143
|
+
const funcRegex = /^\s*(?:function\s+)?(\w+)\s*\(\)\s*\{/gm;
|
|
144
|
+
let match;
|
|
145
|
+
while ((match = funcRegex.exec(content)) !== null) {
|
|
146
|
+
functions.push(match[1]);
|
|
147
|
+
}
|
|
148
|
+
return functions;
|
|
149
|
+
}
|
|
150
|
+
function parseFishAliases(content) {
|
|
151
|
+
const aliases = [];
|
|
152
|
+
// Fish uses: abbr -a name command or alias name command
|
|
153
|
+
const abbrRegex = /^\s*abbr\s+(?:-a\s+)?(\S+)\s+(.+)$/gm;
|
|
154
|
+
let match;
|
|
155
|
+
while ((match = abbrRegex.exec(content)) !== null) {
|
|
156
|
+
aliases.push(`${match[1]}=${match[2]}`);
|
|
157
|
+
}
|
|
158
|
+
const aliasRegex = /^\s*alias\s+(\S+)\s+['"]?(.+?)['"]?\s*$/gm;
|
|
159
|
+
while ((match = aliasRegex.exec(content)) !== null) {
|
|
160
|
+
aliases.push(`${match[1]}=${match[2]}`);
|
|
161
|
+
}
|
|
162
|
+
return aliases;
|
|
163
|
+
}
|
|
164
|
+
function parseFishFunctions(content) {
|
|
165
|
+
const functions = [];
|
|
166
|
+
const funcRegex = /^\s*function\s+(\w+)/gm;
|
|
167
|
+
let match;
|
|
168
|
+
while ((match = funcRegex.exec(content)) !== null) {
|
|
169
|
+
functions.push(match[1]);
|
|
170
|
+
}
|
|
171
|
+
return functions;
|
|
172
|
+
}
|
|
173
|
+
// ============================================================================
|
|
174
|
+
// Core Implementation
|
|
175
|
+
// ============================================================================
|
|
176
|
+
/**
|
|
177
|
+
* Capture a snapshot of the current shell environment.
|
|
178
|
+
*/
|
|
179
|
+
export async function captureShellSnapshot() {
|
|
180
|
+
const home = os.homedir();
|
|
181
|
+
const shell = detectShell();
|
|
182
|
+
const env = captureFilteredEnv();
|
|
183
|
+
const rcFiles = detectRcFiles(home, shell);
|
|
184
|
+
// Parse aliases and functions from rc files
|
|
185
|
+
let aliases = [];
|
|
186
|
+
let functions = [];
|
|
187
|
+
for (const rcFile of rcFiles) {
|
|
188
|
+
const content = readFileSafe(rcFile);
|
|
189
|
+
if (!content)
|
|
190
|
+
continue;
|
|
191
|
+
if (shell === 'fish') {
|
|
192
|
+
aliases.push(...parseFishAliases(content));
|
|
193
|
+
functions.push(...parseFishFunctions(content));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
aliases.push(...parseAliasesFromContent(content));
|
|
197
|
+
functions.push(...parseFunctionsFromContent(content));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// Deduplicate
|
|
201
|
+
aliases = [...new Set(aliases)];
|
|
202
|
+
functions = [...new Set(functions)];
|
|
203
|
+
// Tool versions
|
|
204
|
+
const nodeVersion = execSafe('node --version');
|
|
205
|
+
const npmVersion = execSafe('npm --version');
|
|
206
|
+
const gitVersion = execSafe('git --version')?.replace('git version ', '');
|
|
207
|
+
const pythonVersion = execSafe('python3 --version')?.replace('Python ', '')
|
|
208
|
+
?? execSafe('python --version')?.replace('Python ', '');
|
|
209
|
+
return {
|
|
210
|
+
shell,
|
|
211
|
+
env,
|
|
212
|
+
aliases,
|
|
213
|
+
functions,
|
|
214
|
+
rcFiles,
|
|
215
|
+
nodeVersion,
|
|
216
|
+
npmVersion,
|
|
217
|
+
gitVersion,
|
|
218
|
+
pythonVersion,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Detect the current shell.
|
|
223
|
+
*/
|
|
224
|
+
function detectShell() {
|
|
225
|
+
const shellEnv = process.env['SHELL'] || '';
|
|
226
|
+
const shellName = path.basename(shellEnv);
|
|
227
|
+
if (['bash', 'zsh', 'fish', 'sh', 'dash', 'ksh', 'tcsh', 'csh'].includes(shellName)) {
|
|
228
|
+
return shellName;
|
|
229
|
+
}
|
|
230
|
+
// Fallback: try to detect from parent process
|
|
231
|
+
const parentShell = execSafe('ps -p $PPID -o comm=');
|
|
232
|
+
if (parentShell) {
|
|
233
|
+
const name = path.basename(parentShell);
|
|
234
|
+
if (['bash', 'zsh', 'fish'].includes(name)) {
|
|
235
|
+
return name;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return shellName || 'sh';
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Capture filtered environment variables (exclude secrets).
|
|
242
|
+
*/
|
|
243
|
+
function captureFilteredEnv() {
|
|
244
|
+
const filtered = {};
|
|
245
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
246
|
+
if (value && isSafeEnvVar(key)) {
|
|
247
|
+
// Truncate very long values (e.g., PATH)
|
|
248
|
+
filtered[key] = value.length > 500 ? value.substring(0, 500) + '...' : value;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return filtered;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Detect which rc/config files exist for the user's shell.
|
|
255
|
+
*/
|
|
256
|
+
function detectRcFiles(home, shell) {
|
|
257
|
+
const candidates = [];
|
|
258
|
+
// Common rc files
|
|
259
|
+
const possibleFiles = [
|
|
260
|
+
'.profile',
|
|
261
|
+
'.bashrc',
|
|
262
|
+
'.bash_profile',
|
|
263
|
+
'.bash_aliases',
|
|
264
|
+
'.zshrc',
|
|
265
|
+
'.zprofile',
|
|
266
|
+
'.zshenv',
|
|
267
|
+
'.config/fish/config.fish',
|
|
268
|
+
'.config/fish/fish_variables',
|
|
269
|
+
];
|
|
270
|
+
for (const file of possibleFiles) {
|
|
271
|
+
const fullPath = path.join(home, file);
|
|
272
|
+
if (fileExists(fullPath)) {
|
|
273
|
+
candidates.push(fullPath);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return candidates;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Format a shell snapshot as a concise prompt string for system prompt injection.
|
|
280
|
+
*/
|
|
281
|
+
export function formatSnapshotForPrompt(snapshot) {
|
|
282
|
+
const lines = [];
|
|
283
|
+
lines.push(`## Shell Environment`);
|
|
284
|
+
lines.push(`- Shell: ${snapshot.shell}`);
|
|
285
|
+
if (snapshot.nodeVersion) {
|
|
286
|
+
lines.push(`- Node: ${snapshot.nodeVersion}`);
|
|
287
|
+
}
|
|
288
|
+
if (snapshot.npmVersion) {
|
|
289
|
+
lines.push(`- npm: ${snapshot.npmVersion}`);
|
|
290
|
+
}
|
|
291
|
+
if (snapshot.gitVersion) {
|
|
292
|
+
lines.push(`- Git: ${snapshot.gitVersion}`);
|
|
293
|
+
}
|
|
294
|
+
if (snapshot.pythonVersion) {
|
|
295
|
+
lines.push(`- Python: ${snapshot.pythonVersion}`);
|
|
296
|
+
}
|
|
297
|
+
// Key env vars
|
|
298
|
+
const editor = snapshot.env['EDITOR'] || snapshot.env['VISUAL'];
|
|
299
|
+
if (editor) {
|
|
300
|
+
lines.push(`- Editor: ${editor}`);
|
|
301
|
+
}
|
|
302
|
+
const term = snapshot.env['TERM_PROGRAM'] || snapshot.env['TERM'];
|
|
303
|
+
if (term) {
|
|
304
|
+
lines.push(`- Terminal: ${term}`);
|
|
305
|
+
}
|
|
306
|
+
const wsl = snapshot.env['WSL_DISTRO_NAME'];
|
|
307
|
+
if (wsl) {
|
|
308
|
+
lines.push(`- WSL: ${wsl}`);
|
|
309
|
+
}
|
|
310
|
+
const virtualEnv = snapshot.env['VIRTUAL_ENV'] || snapshot.env['CONDA_DEFAULT_ENV'];
|
|
311
|
+
if (virtualEnv) {
|
|
312
|
+
lines.push(`- Virtual env: ${virtualEnv}`);
|
|
313
|
+
}
|
|
314
|
+
// Aliases (show count, not full list to save tokens)
|
|
315
|
+
if (snapshot.aliases.length > 0) {
|
|
316
|
+
lines.push(`- Shell aliases: ${snapshot.aliases.length} defined`);
|
|
317
|
+
}
|
|
318
|
+
if (snapshot.functions.length > 0) {
|
|
319
|
+
lines.push(`- Shell functions: ${snapshot.functions.length} defined`);
|
|
320
|
+
}
|
|
321
|
+
return lines.join('\n');
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=shell-snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-snapshot.js","sourceRoot":"","sources":["../../src/utils/shell-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,IAAI,CAAC;AA4BpB,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,OAAO;IACP,MAAM;IACN,MAAM;IACN,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,MAAM;IACN,QAAQ;IACR,WAAW;IACX,cAAc;IACd,KAAK;IACL,QAAQ;IACR,UAAU;IACV,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,iBAAiB;IACjB,UAAU;IACV,mBAAmB;IACnB,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,aAAa;IACb,WAAW;IACX,aAAa;IACb,mBAAmB;IACnB,YAAY;IACZ,SAAS;IACT,SAAS;IACT,YAAY;IACZ,WAAW;IACX,aAAa;IACb,aAAa;IACb,YAAY;IACZ,iBAAiB;IACjB,SAAS;IACT,iBAAiB;IACjB,eAAe;CAChB,CA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,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream JSON Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats streaming output as newline-delimited JSON (NDJSON).
|
|
5
|
+
* Each event is a JSON object on its own line, suitable for
|
|
6
|
+
* machine-readable streaming output via --output-format stream-json.
|
|
7
|
+
*/
|
|
8
|
+
export interface StartEvent {
|
|
9
|
+
type: 'start';
|
|
10
|
+
session_id: string;
|
|
11
|
+
model: string;
|
|
12
|
+
}
|
|
13
|
+
export interface TextEvent {
|
|
14
|
+
type: 'text';
|
|
15
|
+
content: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ToolUseEvent {
|
|
18
|
+
type: 'tool_use';
|
|
19
|
+
tool: string;
|
|
20
|
+
input: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface ToolResultEvent {
|
|
23
|
+
type: 'tool_result';
|
|
24
|
+
tool: string;
|
|
25
|
+
output: string;
|
|
26
|
+
success: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface ThinkingEvent {
|
|
29
|
+
type: 'thinking';
|
|
30
|
+
content: string;
|
|
31
|
+
}
|
|
32
|
+
export interface DoneEvent {
|
|
33
|
+
type: 'done';
|
|
34
|
+
cost: number;
|
|
35
|
+
tokens: {
|
|
36
|
+
input: number;
|
|
37
|
+
output: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export type StreamEvent = StartEvent | TextEvent | ToolUseEvent | ToolResultEvent | ThinkingEvent | DoneEvent;
|
|
41
|
+
export declare class StreamJsonFormatter {
|
|
42
|
+
/**
|
|
43
|
+
* Format a single event as an NDJSON line (JSON + newline).
|
|
44
|
+
*/
|
|
45
|
+
formatEvent(event: StreamEvent): string;
|
|
46
|
+
/**
|
|
47
|
+
* Format multiple events as NDJSON.
|
|
48
|
+
*/
|
|
49
|
+
formatEvents(events: StreamEvent[]): string;
|
|
50
|
+
/**
|
|
51
|
+
* Create a start event.
|
|
52
|
+
*/
|
|
53
|
+
start(sessionId: string, model: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Create a text event.
|
|
56
|
+
*/
|
|
57
|
+
text(content: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Create a tool_use event.
|
|
60
|
+
*/
|
|
61
|
+
toolUse(tool: string, input: Record<string, unknown>): string;
|
|
62
|
+
/**
|
|
63
|
+
* Create a tool_result event.
|
|
64
|
+
*/
|
|
65
|
+
toolResult(tool: string, output: string, success: boolean): string;
|
|
66
|
+
/**
|
|
67
|
+
* Create a thinking event.
|
|
68
|
+
*/
|
|
69
|
+
thinking(content: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Create a done event.
|
|
72
|
+
*/
|
|
73
|
+
done(cost: number, tokens: {
|
|
74
|
+
input: number;
|
|
75
|
+
output: number;
|
|
76
|
+
}): string;
|
|
77
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream JSON Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats streaming output as newline-delimited JSON (NDJSON).
|
|
5
|
+
* Each event is a JSON object on its own line, suitable for
|
|
6
|
+
* machine-readable streaming output via --output-format stream-json.
|
|
7
|
+
*/
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Formatter
|
|
10
|
+
// ============================================================================
|
|
11
|
+
export class StreamJsonFormatter {
|
|
12
|
+
/**
|
|
13
|
+
* Format a single event as an NDJSON line (JSON + newline).
|
|
14
|
+
*/
|
|
15
|
+
formatEvent(event) {
|
|
16
|
+
return JSON.stringify(event) + '\n';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Format multiple events as NDJSON.
|
|
20
|
+
*/
|
|
21
|
+
formatEvents(events) {
|
|
22
|
+
return events.map(e => this.formatEvent(e)).join('');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a start event.
|
|
26
|
+
*/
|
|
27
|
+
start(sessionId, model) {
|
|
28
|
+
return this.formatEvent({ type: 'start', session_id: sessionId, model });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a text event.
|
|
32
|
+
*/
|
|
33
|
+
text(content) {
|
|
34
|
+
return this.formatEvent({ type: 'text', content });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a tool_use event.
|
|
38
|
+
*/
|
|
39
|
+
toolUse(tool, input) {
|
|
40
|
+
return this.formatEvent({ type: 'tool_use', tool, input });
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a tool_result event.
|
|
44
|
+
*/
|
|
45
|
+
toolResult(tool, output, success) {
|
|
46
|
+
return this.formatEvent({ type: 'tool_result', tool, output, success });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a thinking event.
|
|
50
|
+
*/
|
|
51
|
+
thinking(content) {
|
|
52
|
+
return this.formatEvent({ type: 'thinking', content });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a done event.
|
|
56
|
+
*/
|
|
57
|
+
done(cost, tokens) {
|
|
58
|
+
return this.formatEvent({ type: 'done', cost, tokens });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=stream-json-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-json-formatter.js","sourceRoot":"","sources":["../../src/utils/stream-json-formatter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAoDH,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,MAAM,OAAO,mBAAmB;IAC9B;;OAEG;IACH,WAAW,CAAC,KAAkB;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,MAAqB;QAChC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAiB,EAAE,KAAa;QACpC,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,OAAe;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,IAAY,EAAE,KAA8B;QAClD,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,IAAY,EAAE,MAAc,EAAE,OAAgB;QACvD,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,OAAe;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,IAAY,EAAE,MAAyC;QAC1D,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lobster Typed Workflow Engine
|
|
3
|
+
* DAG-based workflow definition, validation, and execution ordering.
|
|
4
|
+
*/
|
|
5
|
+
export interface LobsterStep {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
command: string;
|
|
9
|
+
inputs?: Record<string, string>;
|
|
10
|
+
outputs?: string[];
|
|
11
|
+
dependsOn?: string[];
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface LobsterWorkflow {
|
|
15
|
+
name: string;
|
|
16
|
+
version: string;
|
|
17
|
+
steps: LobsterStep[];
|
|
18
|
+
variables?: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
export interface StepResult {
|
|
21
|
+
stepId: string;
|
|
22
|
+
status: 'success' | 'failed' | 'skipped';
|
|
23
|
+
stdout: string;
|
|
24
|
+
exitCode: number;
|
|
25
|
+
duration: number;
|
|
26
|
+
}
|
|
27
|
+
export declare class LobsterEngine {
|
|
28
|
+
private static instance;
|
|
29
|
+
static getInstance(): LobsterEngine;
|
|
30
|
+
static resetInstance(): void;
|
|
31
|
+
parseWorkflow(yaml: string): LobsterWorkflow;
|
|
32
|
+
validateWorkflow(workflow: LobsterWorkflow): {
|
|
33
|
+
valid: boolean;
|
|
34
|
+
errors: string[];
|
|
35
|
+
};
|
|
36
|
+
resolveVariables(template: string, context: Record<string, string>): string;
|
|
37
|
+
getExecutionOrder(workflow: LobsterWorkflow): string[];
|
|
38
|
+
generateResumeToken(completedSteps: string[]): string;
|
|
39
|
+
parseResumeToken(token: string): string[];
|
|
40
|
+
getWorkflowStatus(results: StepResult[]): 'success' | 'failed' | 'partial';
|
|
41
|
+
private hasCycle;
|
|
42
|
+
private parseSimpleYaml;
|
|
43
|
+
}
|