@almadar/agent 1.6.1 → 1.6.2
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/index.d.ts +3 -731
- package/dist/agent/index.js +294 -2184
- package/dist/agent/index.js.map +1 -1
- package/dist/{firestore-checkpointer-BkFR-sZM.d.ts → firestore-checkpointer-CkNKXoun.d.ts} +1 -1
- package/dist/{index-DGdLGf-L.d.ts → index-CV-YHG_P.d.ts} +25 -21
- package/dist/{workflow-tool-wrapper-CXD0A7l3.d.ts → index-CmTX9IiH.d.ts} +4 -3
- package/dist/index.d.ts +9 -536
- package/dist/index.js +3191 -3560
- package/dist/index.js.map +1 -1
- package/dist/{orbital-subagent-CHEeQQr_.d.ts → orbital-subagent-B9lvv_NS.d.ts} +28 -26
- package/dist/persistence/index.d.ts +2 -2
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +283 -131
- package/dist/tools/index.js.map +1 -1
- package/dist/workspace/index.d.ts +355 -0
- package/dist/workspace/index.js +675 -0
- package/dist/workspace/index.js.map +1 -0
- package/package.json +10 -8
- package/dist/prompts/index.d.ts +0 -23
- package/dist/prompts/index.js +0 -126
- package/dist/prompts/index.js.map +0 -1
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { OrbitalSchema } from '@almadar/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Workspace Types
|
|
5
|
+
*
|
|
6
|
+
* Core type definitions for the workspace-centric persistence architecture.
|
|
7
|
+
* The workspace is the central unit: files in a git-tracked directory,
|
|
8
|
+
* with pluggable sinks for Firestore, GitHub, etc.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
/** Standard directory structure inside a workspace. */
|
|
13
|
+
declare const WORKSPACE_LAYOUT: {
|
|
14
|
+
/** Root directory for Almadar workspace state. */
|
|
15
|
+
readonly ALMADAR_DIR: ".almadar";
|
|
16
|
+
/** User preferences and learned patterns. */
|
|
17
|
+
readonly USER_MEMORY: ".almadar/user.orb";
|
|
18
|
+
/** Project-level domain knowledge. */
|
|
19
|
+
readonly PROJECT_MEMORY: ".almadar/project.orb";
|
|
20
|
+
/** The generation artifact (shared memory for all agents). */
|
|
21
|
+
readonly SCHEMA: ".almadar/schema.orb";
|
|
22
|
+
/** Individual orbital files (one per subagent). */
|
|
23
|
+
readonly ORBITALS_DIR: ".almadar/orbitals";
|
|
24
|
+
};
|
|
25
|
+
/** Classification of a file write for routing to appropriate sinks. */
|
|
26
|
+
interface FileMeta {
|
|
27
|
+
/** What kind of file was written. */
|
|
28
|
+
fileType: 'schema' | 'orbital' | 'memory' | 'domain' | 'other';
|
|
29
|
+
/** Orbital name (only when fileType is 'orbital'). */
|
|
30
|
+
orbitalName?: string;
|
|
31
|
+
/** Session ID for attribution. */
|
|
32
|
+
sessionId?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A pluggable persistence backend that reacts to workspace file writes.
|
|
36
|
+
*
|
|
37
|
+
* Sinks are registered with the SinkManager and notified on every file write.
|
|
38
|
+
* Each sink is independent — a failure in one does not affect others.
|
|
39
|
+
*/
|
|
40
|
+
interface WorkspaceSink {
|
|
41
|
+
/** Human-readable name for logging/diagnostics. */
|
|
42
|
+
readonly name: string;
|
|
43
|
+
/**
|
|
44
|
+
* Called when a file is written to the workspace.
|
|
45
|
+
* @param path - Relative path within the workspace root
|
|
46
|
+
* @param content - File content as a string
|
|
47
|
+
* @param meta - Classification metadata for routing
|
|
48
|
+
*/
|
|
49
|
+
onFileWritten(path: string, content: string, meta: FileMeta): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Called when the session ends. Used for cleanup, final sync, tagging, etc.
|
|
52
|
+
* @param sessionId - The session being ended
|
|
53
|
+
*/
|
|
54
|
+
onSessionEnd(sessionId: string): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/** Result of notifying a single sink. */
|
|
57
|
+
interface SinkResult {
|
|
58
|
+
/** Which sink produced this result. */
|
|
59
|
+
sinkName: string;
|
|
60
|
+
/** Whether the sink operation succeeded. */
|
|
61
|
+
success: boolean;
|
|
62
|
+
/** Error details if the operation failed. */
|
|
63
|
+
error?: Error;
|
|
64
|
+
}
|
|
65
|
+
/** Configuration for initializing a workspace. */
|
|
66
|
+
interface WorkspaceConfig {
|
|
67
|
+
/** Absolute path to the workspace root directory. */
|
|
68
|
+
rootDir: string;
|
|
69
|
+
/** User ID for memory file attribution. */
|
|
70
|
+
userId: string;
|
|
71
|
+
/** Session ID for git tags and logging. */
|
|
72
|
+
sessionId: string;
|
|
73
|
+
/** App ID (may be assigned later on first schema write). */
|
|
74
|
+
appId?: string;
|
|
75
|
+
/** Project name for the schema template. */
|
|
76
|
+
projectName?: string;
|
|
77
|
+
/** Whether to initialize git in the workspace. Defaults to true. */
|
|
78
|
+
gitEnabled?: boolean;
|
|
79
|
+
/** Sinks to register on initialization. */
|
|
80
|
+
sinks?: WorkspaceSink[];
|
|
81
|
+
}
|
|
82
|
+
/** Snapshot of all .orb memory file instances, read at session start. */
|
|
83
|
+
interface MemorySnapshot {
|
|
84
|
+
/** User preferences from .almadar/user.orb instances. */
|
|
85
|
+
user: Record<string, unknown>[];
|
|
86
|
+
/** Project context from .almadar/project.orb instances. */
|
|
87
|
+
project: Record<string, unknown>[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* SinkManager — Fan-out file writes to registered workspace sinks.
|
|
92
|
+
*
|
|
93
|
+
* Uses Promise.allSettled for fault isolation: a Firestore error
|
|
94
|
+
* does not prevent the git commit, and vice versa.
|
|
95
|
+
*
|
|
96
|
+
* @packageDocumentation
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
declare class SinkManager {
|
|
100
|
+
private readonly sinks;
|
|
101
|
+
/** Register a sink to receive file write notifications. */
|
|
102
|
+
register(sink: WorkspaceSink): void;
|
|
103
|
+
/** Get registered sink names (for diagnostics). */
|
|
104
|
+
get registeredSinks(): string[];
|
|
105
|
+
/**
|
|
106
|
+
* Notify all sinks that a file was written.
|
|
107
|
+
* Returns results from each sink — failures in one don't affect others.
|
|
108
|
+
*/
|
|
109
|
+
notifyFileWritten(path: string, content: string, meta: FileMeta): Promise<SinkResult[]>;
|
|
110
|
+
/**
|
|
111
|
+
* Notify all sinks that the session has ended.
|
|
112
|
+
* Returns results from each sink — failures in one don't affect others.
|
|
113
|
+
*/
|
|
114
|
+
notifySessionEnd(sessionId: string): Promise<SinkResult[]>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* WorkspaceManager — Lifecycle management for agent workspaces.
|
|
119
|
+
*
|
|
120
|
+
* Handles initialization (create dirs, write .orb templates, git init),
|
|
121
|
+
* file write notifications (fan out to sinks), memory read/write,
|
|
122
|
+
* and session end (final commit, tag, cleanup).
|
|
123
|
+
*
|
|
124
|
+
* @packageDocumentation
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
declare class WorkspaceManager {
|
|
128
|
+
private readonly config;
|
|
129
|
+
private readonly sinkManager;
|
|
130
|
+
private gitSink;
|
|
131
|
+
private initialized;
|
|
132
|
+
constructor(config: WorkspaceConfig);
|
|
133
|
+
/** Get the absolute path to a workspace-relative path. */
|
|
134
|
+
resolve(relativePath: string): string;
|
|
135
|
+
/** Get the SinkManager for direct registration of additional sinks. */
|
|
136
|
+
get sinks(): SinkManager;
|
|
137
|
+
/**
|
|
138
|
+
* Initialize the workspace: create directories, write .orb templates,
|
|
139
|
+
* optionally initialize git.
|
|
140
|
+
*
|
|
141
|
+
* Safe to call multiple times — skips if already initialized.
|
|
142
|
+
*/
|
|
143
|
+
initialize(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Notify sinks that a file was written.
|
|
146
|
+
* Call this from the server when the agent writes a file.
|
|
147
|
+
*
|
|
148
|
+
* @param relativePath - Path relative to workspace root
|
|
149
|
+
* @param content - File content as string
|
|
150
|
+
* @param meta - Optional metadata override (auto-inferred if not provided)
|
|
151
|
+
*/
|
|
152
|
+
onFileWritten(relativePath: string, content: string, meta?: Partial<FileMeta>): Promise<SinkResult[]>;
|
|
153
|
+
/**
|
|
154
|
+
* Load memory from .orb files. Call at session start to provide
|
|
155
|
+
* the agent with user preferences and project context.
|
|
156
|
+
*/
|
|
157
|
+
loadMemory(): Promise<MemorySnapshot>;
|
|
158
|
+
/**
|
|
159
|
+
* Update memory .orb file instances. Call at session end to
|
|
160
|
+
* persist learned preferences and discovered domain knowledge.
|
|
161
|
+
*/
|
|
162
|
+
saveMemory(updates: {
|
|
163
|
+
user?: Record<string, unknown>[];
|
|
164
|
+
project?: Record<string, unknown>[];
|
|
165
|
+
}): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* End the session: notify all sinks, create git tag.
|
|
168
|
+
* Call from the server when the agent session completes.
|
|
169
|
+
*/
|
|
170
|
+
endSession(): Promise<SinkResult[]>;
|
|
171
|
+
private writeTemplateIfMissing;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* GitClient — Thin wrapper around local git CLI operations.
|
|
176
|
+
*
|
|
177
|
+
* Uses child_process.execFile for safety (no shell injection).
|
|
178
|
+
* Designed for workspace-local operations only (init, add, commit, tag).
|
|
179
|
+
* Remote operations (push, PR) use @almadar/integrations instead.
|
|
180
|
+
*
|
|
181
|
+
* @packageDocumentation
|
|
182
|
+
*/
|
|
183
|
+
interface GitLogEntry {
|
|
184
|
+
hash: string;
|
|
185
|
+
message: string;
|
|
186
|
+
date: string;
|
|
187
|
+
author: string;
|
|
188
|
+
}
|
|
189
|
+
interface GitStatus {
|
|
190
|
+
clean: boolean;
|
|
191
|
+
staged: string[];
|
|
192
|
+
modified: string[];
|
|
193
|
+
untracked: string[];
|
|
194
|
+
}
|
|
195
|
+
declare class GitClient {
|
|
196
|
+
private readonly cwd;
|
|
197
|
+
constructor(cwd: string);
|
|
198
|
+
/** Check if git is available on the system. */
|
|
199
|
+
static isAvailable(): Promise<boolean>;
|
|
200
|
+
/** Check if the workspace is already a git repository. */
|
|
201
|
+
isRepo(): Promise<boolean>;
|
|
202
|
+
/** Initialize a new git repository. No-op if already initialized. */
|
|
203
|
+
init(): Promise<void>;
|
|
204
|
+
/** Stage files for commit. */
|
|
205
|
+
add(paths: string[]): Promise<void>;
|
|
206
|
+
/** Stage all changes (equivalent to git add -A). */
|
|
207
|
+
addAll(): Promise<void>;
|
|
208
|
+
/**
|
|
209
|
+
* Create a commit with the given message.
|
|
210
|
+
* Returns the commit hash, or null if there was nothing to commit.
|
|
211
|
+
*/
|
|
212
|
+
commit(message: string): Promise<string | null>;
|
|
213
|
+
/** Create an annotated tag. */
|
|
214
|
+
tag(name: string, message?: string): Promise<void>;
|
|
215
|
+
/** Get recent commits. */
|
|
216
|
+
log(limit?: number): Promise<GitLogEntry[]>;
|
|
217
|
+
/** Get workspace status. */
|
|
218
|
+
status(): Promise<GitStatus>;
|
|
219
|
+
/** Get diff output between two references. */
|
|
220
|
+
diff(from?: string, to?: string): Promise<string>;
|
|
221
|
+
private exec;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* GitSink — Auto-commit workspace file writes to a local git repository.
|
|
226
|
+
*
|
|
227
|
+
* Implements the WorkspaceSink interface. Every file write becomes a git commit
|
|
228
|
+
* with a structured message. Concurrent writes are serialized via a commit queue
|
|
229
|
+
* to prevent git lock contention (handles parallel subagent case).
|
|
230
|
+
*
|
|
231
|
+
* Gracefully degrades if git is not available (logs warning, no-ops).
|
|
232
|
+
*
|
|
233
|
+
* @packageDocumentation
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
declare class GitSink implements WorkspaceSink {
|
|
237
|
+
readonly name = "git";
|
|
238
|
+
private readonly client;
|
|
239
|
+
private commitQueue;
|
|
240
|
+
private available;
|
|
241
|
+
constructor(workspaceRoot: string);
|
|
242
|
+
/** Initialize the git repo. Must be called before onFileWritten. */
|
|
243
|
+
initialize(): Promise<void>;
|
|
244
|
+
onFileWritten(path: string, _content: string, meta: FileMeta): Promise<void>;
|
|
245
|
+
onSessionEnd(sessionId: string): Promise<void>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* FirestoreSink — Per-orbital Firestore persistence as a workspace sink.
|
|
250
|
+
*
|
|
251
|
+
* Takes injected save functions so @almadar/agent stays free of firebase-admin.
|
|
252
|
+
* The server provides concrete implementations via KFlowAccessLayer.
|
|
253
|
+
*
|
|
254
|
+
* Key property: each orbital is its own Firestore document.
|
|
255
|
+
* Two subagents writing different orbitals = zero contention.
|
|
256
|
+
*
|
|
257
|
+
* @packageDocumentation
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Injected dependencies for FirestoreSink.
|
|
262
|
+
* The server provides these — the agent package has no Firestore dependency.
|
|
263
|
+
*/
|
|
264
|
+
interface FirestoreSinkConfig {
|
|
265
|
+
/** User ID for Firestore document paths. */
|
|
266
|
+
userId: string;
|
|
267
|
+
/** App ID (may be assigned later on first schema write). */
|
|
268
|
+
appId?: string;
|
|
269
|
+
/** Save a single orbital to its own Firestore document. */
|
|
270
|
+
saveOrbital(orbitalName: string, orbital: unknown): Promise<void>;
|
|
271
|
+
/** Save schema metadata (name, version, config). */
|
|
272
|
+
saveSchema?(schema: unknown): Promise<{
|
|
273
|
+
appId: string;
|
|
274
|
+
}>;
|
|
275
|
+
/** Save memory updates (user preferences, project context). */
|
|
276
|
+
saveMemory?(memoryType: string, data: unknown): Promise<void>;
|
|
277
|
+
/** Callback when a new app is created (for SSE event emission). */
|
|
278
|
+
onAppCreated?(appId: string): void;
|
|
279
|
+
}
|
|
280
|
+
declare class FirestoreSink implements WorkspaceSink {
|
|
281
|
+
readonly name = "firestore";
|
|
282
|
+
private readonly config;
|
|
283
|
+
constructor(config: FirestoreSinkConfig);
|
|
284
|
+
/** Update the appId after it's been assigned (e.g., on first schema write). */
|
|
285
|
+
setAppId(appId: string): void;
|
|
286
|
+
onFileWritten(_path: string, content: string, meta: FileMeta): Promise<void>;
|
|
287
|
+
onSessionEnd(_sessionId: string): Promise<void>;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Workspace Templates
|
|
292
|
+
*
|
|
293
|
+
* .orb memory file templates as TypeScript constants.
|
|
294
|
+
* These are written to `.almadar/` on workspace initialization.
|
|
295
|
+
*
|
|
296
|
+
* Reuses entity definitions from `memory-orbital.ts` for type consistency.
|
|
297
|
+
*
|
|
298
|
+
* @packageDocumentation
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Create the user.orb template — tracks user preferences with a temporal learning trait.
|
|
303
|
+
*
|
|
304
|
+
* The `instances` field carries the living memory data.
|
|
305
|
+
* Git commits to this file ARE the state transitions over time.
|
|
306
|
+
*/
|
|
307
|
+
declare function createUserOrbTemplate(userId: string): OrbitalSchema;
|
|
308
|
+
/**
|
|
309
|
+
* Create the project.orb template — tracks project domain knowledge.
|
|
310
|
+
*
|
|
311
|
+
* Accumulates known entities, relations, and domain terms across sessions.
|
|
312
|
+
*/
|
|
313
|
+
declare function createProjectOrbTemplate(projectName: string, appId?: string): OrbitalSchema;
|
|
314
|
+
/**
|
|
315
|
+
* Create the schema.orb template — empty scaffold for a new generation.
|
|
316
|
+
*/
|
|
317
|
+
declare function createSchemaOrbTemplate(name: string): OrbitalSchema;
|
|
318
|
+
/** Serialize an OrbitalSchema to a formatted JSON string. */
|
|
319
|
+
declare function serializeOrb(schema: OrbitalSchema): string;
|
|
320
|
+
/** Parse a JSON string into an OrbitalSchema. Returns null on parse failure. */
|
|
321
|
+
declare function parseOrb(content: string): OrbitalSchema | null;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Memory Files — Read/write .orb memory file instances.
|
|
325
|
+
*
|
|
326
|
+
* The `instances` field on an OrbitalSchema entity is the living data carrier.
|
|
327
|
+
* These utilities read and write that field without touching the rest of the schema.
|
|
328
|
+
*
|
|
329
|
+
* @packageDocumentation
|
|
330
|
+
*/
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Read the `instances` array from the first orbital's entity in an .orb file.
|
|
334
|
+
* Returns an empty array if the file doesn't exist or has no instances.
|
|
335
|
+
*/
|
|
336
|
+
declare function readOrbInstances(filePath: string): Promise<Record<string, unknown>[]>;
|
|
337
|
+
/**
|
|
338
|
+
* Read and parse a complete .orb file.
|
|
339
|
+
* Returns null if the file doesn't exist or is invalid JSON.
|
|
340
|
+
*/
|
|
341
|
+
declare function readOrb(filePath: string): Promise<OrbitalSchema | null>;
|
|
342
|
+
/**
|
|
343
|
+
* Update the `instances` array in the first orbital's entity of an .orb file.
|
|
344
|
+
* Preserves the rest of the schema structure (traits, pages, etc.).
|
|
345
|
+
*
|
|
346
|
+
* If the file doesn't exist, this is a no-op (the workspace should be
|
|
347
|
+
* initialized with templates first).
|
|
348
|
+
*/
|
|
349
|
+
declare function writeOrbInstances(filePath: string, instances: Record<string, unknown>[]): Promise<boolean>;
|
|
350
|
+
/**
|
|
351
|
+
* Write a complete OrbitalSchema to an .orb file.
|
|
352
|
+
*/
|
|
353
|
+
declare function writeOrb(filePath: string, schema: OrbitalSchema): Promise<void>;
|
|
354
|
+
|
|
355
|
+
export { type FileMeta, FirestoreSink, type FirestoreSinkConfig, GitClient, type GitLogEntry, GitSink, type GitStatus, type MemorySnapshot, SinkManager, type SinkResult, WORKSPACE_LAYOUT, type WorkspaceConfig, WorkspaceManager, type WorkspaceSink, createProjectOrbTemplate, createSchemaOrbTemplate, createUserOrbTemplate, parseOrb, readOrb, readOrbInstances, serializeOrb, writeOrb, writeOrbInstances };
|