@almadar/agent 2.0.0 → 2.0.1

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 (100) hide show
  1. package/dist/agent/event-budget.d.ts +28 -0
  2. package/dist/agent/experimental/hitl-v2.d.ts +161 -0
  3. package/dist/agent/experimental/hitl-workflow-integration.d.ts +182 -0
  4. package/dist/agent/index.d.ts +14 -0
  5. package/dist/agent/index.js.map +1 -1
  6. package/dist/agent/interrupt-config.d.ts +51 -0
  7. package/dist/agent/session-manager.d.ts +204 -0
  8. package/dist/agent/skill-agent.d.ts +182 -0
  9. package/dist/agent/workflow-middleware.d.ts +63 -0
  10. package/dist/agent/workflow-tool-wrapper.d.ts +87 -0
  11. package/dist/api-types.d.ts +595 -0
  12. package/dist/context/compaction.d.ts +191 -0
  13. package/dist/context-compaction.d.ts +55 -0
  14. package/dist/evals/online-sampling.d.ts +114 -0
  15. package/dist/evals/utils/compact-orbital.d.ts +100 -0
  16. package/dist/event-transformer/event-transformer.d.ts +120 -0
  17. package/dist/event-transformer/index.d.ts +7 -0
  18. package/dist/events.d.ts +85 -0
  19. package/dist/index.d.ts +59 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/memory/MemoryManager.d.ts +243 -0
  22. package/dist/memory/PreferenceLearner.d.ts +59 -0
  23. package/dist/memory/agentic-search.d.ts +116 -0
  24. package/dist/memory/index.d.ts +14 -0
  25. package/dist/memory/memory-orbital.d.ts +66 -0
  26. package/dist/memory/types.d.ts +143 -0
  27. package/dist/metrics.d.ts +77 -0
  28. package/dist/multi-user.d.ts +155 -0
  29. package/dist/observability/index.d.ts +14 -0
  30. package/dist/observability/langsmith-integration.d.ts +203 -0
  31. package/dist/observability.d.ts +196 -0
  32. package/dist/orbitals/archive/sanitize.d.ts +24 -0
  33. package/dist/orbitals/batch/batch-generator.d.ts +41 -0
  34. package/dist/orbitals/batch/concurrency.d.ts +54 -0
  35. package/dist/orbitals/batch/index.d.ts +14 -0
  36. package/dist/orbitals/batch/prompt-assembler.d.ts +92 -0
  37. package/dist/orbitals/batch/types.d.ts +103 -0
  38. package/dist/orbitals/cache/index.d.ts +11 -0
  39. package/dist/orbitals/cache/orbital-fingerprint.d.ts +37 -0
  40. package/dist/orbitals/cache/prompt-assembler.d.ts +65 -0
  41. package/dist/orbitals/cache/structural-templates.d.ts +33 -0
  42. package/dist/orbitals/combiner/index.d.ts +102 -0
  43. package/dist/orbitals/domain-language/index.d.ts +9 -0
  44. package/dist/orbitals/domain-language/prompts/index.d.ts +11 -0
  45. package/dist/orbitals/domain-language/prompts/odl-examples.d.ts +8 -0
  46. package/dist/orbitals/domain-language/prompts/odl-patterns.d.ts +8 -0
  47. package/dist/orbitals/domain-language/prompts/odl-syntax.d.ts +8 -0
  48. package/dist/orbitals/domain-language/prompts/odl-to-schema.d.ts +8 -0
  49. package/dist/orbitals/generation/index.d.ts +10 -0
  50. package/dist/orbitals/generation/orbital-generator.d.ts +120 -0
  51. package/dist/orbitals/shared/constants.d.ts +65 -0
  52. package/dist/orbitals/shared/index.d.ts +11 -0
  53. package/dist/orbitals/shared/types.d.ts +187 -0
  54. package/dist/orbitals/shared/utils.d.ts +97 -0
  55. package/dist/orchestration/complexity-classifier.d.ts +38 -0
  56. package/dist/orchestration/fixing-orchestrator.d.ts +53 -0
  57. package/dist/orchestration/index.d.ts +31 -0
  58. package/dist/orchestration/provider-router.d.ts +45 -0
  59. package/dist/persistence/firestore-checkpointer.d.ts +139 -0
  60. package/dist/persistence/firestore-session-store.d.ts +75 -0
  61. package/dist/persistence/firestore-store.d.ts +86 -0
  62. package/dist/persistence/index.d.ts +10 -0
  63. package/dist/persistence/memory-backend.d.ts +33 -0
  64. package/dist/persistence/types.d.ts +40 -0
  65. package/dist/security/audit-log.d.ts +44 -0
  66. package/dist/state-sync.d.ts +171 -0
  67. package/dist/subagents.d.ts +38 -0
  68. package/dist/tools/combine-schemas.d.ts +154 -0
  69. package/dist/tools/composition.d.ts +119 -0
  70. package/dist/tools/domain-orbital.d.ts +997 -0
  71. package/dist/tools/execute.d.ts +38 -0
  72. package/dist/tools/finish-task.d.ts +56 -0
  73. package/dist/tools/generate-schema.d.ts +53 -0
  74. package/dist/tools/github.d.ts +297 -0
  75. package/dist/tools/index.d.ts +1318 -0
  76. package/dist/tools/orbital-batch-subagent.d.ts +85 -0
  77. package/dist/tools/orbital-subagent.d.ts +454 -0
  78. package/dist/tools/orchestrated-fixing.d.ts +74 -0
  79. package/dist/tools/orchestrated-generation.d.ts +75 -0
  80. package/dist/tools/sandbox-executor.d.ts +31 -0
  81. package/dist/tools/schema-chunking.d.ts +117 -0
  82. package/dist/tools/trait-subagent.d.ts +179 -0
  83. package/dist/tools/validate-schema.d.ts +17 -0
  84. package/dist/types.d.ts +167 -0
  85. package/dist/utils/safety/capability-token.d.ts +50 -0
  86. package/dist/utils/safety/circuit-breaker.d.ts +71 -0
  87. package/dist/utils/safety/index.d.ts +19 -0
  88. package/dist/utils/safety/rate-limiter.d.ts +39 -0
  89. package/dist/utils/safety/threshold-auth.d.ts +70 -0
  90. package/dist/workspace/git-client.d.ts +51 -0
  91. package/dist/workspace/index.d.ts +38 -0
  92. package/dist/workspace/memory-files.d.ts +31 -0
  93. package/dist/workspace/sink-manager.d.ts +26 -0
  94. package/dist/workspace/sinks/firestore-sink.d.ts +41 -0
  95. package/dist/workspace/sinks/git-sink.d.ts +47 -0
  96. package/dist/workspace/sinks/index.d.ts +9 -0
  97. package/dist/workspace/templates.d.ts +32 -0
  98. package/dist/workspace/types.d.ts +86 -0
  99. package/dist/workspace/workspace-manager.d.ts +57 -0
  100. package/package.json +7 -6
