@undefineds.co/linx 0.3.5 → 0.3.7

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 (172) hide show
  1. package/README.md +58 -23
  2. package/dist/generated/version.js +1 -1
  3. package/dist/generated/version.js.map +1 -1
  4. package/dist/index.js +334 -162
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/account-session.js +4 -8
  7. package/dist/lib/account-session.js.map +1 -1
  8. package/dist/lib/ai-command.js +228 -178
  9. package/dist/lib/ai-command.js.map +1 -1
  10. package/dist/lib/auto-mode/archive.js +38 -7
  11. package/dist/lib/auto-mode/archive.js.map +1 -1
  12. package/dist/lib/auto-mode/auth.js.map +1 -1
  13. package/dist/lib/auto-mode/display.js +71 -45
  14. package/dist/lib/auto-mode/display.js.map +1 -1
  15. package/dist/lib/auto-mode/format.js +9 -7
  16. package/dist/lib/auto-mode/format.js.map +1 -1
  17. package/dist/lib/auto-mode/hooks/claude.js +12 -2
  18. package/dist/lib/auto-mode/hooks/claude.js.map +1 -1
  19. package/dist/lib/auto-mode/hooks/codex.js +17 -7
  20. package/dist/lib/auto-mode/hooks/codex.js.map +1 -1
  21. package/dist/lib/auto-mode/hooks/index.js +28 -8
  22. package/dist/lib/auto-mode/hooks/index.js.map +1 -1
  23. package/dist/lib/auto-mode/pod-ai.js +20 -37
  24. package/dist/lib/auto-mode/pod-ai.js.map +1 -1
  25. package/dist/lib/auto-mode/pod-approval.js +124 -195
  26. package/dist/lib/auto-mode/pod-approval.js.map +1 -1
  27. package/dist/lib/auto-mode/pod-persistence.js +169 -90
  28. package/dist/lib/auto-mode/pod-persistence.js.map +1 -1
  29. package/dist/lib/auto-mode/runner.js +683 -81
  30. package/dist/lib/auto-mode/runner.js.map +1 -1
  31. package/dist/lib/auto-mode/secretary.js +186 -41
  32. package/dist/lib/auto-mode/secretary.js.map +1 -1
  33. package/dist/lib/auto-mode-command.js +32 -32
  34. package/dist/lib/auto-mode-command.js.map +1 -1
  35. package/dist/lib/chat-api.js +242 -50
  36. package/dist/lib/chat-api.js.map +1 -1
  37. package/dist/lib/codex-plugin/bridge.js +164 -17
  38. package/dist/lib/codex-plugin/bridge.js.map +1 -1
  39. package/dist/lib/codex-plugin/codex-native-proxy.js +370 -34
  40. package/dist/lib/codex-plugin/codex-native-proxy.js.map +1 -1
  41. package/dist/lib/credentials-store.js +33 -42
  42. package/dist/lib/credentials-store.js.map +1 -1
  43. package/dist/lib/linx-cloud-errors.js +61 -0
  44. package/dist/lib/linx-cloud-errors.js.map +1 -0
  45. package/dist/lib/linx-tui-contract.js +8 -5
  46. package/dist/lib/linx-tui-contract.js.map +1 -1
  47. package/dist/lib/login-command.js +9 -2
  48. package/dist/lib/login-command.js.map +1 -1
  49. package/dist/lib/models.js +3 -20
  50. package/dist/lib/models.js.map +1 -1
  51. package/dist/lib/oidc-auth.js +143 -17
  52. package/dist/lib/oidc-auth.js.map +1 -1
  53. package/dist/lib/oidc-session-storage.js +2 -6
  54. package/dist/lib/oidc-session-storage.js.map +1 -1
  55. package/dist/lib/pi-adapter/auto-input-controller.js +988 -0
  56. package/dist/lib/pi-adapter/auto-input-controller.js.map +1 -0
  57. package/dist/lib/pi-adapter/backend-command.js +2 -0
  58. package/dist/lib/pi-adapter/backend-command.js.map +1 -0
  59. package/dist/lib/pi-adapter/backend-credentials.js +80 -0
  60. package/dist/lib/pi-adapter/backend-credentials.js.map +1 -0
  61. package/dist/lib/pi-adapter/branding.js +246 -108
  62. package/dist/lib/pi-adapter/branding.js.map +1 -1
  63. package/dist/lib/pi-adapter/control-state.js +72 -0
  64. package/dist/lib/pi-adapter/control-state.js.map +1 -0
  65. package/dist/lib/pi-adapter/interactive.js +2634 -30
  66. package/dist/lib/pi-adapter/interactive.js.map +1 -1
  67. package/dist/lib/pi-adapter/pod-approval.js +382 -210
  68. package/dist/lib/pi-adapter/pod-approval.js.map +1 -1
  69. package/dist/lib/pi-adapter/pod-mirror-mapping.js +71 -17
  70. package/dist/lib/pi-adapter/pod-mirror-mapping.js.map +1 -1
  71. package/dist/lib/pi-adapter/pod-mirror.js +531 -64
  72. package/dist/lib/pi-adapter/pod-mirror.js.map +1 -1
  73. package/dist/lib/pi-adapter/pod-native.js +81 -85
  74. package/dist/lib/pi-adapter/pod-native.js.map +1 -1
  75. package/dist/lib/pi-adapter/pod-status-output.js +54 -0
  76. package/dist/lib/pi-adapter/pod-status-output.js.map +1 -0
  77. package/dist/lib/pi-adapter/runtime.js +458 -228
  78. package/dist/lib/pi-adapter/runtime.js.map +1 -1
  79. package/dist/lib/pi-adapter/session-control.js +509 -0
  80. package/dist/lib/pi-adapter/session-control.js.map +1 -0
  81. package/dist/lib/pi-adapter/session.js +35 -22
  82. package/dist/lib/pi-adapter/session.js.map +1 -1
  83. package/dist/lib/pi-adapter/stream.js +89 -32
  84. package/dist/lib/pi-adapter/stream.js.map +1 -1
  85. package/dist/lib/pi-adapter/sync-recovery.js +89 -0
  86. package/dist/lib/pi-adapter/sync-recovery.js.map +1 -0
  87. package/dist/lib/pi-adapter/web-fetch.js +13 -14
  88. package/dist/lib/pi-adapter/web-fetch.js.map +1 -1
  89. package/dist/lib/pod-chat-store.js +254 -78
  90. package/dist/lib/pod-chat-store.js.map +1 -1
  91. package/dist/lib/pod-data-session.js +156 -35
  92. package/dist/lib/pod-data-session.js.map +1 -1
  93. package/dist/lib/solid-auth-store.js +27 -0
  94. package/dist/lib/solid-auth-store.js.map +1 -0
  95. package/dist/lib/solid-auth.js +2 -4
  96. package/dist/lib/solid-auth.js.map +1 -1
  97. package/dist/lib/solid-client-credentials-login.js +100 -0
  98. package/dist/lib/solid-client-credentials-login.js.map +1 -0
  99. package/dist/lib/solid-local-store.js +31 -0
  100. package/dist/lib/solid-local-store.js.map +1 -0
  101. package/dist/lib/symphony/archive.js +328 -18
  102. package/dist/lib/symphony/archive.js.map +1 -1
  103. package/dist/lib/symphony/pod-projection.js +2222 -0
  104. package/dist/lib/symphony/pod-projection.js.map +1 -0
  105. package/dist/lib/symphony-command.js +602 -178
  106. package/dist/lib/symphony-command.js.map +1 -1
  107. package/dist/lib/sync-checkpoint-store.js +74 -0
  108. package/dist/lib/sync-checkpoint-store.js.map +1 -0
  109. package/dist/skills/symphony/SKILL.md +665 -0
  110. package/package.json +15 -9
  111. package/vendor/agent-runtime/dist/agent-runtime.d.ts +137 -0
  112. package/vendor/agent-runtime/dist/agent-runtime.js +211 -0
  113. package/vendor/agent-runtime/dist/auto-mode.d.ts +78 -13
  114. package/vendor/agent-runtime/dist/auto-mode.js +288 -31
  115. package/vendor/agent-runtime/dist/control-plane.d.ts +28 -0
  116. package/vendor/agent-runtime/dist/control-plane.js +79 -0
  117. package/vendor/agent-runtime/dist/file-sync.d.ts +157 -0
  118. package/vendor/agent-runtime/dist/file-sync.js +314 -0
  119. package/vendor/agent-runtime/dist/index.d.ts +7 -0
  120. package/vendor/agent-runtime/dist/index.js +7 -0
  121. package/vendor/agent-runtime/dist/reconciler.d.ts +117 -0
  122. package/vendor/agent-runtime/dist/reconciler.js +361 -0
  123. package/vendor/agent-runtime/dist/symphony.d.ts +128 -8
  124. package/vendor/agent-runtime/dist/symphony.js +362 -57
  125. package/vendor/agent-runtime/dist/sync.d.ts +271 -0
  126. package/vendor/agent-runtime/dist/sync.js +550 -0
  127. package/vendor/agent-runtime/dist/thread-reconciler-controller.d.ts +58 -0
  128. package/vendor/agent-runtime/dist/thread-reconciler-controller.js +137 -0
  129. package/vendor/agent-runtime/dist/turn-controller.js +2 -2
  130. package/vendor/agent-runtime/dist/wake-scheduler.d.ts +67 -0
  131. package/vendor/agent-runtime/dist/wake-scheduler.js +194 -0
  132. package/vendor/agent-runtime/package.json +8 -1
  133. package/vendor/pi-web-access/CHANGELOG.md +387 -0
  134. package/vendor/pi-web-access/LICENSE +21 -0
  135. package/vendor/pi-web-access/README.md +352 -0
  136. package/vendor/pi-web-access/activity.ts +101 -0
  137. package/vendor/pi-web-access/banner.png +0 -0
  138. package/vendor/pi-web-access/chrome-cookies.ts +322 -0
  139. package/vendor/pi-web-access/code-search.ts +107 -0
  140. package/vendor/pi-web-access/curator-page.ts +3359 -0
  141. package/vendor/pi-web-access/curator-server.ts +605 -0
  142. package/vendor/pi-web-access/exa.ts +520 -0
  143. package/vendor/pi-web-access/extract.ts +641 -0
  144. package/vendor/pi-web-access/gemini-api.ts +112 -0
  145. package/vendor/pi-web-access/gemini-search.ts +361 -0
  146. package/vendor/pi-web-access/gemini-url-context.ts +126 -0
  147. package/vendor/pi-web-access/gemini-web-config.ts +52 -0
  148. package/vendor/pi-web-access/gemini-web.ts +396 -0
  149. package/vendor/pi-web-access/github-api.ts +196 -0
  150. package/vendor/pi-web-access/github-extract.ts +634 -0
  151. package/vendor/pi-web-access/index.ts +2346 -0
  152. package/vendor/pi-web-access/package.json +45 -0
  153. package/vendor/pi-web-access/pdf-extract.ts +192 -0
  154. package/vendor/pi-web-access/perplexity.ts +195 -0
  155. package/vendor/pi-web-access/pi-web-fetch-demo.mp4 +0 -0
  156. package/vendor/pi-web-access/rsc-extract.ts +338 -0
  157. package/vendor/pi-web-access/skills/librarian/SKILL.md +195 -0
  158. package/vendor/pi-web-access/storage.ts +72 -0
  159. package/vendor/pi-web-access/summary-review.ts +276 -0
  160. package/vendor/pi-web-access/test/gemini-web-cookie-opt-in.test.mjs +41 -0
  161. package/vendor/pi-web-access/test/pdf-extract.test.mjs +95 -0
  162. package/vendor/pi-web-access/utils.ts +44 -0
  163. package/vendor/pi-web-access/video-extract.ts +378 -0
  164. package/vendor/pi-web-access/youtube-extract.ts +310 -0
  165. package/dist/lib/pi-adapter/auth.js +0 -68
  166. package/dist/lib/pi-adapter/auth.js.map +0 -1
  167. package/dist/lib/pi-adapter/pod-tools.js +0 -140
  168. package/dist/lib/pi-adapter/pod-tools.js.map +0 -1
  169. package/dist/skills/drizzle-solid/SKILL.md +0 -340
  170. package/dist/skills/pod-storage/SKILL.md +0 -100
  171. package/dist/skills/solid-modeling/SKILL.md +0 -274
  172. package/dist/skills/xpod-componentsjs/SKILL.md +0 -284
