@almadar/workspace 0.1.0-alpha.0 → 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.
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Public surface types for `@almadar/workspace`.
3
+ *
4
+ * Six names total are exported from the package barrel; everything else
5
+ * is internal. See docs/Almadar_Workspace.md for the contract.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { JsonObject, JsonValue } from '@almadar/core';
10
+ /**
11
+ * The only extension point. Consumers register one observer via
12
+ * `service.subscribe(observer)`; every workspace write fans out
13
+ * through `onWrite`. Adding a new `WorkspaceWriteEvent.kind` is a
14
+ * compile-time forcing function for every consumer's switch.
15
+ */
16
+ export interface WorkspaceObserver {
17
+ onWrite(event: WorkspaceWriteEvent): Promise<void> | void;
18
+ }
19
+ /**
20
+ * Discriminated union covering every reason the workspace touches storage.
21
+ * Strict typed payload per variant — no `unknown`, no `any`.
22
+ *
23
+ * Consumers exhaust the union with
24
+ * `switch (event.kind) { …; default: const _: never = event; }`.
25
+ */
26
+ export type WorkspaceWriteEvent = {
27
+ kind: 'orbital';
28
+ name: string;
29
+ content: string;
30
+ } | {
31
+ kind: 'schema';
32
+ content: string;
33
+ } | {
34
+ kind: 'analysis';
35
+ content: JsonObject;
36
+ } | {
37
+ kind: 'plan';
38
+ content: JsonObject;
39
+ } | {
40
+ kind: 'clarifications';
41
+ content: Record<string, string>;
42
+ } | {
43
+ kind: 'coordinator-messages';
44
+ content: JsonValue[];
45
+ } | {
46
+ kind: 'spec';
47
+ orbital: string;
48
+ content: JsonObject;
49
+ } | {
50
+ kind: 'memory';
51
+ orbital: string;
52
+ content: JsonObject;
53
+ } | {
54
+ kind: 'history';
55
+ orbital: string;
56
+ entry: JsonObject;
57
+ } | {
58
+ kind: 'params-history';
59
+ orbital: string;
60
+ row: JsonObject;
61
+ } | {
62
+ kind: 'errors';
63
+ orbital: string;
64
+ content: JsonObject[];
65
+ } | {
66
+ kind: 'subagent-messages';
67
+ orbital: string;
68
+ content: JsonValue[];
69
+ } | {
70
+ kind: 'trace';
71
+ event: JsonObject;
72
+ } | {
73
+ kind: 'compiled';
74
+ relPath: string;
75
+ content: string;
76
+ } | {
77
+ kind: 'orbital-archived';
78
+ name: string;
79
+ } | {
80
+ kind: 'orbital-renamed';
81
+ from: string;
82
+ to: string;
83
+ } | {
84
+ kind: 'file';
85
+ relPath: string;
86
+ content: string;
87
+ };
88
+ /**
89
+ * Caller-supplied backend used when the local cache misses but the
90
+ * workspace state lives somewhere addressable (Firestore, S3, etc.).
91
+ * Zero vendor dependencies inside this package; the consumer supplies
92
+ * the network/SDK plumbing.
93
+ */
94
+ export interface RestoreBackend {
95
+ listFiles(): Promise<string[]>;
96
+ readFile(path: string): Promise<string | null>;
97
+ }
98
+ /**
99
+ * Opt-in git lifecycle config. When set on `openWorkspace`, the service
100
+ * exposes `commitAndPush` / `pullIfLinked` / `gitStatus`, and `dispose()`
101
+ * commits + pushes any pending changes.
102
+ */
103
+ export interface GitHubConfig {
104
+ token: string;
105
+ owner?: string;
106
+ repo?: string;
107
+ /** Optional remote URL when cloning on resume (https with token-auth). */
108
+ repoUrl?: string;
109
+ /** Default branch — `main` if unset. */
110
+ branch?: string;
111
+ }
112
+ /** Git working-tree snapshot returned by `gitStatus()`. */
113
+ export interface GitStatusInfo {
114
+ clean: boolean;
115
+ staged: string[];
116
+ modified: string[];
117
+ untracked: string[];
118
+ /** Resolved when an upstream remote+branch is configured. */
119
+ linked: boolean;
120
+ }
121
+ /** Single node returned by `listTree(relPath?)`. */
122
+ export interface FileTreeNode {
123
+ /** Workspace-relative POSIX path (forward slashes). */
124
+ path: string;
125
+ /** Directory or regular file. Symlinks are not followed. */
126
+ type: 'file' | 'directory';
127
+ /** Byte size for files; `0` for directories. */
128
+ size: number;
129
+ }
130
+ /**
131
+ * Factory input. Lifecycle resolution order: `adopt` → resume-from-disk →
132
+ * `restore` backend → `github` clone → mint fresh.
133
+ */
134
+ export interface OpenWorkspaceOptions {
135
+ /** Workspaces root, e.g. `/workspaces` — user dirs nest under it. */
136
+ root: string;
137
+ /** Owning user id. */
138
+ userId: string;
139
+ /** Resume an identified workspace, or promote later via `setAppId()`. */
140
+ appId?: string;
141
+ /** Adopt an existing absolute workDir as-is. */
142
+ adopt?: string;
143
+ /** Clone-on-resume / push-on-dispose configuration. */
144
+ github?: GitHubConfig;
145
+ /** Fallback fetcher used when the local cache misses. */
146
+ restore?: RestoreBackend;
147
+ /** Storage selector. `'memory'` is for tests; `'local'` is default. */
148
+ backend?: 'local' | 'memory';
149
+ /** Optional project name baked into the mint-time schema template. */
150
+ projectName?: string;
151
+ }
152
+ /**
153
+ * The single workspace I/O surface. Every consumer (rabit, apps/builder,
154
+ * cli, future tools) operates through this. Methods are grouped per
155
+ * docs/Almadar_Workspace.md §3.
156
+ *
157
+ * Generic parameters carry the caller's payload types through serialize +
158
+ * observer. The service stays neutral — it serializes JSON and emits typed
159
+ * `WorkspaceWriteEvent`s.
160
+ */
161
+ export interface WorkspaceService {
162
+ readonly appId: string | undefined;
163
+ readonly workDir: string;
164
+ setAppId(id: string): void;
165
+ readOrbital(name: string): string | null;
166
+ writeOrbital(name: string, content: string): Promise<void>;
167
+ listOrbitals(): string[];
168
+ archiveOrbital(name: string): Promise<void>;
169
+ renameOrbital(from: string, to: string): Promise<void>;
170
+ readSchema(): string | null;
171
+ writeSchema(content: string): Promise<void>;
172
+ readAnalysis<T extends JsonObject>(): T | null;
173
+ writeAnalysis<T extends JsonObject>(analysis: T): Promise<void>;
174
+ readPlan<T extends JsonObject>(): T | null;
175
+ writePlan<T extends JsonObject>(plan: T): Promise<void>;
176
+ readClarificationAnswers(): Record<string, string>;
177
+ writeClarificationAnswers(answers: Record<string, string>): Promise<void>;
178
+ readCoordinatorMessages<T extends JsonValue>(): T[] | null;
179
+ writeCoordinatorMessages<T extends JsonValue>(messages: T[]): Promise<void>;
180
+ readSpec<T extends JsonObject>(orbital: string): T | null;
181
+ writeSpec<T extends JsonObject>(orbital: string, spec: T): Promise<void>;
182
+ readMemory<T extends JsonObject>(orbital: string): T | null;
183
+ writeMemory<T extends JsonObject>(orbital: string, memory: T): Promise<void>;
184
+ appendHistory<T extends JsonObject>(orbital: string, entry: T): Promise<void>;
185
+ readHistory<T extends JsonObject>(orbital: string): T[];
186
+ appendParamsHistory<T extends JsonObject>(orbital: string, row: T): Promise<void>;
187
+ readErrors<T extends JsonObject>(orbital: string): T[];
188
+ writeErrors<T extends JsonObject>(orbital: string, errors: T[]): Promise<void>;
189
+ readSubagentMessages<T extends JsonValue>(orbital: string): T[] | null;
190
+ writeSubagentMessages<T extends JsonValue>(orbital: string, messages: T[]): Promise<void>;
191
+ emitTrace<T extends JsonObject>(event: T): Promise<void>;
192
+ readTrace<T extends JsonObject>(): T[];
193
+ writeCompiled(relPath: string, content: string): Promise<void>;
194
+ readCompiled(relPath: string): string | null;
195
+ clearCompiled(): Promise<void>;
196
+ readFile(relPath: string): Promise<string | null>;
197
+ writeFile(relPath: string, content: string): Promise<void>;
198
+ listTree(relPath?: string): Promise<FileTreeNode[]>;
199
+ exists(relPath: string): Promise<boolean>;
200
+ commitAndPush(opts: {
201
+ message: string;
202
+ tags?: string[];
203
+ }): Promise<{
204
+ sha: string;
205
+ } | null>;
206
+ pullIfLinked(): Promise<boolean>;
207
+ gitStatus(): Promise<GitStatusInfo>;
208
+ subscribe(observer: WorkspaceObserver): () => void;
209
+ dispose(): Promise<void>;
210
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/workspace",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.1.0",
4
4
  "description": "Storage-agnostic workspace primitives shared by Almadar consumers. One service, six exports, hidden paths, single observer. See docs/Almadar_Workspace.md.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",