@@ -0,0 +1,70 @@
1
+ /**
2
+ * ThresholdAuthorizer — K-of-N approval voting for critical agent actions.
3
+ *
4
+ * TypeScript port of saezbaldo/ic-agi `ic_agi/threshold_auth.py`.
5
+ * See: https://github.com/saezbaldo/ic-agi
6
+ *
7
+ * TLA+ properties verified in ThresholdAuth.tla:
8
+ * P1 ThresholdSafety: executed => approvals >= K
9
+ * P2 NoUnilateralAuthority: K >= 2 enforced in constructor
10
+ * P3 DenialFinality: once denied, resolution immutable
11
+ * P4 ResolutionImmutability: resolved => resolution never changes
12
+ *
13
+ * Early-denial formula: deny_count > (N - K)
14
+ * Once enough denials make threshold mathematically unreachable,
15
+ * the request is immediately resolved as denied.
16
+ */
17
+ import type { AuditLog } from '../../security/audit-log.js';
18
+ export interface ApprovalRequest {
19
+ requestId: string;
20
+ actionDescription: string;
21
+ criticality: string;
22
+ requester: string;
23
+ /** Unix epoch seconds. */
24
+ createdAt: number;
25
+ ttlSeconds: number;
26
+ /** Map of approverId → vote (true = approve, false = deny). */
27
+ approvals: Map<string, boolean>;
28
+ resolved: boolean;
29
+ resolution: 'approved' | 'denied' | 'expired' | null;
30
+ }
31
+ export interface VoteResult {
32
+ status: 'approved' | 'denied' | 'pending';
33
+ approvals: number;
34
+ denials: number;
35
+ threshold: number;
36
+ /** Remaining approvals needed to reach threshold. */
37
+ remaining: number;
38
+ }
39
+ export declare class ThresholdAuthorizer {
40
+ private requests;
41
+ private readonly k;
42
+ private readonly n;
43
+ private readonly approverIds;
44
+ private readonly auditLog?;
45
+ /**
46
+ * @param k Minimum approvals required (must be >= 2, P2)
47
+ * @param approverIds List of registered approver IDs (length >= k)
48
+ * @param auditLog Optional audit chain for all voting events
49
+ */
50
+ constructor(k: number, approverIds: string[], auditLog?: AuditLog);
51
+ /**
52
+ * Create a new approval request for a critical action.
53
+ * The request window is 5 minutes (300s).
54
+ */
55
+ createRequest(actionDescription: string, requester: string, criticality?: string): ApprovalRequest;
56
+ /**
57
+ * Submit a vote for a pending request.
58
+ * Auto-resolves the request when threshold is reached (approve)
59
+ * or when threshold becomes mathematically unreachable (deny).
60
+ *
61
+ * @throws if request not found, already resolved, expired, approver not registered, or double-vote
62
+ */
63
+ submitVote(requestId: string, approverId: string, vote: boolean): VoteResult;
64
+ /** Returns true iff the request is resolved and approved (P1). */
65
+ isApproved(requestId: string): boolean;
66
+ /** Returns true iff the request is resolved and denied (P3). */
67
+ isDenied(requestId: string): boolean;
68
+ isExpired(requestId: string): boolean;
69
+ getRequest(requestId: string): ApprovalRequest | undefined;
70
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * GitClient — Thin wrapper around local git CLI operations.
3
+ *
4
+ * Uses child_process.execFile for safety (no shell injection).
5
+ * Designed for workspace-local operations only (init, add, commit, tag).
6
+ * Remote operations (push, PR) use @almadar/integrations instead.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ export interface GitLogEntry {
11
+ hash: string;
12
+ message: string;
13
+ date: string;
14
+ author: string;
15
+ }
16
+ export interface GitStatus {
17
+ clean: boolean;
18
+ staged: string[];
19
+ modified: string[];
20
+ untracked: string[];
21
+ }
22
+ export declare class GitClient {
23
+ private readonly cwd;
24
+ constructor(cwd: string);
25
+ /** Get the working directory path. */
26
+ getCwd(): string;
27
+ /** Check if git is available on the system. */
28
+ static isAvailable(): Promise<boolean>;
29
+ /** Check if the workspace is already a git repository. */
30
+ isRepo(): Promise<boolean>;
31
+ /** Initialize a new git repository. No-op if already initialized. */
32
+ init(): Promise<void>;
33
+ /** Stage files for commit. */
34
+ add(paths: string[]): Promise<void>;
35
+ /** Stage all changes (equivalent to git add -A). */
36
+ addAll(): Promise<void>;
37
+ /**
38
+ * Create a commit with the given message.
39
+ * Returns the commit hash, or null if there was nothing to commit.
40
+ */
41
+ commit(message: string): Promise<string | null>;
42
+ /** Create an annotated tag. */
43
+ tag(name: string, message?: string): Promise<void>;
44
+ /** Get recent commits. */
45
+ log(limit?: number): Promise<GitLogEntry[]>;
46
+ /** Get workspace status. */
47
+ status(): Promise<GitStatus>;
48
+ /** Get diff output between two references. */
49
+ diff(from?: string, to?: string): Promise<string>;
50
+ private exec;
51
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Workspace Module
3
+ *
4
+ * Workspace-centric persistence architecture for Almadar agents.
5
+ * Files in a git-tracked workspace, with pluggable sinks for Firestore, GitHub, etc.
6
+ *
7
+ * ## Quick Start
8
+ *
9
+ * ```typescript
10
+ * import { WorkspaceManager, FirestoreSink } from '@almadar/agent/workspace';
11
+ *
12
+ * const workspace = new WorkspaceManager({
13
+ * rootDir: '/workspaces/user-123/session-456',
14
+ * userId: 'user-123',
15
+ * sessionId: 'session-456',
16
+ * projectName: 'Taskly',
17
+ * sinks: [new FirestoreSink({ userId: 'user-123', saveOrbital: ... })],
18
+ * });
19
+ *
20
+ * await workspace.initialize(); // Create dirs, templates, git init
21
+ * const memory = await workspace.loadMemory(); // Read .orb instances
22
+ * // ... agent runs, server calls workspace.onFileWritten() on each write ...
23
+ * await workspace.endSession(); // Tag, cleanup
24
+ * ```
25
+ *
26
+ * @packageDocumentation
27
+ */
28
+ export type { WorkspaceSink, WorkspaceConfig, FileMeta, SinkResult, MemorySnapshot, } from './types.js';
29
+ export { WORKSPACE_LAYOUT } from './types.js';
30
+ export { WorkspaceManager } from './workspace-manager.js';
31
+ export { SinkManager } from './sink-manager.js';
32
+ export { GitClient } from './git-client.js';
33
+ export type { GitLogEntry, GitStatus } from './git-client.js';
34
+ export { GitSink } from './sinks/git-sink.js';
35
+ export { FirestoreSink } from './sinks/firestore-sink.js';
36
+ export type { FirestoreSinkConfig } from './sinks/firestore-sink.js';
37
+ export { createUserOrbTemplate, createProjectOrbTemplate, createSchemaOrbTemplate, serializeOrb, parseOrb, } from './templates.js';
38
+ export { readOrbInstances, readOrb, writeOrbInstances, writeOrb, } from './memory-files.js';
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Memory Files — Read/write .orb memory file instances.
3
+ *
4
+ * The `instances` field on an OrbitalSchema entity is the living data carrier.
5
+ * These utilities read and write that field without touching the rest of the schema.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { OrbitalSchema } from '@almadar/core';
10
+ /**
11
+ * Read the `instances` array from the first orbital's entity in an .orb file.
12
+ * Returns an empty array if the file doesn't exist or has no instances.
13
+ */
14
+ export declare function readOrbInstances(filePath: string): Promise<Record<string, unknown>[]>;
15
+ /**
16
+ * Read and parse a complete .orb file.
17
+ * Returns null if the file doesn't exist or is invalid JSON.
18
+ */
19
+ export declare function readOrb(filePath: string): Promise<OrbitalSchema | null>;
20
+ /**
21
+ * Update the `instances` array in the first orbital's entity of an .orb file.
22
+ * Preserves the rest of the schema structure (traits, pages, etc.).
23
+ *
24
+ * If the file doesn't exist, this is a no-op (the workspace should be
25
+ * initialized with templates first).
26
+ */
27
+ export declare function writeOrbInstances(filePath: string, instances: Record<string, unknown>[]): Promise<boolean>;
28
+ /**
29
+ * Write a complete OrbitalSchema to an .orb file.
30
+ */
31
+ export declare function writeOrb(filePath: string, schema: OrbitalSchema): Promise<void>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * SinkManager — Fan-out file writes to registered workspace sinks.
3
+ *
4
+ * Uses Promise.allSettled for fault isolation: a Firestore error
5
+ * does not prevent the git commit, and vice versa.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { WorkspaceSink, FileMeta, SinkResult } from './types.js';
10
+ export declare class SinkManager {
11
+ private readonly sinks;
12
+ /** Register a sink to receive file write notifications. */
13
+ register(sink: WorkspaceSink): void;
14
+ /** Get registered sink names (for diagnostics). */
15
+ get registeredSinks(): string[];
16
+ /**
17
+ * Notify all sinks that a file was written.
18
+ * Returns results from each sink — failures in one don't affect others.
19
+ */
20
+ notifyFileWritten(path: string, content: string, meta: FileMeta): Promise<SinkResult[]>;
21
+ /**
22
+ * Notify all sinks that the session has ended.
23
+ * Returns results from each sink — failures in one don't affect others.
24
+ */
25
+ notifySessionEnd(sessionId: string): Promise<SinkResult[]>;
26
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * FirestoreSink — Per-orbital Firestore persistence as a workspace sink.
3
+ *
4
+ * Takes injected save functions so @almadar/agent stays free of firebase-admin.
5
+ * The server provides concrete implementations via KFlowAccessLayer.
6
+ *
7
+ * Key property: each orbital is its own Firestore document.
8
+ * Two subagents writing different orbitals = zero contention.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ import type { WorkspaceSink, FileMeta } from '../types.js';
13
+ /**
14
+ * Injected dependencies for FirestoreSink.
15
+ * The server provides these — the agent package has no Firestore dependency.
16
+ */
17
+ export interface FirestoreSinkConfig {
18
+ /** User ID for Firestore document paths. */
19
+ userId: string;
20
+ /** App ID (may be assigned later on first schema write). */
21
+ appId?: string;
22
+ /** Save a single orbital to its own Firestore document. */
23
+ saveOrbital(orbitalName: string, orbital: unknown): Promise<void>;
24
+ /** Save schema metadata (name, version, config). */
25
+ saveSchema?(schema: unknown): Promise<{
26
+ appId: string;
27
+ }>;
28
+ /** Save memory updates (user preferences, project context). */
29
+ saveMemory?(memoryType: string, data: unknown): Promise<void>;
30
+ /** Callback when a new app is created (for SSE event emission). */
31
+ onAppCreated?(appId: string): void;
32
+ }
33
+ export declare class FirestoreSink implements WorkspaceSink {
34
+ readonly name = "firestore";
35
+ private readonly config;
36
+ constructor(config: FirestoreSinkConfig);
37
+ /** Update the appId after it's been assigned (e.g., on first schema write). */
38
+ setAppId(appId: string): void;
39
+ onFileWritten(_path: string, content: string, meta: FileMeta): Promise<void>;
40
+ onSessionEnd(_sessionId: string): Promise<void>;
41
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * GitSink — Auto-commit workspace file writes to a local git repository.
3
+ *
4
+ * Implements the WorkspaceSink interface. Every file write becomes a git commit
5
+ * with a structured message. Concurrent writes are serialized via a commit queue
6
+ * to prevent git lock contention (handles parallel subagent case).
7
+ *
8
+ * Optionally pushes to a remote GitHub repo on session end via `enablePush()`.
9
+ * Push failures are non-fatal (logged, local commits preserved).
10
+ *
11
+ * Gracefully degrades if git is not available (logs warning, no-ops).
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+ import type { WorkspaceSink, FileMeta } from '../types.js';
16
+ /**
17
+ * Configuration for pushing to a remote GitHub repository on session end.
18
+ */
19
+ export interface GitSinkPushConfig {
20
+ token: string;
21
+ branch: string;
22
+ repoUrl: string;
23
+ }
24
+ export declare class GitSink implements WorkspaceSink {
25
+ readonly name = "git";
26
+ private readonly client;
27
+ private commitQueue;
28
+ private available;
29
+ private pushConfig;
30
+ constructor(workspaceRoot: string);
31
+ /** Initialize the git repo. Must be called before onFileWritten. */
32
+ initialize(): Promise<void>;
33
+ /**
34
+ * Enable pushing to a remote GitHub repo on session end.
35
+ * Push failures are non-fatal — local commits are always preserved.
36
+ */
37
+ enablePush(config: GitSinkPushConfig): void;
38
+ /** Get the working directory path. */
39
+ getCwd(): string;
40
+ onFileWritten(path: string, _content: string, meta: FileMeta): Promise<void>;
41
+ onSessionEnd(sessionId: string): Promise<void>;
42
+ /**
43
+ * Push local commits to the remote GitHub repository.
44
+ * Non-fatal — failures are logged but do not throw.
45
+ */
46
+ private pushToRemote;
47
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Workspace Sinks
3
+ *
4
+ * Pluggable persistence backends for workspace file writes.
5
+ */
6
+ export { GitSink } from './git-sink.js';
7
+ export type { GitSinkPushConfig } from './git-sink.js';
8
+ export { FirestoreSink } from './firestore-sink.js';
9
+ export type { FirestoreSinkConfig } from './firestore-sink.js';
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Workspace Templates
3
+ *
4
+ * .orb memory file templates as TypeScript constants.
5
+ * These are written to `.almadar/` on workspace initialization.
6
+ *
7
+ * Reuses entity definitions from `memory-orbital.ts` for type consistency.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import type { OrbitalSchema } from '@almadar/core';
12
+ /**
13
+ * Create the user.orb template — tracks user preferences with a temporal learning trait.
14
+ *
15
+ * The `instances` field carries the living memory data.
16
+ * Git commits to this file ARE the state transitions over time.
17
+ */
18
+ export declare function createUserOrbTemplate(userId: string): OrbitalSchema;
19
+ /**
20
+ * Create the project.orb template — tracks project domain knowledge.
21
+ *
22
+ * Accumulates known entities, relations, and domain terms across sessions.
23
+ */
24
+ export declare function createProjectOrbTemplate(projectName: string, appId?: string): OrbitalSchema;
25
+ /**
26
+ * Create the schema.orb template — empty scaffold for a new generation.
27
+ */
28
+ export declare function createSchemaOrbTemplate(name: string): OrbitalSchema;
29
+ /** Serialize an OrbitalSchema to a formatted JSON string. */
30
+ export declare function serializeOrb(schema: OrbitalSchema): string;
31
+ /** Parse a JSON string into an OrbitalSchema. Returns null on parse failure. */
32
+ export declare function parseOrb(content: string): OrbitalSchema | null;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Workspace Types
3
+ *
4
+ * Core type definitions for the workspace-centric persistence architecture.
5
+ * The workspace is the central unit: files in a git-tracked directory,
6
+ * with pluggable sinks for Firestore, GitHub, etc.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ /** Standard directory structure inside a workspace. */
11
+ export declare const WORKSPACE_LAYOUT: {
12
+ /** Root directory for Almadar workspace state. */
13
+ readonly ALMADAR_DIR: ".almadar";
14
+ /** User preferences and learned patterns. */
15
+ readonly USER_MEMORY: ".almadar/user.orb";
16
+ /** Project-level domain knowledge. */
17
+ readonly PROJECT_MEMORY: ".almadar/project.orb";
18
+ /** The generation artifact (shared memory for all agents). */
19
+ readonly SCHEMA: ".almadar/schema.orb";
20
+ /** Individual orbital files (one per subagent). */
21
+ readonly ORBITALS_DIR: ".almadar/orbitals";
22
+ };
23
+ /** Classification of a file write for routing to appropriate sinks. */
24
+ export interface FileMeta {
25
+ /** What kind of file was written. */
26
+ fileType: 'schema' | 'orbital' | 'memory' | 'domain' | 'other';
27
+ /** Orbital name (only when fileType is 'orbital'). */
28
+ orbitalName?: string;
29
+ /** Session ID for attribution. */
30
+ sessionId?: string;
31
+ }
32
+ /**
33
+ * A pluggable persistence backend that reacts to workspace file writes.
34
+ *
35
+ * Sinks are registered with the SinkManager and notified on every file write.
36
+ * Each sink is independent — a failure in one does not affect others.
37
+ */
38
+ export interface WorkspaceSink {
39
+ /** Human-readable name for logging/diagnostics. */
40
+ readonly name: string;
41
+ /**
42
+ * Called when a file is written to the workspace.
43
+ * @param path - Relative path within the workspace root
44
+ * @param content - File content as a string
45
+ * @param meta - Classification metadata for routing
46
+ */
47
+ onFileWritten(path: string, content: string, meta: FileMeta): Promise<void>;
48
+ /**
49
+ * Called when the session ends. Used for cleanup, final sync, tagging, etc.
50
+ * @param sessionId - The session being ended
51
+ */
52
+ onSessionEnd(sessionId: string): Promise<void>;
53
+ }
54
+ /** Result of notifying a single sink. */
55
+ export interface SinkResult {
56
+ /** Which sink produced this result. */
57
+ sinkName: string;
58
+ /** Whether the sink operation succeeded. */
59
+ success: boolean;
60
+ /** Error details if the operation failed. */
61
+ error?: Error;
62
+ }
63
+ /** Configuration for initializing a workspace. */
64
+ export interface WorkspaceConfig {
65
+ /** Absolute path to the workspace root directory. */
66
+ rootDir: string;
67
+ /** User ID for memory file attribution. */
68
+ userId: string;
69
+ /** Session ID for git tags and logging. */
70
+ sessionId: string;
71
+ /** App ID (may be assigned later on first schema write). */
72
+ appId?: string;
73
+ /** Project name for the schema template. */
74
+ projectName?: string;
75
+ /** Whether to initialize git in the workspace. Defaults to true. */
76
+ gitEnabled?: boolean;
77
+ /** Sinks to register on initialization. */
78
+ sinks?: WorkspaceSink[];
79
+ }
80
+ /** Snapshot of all .orb memory file instances, read at session start. */
81
+ export interface MemorySnapshot {
82
+ /** User preferences from .almadar/user.orb instances. */
83
+ user: Record<string, unknown>[];
84
+ /** Project context from .almadar/project.orb instances. */
85
+ project: Record<string, unknown>[];
86
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * WorkspaceManager — Lifecycle management for agent workspaces.
3
+ *
4
+ * Handles initialization (create dirs, write .orb templates, git init),
5
+ * file write notifications (fan out to sinks), memory read/write,
6
+ * and session end (final commit, tag, cleanup).
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import type { WorkspaceConfig, FileMeta, SinkResult, MemorySnapshot } from './types.js';
11
+ import { SinkManager } from './sink-manager.js';
12
+ export declare class WorkspaceManager {
13
+ private readonly config;
14
+ private readonly sinkManager;
15
+ private gitSink;
16
+ private initialized;
17
+ constructor(config: WorkspaceConfig);
18
+ /** Get the absolute path to a workspace-relative path. */
19
+ resolve(relativePath: string): string;
20
+ /** Get the SinkManager for direct registration of additional sinks. */
21
+ get sinks(): SinkManager;
22
+ /**
23
+ * Initialize the workspace: create directories, write .orb templates,
24
+ * optionally initialize git.
25
+ *
26
+ * Safe to call multiple times — skips if already initialized.
27
+ */
28
+ initialize(): Promise<void>;
29
+ /**
30
+ * Notify sinks that a file was written.
31
+ * Call this from the server when the agent writes a file.
32
+ *
33
+ * @param relativePath - Path relative to workspace root
34
+ * @param content - File content as string
35
+ * @param meta - Optional metadata override (auto-inferred if not provided)
36
+ */
37
+ onFileWritten(relativePath: string, content: string, meta?: Partial<FileMeta>): Promise<SinkResult[]>;
38
+ /**
39
+ * Load memory from .orb files. Call at session start to provide
40
+ * the agent with user preferences and project context.
41
+ */
42
+ loadMemory(): Promise<MemorySnapshot>;
43
+ /**
44
+ * Update memory .orb file instances. Call at session end to
45
+ * persist learned preferences and discovered domain knowledge.
46
+ */
47
+ saveMemory(updates: {
48
+ user?: Record<string, unknown>[];
49
+ project?: Record<string, unknown>[];
50
+ }): Promise<void>;
51
+ /**
52
+ * End the session: notify all sinks, create git tag.
53
+ * Call from the server when the agent session completes.
54
+ */
55
+ endSession(): Promise<SinkResult[]>;
56
+ private writeTemplateIfMissing;
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/agent",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "AI agent infrastructure for Almadar orbital schema generation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -44,10 +44,10 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@almadar/core": ">=2.0.0",
47
- "@almadar/integrations": ">=2.0.0",
48
- "@almadar/llm": ">=2.0.0",
47
+ "@almadar/integrations": ">=2.0.1",
48
+ "@almadar/llm": ">=2.0.1",
49
49
  "@almadar/patterns": ">=2.0.0",
50
- "@almadar/skills": ">=2.0.0",
50
+ "@almadar/skills": ">=2.0.1",
51
51
  "uuid": "^9.0.0",
52
52
  "zod": "^3.22.0"
53
53
  },
@@ -82,7 +82,8 @@
82
82
  "deepagents": "^1.7.3",
83
83
  "tsup": "^8.0.0",
84
84
  "typescript": "^5.4.0",
85
- "vitest": "^3.0.0"
85
+ "vitest": "^3.0.0",
86
+ "@types/node": "^22.0.0"
86
87
  },
87
88
  "repository": {
88
89
  "type": "git",
@@ -99,7 +100,7 @@
99
100
  ],
100
101
  "homepage": "https://github.com/almadar-io/almadar#readme",
101
102
  "scripts": {
102
- "build": "tsup",
103
+ "build": "tsup && tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src --skipLibCheck || true",
103
104
  "build:watch": "tsup --watch",
104
105
  "test": "vitest run",
105
106
  "typecheck": "tsc --noEmit",