@@ -0,0 +1,157 @@
1
+ import { type LinxSyncAuthority, type LinxSyncCheckpointStore, type LinxSyncContext, type LinxSyncDirection, type LinxSyncOperationKind, type LinxSyncPlane, type LinxSyncRunResult } from './sync.js';
2
+ type MaybePromise<T> = T | Promise<T>;
3
+ export type FileSyncShape = 'file-to-file' | 'file-to-json-list';
4
+ export type FileSyncWriteMode = 'overwrite' | 'append';
5
+ export type FileSyncContent = string | Uint8Array;
6
+ export type FileSyncJsonRecord = Record<string, unknown>;
7
+ export interface FileSyncArtifactRef {
8
+ uri?: string;
9
+ local?: string;
10
+ contentType?: string;
11
+ etag?: string;
12
+ checksum?: string;
13
+ offset?: number;
14
+ size?: number;
15
+ updatedAt?: string;
16
+ metadata?: Record<string, unknown>;
17
+ }
18
+ export interface FileSyncReadResult {
19
+ uri?: string;
20
+ local?: string;
21
+ content: FileSyncContent;
22
+ contentType?: string;
23
+ etag?: string;
24
+ checksum?: string;
25
+ offset?: number;
26
+ size?: number;
27
+ updatedAt?: string;
28
+ metadata?: Record<string, unknown>;
29
+ }
30
+ export interface FileSyncWriteCondition {
31
+ etag?: string;
32
+ offset?: number;
33
+ }
34
+ export interface FileSyncWriteInput {
35
+ source: FileSyncArtifactRef;
36
+ target: FileSyncArtifactRef;
37
+ content: FileSyncContent;
38
+ contentType?: string;
39
+ mode: FileSyncWriteMode;
40
+ expectedTarget?: FileSyncWriteCondition;
41
+ metadata?: Record<string, unknown>;
42
+ }
43
+ export interface FileSyncWriteResult {
44
+ uri?: string;
45
+ local?: string;
46
+ contentType?: string;
47
+ etag?: string;
48
+ checksum?: string;
49
+ offset?: number;
50
+ size?: number;
51
+ updatedAt?: string;
52
+ bytesWritten?: number;
53
+ metadata?: Record<string, unknown>;
54
+ }
55
+ export interface FileSyncTaskContext {
56
+ signal?: AbortSignal;
57
+ now: () => Date;
58
+ metadata?: Record<string, unknown>;
59
+ sync: LinxSyncContext;
60
+ }
61
+ export type FileSyncRead = (ref: FileSyncArtifactRef, context: FileSyncTaskContext) => MaybePromise<FileSyncReadResult>;
62
+ export type FileSyncWrite = (input: FileSyncWriteInput, context: FileSyncTaskContext) => MaybePromise<FileSyncWriteResult | void>;
63
+ export interface FileSyncArtifactMaterializedEvent {
64
+ kind: 'artifact.materialized';
65
+ shape: 'file-to-file';
66
+ source: FileSyncArtifactRef;
67
+ target: FileSyncArtifactRef;
68
+ writeMode: FileSyncWriteMode;
69
+ contentType?: string;
70
+ bytesRead?: number;
71
+ bytesWritten?: number;
72
+ emittedAt: string;
73
+ metadata?: Record<string, unknown>;
74
+ }
75
+ export interface FileSyncRecordsMaterializedEvent {
76
+ kind: 'records.materialized';
77
+ shape: 'file-to-json-list';
78
+ source: FileSyncArtifactRef;
79
+ records: FileSyncJsonRecord[];
80
+ recordCount: number;
81
+ contentType?: string;
82
+ bytesRead?: number;
83
+ emittedAt: string;
84
+ metadata?: Record<string, unknown>;
85
+ }
86
+ export type FileSyncMaterializedEvent = FileSyncArtifactMaterializedEvent | FileSyncRecordsMaterializedEvent;
87
+ export interface FileSyncScopeOptions {
88
+ source: string;
89
+ target: string;
90
+ direction?: LinxSyncDirection;
91
+ plane?: LinxSyncPlane;
92
+ authority?: LinxSyncAuthority;
93
+ signal?: AbortSignal;
94
+ now?: () => Date;
95
+ metadata?: Record<string, unknown>;
96
+ checkpoint?: LinxSyncCheckpointStore;
97
+ checkpointId?: string | ((result: LinxSyncRunResult) => string);
98
+ onEvent?: (event: FileSyncMaterializedEvent, result: LinxSyncRunResult) => MaybePromise<void>;
99
+ onResult?: (result: LinxSyncRunResult) => MaybePromise<void>;
100
+ }
101
+ export interface FileSyncTaskOptionsBase<TEvent extends FileSyncMaterializedEvent> {
102
+ action?: string;
103
+ operationId?: string;
104
+ checkpointId?: string | ((result: LinxSyncRunResult) => string);
105
+ subject?: string | null;
106
+ kind?: LinxSyncOperationKind;
107
+ source?: string;
108
+ target?: string;
109
+ direction?: LinxSyncDirection;
110
+ plane?: LinxSyncPlane;
111
+ authority?: LinxSyncAuthority;
112
+ metadata?: Record<string, unknown>;
113
+ onEvent?: (event: TEvent, result: LinxSyncRunResult) => MaybePromise<void>;
114
+ onResult?: (result: LinxSyncRunResult) => MaybePromise<void>;
115
+ }
116
+ export interface FileToFileSyncTaskOptions extends FileSyncTaskOptionsBase<FileSyncArtifactMaterializedEvent> {
117
+ sourceFile: FileSyncArtifactRef;
118
+ targetFile: FileSyncArtifactRef;
119
+ read: FileSyncRead;
120
+ write: FileSyncWrite;
121
+ writeMode?: FileSyncWriteMode;
122
+ expectedTarget?: FileSyncWriteCondition;
123
+ requireAppendCondition?: boolean;
124
+ }
125
+ export interface FileToJsonListSyncTaskOptions extends FileSyncTaskOptionsBase<FileSyncRecordsMaterializedEvent> {
126
+ sourceFile: FileSyncArtifactRef;
127
+ read: FileSyncRead;
128
+ parse?: FileSyncJsonListParser;
129
+ parseOptions?: FileSyncJsonListParseOptions;
130
+ }
131
+ export interface FileSyncJsonListParseOptions {
132
+ format?: 'auto' | 'json' | 'jsonl';
133
+ allowSingleRecord?: boolean;
134
+ }
135
+ export type FileSyncJsonListParser = (content: FileSyncContent, options?: FileSyncJsonListParseOptions) => FileSyncJsonRecord[];
136
+ export declare class FileSyncScope {
137
+ private readonly options;
138
+ private readonly results;
139
+ private sequence;
140
+ constructor(options: FileSyncScopeOptions);
141
+ getResults(): LinxSyncRunResult[];
142
+ getLastResult(): LinxSyncRunResult | null;
143
+ fileToFile(options: FileToFileSyncTaskOptions): Promise<FileSyncArtifactMaterializedEvent>;
144
+ fileToJsonList(options: FileToJsonListSyncTaskOptions): Promise<FileSyncRecordsMaterializedEvent>;
145
+ private nextOperationId;
146
+ }
147
+ export declare function createFileSyncScope(options: FileSyncScopeOptions): FileSyncScope;
148
+ export declare function parseFileSyncJsonList(content: FileSyncContent, options?: FileSyncJsonListParseOptions): FileSyncJsonRecord[];
149
+ export declare function createFileSyncMetadata(input: {
150
+ action: string;
151
+ shape: FileSyncShape;
152
+ source?: FileSyncArtifactRef | null;
153
+ target?: FileSyncArtifactRef | null;
154
+ writeMode?: FileSyncWriteMode;
155
+ metadata?: Record<string, unknown> | null;
156
+ }): Record<string, unknown>;
157
+ export {};
@@ -0,0 +1,314 @@
1
+ import { runLinxSyncTask, } from './sync.js';
2
+ export class FileSyncScope {
3
+ options;
4
+ results = [];
5
+ sequence = 0;
6
+ constructor(options) {
7
+ this.options = options;
8
+ }
9
+ getResults() {
10
+ return [...this.results];
11
+ }
12
+ getLastResult() {
13
+ return this.results.length > 0 ? this.results[this.results.length - 1] : null;
14
+ }
15
+ async fileToFile(options) {
16
+ const action = options.action ?? defaultFileToFileAction(options.writeMode);
17
+ const writeMode = options.writeMode ?? 'overwrite';
18
+ const initialMetadata = createFileSyncMetadata({
19
+ action,
20
+ shape: 'file-to-file',
21
+ source: options.sourceFile,
22
+ target: options.targetFile,
23
+ writeMode,
24
+ metadata: {
25
+ ...this.options.metadata,
26
+ ...options.metadata,
27
+ },
28
+ });
29
+ const operationId = options.operationId ?? this.nextOperationId(action, options.subject ?? options.targetFile.local ?? options.targetFile.uri);
30
+ const run = await runLinxSyncTask({
31
+ operationId,
32
+ kind: options.kind ?? (writeMode === 'append' ? 'update' : 'upsert'),
33
+ description: action,
34
+ source: options.source ?? this.options.source,
35
+ target: options.target ?? this.options.target,
36
+ direction: options.direction ?? this.options.direction ?? 'local-to-core',
37
+ plane: options.plane ?? this.options.plane ?? 'projection',
38
+ authority: options.authority ?? this.options.authority ?? 'core',
39
+ signal: this.options.signal,
40
+ now: this.options.now,
41
+ checkpoint: this.options.checkpoint,
42
+ checkpointId: options.checkpointId ?? this.options.checkpointId ?? operationId,
43
+ initialMetadata,
44
+ metadata: (event) => ({
45
+ ...initialMetadata,
46
+ bytesRead: event.bytesRead,
47
+ bytesWritten: event.bytesWritten,
48
+ contentType: event.contentType,
49
+ }),
50
+ onResult: async (result) => {
51
+ this.results.push(result);
52
+ await this.options.onResult?.(result);
53
+ await options.onResult?.(result);
54
+ },
55
+ task: async (syncContext) => {
56
+ if (writeMode === 'append' && options.requireAppendCondition && !hasWriteCondition(options.expectedTarget)) {
57
+ throw new Error('Append file sync requires an expected target etag or offset.');
58
+ }
59
+ const context = createFileSyncTaskContext(syncContext);
60
+ const readResult = await options.read(options.sourceFile, context);
61
+ const contentType = readResult.contentType ?? options.sourceFile.contentType ?? options.targetFile.contentType;
62
+ const bytesRead = contentByteLength(readResult.content);
63
+ const rawWriteResult = await options.write({
64
+ source: mergeArtifactRef(options.sourceFile, readResult),
65
+ target: options.targetFile,
66
+ content: readResult.content,
67
+ contentType,
68
+ mode: writeMode,
69
+ expectedTarget: options.expectedTarget,
70
+ metadata: {
71
+ ...readResult.metadata,
72
+ ...options.metadata,
73
+ },
74
+ }, context);
75
+ const writeResult = normalizeFileSyncWriteResult(rawWriteResult);
76
+ const target = mergeArtifactRef(options.targetFile, writeResult);
77
+ const event = {
78
+ kind: 'artifact.materialized',
79
+ shape: 'file-to-file',
80
+ source: mergeArtifactRef(options.sourceFile, readResult),
81
+ target,
82
+ writeMode,
83
+ contentType: writeResult?.contentType ?? contentType,
84
+ bytesRead,
85
+ bytesWritten: writeResult?.bytesWritten ?? bytesRead,
86
+ emittedAt: context.now().toISOString(),
87
+ metadata: compactMetadata({
88
+ ...this.options.metadata,
89
+ ...options.metadata,
90
+ ...readResult.metadata,
91
+ ...writeResult?.metadata,
92
+ }),
93
+ };
94
+ return event;
95
+ },
96
+ });
97
+ await this.options.onEvent?.(run.value, run.result);
98
+ await options.onEvent?.(run.value, run.result);
99
+ return run.value;
100
+ }
101
+ async fileToJsonList(options) {
102
+ const action = options.action ?? 'file.records.materialize';
103
+ const initialMetadata = createFileSyncMetadata({
104
+ action,
105
+ shape: 'file-to-json-list',
106
+ source: options.sourceFile,
107
+ metadata: {
108
+ ...this.options.metadata,
109
+ ...options.metadata,
110
+ },
111
+ });
112
+ const operationId = options.operationId ?? this.nextOperationId(action, options.subject ?? options.sourceFile.local ?? options.sourceFile.uri);
113
+ const run = await runLinxSyncTask({
114
+ operationId,
115
+ kind: options.kind ?? 'upsert',
116
+ description: action,
117
+ source: options.source ?? this.options.source,
118
+ target: options.target ?? this.options.target,
119
+ direction: options.direction ?? this.options.direction ?? 'core-to-local',
120
+ plane: options.plane ?? this.options.plane ?? 'projection',
121
+ authority: options.authority ?? this.options.authority ?? 'core',
122
+ signal: this.options.signal,
123
+ now: this.options.now,
124
+ checkpoint: this.options.checkpoint,
125
+ checkpointId: options.checkpointId ?? this.options.checkpointId ?? operationId,
126
+ initialMetadata,
127
+ metadata: (event) => ({
128
+ ...initialMetadata,
129
+ bytesRead: event.bytesRead,
130
+ contentType: event.contentType,
131
+ recordCount: event.recordCount,
132
+ }),
133
+ onResult: async (result) => {
134
+ this.results.push(result);
135
+ await this.options.onResult?.(result);
136
+ await options.onResult?.(result);
137
+ },
138
+ task: async (syncContext) => {
139
+ const context = createFileSyncTaskContext(syncContext);
140
+ const readResult = await options.read(options.sourceFile, context);
141
+ const parser = options.parse ?? parseFileSyncJsonList;
142
+ const records = parser(readResult.content, options.parseOptions);
143
+ const event = {
144
+ kind: 'records.materialized',
145
+ shape: 'file-to-json-list',
146
+ source: mergeArtifactRef(options.sourceFile, readResult),
147
+ records,
148
+ recordCount: records.length,
149
+ contentType: readResult.contentType ?? options.sourceFile.contentType,
150
+ bytesRead: contentByteLength(readResult.content),
151
+ emittedAt: context.now().toISOString(),
152
+ metadata: compactMetadata({
153
+ ...this.options.metadata,
154
+ ...options.metadata,
155
+ ...readResult.metadata,
156
+ }),
157
+ };
158
+ return event;
159
+ },
160
+ });
161
+ await this.options.onEvent?.(run.value, run.result);
162
+ await options.onEvent?.(run.value, run.result);
163
+ return run.value;
164
+ }
165
+ nextOperationId(action, subject) {
166
+ const timestamp = (this.options.now?.() ?? new Date()).toISOString().replace(/[:.]/g, '-');
167
+ return `${this.options.source}:${action}:${normalizeOperationSegment(subject ?? 'file')}:${timestamp}:${++this.sequence}`;
168
+ }
169
+ }
170
+ export function createFileSyncScope(options) {
171
+ return new FileSyncScope(options);
172
+ }
173
+ export function parseFileSyncJsonList(content, options = {}) {
174
+ const format = options.format ?? 'auto';
175
+ const text = contentToText(content).trim();
176
+ if (!text) {
177
+ return [];
178
+ }
179
+ if (format === 'jsonl') {
180
+ return parseJsonLines(text);
181
+ }
182
+ if (format === 'json') {
183
+ return normalizeJsonList(JSON.parse(text), options);
184
+ }
185
+ try {
186
+ return normalizeJsonList(JSON.parse(text), options);
187
+ }
188
+ catch (error) {
189
+ if (!looksLikeJsonLines(text)) {
190
+ throw error;
191
+ }
192
+ return parseJsonLines(text);
193
+ }
194
+ }
195
+ export function createFileSyncMetadata(input) {
196
+ return compactMetadata({
197
+ action: input.action,
198
+ shape: input.shape,
199
+ artifacts: compactMetadata({
200
+ source: compactArtifactMetadataRef(input.source),
201
+ target: compactArtifactMetadataRef(input.target),
202
+ }),
203
+ contentType: input.source?.contentType ?? input.target?.contentType,
204
+ writeMode: input.writeMode,
205
+ ...input.metadata,
206
+ });
207
+ }
208
+ function compactArtifactMetadataRef(ref) {
209
+ if (!ref) {
210
+ return undefined;
211
+ }
212
+ const compacted = compactMetadata({
213
+ uri: ref.uri,
214
+ local: ref.local,
215
+ contentType: ref.contentType,
216
+ etag: ref.etag,
217
+ checksum: ref.checksum,
218
+ offset: ref.offset,
219
+ size: ref.size,
220
+ updatedAt: ref.updatedAt,
221
+ metadata: ref.metadata,
222
+ });
223
+ return Object.keys(compacted).length > 0 ? compacted : undefined;
224
+ }
225
+ function createFileSyncTaskContext(sync) {
226
+ return {
227
+ signal: sync.signal,
228
+ now: sync.now,
229
+ metadata: sync.metadata,
230
+ sync,
231
+ };
232
+ }
233
+ function mergeArtifactRef(base, patch) {
234
+ if (!patch) {
235
+ return { ...base };
236
+ }
237
+ return compactArtifactRef({
238
+ ...base,
239
+ uri: patch.uri ?? base.uri,
240
+ local: patch.local ?? base.local,
241
+ contentType: patch.contentType ?? base.contentType,
242
+ etag: patch.etag ?? base.etag,
243
+ checksum: patch.checksum ?? base.checksum,
244
+ offset: patch.offset ?? base.offset,
245
+ size: patch.size ?? base.size,
246
+ updatedAt: patch.updatedAt ?? base.updatedAt,
247
+ metadata: compactMetadata({
248
+ ...base.metadata,
249
+ ...patch.metadata,
250
+ }),
251
+ });
252
+ }
253
+ function compactArtifactRef(ref) {
254
+ return compactMetadata(ref);
255
+ }
256
+ function compactMetadata(input) {
257
+ const output = {};
258
+ for (const [key, value] of Object.entries(input)) {
259
+ if (value !== undefined && value !== null) {
260
+ output[key] = value;
261
+ }
262
+ }
263
+ return output;
264
+ }
265
+ function contentByteLength(content) {
266
+ return typeof content === 'string'
267
+ ? new TextEncoder().encode(content).byteLength
268
+ : content.byteLength;
269
+ }
270
+ function contentToText(content) {
271
+ return typeof content === 'string'
272
+ ? content
273
+ : new TextDecoder().decode(content);
274
+ }
275
+ function parseJsonLines(text) {
276
+ return text
277
+ .split(/\r?\n/)
278
+ .map((line) => line.trim())
279
+ .filter(Boolean)
280
+ .map((line) => normalizeJsonRecord(JSON.parse(line)));
281
+ }
282
+ function normalizeJsonList(value, options) {
283
+ if (Array.isArray(value)) {
284
+ return value.map(normalizeJsonRecord);
285
+ }
286
+ if (options.allowSingleRecord !== false) {
287
+ return [normalizeJsonRecord(value)];
288
+ }
289
+ throw new Error('Expected a JSON array of records.');
290
+ }
291
+ function normalizeJsonRecord(value) {
292
+ if (!isJsonRecord(value)) {
293
+ throw new Error('Expected JSON records to be objects.');
294
+ }
295
+ return value;
296
+ }
297
+ function isJsonRecord(value) {
298
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
299
+ }
300
+ function looksLikeJsonLines(text) {
301
+ return /\r?\n/.test(text);
302
+ }
303
+ function hasWriteCondition(value) {
304
+ return Boolean(value?.etag) || typeof value?.offset === 'number';
305
+ }
306
+ function normalizeFileSyncWriteResult(value) {
307
+ return typeof value === 'object' && value !== null ? value : undefined;
308
+ }
309
+ function defaultFileToFileAction(writeMode) {
310
+ return writeMode === 'append' ? 'file.append' : 'file.copy';
311
+ }
312
+ function normalizeOperationSegment(value) {
313
+ return value.replace(/[:\s]+/g, '-');
314
+ }
@@ -1,6 +1,13 @@
1
1
  export * from './acp.js';
