@almadar/agent 1.6.4 → 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.
- package/LICENSE +21 -72
- package/README.md +25 -0
- package/dist/agent/event-budget.d.ts +28 -0
- package/dist/agent/experimental/hitl-v2.d.ts +161 -0
- package/dist/agent/experimental/hitl-workflow-integration.d.ts +182 -0
- package/dist/agent/index.d.ts +14 -13
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/interrupt-config.d.ts +51 -0
- package/dist/agent/session-manager.d.ts +204 -0
- package/dist/agent/skill-agent.d.ts +182 -0
- package/dist/agent/workflow-middleware.d.ts +63 -0
- package/dist/agent/workflow-tool-wrapper.d.ts +87 -0
- package/dist/{api-types-CXrq-fts.d.ts → api-types.d.ts} +85 -51
- package/dist/context/compaction.d.ts +191 -0
- package/dist/context-compaction.d.ts +55 -0
- package/dist/evals/online-sampling.d.ts +114 -0
- package/dist/evals/utils/compact-orbital.d.ts +100 -0
- package/dist/event-transformer/event-transformer.d.ts +120 -0
- package/dist/event-transformer/index.d.ts +4 -122
- package/dist/events.d.ts +85 -0
- package/dist/index.d.ts +58 -1678
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/MemoryManager.d.ts +243 -0
- package/dist/memory/PreferenceLearner.d.ts +59 -0
- package/dist/memory/agentic-search.d.ts +116 -0
- package/dist/memory/index.d.ts +14 -0
- package/dist/memory/memory-orbital.d.ts +66 -0
- package/dist/memory/types.d.ts +143 -0
- package/dist/metrics.d.ts +77 -0
- package/dist/multi-user.d.ts +155 -0
- package/dist/observability/index.d.ts +14 -0
- package/dist/observability/langsmith-integration.d.ts +203 -0
- package/dist/observability.d.ts +196 -0
- package/dist/orbitals/archive/sanitize.d.ts +24 -0
- package/dist/orbitals/batch/batch-generator.d.ts +41 -0
- package/dist/orbitals/batch/concurrency.d.ts +54 -0
- package/dist/orbitals/batch/index.d.ts +14 -0
- package/dist/orbitals/batch/prompt-assembler.d.ts +92 -0
- package/dist/orbitals/batch/types.d.ts +103 -0
- package/dist/orbitals/cache/index.d.ts +11 -0
- package/dist/orbitals/cache/orbital-fingerprint.d.ts +37 -0
- package/dist/orbitals/cache/prompt-assembler.d.ts +65 -0
- package/dist/orbitals/cache/structural-templates.d.ts +33 -0
- package/dist/orbitals/combiner/index.d.ts +102 -0
- package/dist/orbitals/domain-language/index.d.ts +9 -0
- package/dist/orbitals/domain-language/prompts/index.d.ts +11 -0
- package/dist/orbitals/domain-language/prompts/odl-examples.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-patterns.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-syntax.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-to-schema.d.ts +8 -0
- package/dist/orbitals/generation/index.d.ts +10 -0
- package/dist/orbitals/generation/orbital-generator.d.ts +120 -0
- package/dist/orbitals/shared/constants.d.ts +65 -0
- package/dist/orbitals/shared/index.d.ts +11 -0
- package/dist/orbitals/shared/types.d.ts +187 -0
- package/dist/orbitals/shared/utils.d.ts +97 -0
- package/dist/orchestration/complexity-classifier.d.ts +38 -0
- package/dist/orchestration/fixing-orchestrator.d.ts +53 -0
- package/dist/orchestration/index.d.ts +31 -0
- package/dist/orchestration/provider-router.d.ts +45 -0
- package/dist/{firestore-checkpointer-CkNKXoun.d.ts → persistence/firestore-checkpointer.d.ts} +13 -58
- package/dist/persistence/firestore-session-store.d.ts +75 -0
- package/dist/persistence/firestore-store.d.ts +86 -0
- package/dist/persistence/index.d.ts +7 -198
- package/dist/persistence/memory-backend.d.ts +33 -0
- package/dist/persistence/types.d.ts +40 -0
- package/dist/security/audit-log.d.ts +44 -0
- package/dist/state-sync.d.ts +171 -0
- package/dist/subagents.d.ts +38 -0
- package/dist/tools/combine-schemas.d.ts +154 -0
- package/dist/tools/composition.d.ts +119 -0
- package/dist/{orbital-subagent-BdFuf77p.d.ts → tools/domain-orbital.d.ts} +22 -461
- package/dist/tools/execute.d.ts +38 -0
- package/dist/tools/finish-task.d.ts +56 -0
- package/dist/tools/generate-schema.d.ts +53 -0
- package/dist/tools/github.d.ts +297 -0
- package/dist/tools/index.d.ts +1318 -8
- package/dist/tools/orbital-batch-subagent.d.ts +85 -0
- package/dist/tools/orbital-subagent.d.ts +454 -0
- package/dist/tools/orchestrated-fixing.d.ts +74 -0
- package/dist/tools/orchestrated-generation.d.ts +75 -0
- package/dist/tools/sandbox-executor.d.ts +31 -0
- package/dist/tools/schema-chunking.d.ts +117 -0
- package/dist/tools/trait-subagent.d.ts +179 -0
- package/dist/tools/validate-schema.d.ts +17 -0
- package/dist/types.d.ts +14 -17
- package/dist/utils/safety/capability-token.d.ts +50 -0
- package/dist/utils/safety/circuit-breaker.d.ts +71 -0
- package/dist/utils/safety/index.d.ts +19 -0
- package/dist/utils/safety/rate-limiter.d.ts +39 -0
- package/dist/utils/safety/threshold-auth.d.ts +70 -0
- package/dist/workspace/git-client.d.ts +51 -0
- package/dist/workspace/index.d.ts +29 -346
- package/dist/workspace/index.js +39 -0
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/memory-files.d.ts +31 -0
- package/dist/workspace/sink-manager.d.ts +26 -0
- package/dist/workspace/sinks/firestore-sink.d.ts +41 -0
- package/dist/workspace/sinks/git-sink.d.ts +47 -0
- package/dist/workspace/sinks/index.d.ts +9 -0
- package/dist/workspace/templates.d.ts +32 -0
- package/dist/workspace/types.d.ts +86 -0
- package/dist/workspace/workspace-manager.d.ts +57 -0
- package/package.json +12 -10
- package/dist/index-DW3F-Ihx.d.ts +0 -2501
- package/dist/index-DZn69no8.d.ts +0 -1014
|
@@ -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
|
+
}
|
|
@@ -1,355 +1,38 @@
|
|
|
1
|
-
import { OrbitalSchema } from '@almadar/core';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
* Workspace
|
|
2
|
+
* Workspace Module
|
|
5
3
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* with pluggable sinks for Firestore, GitHub, etc.
|
|
4
|
+
* Workspace-centric persistence architecture for Almadar agents.
|
|
5
|
+
* Files in a git-tracked workspace, with pluggable sinks for Firestore, GitHub, etc.
|
|
9
6
|
*
|
|
10
|
-
*
|
|
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.
|
|
7
|
+
* ## Quick Start
|
|
253
8
|
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { WorkspaceManager, FirestoreSink } from '@almadar/agent/workspace';
|
|
256
11
|
*
|
|
257
|
-
*
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
*
|
|
262
|
-
*
|
|
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.
|
|
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
|
+
* });
|
|
310
19
|
*
|
|
311
|
-
*
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
*
|
|
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.
|
|
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
|
+
* ```
|
|
328
25
|
*
|
|
329
26
|
* @packageDocumentation
|
|
330
27
|
*/
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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 };
|
|
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';
|
package/dist/workspace/index.js
CHANGED
|
@@ -68,6 +68,10 @@ var GitClient = class {
|
|
|
68
68
|
constructor(cwd) {
|
|
69
69
|
this.cwd = cwd;
|
|
70
70
|
}
|
|
71
|
+
/** Get the working directory path. */
|
|
72
|
+
getCwd() {
|
|
73
|
+
return this.cwd;
|
|
74
|
+
}
|
|
71
75
|
/** Check if git is available on the system. */
|
|
72
76
|
static async isAvailable() {
|
|
73
77
|
try {
|
|
@@ -198,6 +202,7 @@ var GitSink = class {
|
|
|
198
202
|
this.name = "git";
|
|
199
203
|
this.commitQueue = Promise.resolve();
|
|
200
204
|
this.available = null;
|
|
205
|
+
this.pushConfig = null;
|
|
201
206
|
this.client = new GitClient(workspaceRoot);
|
|
202
207
|
}
|
|
203
208
|
/** Initialize the git repo. Must be called before onFileWritten. */
|
|
@@ -209,6 +214,17 @@ var GitSink = class {
|
|
|
209
214
|
}
|
|
210
215
|
await this.client.init();
|
|
211
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Enable pushing to a remote GitHub repo on session end.
|
|
219
|
+
* Push failures are non-fatal — local commits are always preserved.
|
|
220
|
+
*/
|
|
221
|
+
enablePush(config) {
|
|
222
|
+
this.pushConfig = config;
|
|
223
|
+
}
|
|
224
|
+
/** Get the working directory path. */
|
|
225
|
+
getCwd() {
|
|
226
|
+
return this.client.getCwd();
|
|
227
|
+
}
|
|
212
228
|
async onFileWritten(path, _content, meta) {
|
|
213
229
|
if (!this.available) return;
|
|
214
230
|
this.commitQueue = this.commitQueue.then(async () => {
|
|
@@ -230,6 +246,29 @@ var GitSink = class {
|
|
|
230
246
|
`session/${sessionId}`,
|
|
231
247
|
`Session ${sessionId} complete`
|
|
232
248
|
);
|
|
249
|
+
if (this.pushConfig) {
|
|
250
|
+
await this.pushToRemote();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Push local commits to the remote GitHub repository.
|
|
255
|
+
* Non-fatal — failures are logged but do not throw.
|
|
256
|
+
*/
|
|
257
|
+
async pushToRemote() {
|
|
258
|
+
if (!this.pushConfig) return;
|
|
259
|
+
const { token, branch, repoUrl } = this.pushConfig;
|
|
260
|
+
const cwd = this.client.getCwd();
|
|
261
|
+
try {
|
|
262
|
+
console.log(`[GitSink] Pushing to ${repoUrl} branch ${branch}...`);
|
|
263
|
+
const { push } = await import('@almadar/integrations/github');
|
|
264
|
+
await push({ branchName: branch, workDir: cwd }, cwd, token);
|
|
265
|
+
console.log(`[GitSink] Push successful`);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
console.error(
|
|
268
|
+
`[GitSink] Push failed (local commits preserved):`,
|
|
269
|
+
error instanceof Error ? error.message : error
|
|
270
|
+
);
|
|
271
|
+
}
|
|
233
272
|
}
|
|
234
273
|
};
|
|
235
274
|
function formatCommitMessage(path, meta) {
|