@bbigbang/agent-node 0.1.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.
Files changed (47) hide show
  1. package/dist/agentHost.js +483 -0
  2. package/dist/appVersion.js +14 -0
  3. package/dist/assetCachePaths.js +35 -0
  4. package/dist/attachmentInput.js +588 -0
  5. package/dist/attachmentMaterializer.js +230 -0
  6. package/dist/bigbangCli.js +17 -0
  7. package/dist/bigbangMessageSendDetection.js +284 -0
  8. package/dist/builtinSkillRoots.js +54 -0
  9. package/dist/claudeConfig.js +32 -0
  10. package/dist/claudeDirectRuntime.js +1960 -0
  11. package/dist/claudeSessionControls.js +78 -0
  12. package/dist/claudeTranscriptFs.js +147 -0
  13. package/dist/codexAppServerClient.js +188 -0
  14. package/dist/codexAppServerEnv.js +14 -0
  15. package/dist/codexAppServerRpc.js +273 -0
  16. package/dist/codexAppServerRuntime.js +3495 -0
  17. package/dist/codexBuiltinPrompt.js +117 -0
  18. package/dist/codexConversationSummarizer.js +76 -0
  19. package/dist/codexTranscriptFs.js +145 -0
  20. package/dist/config.js +129 -0
  21. package/dist/connection.js +151 -0
  22. package/dist/dispatchQueueStore.js +39 -0
  23. package/dist/dreamEnv.js +1 -0
  24. package/dist/dreamMemoryFallback.js +118 -0
  25. package/dist/dreamToolPolicy.js +293 -0
  26. package/dist/droidMissionRunner.js +808 -0
  27. package/dist/executor.js +1078 -0
  28. package/dist/hostRuntime.js +1 -0
  29. package/dist/libraryAuthorityFs.js +74 -0
  30. package/dist/libraryMirror.js +183 -0
  31. package/dist/main.js +1659 -0
  32. package/dist/native-worker/native-worker.mjs +475 -0
  33. package/dist/nativeMissionAgentDispatch.js +463 -0
  34. package/dist/nativeMissionRunner.js +461 -0
  35. package/dist/nativeSkillMounts.js +204 -0
  36. package/dist/nativeWorkerHost.js +142 -0
  37. package/dist/nodeSink.js +142 -0
  38. package/dist/panelHttpFetch.js +334 -0
  39. package/dist/runtimeDrivers.js +62 -0
  40. package/dist/skillFs.js +229 -0
  41. package/dist/soloHost.js +165 -0
  42. package/dist/soloNodeSink.js +138 -0
  43. package/dist/terminalManager.js +254 -0
  44. package/dist/workspaceFs.js +1020 -0
  45. package/dist/workspaceGit.js +694 -0
  46. package/dist/workspaceInspect.js +22 -0
  47. package/package.json +49 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ function normalizeLibraryRelativePath(rawPath) {
4
+ const trimmed = rawPath.trim().replace(/\\/g, '/');
5
+ const normalized = path.posix.normalize(trimmed).replace(/^\/+/, '').replace(/\/+$/, '');
6
+ if (!normalized
7
+ || normalized === '.'
8
+ || normalized === '..'
9
+ || normalized.startsWith('../')
10
+ || normalized.includes('/../')) {
11
+ throw new Error('Invalid library path');
12
+ }
13
+ return normalized;
14
+ }
15
+ export function deleteLibraryAuthorityPath(libraryRootPath, relativePath, options) {
16
+ const normalizedPath = normalizeLibraryRelativePath(relativePath);
17
+ const libraryRoot = path.resolve(libraryRootPath);
18
+ const absolutePath = path.resolve(libraryRoot, normalizedPath);
19
+ if (absolutePath !== libraryRoot && !absolutePath.startsWith(`${libraryRoot}${path.sep}`)) {
20
+ throw new Error('Invalid library path');
21
+ }
22
+ const stat = fs.lstatSync(absolutePath, { throwIfNoEntry: false });
23
+ if (!stat)
24
+ return;
25
+ if (stat.isDirectory()) {
26
+ if (!options?.recursive) {
27
+ throw new Error('Directory deletion requires recursive=true');
28
+ }
29
+ fs.rmSync(absolutePath, { recursive: true, force: true });
30
+ }
31
+ else {
32
+ fs.rmSync(absolutePath, { force: true });
33
+ }
34
+ let cursor = path.dirname(absolutePath);
35
+ while (cursor.startsWith(libraryRoot) && cursor !== libraryRoot) {
36
+ const remaining = fs.readdirSync(cursor);
37
+ if (remaining.length > 0)
38
+ break;
39
+ fs.rmdirSync(cursor);
40
+ cursor = path.dirname(cursor);
41
+ }
42
+ }
43
+ export function renameLibraryAuthorityPath(libraryRootPath, relativePath, nextRelativePath) {
44
+ const normalizedPath = normalizeLibraryRelativePath(relativePath);
45
+ const normalizedNextPath = normalizeLibraryRelativePath(nextRelativePath);
46
+ const libraryRoot = path.resolve(libraryRootPath);
47
+ const absolutePath = path.resolve(libraryRoot, normalizedPath);
48
+ const absoluteNextPath = path.resolve(libraryRoot, normalizedNextPath);
49
+ if ((absolutePath !== libraryRoot && !absolutePath.startsWith(`${libraryRoot}${path.sep}`))
50
+ || (absoluteNextPath !== libraryRoot && !absoluteNextPath.startsWith(`${libraryRoot}${path.sep}`))) {
51
+ throw new Error('Invalid library path');
52
+ }
53
+ if (absolutePath === absoluteNextPath) {
54
+ throw new Error('Source and destination paths are the same');
55
+ }
56
+ const sourceStat = fs.lstatSync(absolutePath, { throwIfNoEntry: false });
57
+ if (!sourceStat) {
58
+ throw new Error('Path not found');
59
+ }
60
+ const targetStat = fs.lstatSync(absoluteNextPath, { throwIfNoEntry: false });
61
+ if (targetStat) {
62
+ throw new Error('Destination already exists');
63
+ }
64
+ fs.mkdirSync(path.dirname(absoluteNextPath), { recursive: true });
65
+ fs.renameSync(absolutePath, absoluteNextPath);
66
+ let cursor = path.dirname(absolutePath);
67
+ while (cursor.startsWith(libraryRoot) && cursor !== libraryRoot) {
68
+ const remaining = fs.readdirSync(cursor);
69
+ if (remaining.length > 0)
70
+ break;
71
+ fs.rmdirSync(cursor);
72
+ cursor = path.dirname(cursor);
73
+ }
74
+ }
@@ -0,0 +1,183 @@
1
+ import { createHash } from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ const LIBRARY_ROOT_DIRECTORY = '.library';
5
+ const MANAGED_MARKER_FILE = '.bigbang-managed.json';
6
+ const AGENT_COLLAB_MANAGED_MARKER_FILE = '.agent-collab-managed.json';
7
+ const LEGACY_MANAGED_MARKER_FILE = '.managed-by-bigbang';
8
+ const SHARED_README_FILE = 'README.txt';
9
+ const SHARED_README_CONTENT = [
10
+ 'Shared library workspace',
11
+ '',
12
+ 'Shared documents are mounted in this directory at .library/shared.',
13
+ '',
14
+ 'Usage rules:',
15
+ '- Inspect the directory and any relevant existing documents before modifying shared documents.',
16
+ '- For ordinary parallel task-thread work, prefer creating a unique markdown file for your contribution, such as a filename containing your agent name or the date.',
17
+ '- Update an existing markdown document only when the user explicitly asks for that file or the task clearly assigns one shared file to maintain.',
18
+ '- Do not edit .meta/manifest.json, INDEX.md, README.txt, or generated index/metadata files.',
19
+ '- Do not have multiple agents concurrently maintain the same index.md file unless the task thread explicitly assigns that coordination pattern.',
20
+ '- The platform rebuilds shared library manifest/index metadata after writeback.',
21
+ '- If several agents must update the same shared document, agree on ownership and merge order in the task thread first.',
22
+ '',
23
+ ].join('\n');
24
+ const MANAGED_TOP_LEVEL_ENTRIES = new Set([
25
+ MANAGED_MARKER_FILE,
26
+ AGENT_COLLAB_MANAGED_MARKER_FILE,
27
+ LEGACY_MANAGED_MARKER_FILE,
28
+ 'shared',
29
+ 'personal',
30
+ ]);
31
+ export function applyLibraryMirror(workspaceRoot, mirror) {
32
+ const managedRootPath = ensureManagedLibraryRoot(workspaceRoot);
33
+ pruneUnexpectedManagedEntries(managedRootPath);
34
+ applyScopeTree(managedRootPath, 'shared', mirror.shared);
35
+ writeSharedReadmeIfNeeded(managedRootPath, mirror.shared);
36
+ applyScopeTree(managedRootPath, 'personal', mirror.personal);
37
+ writeManagedMarker(managedRootPath);
38
+ }
39
+ export function snapshotLibraryMirror(workspaceRoot) {
40
+ const managedRootPath = path.join(path.resolve(workspaceRoot), LIBRARY_ROOT_DIRECTORY);
41
+ const rootStat = fs.lstatSync(managedRootPath, { throwIfNoEntry: false });
42
+ if (!rootStat) {
43
+ return { shared: null, personal: null };
44
+ }
45
+ if (!rootStat.isDirectory()) {
46
+ throw new Error(`[libraryMirror] expected managed directory at ${managedRootPath}`);
47
+ }
48
+ if (!isManagedLibraryDirectory(managedRootPath)) {
49
+ throw new Error(`[libraryMirror] refusing to snapshot unmanaged library directory at ${managedRootPath}`);
50
+ }
51
+ return {
52
+ shared: collectScopeTree(managedRootPath, 'shared'),
53
+ personal: collectScopeTree(managedRootPath, 'personal'),
54
+ };
55
+ }
56
+ function ensureManagedLibraryRoot(workspaceRoot) {
57
+ const managedRootPath = path.join(path.resolve(workspaceRoot), LIBRARY_ROOT_DIRECTORY);
58
+ const rootStat = fs.lstatSync(managedRootPath, { throwIfNoEntry: false });
59
+ if (!rootStat) {
60
+ fs.mkdirSync(managedRootPath, { recursive: true });
61
+ writeManagedMarker(managedRootPath);
62
+ return managedRootPath;
63
+ }
64
+ if (rootStat.isSymbolicLink()) {
65
+ fs.unlinkSync(managedRootPath);
66
+ fs.mkdirSync(managedRootPath, { recursive: true });
67
+ writeManagedMarker(managedRootPath);
68
+ return managedRootPath;
69
+ }
70
+ if (!rootStat.isDirectory()) {
71
+ throw new Error(`[libraryMirror] refusing to replace existing file at ${managedRootPath}`);
72
+ }
73
+ if (!isManagedLibraryDirectory(managedRootPath)) {
74
+ throw new Error(`[libraryMirror] refusing to replace existing directory at ${managedRootPath}`);
75
+ }
76
+ for (const legacyMarkerPath of [
77
+ path.join(managedRootPath, AGENT_COLLAB_MANAGED_MARKER_FILE),
78
+ path.join(managedRootPath, LEGACY_MANAGED_MARKER_FILE),
79
+ ]) {
80
+ if (fs.existsSync(legacyMarkerPath)) {
81
+ fs.rmSync(legacyMarkerPath, { force: true });
82
+ }
83
+ }
84
+ writeManagedMarker(managedRootPath);
85
+ return managedRootPath;
86
+ }
87
+ function isManagedLibraryDirectory(managedRootPath) {
88
+ return fs.existsSync(path.join(managedRootPath, MANAGED_MARKER_FILE))
89
+ || fs.existsSync(path.join(managedRootPath, AGENT_COLLAB_MANAGED_MARKER_FILE))
90
+ || fs.existsSync(path.join(managedRootPath, LEGACY_MANAGED_MARKER_FILE));
91
+ }
92
+ function writeManagedMarker(managedRootPath) {
93
+ fs.writeFileSync(path.join(managedRootPath, MANAGED_MARKER_FILE), JSON.stringify({
94
+ kind: 'library_mirror',
95
+ version: 1,
96
+ }, null, 2) + '\n', 'utf8');
97
+ }
98
+ function pruneUnexpectedManagedEntries(managedRootPath) {
99
+ for (const entry of fs.readdirSync(managedRootPath, { withFileTypes: true })) {
100
+ if (MANAGED_TOP_LEVEL_ENTRIES.has(entry.name))
101
+ continue;
102
+ fs.rmSync(path.join(managedRootPath, entry.name), { recursive: true, force: true });
103
+ }
104
+ }
105
+ function applyScopeTree(managedRootPath, scopeName, tree) {
106
+ const scopeRootPath = path.join(managedRootPath, scopeName);
107
+ fs.rmSync(scopeRootPath, { recursive: true, force: true });
108
+ if (!tree)
109
+ return;
110
+ fs.mkdirSync(scopeRootPath, { recursive: true });
111
+ for (const file of tree.files) {
112
+ const normalizedPath = normalizeMirrorRelativePath(file.path);
113
+ const normalizedContent = file.content.replace(/\r\n/g, '\n');
114
+ const actualSha = sha256(normalizedContent);
115
+ if (actualSha !== file.sha256) {
116
+ throw new Error(`[libraryMirror] checksum mismatch for ${scopeName}/${normalizedPath}`);
117
+ }
118
+ const absolutePath = path.join(scopeRootPath, normalizedPath);
119
+ fs.mkdirSync(path.dirname(absolutePath), { recursive: true });
120
+ fs.writeFileSync(absolutePath, normalizedContent, 'utf8');
121
+ }
122
+ }
123
+ function writeSharedReadmeIfNeeded(managedRootPath, sharedTree) {
124
+ if (!sharedTree)
125
+ return;
126
+ const sharedRootPath = path.join(managedRootPath, 'shared');
127
+ fs.writeFileSync(path.join(sharedRootPath, SHARED_README_FILE), SHARED_README_CONTENT, 'utf8');
128
+ }
129
+ function collectScopeTree(managedRootPath, scopeName) {
130
+ const scopeRootPath = path.join(managedRootPath, scopeName);
131
+ const stat = fs.lstatSync(scopeRootPath, { throwIfNoEntry: false });
132
+ if (!stat)
133
+ return null;
134
+ if (!stat.isDirectory()) {
135
+ throw new Error(`[libraryMirror] expected directory at ${scopeRootPath}`);
136
+ }
137
+ const files = [];
138
+ collectScopeFiles(scopeRootPath, scopeName, '', files);
139
+ return {
140
+ files: files.sort((left, right) => left.path.localeCompare(right.path)),
141
+ };
142
+ }
143
+ function collectScopeFiles(scopeRootPath, scopeName, relativePrefix, files) {
144
+ const entries = fs
145
+ .readdirSync(path.join(scopeRootPath, relativePrefix), { withFileTypes: true })
146
+ .sort((left, right) => left.name.localeCompare(right.name));
147
+ for (const entry of entries) {
148
+ const relativePath = relativePrefix ? path.posix.join(relativePrefix, entry.name) : entry.name;
149
+ const absolutePath = path.join(scopeRootPath, relativePath);
150
+ if (entry.isSymbolicLink()) {
151
+ throw new Error(`[libraryMirror] refusing to snapshot symlink at ${absolutePath}`);
152
+ }
153
+ if (entry.isDirectory()) {
154
+ collectScopeFiles(scopeRootPath, scopeName, relativePath, files);
155
+ continue;
156
+ }
157
+ if (!entry.isFile())
158
+ continue;
159
+ if (scopeName === 'shared' && relativePath === SHARED_README_FILE)
160
+ continue;
161
+ const content = fs.readFileSync(absolutePath, 'utf8').replace(/\r\n/g, '\n');
162
+ files.push({
163
+ path: relativePath,
164
+ content,
165
+ sha256: sha256(content),
166
+ });
167
+ }
168
+ }
169
+ function normalizeMirrorRelativePath(rawPath) {
170
+ const trimmed = rawPath.trim().replace(/\\/g, '/');
171
+ const normalized = path.posix.normalize(trimmed).replace(/^\/+/, '').replace(/\/+$/, '');
172
+ if (!normalized
173
+ || normalized === '.'
174
+ || normalized === '..'
175
+ || normalized.startsWith('../')
176
+ || normalized.includes('/../')) {
177
+ throw new Error(`Invalid library mirror path: ${rawPath}`);
178
+ }
179
+ return normalized;
180
+ }
181
+ function sha256(content) {
182
+ return createHash('sha256').update(content, 'utf8').digest('hex');
183
+ }