2
+ export * from './agent-runtime.js';
2
3
  export * from './auto-mode.js';
3
4
  export * from './companion-model.js';
5
+ export * from './control-plane.js';
6
+ export * from './file-sync.js';
7
+ export * from './reconciler.js';
4
8
  export * from './runtime.js';
5
9
  export * from './symphony.js';
10
+ export * from './sync.js';
11
+ export * from './thread-reconciler-controller.js';
6
12
  export * from './turn-controller.js';
13
+ export * from './wake-scheduler.js';
@@ -1,6 +1,13 @@
1
1
  export * from './acp.js';
2
+ export * from './agent-runtime.js';
2
3
  export * from './auto-mode.js';
3
4
  export * from './companion-model.js';
5
+ export * from './control-plane.js';
6
+ export * from './file-sync.js';
7
+ export * from './reconciler.js';
4
8
  export * from './runtime.js';
5
9
  export * from './symphony.js';
10
+ export * from './sync.js';
11
+ export * from './thread-reconciler-controller.js';
6
12
  export * from './turn-controller.js';
13
+ export * from './wake-scheduler.js';
@@ -0,0 +1,117 @@
1
+ import type { AgentParticipantRole } from './turn-controller.js';
2
+ export type ThreadPolicyKind = 'direct' | 'auto' | 'symphony' | 'open_group' | 'review';
3
+ export type ThreadKind = 'main' | 'control' | 'worker' | 'review' | 'schedule' | 'schedule_run';
4
+ export type ReconcilerEventType = 'message.appended' | 'input.required' | 'approval.required' | 'delivery.submitted' | 'delivery.completed' | 'delivery.failed' | 'schedule.tick' | 'worker.blocked' | 'change.requested' | 'issue.updated' | 'task.updated' | 'run.updated' | (string & {});
5
+ export type ReconcilerActorRole = AgentParticipantRole | 'worker' | 'reviewer' | 'runtime' | 'scheduler' | 'tool' | 'assistant';
6
+ export type WakeJobTargetRole = AgentParticipantRole | 'worker' | 'reviewer';
7
+ export type WakeJobPriority = 'low' | 'normal' | 'high';
8
+ export type WakeJobStatus = 'queued';
9
+ export interface ReconcilerActorRef {
10
+ id?: string;
11
+ role?: ReconcilerActorRole;
12
+ label?: string;
13
+ }
14
+ export interface ReconcilerAgentRef {
15
+ id: string;
16
+ role?: WakeJobTargetRole;
17
+ aliases?: string[];
18
+ subscribed?: boolean;
19
+ }
20
+ export interface ThreadControlEvent<TData extends Record<string, unknown> = Record<string, unknown>> {
21
+ id?: string;
22
+ type: ReconcilerEventType;
23
+ chat?: string;
24
+ thread?: string;
25
+ resource?: string;
26
+ actor?: ReconcilerActorRef;
27
+ content?: string;
28
+ createdAt?: string;
29
+ data?: TData;
30
+ }
31
+ export interface ThreadPolicy {
32
+ kind: ThreadPolicyKind;
33
+ secretaryAgent?: string;
34
+ defaultAssistantAgent?: string;
35
+ assignedWorkerAgent?: string;
36
+ reviewerAgent?: string;
37
+ subscribedAgents?: string[];
38
+ agents?: ReconcilerAgentRef[];
39
+ }
40
+ export interface ThreadPlacement {
41
+ chat?: string;
42
+ thread: string;
43
+ kind: ThreadKind;
44
+ parentThread?: string;
45
+ rootThread?: string;
46
+ splitFrom?: string;
47
+ splitReason?: string;
48
+ }
49
+ export interface WakeJob {
50
+ id: string;
51
+ thread: string;
52
+ chat?: string;
53
+ targetAgent: string;
54
+ targetRole: WakeJobTargetRole;
55
+ trigger: ReconcilerEventType;
56
+ priority: WakeJobPriority;
57
+ status: WakeJobStatus;
58
+ reason: string;
59
+ sourceEventId?: string;
60
+ sourceEventType: ReconcilerEventType;
61
+ createdAt: string;
62
+ }
63
+ export interface ReconcileDecision {
64
+ id: string;
65
+ policyKind: ThreadPolicyKind;
66
+ event: ThreadControlEvent;
67
+ placement: ThreadPlacement;
68
+ wakeJobs: WakeJob[];
69
+ skippedReason?: string;
70
+ createdAt: string;
71
+ }
72
+ export interface WakeJobSummary {
73
+ id: string;
74
+ thread: string;
75
+ chat?: string;
76
+ targetAgent: string;
77
+ targetRole: WakeJobTargetRole;
78
+ trigger: ReconcilerEventType;
79
+ priority: WakeJobPriority;
80
+ status: WakeJobStatus;
81
+ reason: string;
82
+ sourceEventId?: string;
83
+ sourceEventType: ReconcilerEventType;
84
+ sourceResource?: string;
85
+ controlGate?: string;
86
+ }
87
+ export interface ReconcileDecisionSummary {
88
+ id: string;
89
+ policyKind: ThreadPolicyKind;
90
+ eventType: ReconcilerEventType;
91
+ thread: string;
92
+ chat?: string;
93
+ skippedReason?: string;
94
+ wakeJobs: WakeJobSummary[];
95
+ createdAt: string;
96
+ }
97
+ export interface ReconcileThreadEventInput {
98
+ policy: ThreadPolicyKind | ThreadPolicy;
99
+ event: ThreadControlEvent;
100
+ chat?: string;
101
+ thread?: string;
102
+ now?: Date;
103
+ randomId?: string;
104
+ }
105
+ export interface ThreadReconciler {
106
+ readonly policy: ThreadPolicy;
107
+ reconcile(event: ThreadControlEvent, options?: Omit<ReconcileThreadEventInput, 'policy' | 'event'>): ReconcileDecision;
108
+ }
109
+ export declare function createThreadReconciler(policy: ThreadPolicyKind | ThreadPolicy): ThreadReconciler;
110
+ export declare function reconcileThreadEvent(input: ReconcileThreadEventInput): ReconcileDecision;
111
+ export declare function summarizeReconcileDecision(decision: ReconcileDecision): ReconcileDecisionSummary;
112
+ export declare function resolveThreadPlacement(input: {
113
+ event: ThreadControlEvent;
114
+ chat?: string;
115
+ thread?: string;
116
+ randomId?: string;
117
+ }): ThreadPlacement;