@hybridaione/hybridclaw 0.1.5
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/.env.example +14 -0
- package/.github/workflows/pages.yml +41 -0
- package/AGENTS.md +24 -0
- package/CHANGELOG.md +113 -0
- package/LICENSE +21 -0
- package/README.md +226 -0
- package/SECURITY.md +67 -0
- package/config.example.json +62 -0
- package/container/Dockerfile +23 -0
- package/container/package-lock.json +246 -0
- package/container/package.json +17 -0
- package/container/src/hybridai-client.ts +38 -0
- package/container/src/index.ts +198 -0
- package/container/src/ipc.ts +37 -0
- package/container/src/tools.ts +1008 -0
- package/container/src/types.ts +74 -0
- package/container/src/web-fetch.ts +389 -0
- package/container/tsconfig.json +16 -0
- package/dist/agent.d.ts +3 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +21 -0
- package/dist/agent.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +32 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +107 -0
- package/dist/config.js.map +1 -0
- package/dist/container-runner.d.ts +11 -0
- package/dist/container-runner.d.ts.map +1 -0
- package/dist/container-runner.js +246 -0
- package/dist/container-runner.js.map +1 -0
- package/dist/conversation.d.ts +18 -0
- package/dist/conversation.d.ts.map +1 -0
- package/dist/conversation.js +29 -0
- package/dist/conversation.js.map +1 -0
- package/dist/db.d.ts +29 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +205 -0
- package/dist/db.js.map +1 -0
- package/dist/discord.d.ts +17 -0
- package/dist/discord.d.ts.map +1 -0
- package/dist/discord.js +115 -0
- package/dist/discord.js.map +1 -0
- package/dist/env.d.ts +6 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +36 -0
- package/dist/env.js.map +1 -0
- package/dist/gateway-client.d.ts +8 -0
- package/dist/gateway-client.d.ts.map +1 -0
- package/dist/gateway-client.js +57 -0
- package/dist/gateway-client.js.map +1 -0
- package/dist/gateway-service.d.ts +23 -0
- package/dist/gateway-service.d.ts.map +1 -0
- package/dist/gateway-service.js +360 -0
- package/dist/gateway-service.js.map +1 -0
- package/dist/gateway-types.d.ts +40 -0
- package/dist/gateway-types.d.ts.map +1 -0
- package/dist/gateway-types.js +6 -0
- package/dist/gateway-types.js.map +1 -0
- package/dist/gateway.d.ts +2 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +138 -0
- package/dist/gateway.js.map +1 -0
- package/dist/hatch.d.ts +7 -0
- package/dist/hatch.d.ts.map +1 -0
- package/dist/hatch.js +99 -0
- package/dist/hatch.js.map +1 -0
- package/dist/health.d.ts +2 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +169 -0
- package/dist/health.js.map +1 -0
- package/dist/heartbeat.d.ts +3 -0
- package/dist/heartbeat.d.ts.map +1 -0
- package/dist/heartbeat.js +103 -0
- package/dist/heartbeat.js.map +1 -0
- package/dist/hybridai-bots.d.ts +5 -0
- package/dist/hybridai-bots.d.ts.map +1 -0
- package/dist/hybridai-bots.js +34 -0
- package/dist/hybridai-bots.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc.d.ts +33 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +142 -0
- package/dist/ipc.js.map +1 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +21 -0
- package/dist/logger.js.map +1 -0
- package/dist/mount-security.d.ts +28 -0
- package/dist/mount-security.d.ts.map +1 -0
- package/dist/mount-security.js +187 -0
- package/dist/mount-security.js.map +1 -0
- package/dist/onboarding.d.ts +7 -0
- package/dist/onboarding.d.ts.map +1 -0
- package/dist/onboarding.js +445 -0
- package/dist/onboarding.js.map +1 -0
- package/dist/prompt-hooks.d.ts +17 -0
- package/dist/prompt-hooks.d.ts.map +1 -0
- package/dist/prompt-hooks.js +83 -0
- package/dist/prompt-hooks.js.map +1 -0
- package/dist/runtime-config.d.ts +78 -0
- package/dist/runtime-config.d.ts.map +1 -0
- package/dist/runtime-config.js +471 -0
- package/dist/runtime-config.js.map +1 -0
- package/dist/scheduled-task-runner.d.ts +11 -0
- package/dist/scheduled-task-runner.d.ts.map +1 -0
- package/dist/scheduled-task-runner.js +16 -0
- package/dist/scheduled-task-runner.js.map +1 -0
- package/dist/scheduler.d.ts +11 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +165 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/session-maintenance.d.ts +9 -0
- package/dist/session-maintenance.d.ts.map +1 -0
- package/dist/session-maintenance.js +168 -0
- package/dist/session-maintenance.js.map +1 -0
- package/dist/session-transcripts.d.ts +11 -0
- package/dist/session-transcripts.d.ts.map +1 -0
- package/dist/session-transcripts.js +32 -0
- package/dist/session-transcripts.js.map +1 -0
- package/dist/side-effects.d.ts +3 -0
- package/dist/side-effects.d.ts.map +1 -0
- package/dist/side-effects.js +30 -0
- package/dist/side-effects.js.map +1 -0
- package/dist/skills.d.ts +32 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +376 -0
- package/dist/skills.js.map +1 -0
- package/dist/tui.d.ts +2 -0
- package/dist/tui.d.ts.map +1 -0
- package/dist/tui.js +305 -0
- package/dist/tui.js.map +1 -0
- package/dist/types.d.ts +132 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/workspace.d.ts +25 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +154 -0
- package/dist/workspace.js.map +1 -0
- package/docs/chat.html +929 -0
- package/docs/hai_logo_free.png +0 -0
- package/docs/hero.png +0 -0
- package/docs/index.html +1213 -0
- package/package.json +34 -0
- package/skills/current-time/SKILL.md +26 -0
- package/skills/iss-position/SKILL.md +46 -0
- package/skills/iss-position/agents/openai.yaml +3 -0
- package/skills/iss-position/scripts/get_iss_position.py +107 -0
- package/skills/repo-orientation/SKILL.md +74 -0
- package/src/agent.ts +35 -0
- package/src/cli.ts +35 -0
- package/src/config.ts +137 -0
- package/src/container-runner.ts +305 -0
- package/src/conversation.ts +49 -0
- package/src/db.ts +290 -0
- package/src/discord.ts +156 -0
- package/src/env.ts +36 -0
- package/src/gateway-client.ts +73 -0
- package/src/gateway-service.ts +456 -0
- package/src/gateway-types.ts +47 -0
- package/src/gateway.ts +199 -0
- package/src/health.ts +189 -0
- package/src/heartbeat.ts +121 -0
- package/src/hybridai-bots.ts +48 -0
- package/src/ipc.ts +163 -0
- package/src/logger.ts +26 -0
- package/src/mount-security.ts +216 -0
- package/src/onboarding.ts +569 -0
- package/src/prompt-hooks.ts +113 -0
- package/src/runtime-config.ts +588 -0
- package/src/scheduled-task-runner.ts +26 -0
- package/src/scheduler.ts +196 -0
- package/src/session-maintenance.ts +263 -0
- package/src/session-transcripts.ts +45 -0
- package/src/side-effects.ts +41 -0
- package/src/skills.ts +429 -0
- package/src/tui.ts +327 -0
- package/src/types.ts +135 -0
- package/src/workspace.ts +171 -0
- package/templates/AGENTS.md +104 -0
- package/templates/BOOT.md +3 -0
- package/templates/BOOTSTRAP.md +54 -0
- package/templates/HEARTBEAT.md +5 -0
- package/templates/IDENTITY.md +18 -0
- package/templates/MEMORY.md +19 -0
- package/templates/SOUL.md +36 -0
- package/templates/TOOLS.md +22 -0
- package/templates/USER.md +17 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mount Security — validates additional mounts against an allowlist stored
|
|
3
|
+
* OUTSIDE the project root, preventing container agents from modifying
|
|
4
|
+
* security configuration.
|
|
5
|
+
*
|
|
6
|
+
* Allowlist location: ~/.config/hybridclaw/mount-allowlist.json
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import os from 'os';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
|
|
12
|
+
import { MOUNT_ALLOWLIST_PATH } from './config.js';
|
|
13
|
+
import { logger } from './logger.js';
|
|
14
|
+
import type { AdditionalMount, AllowedRoot, MountAllowlist } from './types.js';
|
|
15
|
+
|
|
16
|
+
// Cache the allowlist in memory — only reloads on process restart
|
|
17
|
+
let cachedAllowlist: MountAllowlist | null = null;
|
|
18
|
+
let allowlistLoadError: string | null = null;
|
|
19
|
+
|
|
20
|
+
const DEFAULT_BLOCKED_PATTERNS = [
|
|
21
|
+
'.ssh',
|
|
22
|
+
'.gnupg',
|
|
23
|
+
'.gpg',
|
|
24
|
+
'.aws',
|
|
25
|
+
'.azure',
|
|
26
|
+
'.gcloud',
|
|
27
|
+
'.kube',
|
|
28
|
+
'.docker',
|
|
29
|
+
'credentials',
|
|
30
|
+
'.env',
|
|
31
|
+
'.netrc',
|
|
32
|
+
'.npmrc',
|
|
33
|
+
'.pypirc',
|
|
34
|
+
'id_rsa',
|
|
35
|
+
'id_ed25519',
|
|
36
|
+
'private_key',
|
|
37
|
+
'.secret',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Load the mount allowlist from the external config location.
|
|
42
|
+
* Returns null if the file doesn't exist or is invalid.
|
|
43
|
+
* Result is cached in memory for the lifetime of the process.
|
|
44
|
+
*/
|
|
45
|
+
export function loadMountAllowlist(): MountAllowlist | null {
|
|
46
|
+
if (cachedAllowlist !== null) return cachedAllowlist;
|
|
47
|
+
if (allowlistLoadError !== null) return null;
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
if (!fs.existsSync(MOUNT_ALLOWLIST_PATH)) {
|
|
51
|
+
allowlistLoadError = `Mount allowlist not found at ${MOUNT_ALLOWLIST_PATH}`;
|
|
52
|
+
logger.warn(
|
|
53
|
+
{ path: MOUNT_ALLOWLIST_PATH },
|
|
54
|
+
'Mount allowlist not found — additional mounts will be BLOCKED. Create the file to enable additional mounts.',
|
|
55
|
+
);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const content = fs.readFileSync(MOUNT_ALLOWLIST_PATH, 'utf-8');
|
|
60
|
+
const allowlist = JSON.parse(content) as MountAllowlist;
|
|
61
|
+
|
|
62
|
+
if (!Array.isArray(allowlist.allowedRoots)) {
|
|
63
|
+
throw new Error('allowedRoots must be an array');
|
|
64
|
+
}
|
|
65
|
+
if (!Array.isArray(allowlist.blockedPatterns)) {
|
|
66
|
+
throw new Error('blockedPatterns must be an array');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Merge with default blocked patterns
|
|
70
|
+
allowlist.blockedPatterns = [
|
|
71
|
+
...new Set([...DEFAULT_BLOCKED_PATTERNS, ...allowlist.blockedPatterns]),
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
cachedAllowlist = allowlist;
|
|
75
|
+
logger.info(
|
|
76
|
+
{ path: MOUNT_ALLOWLIST_PATH, allowedRoots: allowlist.allowedRoots.length, blockedPatterns: allowlist.blockedPatterns.length },
|
|
77
|
+
'Mount allowlist loaded',
|
|
78
|
+
);
|
|
79
|
+
return cachedAllowlist;
|
|
80
|
+
} catch (err) {
|
|
81
|
+
allowlistLoadError = err instanceof Error ? err.message : String(err);
|
|
82
|
+
logger.error(
|
|
83
|
+
{ path: MOUNT_ALLOWLIST_PATH, error: allowlistLoadError },
|
|
84
|
+
'Failed to load mount allowlist — additional mounts will be BLOCKED',
|
|
85
|
+
);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function expandPath(p: string): string {
|
|
91
|
+
const homeDir = process.env.HOME || os.homedir();
|
|
92
|
+
if (p.startsWith('~/')) return path.join(homeDir, p.slice(2));
|
|
93
|
+
if (p === '~') return homeDir;
|
|
94
|
+
return path.resolve(p);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getRealPath(p: string): string | null {
|
|
98
|
+
try {
|
|
99
|
+
return fs.realpathSync(p);
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function matchesBlockedPattern(realPath: string, blockedPatterns: string[]): string | null {
|
|
106
|
+
const pathParts = realPath.split(path.sep);
|
|
107
|
+
for (const pattern of blockedPatterns) {
|
|
108
|
+
for (const part of pathParts) {
|
|
109
|
+
if (part === pattern || part.includes(pattern)) return pattern;
|
|
110
|
+
}
|
|
111
|
+
if (realPath.includes(pattern)) return pattern;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function findAllowedRoot(realPath: string, allowedRoots: AllowedRoot[]): AllowedRoot | null {
|
|
117
|
+
for (const root of allowedRoots) {
|
|
118
|
+
const realRoot = getRealPath(expandPath(root.path));
|
|
119
|
+
if (realRoot === null) continue;
|
|
120
|
+
const relative = path.relative(realRoot, realPath);
|
|
121
|
+
if (!relative.startsWith('..') && !path.isAbsolute(relative)) return root;
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function isValidContainerPath(containerPath: string): boolean {
|
|
127
|
+
if (containerPath.includes('..')) return false;
|
|
128
|
+
if (containerPath.startsWith('/')) return false;
|
|
129
|
+
if (!containerPath || containerPath.trim() === '') return false;
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface MountValidationResult {
|
|
134
|
+
allowed: boolean;
|
|
135
|
+
reason: string;
|
|
136
|
+
realHostPath?: string;
|
|
137
|
+
resolvedContainerPath?: string;
|
|
138
|
+
effectiveReadonly?: boolean;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Validate a single additional mount against the allowlist.
|
|
143
|
+
*/
|
|
144
|
+
export function validateMount(mount: AdditionalMount): MountValidationResult {
|
|
145
|
+
const allowlist = loadMountAllowlist();
|
|
146
|
+
if (allowlist === null) {
|
|
147
|
+
return { allowed: false, reason: `No mount allowlist configured at ${MOUNT_ALLOWLIST_PATH}` };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const containerPath = mount.containerPath || path.basename(mount.hostPath);
|
|
151
|
+
if (!isValidContainerPath(containerPath)) {
|
|
152
|
+
return { allowed: false, reason: `Invalid container path: "${containerPath}" — must be relative, non-empty, and not contain ".."` };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const expandedPath = expandPath(mount.hostPath);
|
|
156
|
+
const realPath = getRealPath(expandedPath);
|
|
157
|
+
if (realPath === null) {
|
|
158
|
+
return { allowed: false, reason: `Host path does not exist: "${mount.hostPath}" (expanded: "${expandedPath}")` };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const blockedMatch = matchesBlockedPattern(realPath, allowlist.blockedPatterns);
|
|
162
|
+
if (blockedMatch !== null) {
|
|
163
|
+
return { allowed: false, reason: `Path matches blocked pattern "${blockedMatch}": "${realPath}"` };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const allowedRoot = findAllowedRoot(realPath, allowlist.allowedRoots);
|
|
167
|
+
if (allowedRoot === null) {
|
|
168
|
+
return {
|
|
169
|
+
allowed: false,
|
|
170
|
+
reason: `Path "${realPath}" is not under any allowed root. Allowed roots: ${allowlist.allowedRoots.map((r) => expandPath(r.path)).join(', ')}`,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Determine effective readonly status
|
|
175
|
+
let effectiveReadonly = true;
|
|
176
|
+
if (mount.readonly === false && allowedRoot.allowReadWrite) {
|
|
177
|
+
effectiveReadonly = false;
|
|
178
|
+
} else if (mount.readonly === false && !allowedRoot.allowReadWrite) {
|
|
179
|
+
logger.info({ mount: mount.hostPath, root: allowedRoot.path }, 'Mount forced to read-only — root does not allow read-write');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
allowed: true,
|
|
184
|
+
reason: `Allowed under root "${allowedRoot.path}"${allowedRoot.description ? ` (${allowedRoot.description})` : ''}`,
|
|
185
|
+
realHostPath: realPath,
|
|
186
|
+
resolvedContainerPath: containerPath,
|
|
187
|
+
effectiveReadonly,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Validate all additional mounts.
|
|
193
|
+
* Returns only mounts that passed validation; logs warnings for rejected ones.
|
|
194
|
+
*/
|
|
195
|
+
export function validateAdditionalMounts(
|
|
196
|
+
mounts: AdditionalMount[],
|
|
197
|
+
): Array<{ hostPath: string; containerPath: string; readonly: boolean }> {
|
|
198
|
+
const validated: Array<{ hostPath: string; containerPath: string; readonly: boolean }> = [];
|
|
199
|
+
|
|
200
|
+
for (const mount of mounts) {
|
|
201
|
+
const result = validateMount(mount);
|
|
202
|
+
if (result.allowed) {
|
|
203
|
+
validated.push({
|
|
204
|
+
hostPath: result.realHostPath!,
|
|
205
|
+
containerPath: `/workspace/extra/${result.resolvedContainerPath}`,
|
|
206
|
+
readonly: result.effectiveReadonly!,
|
|
207
|
+
});
|
|
208
|
+
logger.debug({ hostPath: result.realHostPath, containerPath: result.resolvedContainerPath, readonly: result.effectiveReadonly }, 'Mount validated');
|
|
209
|
+
} else {
|
|
210
|
+
logger.warn({ requestedPath: mount.hostPath, containerPath: mount.containerPath, reason: result.reason }, 'Additional mount REJECTED');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return validated;
|
|
215
|
+
}
|
|
216
|
+
|