@dsh-enhanced/lark-channel 0.1.65 → 0.1.67

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 (184) hide show
  1. package/README.md +25 -7
  2. package/cordis.patch.yml +1 -0
  3. package/docs/operations.md +1 -1
  4. package/docs/progress-security.md +3 -0
  5. package/docs/rsi-setup.md +13 -7
  6. package/docs/setup.md +2 -1
  7. package/lib/adapter.d.ts +8 -0
  8. package/lib/adapter.d.ts.map +1 -1
  9. package/lib/adapter.js +44 -7
  10. package/lib/adapter.js.map +1 -1
  11. package/lib/config.d.ts +6 -0
  12. package/lib/config.d.ts.map +1 -1
  13. package/lib/config.js +54 -8
  14. package/lib/config.js.map +1 -1
  15. package/lib/group-thread.d.ts +9 -0
  16. package/lib/group-thread.d.ts.map +1 -1
  17. package/lib/group-thread.js +16 -2
  18. package/lib/group-thread.js.map +1 -1
  19. package/lib/index.d.ts +5 -0
  20. package/lib/index.d.ts.map +1 -1
  21. package/lib/index.js +24 -1
  22. package/lib/index.js.map +1 -1
  23. package/lib/normalize.d.ts.map +1 -1
  24. package/lib/normalize.js +7 -4
  25. package/lib/normalize.js.map +1 -1
  26. package/lib/progress.d.ts +11 -1
  27. package/lib/progress.d.ts.map +1 -1
  28. package/lib/progress.js +13 -1
  29. package/lib/progress.js.map +1 -1
  30. package/lib/rsi-authority-runtime.d.ts +1 -0
  31. package/lib/rsi-authority-runtime.d.ts.map +1 -1
  32. package/lib/rsi-authority-runtime.js +17 -7
  33. package/lib/rsi-authority-runtime.js.map +1 -1
  34. package/lib/rsi-bootstrap-manifest.d.ts +17 -5
  35. package/lib/rsi-bootstrap-manifest.d.ts.map +1 -1
  36. package/lib/rsi-bootstrap-manifest.js +160 -10
  37. package/lib/rsi-bootstrap-manifest.js.map +1 -1
  38. package/lib/rsi-bootstrap.js +3 -3
  39. package/lib/rsi-bootstrap.js.map +1 -1
  40. package/lib/rsi-build.d.ts +12 -0
  41. package/lib/rsi-build.d.ts.map +1 -1
  42. package/lib/rsi-build.js +55 -5
  43. package/lib/rsi-build.js.map +1 -1
  44. package/lib/rsi-creation-build.d.ts +3 -0
  45. package/lib/rsi-creation-build.d.ts.map +1 -1
  46. package/lib/rsi-creation-build.js +45 -0
  47. package/lib/rsi-creation-build.js.map +1 -1
  48. package/lib/rsi-host-update.d.ts +51 -0
  49. package/lib/rsi-host-update.d.ts.map +1 -1
  50. package/lib/rsi-host-update.js +61 -1
  51. package/lib/rsi-host-update.js.map +1 -1
  52. package/lib/rsi-install.d.ts +15 -3
  53. package/lib/rsi-install.d.ts.map +1 -1
  54. package/lib/rsi-install.js +80 -15
  55. package/lib/rsi-install.js.map +1 -1
  56. package/lib/rsi-linux-cgroup-roots.d.ts +3 -0
  57. package/lib/rsi-linux-cgroup-roots.d.ts.map +1 -0
  58. package/lib/rsi-linux-cgroup-roots.js +3 -0
  59. package/lib/rsi-linux-cgroup-roots.js.map +1 -0
  60. package/lib/rsi-linux-creation-build.d.ts +36 -0
  61. package/lib/rsi-linux-creation-build.d.ts.map +1 -0
  62. package/lib/rsi-linux-creation-build.js +213 -0
  63. package/lib/rsi-linux-creation-build.js.map +1 -0
  64. package/lib/rsi-linux-native-materialize.d.ts +31 -0
  65. package/lib/rsi-linux-native-materialize.d.ts.map +1 -0
  66. package/lib/rsi-linux-native-materialize.js +162 -0
  67. package/lib/rsi-linux-native-materialize.js.map +1 -0
  68. package/lib/rsi-linux-native-relocation.d.ts +120 -0
  69. package/lib/rsi-linux-native-relocation.d.ts.map +1 -0
  70. package/lib/rsi-linux-native-relocation.js +1555 -0
  71. package/lib/rsi-linux-native-relocation.js.map +1 -0
  72. package/lib/rsi-linux-native-resources.d.ts +97 -0
  73. package/lib/rsi-linux-native-resources.d.ts.map +1 -0
  74. package/lib/rsi-linux-native-resources.js +521 -0
  75. package/lib/rsi-linux-native-resources.js.map +1 -0
  76. package/lib/rsi-linux-repository-bootstrap.d.ts +17 -0
  77. package/lib/rsi-linux-repository-bootstrap.d.ts.map +1 -0
  78. package/lib/rsi-linux-repository-bootstrap.js +317 -0
  79. package/lib/rsi-linux-repository-bootstrap.js.map +1 -0
  80. package/lib/rsi-linux-runner-states.d.ts +20 -0
  81. package/lib/rsi-linux-runner-states.d.ts.map +1 -0
  82. package/lib/rsi-linux-runner-states.js +70 -0
  83. package/lib/rsi-linux-runner-states.js.map +1 -0
  84. package/lib/rsi-linux-runtime-bootstrap.d.ts +10 -0
  85. package/lib/rsi-linux-runtime-bootstrap.d.ts.map +1 -0
  86. package/lib/rsi-linux-runtime-bootstrap.js +38 -0
  87. package/lib/rsi-linux-runtime-bootstrap.js.map +1 -0
  88. package/lib/rsi-linux-source-build.d.ts +28 -0
  89. package/lib/rsi-linux-source-build.d.ts.map +1 -0
  90. package/lib/rsi-linux-source-build.js +43 -0
  91. package/lib/rsi-linux-source-build.js.map +1 -0
  92. package/lib/rsi-local-install.d.ts +2 -0
  93. package/lib/rsi-local-install.d.ts.map +1 -1
  94. package/lib/rsi-local-install.js +42 -1
  95. package/lib/rsi-local-install.js.map +1 -1
  96. package/lib/rsi-local-pair-install.d.ts +15 -0
  97. package/lib/rsi-local-pair-install.d.ts.map +1 -1
  98. package/lib/rsi-local-pair-install.js +21 -6
  99. package/lib/rsi-local-pair-install.js.map +1 -1
  100. package/lib/rsi-local-resources.d.ts +2 -2
  101. package/lib/rsi-local-resources.d.ts.map +1 -1
  102. package/lib/rsi-local-resources.js +5 -0
  103. package/lib/rsi-local-resources.js.map +1 -1
  104. package/lib/rsi-local-update-build.d.ts +25 -6
  105. package/lib/rsi-local-update-build.d.ts.map +1 -1
  106. package/lib/rsi-local-update-build.js +46 -7
  107. package/lib/rsi-local-update-build.js.map +1 -1
  108. package/lib/rsi-local-update.d.ts +5 -2
  109. package/lib/rsi-local-update.d.ts.map +1 -1
  110. package/lib/rsi-local-update.js +6 -5
  111. package/lib/rsi-local-update.js.map +1 -1
  112. package/lib/rsi-memory-learning.d.ts +7 -1
  113. package/lib/rsi-memory-learning.d.ts.map +1 -1
  114. package/lib/rsi-memory-learning.js +11 -4
  115. package/lib/rsi-memory-learning.js.map +1 -1
  116. package/lib/rsi-native-install.d.ts.map +1 -1
  117. package/lib/rsi-native-install.js +12 -1
  118. package/lib/rsi-native-install.js.map +1 -1
  119. package/lib/rsi-native-profile.d.ts +8 -0
  120. package/lib/rsi-native-profile.d.ts.map +1 -1
  121. package/lib/rsi-native-profile.js +102 -4
  122. package/lib/rsi-native-profile.js.map +1 -1
  123. package/lib/rsi-ordinary-use-learning.d.ts +60 -0
  124. package/lib/rsi-ordinary-use-learning.d.ts.map +1 -0
  125. package/lib/rsi-ordinary-use-learning.js +103 -0
  126. package/lib/rsi-ordinary-use-learning.js.map +1 -0
  127. package/lib/rsi-plugin-creation.d.ts +16 -1
  128. package/lib/rsi-plugin-creation.d.ts.map +1 -1
  129. package/lib/rsi-plugin-creation.js +60 -14
  130. package/lib/rsi-plugin-creation.js.map +1 -1
  131. package/lib/rsi-plugin-revision.d.ts +35 -0
  132. package/lib/rsi-plugin-revision.d.ts.map +1 -0
  133. package/lib/rsi-plugin-revision.js +200 -0
  134. package/lib/rsi-plugin-revision.js.map +1 -0
  135. package/lib/rsi-profile.d.ts +11 -0
  136. package/lib/rsi-profile.d.ts.map +1 -1
  137. package/lib/rsi-profile.js +109 -3
  138. package/lib/rsi-profile.js.map +1 -1
  139. package/lib/rsi-release-build.d.ts +24 -8
  140. package/lib/rsi-release-build.d.ts.map +1 -1
  141. package/lib/rsi-release-build.js +89 -37
  142. package/lib/rsi-release-build.js.map +1 -1
  143. package/lib/rsi-scanner-retirement-config.d.ts +34 -0
  144. package/lib/rsi-scanner-retirement-config.d.ts.map +1 -0
  145. package/lib/rsi-scanner-retirement-config.js +272 -0
  146. package/lib/rsi-scanner-retirement-config.js.map +1 -0
  147. package/lib/rsi-scanner-retirement-runtime.d.ts +23 -0
  148. package/lib/rsi-scanner-retirement-runtime.d.ts.map +1 -0
  149. package/lib/rsi-scanner-retirement-runtime.js +98 -0
  150. package/lib/rsi-scanner-retirement-runtime.js.map +1 -0
  151. package/lib/rsi-scanner-retirement-stage.d.ts +55 -0
  152. package/lib/rsi-scanner-retirement-stage.d.ts.map +1 -0
  153. package/lib/rsi-scanner-retirement-stage.js +183 -0
  154. package/lib/rsi-scanner-retirement-stage.js.map +1 -0
  155. package/lib/rsi-scanner-retirement-transition.d.ts +57 -0
  156. package/lib/rsi-scanner-retirement-transition.d.ts.map +1 -0
  157. package/lib/rsi-scanner-retirement-transition.js +320 -0
  158. package/lib/rsi-scanner-retirement-transition.js.map +1 -0
  159. package/lib/rsi-setup.d.ts +24 -0
  160. package/lib/rsi-setup.d.ts.map +1 -1
  161. package/lib/rsi-setup.js +122 -7
  162. package/lib/rsi-setup.js.map +1 -1
  163. package/lib/rsi-source-maintenance.d.ts +9 -1
  164. package/lib/rsi-source-maintenance.d.ts.map +1 -1
  165. package/lib/rsi-source-maintenance.js +64 -5
  166. package/lib/rsi-source-maintenance.js.map +1 -1
  167. package/lib/rsi-source-update.js +2 -2
  168. package/lib/rsi-source-update.js.map +1 -1
  169. package/lib/sdk.d.ts +3 -1
  170. package/lib/sdk.d.ts.map +1 -1
  171. package/lib/sdk.js +8 -2
  172. package/lib/sdk.js.map +1 -1
  173. package/lib/service.d.ts.map +1 -1
  174. package/lib/service.js +2 -0
  175. package/lib/service.js.map +1 -1
  176. package/lib/setup-profile.d.ts.map +1 -1
  177. package/lib/setup-profile.js +1 -0
  178. package/lib/setup-profile.js.map +1 -1
  179. package/lib/types.d.ts +4 -0
  180. package/lib/types.d.ts.map +1 -1
  181. package/lib/types.js.map +1 -1
  182. package/lib/version.d.ts +1 -1
  183. package/lib/version.js +1 -1
  184. package/package.json +21 -21
@@ -0,0 +1,320 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { externalPrincipalId, ownerRouteAuthorityHash } from '@dsh-enhanced/assistant-delivery';
3
+ const scannerPrefixes = {
4
+ 'assistant-memory-learning': 'memory-scan-',
5
+ 'assistant-growth-usage': 'usage-scan-',
6
+ 'plugin-control-plane-task-observations': 'task-observation-scan-',
7
+ 'plugin-control-plane-live-qualification': 'live-qualification-scan-',
8
+ };
9
+ export const scannerRetirementTransitionProtocol = 'lark-channel/scanner-retirement-transition/v1';
10
+ export class ScannerRetirementTransitionError extends Error {
11
+ code;
12
+ constructor(code) {
13
+ super(`scanner retirement transition rejected: ${code}`);
14
+ this.code = code;
15
+ this.name = 'ScannerRetirementTransitionError';
16
+ }
17
+ }
18
+ const digestPattern = /^[a-f0-9]{64}$/u;
19
+ const digest = (value) => createHash('sha256').update(value).digest('hex');
20
+ const jsonDigest = (value) => digest(JSON.stringify(value));
21
+ const integer = (value, minimum = 0) => typeof value === 'number'
22
+ && Number.isSafeInteger(value) && value >= minimum;
23
+ function reject(code) { throw new ScannerRetirementTransitionError(code); }
24
+ function canonicalJson(value) {
25
+ if (value === null || typeof value !== 'object')
26
+ return JSON.stringify(value);
27
+ if (Array.isArray(value))
28
+ return `[${value.map(canonicalJson).join(',')}]`;
29
+ const object = value;
30
+ return `{${Object.keys(object).sort().map(key => `${JSON.stringify(key)}:${canonicalJson(object[key])}`).join(',')}}`;
31
+ }
32
+ function same(left, right) { return canonicalJson(left) === canonicalJson(right); }
33
+ function freeze(value) {
34
+ if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
35
+ Object.values(value).forEach(freeze);
36
+ Object.freeze(value);
37
+ }
38
+ return value;
39
+ }
40
+ function uniqueMap(items, key, code) {
41
+ const result = new Map();
42
+ for (const item of items) {
43
+ const identity = key(item);
44
+ if (result.has(identity))
45
+ reject(code);
46
+ result.set(identity, item);
47
+ }
48
+ return result;
49
+ }
50
+ const markerKey = (marker) => JSON.stringify([marker.owner, marker.automationId]);
51
+ const schemaKey = (entry) => JSON.stringify([entry.type, entry.name]);
52
+ /** Reconstruct the exact scope insertion order passed by each production scanner runtime. */
53
+ function ownerEvidence(proof) {
54
+ if (proof.protocol !== 'assistant-delivery/revoked-owner-route-snapshot/v1'
55
+ || ![23, 24, 25, 26, 27, 28, 29, 30, 31].includes(proof.schemaVersion)
56
+ || !integer(proof.frozenPrincipalVersion, 1) || !digestPattern.test(proof.snapshotDigest))
57
+ reject('invalid-proof');
58
+ const authority = proof.authority;
59
+ const authorityHash = ownerRouteAuthorityHash(authority);
60
+ // The public hash function validates the full authority and canonicalizes it.
61
+ // Rebuild canonical field order to reject noncanonical values while accepting
62
+ // arbitrary incoming JSON key order, without importing another bundle's internals.
63
+ const conversation = authority.conversation;
64
+ const principal = authority.principal;
65
+ const orderedAuthority = {
66
+ id: authority.id,
67
+ conversation: { channel: conversation.channel, account: conversation.account, tenant: conversation.tenant,
68
+ kind: conversation.kind, chat: conversation.chat, ...(conversation.thread === undefined ? {} : { thread: conversation.thread }) },
69
+ principal: { channel: principal.channel, account: principal.account, tenant: principal.tenant, user: principal.user },
70
+ workspace: authority.workspace, agentPreset: authority.agentPreset, policyRef: authority.policyRef,
71
+ minimumGeneration: authority.minimumGeneration,
72
+ };
73
+ if (jsonDigest(orderedAuthority) !== authorityHash)
74
+ reject('invalid-proof');
75
+ const state = proof.state;
76
+ if (state.status !== 'revoked' || state.authorityId !== authority.id || state.authorityHash !== authorityHash
77
+ || state.principalId !== externalPrincipalId(principal)
78
+ || typeof state.principalRecordId !== 'string' || !/^principal_[0-9a-f-]{8,}$/u.test(state.principalRecordId)
79
+ || !integer(state.principalVersion, 1) || state.principalVersion < proof.frozenPrincipalVersion)
80
+ reject('invalid-proof');
81
+ const orderedState = { status: 'revoked', authorityId: authority.id, authorityHash,
82
+ principalId: externalPrincipalId(principal), principalRecordId: state.principalRecordId, principalVersion: state.principalVersion };
83
+ if (!same(state, orderedState))
84
+ reject('invalid-proof');
85
+ const { snapshotDigest, ...unsigned } = proof;
86
+ if (digest(canonicalJson(unsigned)) !== snapshotDigest)
87
+ reject('invalid-proof');
88
+ return owner => jsonDigest({ protocol: 'scanner-owner-revoked/v1',
89
+ scope: { authorityId: authority.id, principalId: orderedState.principalId,
90
+ workspace: authority.workspace, agentPreset: authority.agentPreset,
91
+ ...(owner === 'assistant-memory-learning' ? { expectedOwner: { authorityHash,
92
+ principalRecordId: orderedState.principalRecordId, principalVersion: proof.frozenPrincipalVersion } } : {}) },
93
+ state: orderedState });
94
+ }
95
+ function stableDefinition(record) {
96
+ const { status: _status, nextRunAt: _nextRunAt, updatedAt: _updatedAt, version: _version, ...stable } = record;
97
+ return stable;
98
+ }
99
+ /** Reproduce SQLite ADD COLUMN's insertion before the table constraints. */
100
+ function addRunQuiescenceColumnSql(sql) {
101
+ if (sql === null)
102
+ return undefined;
103
+ let depth = 0;
104
+ // Skip quoted strings/identifiers and comments when finding structural commas.
105
+ const tokens = /'(?:''|[^'])*'|"(?:""|[^"])*"|`(?:``|[^`])*`|\[[^\]]*\]|--[^\n]*|\/\*[\s\S]*?\*\/|[(),]/gu;
106
+ for (const token of sql.matchAll(tokens)) {
107
+ if (token[0] === '(')
108
+ depth++;
109
+ if (token[0] === ')') {
110
+ depth--;
111
+ if (depth === 0)
112
+ return `${sql.slice(0, token.index)}, quiescent INTEGER CHECK(quiescent IN (0, 1))${sql.slice(token.index)}`;
113
+ }
114
+ if (token[0] === ',' && depth === 1
115
+ && /^\s*(?:CHECK|CONSTRAINT|FOREIGN\s+KEY|PRIMARY\s+KEY|UNIQUE)\b/iu.test(sql.slice(token.index + 1))) {
116
+ return `${sql.slice(0, token.index)}, quiescent INTEGER CHECK(quiescent IN (0, 1))${sql.slice(token.index)}`;
117
+ }
118
+ }
119
+ return undefined;
120
+ }
121
+ function verifySchema(before, after) {
122
+ const original = uniqueMap(before.schemaEntries, schemaKey, 'schema-changed');
123
+ const current = uniqueMap(after.schemaEntries, schemaKey, 'schema-changed');
124
+ const upgradesQuiescence = before.schemaVersion < 17 && after.schemaVersion === 17;
125
+ for (const [key, entry] of original) {
126
+ const updated = current.get(key);
127
+ if (upgradesQuiescence && entry.type === 'table' && entry.name === 'automation_runs') {
128
+ // Preserve every byte of the pre-existing SQL, including table constraints.
129
+ const expectedSql = addRunQuiescenceColumnSql(entry.sql);
130
+ if (typeof expectedSql !== 'string' || expectedSql === entry.sql
131
+ || !same({ ...entry, sql: expectedSql }, updated))
132
+ reject('schema-changed');
133
+ }
134
+ else if (!same(entry, updated))
135
+ reject('schema-changed');
136
+ }
137
+ if (before.schemaVersion === after.schemaVersion) {
138
+ if (original.size !== current.size || !same(before.schemaEntries, after.schemaEntries)
139
+ || before.schemaDigest !== after.schemaDigest)
140
+ reject('schema-changed');
141
+ return;
142
+ }
143
+ // Formal readers verify the exact retirement table/trigger SQL. Preserve the
144
+ // historical seven-identity v15->v16 allowance; upgrading to v17 additionally
145
+ // permits only the exact run quiescence column and immutable trigger.
146
+ const additions = before.schemaVersion === 15 ? [
147
+ { type: 'table', name: 'automation_system_retirements', table: 'automation_system_retirements', sql: '' },
148
+ { type: 'index', name: 'sqlite_autoindex_automation_system_retirements_1', table: 'automation_system_retirements', sql: null },
149
+ { type: 'index', name: 'sqlite_autoindex_automation_system_retirements_2', table: 'automation_system_retirements', sql: null },
150
+ { type: 'trigger', name: 'automation_retirements_no_update', table: 'automation_system_retirements', sql: '' },
151
+ { type: 'trigger', name: 'automation_retirements_no_delete', table: 'automation_system_retirements', sql: '' },
152
+ { type: 'trigger', name: 'automation_retired_no_activate_insert', table: 'automation_definitions', sql: '' },
153
+ { type: 'trigger', name: 'automation_retired_no_activate_update', table: 'automation_definitions', sql: '' },
154
+ ] : [];
155
+ if (upgradesQuiescence)
156
+ additions.push({ type: 'trigger', name: 'automation_run_quiescence_immutable',
157
+ table: 'automation_runs', sql: `CREATE TRIGGER automation_run_quiescence_immutable\n BEFORE UPDATE OF quiescent ON automation_runs WHEN NEW.quiescent IS NOT OLD.quiescent\n BEGIN SELECT RAISE(ABORT, 'run quiescence observation is immutable'); END` });
158
+ const allowed = new Map(additions.map(entry => [schemaKey(entry), entry]));
159
+ if (current.size !== original.size + allowed.size)
160
+ reject('schema-changed');
161
+ for (const [key, entry] of current) {
162
+ if (original.has(key))
163
+ continue;
164
+ const expected = allowed.get(key);
165
+ if (expected === undefined || entry.table !== expected.table
166
+ || (entry.name === 'automation_run_quiescence_immutable' && entry.sql !== expected.sql)
167
+ || (expected.sql === null ? entry.sql !== null : typeof entry.sql !== 'string' || entry.sql.length === 0))
168
+ reject('schema-changed');
169
+ allowed.delete(key);
170
+ }
171
+ if (allowed.size !== 0)
172
+ reject('schema-changed');
173
+ }
174
+ /**
175
+ * Freeze the exact operations before any staged service is mounted. Inputs have
176
+ * the same trusted-reader and independently derived configuration requirements
177
+ * as transition verification. These tuples confer no permission: the writer must
178
+ * use the formal Automations service and retain them unchanged across retries.
179
+ */
180
+ export function prepareScannerRetirementOperations(input) {
181
+ try {
182
+ const { before, ownerProof } = input;
183
+ if (before.protocol !== 'assistant-automations/retirement-snapshot/v1'
184
+ || ![15, 16, 17].includes(before.schemaVersion) || before.inFlightCount !== 0
185
+ || !digestPattern.test(before.snapshotDigest))
186
+ reject('invalid-proof');
187
+ const evidenceForOwner = ownerEvidence(ownerProof);
188
+ if (!Array.isArray(input.targets) || input.targets.length > 4)
189
+ reject('invalid-targets');
190
+ const originals = uniqueMap(before.records, record => record.id, 'definitions-changed');
191
+ const oldMarkers = uniqueMap(before.retirements, markerKey, 'retirements-changed');
192
+ if (before.schemaVersion === 15 && oldMarkers.size !== 0)
193
+ reject('retirements-changed');
194
+ const owners = new Set();
195
+ return freeze(input.targets.map((inputTarget) => {
196
+ const target = { owner: inputTarget.owner, automationId: inputTarget.automationId };
197
+ const prefix = Object.hasOwn(scannerPrefixes, target.owner) ? scannerPrefixes[target.owner] : undefined;
198
+ if (!same(target, inputTarget) || prefix === undefined || typeof target.automationId !== 'string'
199
+ || !new RegExp(`^${prefix}[a-f0-9]{64}$`, 'u').test(target.automationId) || owners.has(target.owner))
200
+ reject('invalid-targets');
201
+ owners.add(target.owner);
202
+ const record = originals.get(target.automationId);
203
+ if (record === undefined || record.owner !== target.owner || record.runningTaskCount !== 0
204
+ || !['active', 'paused'].includes(record.status) || !integer(record.version, 1)
205
+ || !digestPattern.test(record.definitionHash))
206
+ reject('definitions-changed');
207
+ if (oldMarkers.has(markerKey(target)))
208
+ reject('retirements-changed');
209
+ const evidenceDigest = evidenceForOwner(target.owner);
210
+ return { ...target, definitionHash: record.definitionHash, expectedVersion: record.version,
211
+ operationId: `owner-revoked:${jsonDigest([target.owner, target.automationId, record.definitionHash, record.version, evidenceDigest])}`,
212
+ reason: 'owner-revoked', evidenceDigest };
213
+ }));
214
+ }
215
+ catch (error) {
216
+ if (error instanceof ScannerRetirementTransitionError)
217
+ throw error;
218
+ return reject('invalid-proof');
219
+ }
220
+ }
221
+ /**
222
+ * Pure verification of a preselected retirement change; grants no write or execution permission.
223
+ * Both snapshots and ownerProof MUST come from the formal trusted local readers.
224
+ * The parent installer MUST independently derive exact targets from frozen effective
225
+ * configuration and bind that configuration, owner route and transaction to this call.
226
+ * For Memory, ownerProof.frozenPrincipalVersion MUST equal the frozen learning
227
+ * grant owner.principalVersion; its expectedOwner scope uses that grant version,
228
+ * while the observed revoked state can be at a later durable principal version.
229
+ * A matching scanner prefix does not prove that a definition belongs to that config.
230
+ * Digests are consistency checks after trusted reads, never external authenticity signatures.
231
+ */
232
+ export function verifyScannerRetirementTransition(input) {
233
+ try {
234
+ const { before, after, ownerProof } = input;
235
+ if (before.protocol !== 'assistant-automations/retirement-snapshot/v1' || after.protocol !== before.protocol
236
+ || ![15, 16, 17].includes(before.schemaVersion) || ![16, 17].includes(after.schemaVersion)
237
+ || after.schemaVersion < before.schemaVersion
238
+ || before.inFlightCount !== 0 || after.inFlightCount !== 0
239
+ || !digestPattern.test(before.snapshotDigest) || !digestPattern.test(after.snapshotDigest))
240
+ reject('invalid-proof');
241
+ const operations = prepareScannerRetirementOperations(input);
242
+ const targets = input.targets.map(target => ({ owner: target.owner, automationId: target.automationId }));
243
+ const selected = uniqueMap(targets, target => target.automationId, 'invalid-targets');
244
+ const originals = uniqueMap(before.records, record => record.id, 'definitions-changed');
245
+ const current = uniqueMap(after.records, record => record.id, 'definitions-changed');
246
+ if (originals.size !== current.size)
247
+ reject('definitions-changed');
248
+ for (const [id, record] of originals) {
249
+ const updated = current.get(id);
250
+ if (updated === undefined || record.runningTaskCount !== 0 || updated.runningTaskCount !== 0
251
+ || record.immutableDigest !== updated.immutableDigest)
252
+ reject('definitions-changed');
253
+ if (!selected.has(id) && !same(record, updated))
254
+ reject('definitions-changed');
255
+ }
256
+ const oldMarkers = uniqueMap(before.retirements, markerKey, 'retirements-changed');
257
+ const newMarkers = uniqueMap(after.retirements, markerKey, 'retirements-changed');
258
+ uniqueMap(after.retirements, marker => marker.operationId, 'retirements-changed');
259
+ if ((before.schemaVersion === 15 && oldMarkers.size !== 0)
260
+ || newMarkers.size !== oldMarkers.size + targets.length)
261
+ reject('retirements-changed');
262
+ for (const [key, marker] of oldMarkers)
263
+ if (!same(marker, newMarkers.get(key)))
264
+ reject('retirements-changed');
265
+ const receipts = targets.map((target, index) => {
266
+ const operation = operations[index];
267
+ const { evidenceDigest } = operation;
268
+ const record = originals.get(target.automationId);
269
+ const updated = current.get(target.automationId);
270
+ if (record === undefined || updated === undefined || record.owner !== target.owner
271
+ || (record.status !== 'active' && record.status !== 'paused') || record.runningTaskCount !== 0
272
+ || updated.runningTaskCount !== 0 || !integer(record.version, 1) || !integer(updated.version, 2)
273
+ || updated.version !== record.version + 1 || updated.status !== 'paused' || Object.hasOwn(updated, 'nextRunAt')
274
+ || !same(stableDefinition(record), stableDefinition(updated)))
275
+ reject('definitions-changed');
276
+ const key = markerKey(target);
277
+ const marker = newMarkers.get(key);
278
+ if (oldMarkers.has(key) || marker === undefined || !integer(marker.retiredAt)
279
+ || updated.updatedAt !== marker.retiredAt)
280
+ reject('retirements-changed');
281
+ const expected = {
282
+ ...operation, definitionVersion: updated.version, automationStatus: 'paused', retiredAt: marker.retiredAt,
283
+ };
284
+ if (!same(marker, expected))
285
+ reject('retirements-changed');
286
+ return { ...target, evidenceDigest, markerDigest: digest(canonicalJson(expected)) };
287
+ });
288
+ const history = uniqueMap(before.historyTables, table => table.name, 'history-changed');
289
+ const updatedHistory = uniqueMap(after.historyTables, table => table.name, 'history-changed');
290
+ if (history.size !== updatedHistory.size)
291
+ reject('history-changed');
292
+ for (const [index, table] of before.historyTables.entries()) {
293
+ const updated = updatedHistory.get(table.name);
294
+ if (after.historyTables[index]?.name !== table.name)
295
+ reject('history-changed');
296
+ if (before.schemaVersion < 17 && after.schemaVersion === 17 && table.name === 'automation_runs') {
297
+ // Only the trusted reader can compute this old-column projection. The
298
+ // new nullable column must carry no retrospectively signed observations.
299
+ if (!updated || updated.rowCount !== table.rowCount || updated.legacyDigest !== table.digest
300
+ || updated.nonNullQuiescentCount !== 0
301
+ || Object.keys(table).sort().join(',') !== 'digest,name,rowCount'
302
+ || Object.keys(updated).sort().join(',') !== 'digest,legacyDigest,name,nonNullQuiescentCount,rowCount')
303
+ reject('history-changed');
304
+ }
305
+ else if (!same(table, updated))
306
+ reject('history-changed');
307
+ }
308
+ verifySchema(before, after);
309
+ receipts.sort((left, right) => left.owner < right.owner ? -1 : left.owner > right.owner ? 1 : 0);
310
+ const unsigned = { protocol: scannerRetirementTransitionProtocol, beforeSnapshotDigest: before.snapshotDigest,
311
+ afterSnapshotDigest: after.snapshotDigest, ownerProofSnapshotDigest: ownerProof.snapshotDigest, targets: receipts };
312
+ return freeze({ ...unsigned, receiptDigest: digest(canonicalJson(unsigned)) });
313
+ }
314
+ catch (error) {
315
+ if (error instanceof ScannerRetirementTransitionError)
316
+ throw error;
317
+ return reject('invalid-proof');
318
+ }
319
+ }
320
+ //# sourceMappingURL=rsi-scanner-retirement-transition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsi-scanner-retirement-transition.js","sourceRoot":"","sources":["../src/rsi-scanner-retirement-transition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAOxC,OAAO,EAAE,mBAAmB,E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CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,gCAAgC;YAAE,MAAM,KAAK,CAAA;QAClE,OAAO,MAAM,CAAC,eAAe,CAAC,CAAA;IAChC,CAAC;AACH,CAAC"}
@@ -20,7 +20,14 @@ export interface RsiSetupArgs {
20
20
  dockerPath?: string;
21
21
  prepareAuthorities?: boolean;
22
22
  installOwner?: boolean;
23
+ /** Read-only onboarding wait: poll until the owner's first Lark DM binding exists. */
24
+ waitOwnerDm?: boolean;
25
+ timeoutSeconds?: number;
23
26
  ackExistingAutomations?: boolean;
27
+ /** Fresh-install-only ordinary-use learning assembly; retries preserve the stored opt-in. */
28
+ enableOrdinaryUseLearning?: boolean;
29
+ intakeProvider?: string;
30
+ intakeModel?: string;
24
31
  /** Installer's pre-stop source and destination inventories; never parsed from CLI. */
25
32
  expectedAutomationInventories?: RsiAutomationInventories;
26
33
  installLocalCohort?: boolean;
@@ -59,5 +66,22 @@ export declare function configureRsiSetupLocked(args: RsiSetupArgs, ports?: RsiS
59
66
  mode: string;
60
67
  profiles: readonly string[];
61
68
  }>;
69
+ export interface OwnerDmWaitResult {
70
+ mode: 'ready' | 'timeout' | 'ambiguous';
71
+ bindings: number;
72
+ }
73
+ /**
74
+ * Onboarding helper: read-only poll of the delivery database until the owner's
75
+ * first Lark DM has produced exactly one active owner binding. It never creates
76
+ * or widens a binding; owner authorization stays with the Lark DSH-CONNECT flow.
77
+ * A missing database is "not yet" because the Host creates it on first message.
78
+ */
79
+ export declare function waitForOwnerDmBinding(input: {
80
+ profile: string;
81
+ dshHome: string;
82
+ timeoutMs: number;
83
+ intervalMs?: number;
84
+ signal?: AbortSignal;
85
+ }, ports?: Pick<RsiSetupPorts, 'dump' | 'snapshot'>, sleep?: (ms: number, signal?: AbortSignal) => Promise<void>, now?: () => number): Promise<OwnerDmWaitResult>;
62
86
  export declare function runRsiSetup(argv?: readonly string[]): Promise<void>;
63
87
  //# sourceMappingURL=rsi-setup.d.ts.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AAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAC/F,EAAE,KAAK,GAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,UAAU,CAAiB,EAClE,KAAK,GAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAGvD,EAAE,GAAG,GAAE,MAAM,MAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAY5D;AAED,wBAAsB,WAAW,CAAC,IAAI,GAAE,SAAS,MAAM,EAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAoJhG"}
package/lib/rsi-setup.js CHANGED
@@ -14,6 +14,7 @@ import { installDshResidentService } from './resident.js';
14
14
  import { prepareRsiSourceWorkspace } from './rsi-source.js';
15
15
  import { prepareRsiBuildEnvironment, RsiBuildUnavailableError } from './rsi-build.js';
16
16
  import { prepareRsiReleaseBuildEnvironment, RsiReleaseBuildUnavailableError } from './rsi-release-build.js';
17
+ import { prepareLinuxRsiRuntime, LinuxRsiRuntimeUnavailableError } from './rsi-linux-runtime-bootstrap.js';
17
18
  import { prepareRsiAuthorityRuntime } from './rsi-authority-runtime.js';
18
19
  import { prepareRsiAuthorityResources } from './rsi-authority-resources.js';
19
20
  import { version } from './version.js';
@@ -92,8 +93,18 @@ export function parseRsiSetupArgs(argv) {
92
93
  result.prepareAuthorities = true;
93
94
  else if (key === '--install-owner')
94
95
  result.installOwner = true;
96
+ else if (key === '--wait-owner-dm')
97
+ result.waitOwnerDm = true;
98
+ else if (key === '--timeout-seconds') {
99
+ const value = argv[++i];
100
+ if (!value || !/^[1-9][0-9]{0,4}$/u.test(value) || Number(value) > 3600)
101
+ fail('--timeout-seconds requires an integer from 1 to 3600');
102
+ result.timeoutSeconds = Number(value);
103
+ }
95
104
  else if (key === '--ack-existing-automations')
96
105
  result.ackExistingAutomations = true;
106
+ else if (key === '--enable-ordinary-use-learning')
107
+ result.enableOrdinaryUseLearning = true;
97
108
  else if (key === '--install-local-cohort')
98
109
  result.installLocalCohort = true;
99
110
  else if (key === '--prepare-local-update')
@@ -108,7 +119,8 @@ export function parseRsiSetupArgs(argv) {
108
119
  }
109
120
  else if (key === '--optional-build')
110
121
  result.optionalBuild = true;
111
- else if (key === '--manifest' || key === '--dsh-home' || key === '--profile' || key === '--source-repository' || key === '--docker-path') {
122
+ else if (key === '--manifest' || key === '--dsh-home' || key === '--profile' || key === '--source-repository' || key === '--docker-path'
123
+ || key === '--intake-provider' || key === '--intake-model') {
112
124
  const value = argv[++i];
113
125
  if (!value || value.startsWith('--'))
114
126
  fail(`${key} needs a value`);
@@ -120,6 +132,10 @@ export function parseRsiSetupArgs(argv) {
120
132
  result.sourceRepository = value;
121
133
  else if (key === '--docker-path')
122
134
  result.dockerPath = value;
135
+ else if (key === '--intake-provider')
136
+ result.intakeProvider = value;
137
+ else if (key === '--intake-model')
138
+ result.intakeModel = value;
123
139
  else
124
140
  result.dshHome = value;
125
141
  }
@@ -128,6 +144,27 @@ export function parseRsiSetupArgs(argv) {
128
144
  }
129
145
  if (result.help)
130
146
  return result;
147
+ if (result.enableOrdinaryUseLearning && !result.installOwner)
148
+ fail('--enable-ordinary-use-learning requires --install-owner');
149
+ if ((result.intakeProvider === undefined) !== (result.intakeModel === undefined))
150
+ fail('--intake-provider and --intake-model must be provided together');
151
+ if ((result.intakeProvider !== undefined || result.intakeModel !== undefined) && result.enableOrdinaryUseLearning !== true) {
152
+ fail('--intake-provider/--intake-model require --enable-ordinary-use-learning');
153
+ }
154
+ if (result.timeoutSeconds !== undefined && !result.waitOwnerDm)
155
+ fail('--timeout-seconds requires --wait-owner-dm');
156
+ if (result.waitOwnerDm) {
157
+ if (result.manifestPath || result.apply || result.rollback || result.start || result.confirmStopped || result.installOwner
158
+ || result.prepareSource || result.prepareBuild || result.prepareAuthorities || result.optionalBuild || result.dockerPath
159
+ || result.sourceRepository || result.ackExistingAutomations || result.installLocalCohort || result.bundles
160
+ || result.prepareLocalUpdate || result.addMemoryLearning || result.enableOrdinaryUseLearning
161
+ || result.intakeProvider || result.intakeModel) {
162
+ fail('owner DM wait cannot be combined with other operations');
163
+ }
164
+ if (!isAbsolute(result.dshHome) || !result.profile || !profilePattern.test(result.profile))
165
+ fail('owner DM wait requires --profile and absolute DSH_HOME');
166
+ return result;
167
+ }
131
168
  if (result.addMemoryLearning && !result.prepareLocalUpdate)
132
169
  fail('--add-memory-learning requires --prepare-local-update');
133
170
  if (result.ackExistingAutomations && (!result.installOwner && !result.apply || result.rollback
@@ -136,12 +173,18 @@ export function parseRsiSetupArgs(argv) {
136
173
  if (result.prepareLocalUpdate) {
137
174
  if (result.installLocalCohort || result.installOwner || result.prepareSource || result.prepareBuild
138
175
  || result.prepareAuthorities || result.manifestPath || result.apply || result.rollback || result.start
139
- || result.confirmStopped || result.optionalBuild || result.dockerPath || result.bundles)
176
+ || result.confirmStopped || result.optionalBuild || result.bundles)
140
177
  fail('local update preparation cannot be combined with other operations');
141
178
  if (!isAbsolute(result.dshHome) || !result.profile || !profilePattern.test(result.profile))
142
179
  fail('local update preparation requires --profile and absolute DSH_HOME');
143
180
  if (result.sourceRepository && !isAbsolute(result.sourceRepository))
144
181
  fail('--source-repository must be absolute');
182
+ // Linux defaults to the native runtime; an explicit absolute --docker-path
183
+ // keeps a legacy image receipt replayable during coexistence.
184
+ if (result.dockerPath && process.platform === 'darwin')
185
+ fail('--docker-path is not supported by macOS native build preparation');
186
+ if (result.dockerPath && !isAbsolute(result.dockerPath))
187
+ fail('--docker-path must be absolute');
145
188
  return result;
146
189
  }
147
190
  if (result.bundles && !result.installLocalCohort)
@@ -662,12 +705,60 @@ export async function configureRsiSetupLocked(args, ports = rsiSetupPorts) {
662
705
  return { mode: args.start ? 'services-started' : 'configured', profiles: pair };
663
706
  })();
664
707
  }
708
+ /**
709
+ * Onboarding helper: read-only poll of the delivery database until the owner's
710
+ * first Lark DM has produced exactly one active owner binding. It never creates
711
+ * or widens a binding; owner authorization stays with the Lark DSH-CONNECT flow.
712
+ * A missing database is "not yet" because the Host creates it on first message.
713
+ */
714
+ export async function waitForOwnerDmBinding(input, ports = rsiSetupPorts, sleep = (ms, signal) => new Promise((resolveSleep, reject) => {
715
+ const timer = setTimeout(resolveSleep, ms);
716
+ signal?.addEventListener('abort', () => { clearTimeout(timer); reject(signal.reason); }, { once: true });
717
+ }), now = Date.now) {
718
+ const effective = ports.dump(input.profile, input.dshHome);
719
+ const deadline = now() + input.timeoutMs, interval = input.intervalMs ?? 3_000;
720
+ let bindings = 0;
721
+ for (;;) {
722
+ input.signal?.throwIfAborted();
723
+ try {
724
+ bindings = (await ports.snapshot(effective, input.dshHome)).bindings.length;
725
+ }
726
+ catch {
727
+ bindings = 0;
728
+ }
729
+ if (bindings === 1)
730
+ return { mode: 'ready', bindings };
731
+ if (bindings > 1)
732
+ return { mode: 'ambiguous', bindings };
733
+ if (now() >= deadline)
734
+ return { mode: 'timeout', bindings };
735
+ await sleep(Math.min(interval, Math.max(0, deadline - now())), input.signal);
736
+ }
737
+ }
665
738
  export async function runRsiSetup(argv = process.argv.slice(2)) {
666
739
  const args = parseRsiSetupArgs(argv);
667
740
  if (args.help) {
668
- process.stdout.write('Usage: dsh-rsi-setup --manifest <private.json> [--dsh-home <absolute>] [--apply --confirm-hosts-stopped [--ack-existing-automations] [--start] | --rollback --confirm-hosts-stopped]\n dsh-rsi-setup --prepare-source --profile <name> [--dsh-home <absolute>] [--source-repository <local-absolute>]\n dsh-rsi-setup --prepare-build --profile <name> [--dsh-home <absolute>] [--source-repository <local-absolute>] [--docker-path <absolute>] [--optional-build]\n dsh-rsi-setup --prepare-authorities --profile <name> [--dsh-home <absolute>]\n dsh-rsi-setup --install-owner --profile <name> [--dsh-home <absolute>] [--source-repository <local-absolute>] [--ack-existing-automations]\n dsh-rsi-setup --install-local-cohort --profile <name> --source-repository <local-absolute> --bundle <slug> [--bundle <slug> ...] [--dsh-home <absolute>]\n--ack-existing-automations acknowledges active or paused durable rows when enabling or switching an Automation scheduler; accepted only with --install-owner or --apply, and does not bypass inventory drift checks.\nDefault: validate installed profiles and finite authority configuration without changing profiles.\nSource preparation creates a private checkout and release repository for the installed version. Build preparation also prepares private authority tools, signing identities and local release storage on Linux, creates an offline image and exports a pinned native release toolchain/store/cache; --optional-build reports which build prerequisites are unavailable. Authority preparation alone needs neither Docker nor a source checkout and does not issue grants or start Hosts.\n');
741
+ process.stdout.write('Usage: dsh-rsi-setup --manifest <private.json> [--dsh-home <absolute>] [--apply --confirm-hosts-stopped [--ack-existing-automations] [--start] | --rollback --confirm-hosts-stopped]\n dsh-rsi-setup --prepare-source --profile <name> [--dsh-home <absolute>] [--source-repository <local-absolute>]\n dsh-rsi-setup --prepare-build --profile <name> [--dsh-home <absolute>] [--source-repository <local-absolute>] [--docker-path <absolute>] [--optional-build]\n dsh-rsi-setup --prepare-authorities --profile <name> [--dsh-home <absolute>]\n dsh-rsi-setup --install-owner --profile <name> [--dsh-home <absolute>] [--source-repository <local-absolute>] [--ack-existing-automations] [--enable-ordinary-use-learning [--intake-provider <id> --intake-model <id>]]\n dsh-rsi-setup --wait-owner-dm --profile <name> [--dsh-home <absolute>] [--timeout-seconds <1-3600>]\n dsh-rsi-setup --install-local-cohort --profile <name> --source-repository <local-absolute> --bundle <slug> [--bundle <slug> ...] [--dsh-home <absolute>]\n--ack-existing-automations acknowledges active or paused durable rows when enabling or switching an Automation scheduler; accepted only with --install-owner or --apply, and does not bypass inventory drift checks.\n--enable-ordinary-use-learning is accepted only with --install-owner and only on a fresh profile: it emits the observe-only intake evaluator (rules plus the Delivery or explicit provider/model) and the flagged memory grants. A retry preserves the stored opt-in and never expands an existing installation; no admission, revision key or Growth failure pin is added.\nDefault: validate installed profiles and finite authority configuration without changing profiles.\nSource preparation creates a private checkout and release repository for the installed version. Build preparation also prepares private authority tools, signing identities and local release storage on Linux, prepares a pinned native offline runtime by default and exports its release toolchain/store/cache (--docker-path instead prepares the legacy offline image); --optional-build reports which build prerequisites are unavailable. Authority preparation alone needs neither Docker nor a source checkout and does not issue grants or start Hosts.\n');
669
742
  process.stdout.write('macOS: --prepare-build installs a pinned private Node and frozen manifest-only dependencies for offline Seatbelt checks; --docker-path is rejected and --optional-build does not suppress native preparation failure. --install-owner configures a native launchd Host with finite memory learning and verified plugin creation. Source replacement/release remains Linux-only.\n');
670
- process.stdout.write(' dsh-rsi-setup --prepare-local-update --profile <name> [--dsh-home <absolute>] [--source-repository <local-absolute>] [--add-memory-learning]\nPrepare local update source and tarballs outside the active Home; does not install or activate them. --add-memory-learning explicitly prepares the disabled learner bundle for a verified pre-owner installation.\n');
743
+ process.stdout.write(' dsh-rsi-setup --prepare-local-update --profile <name> [--dsh-home <absolute>] [--source-repository <local-absolute>] [--add-memory-learning] [--docker-path <absolute>]\nPrepare local update source and tarballs outside the active Home; does not install or activate them. Linux builds with the native runtime by default; --docker-path keeps the legacy image builder. --add-memory-learning explicitly prepares the disabled learner bundle for a verified pre-owner installation.\n');
744
+ return;
745
+ }
746
+ if (args.waitOwnerDm) {
747
+ const controller = new AbortController();
748
+ const cancel = () => controller.abort(new Error('owner DM wait interrupted'));
749
+ process.once('SIGINT', cancel);
750
+ process.once('SIGTERM', cancel);
751
+ try {
752
+ const result = await waitForOwnerDmBinding({ profile: args.profile, dshHome: args.dshHome,
753
+ timeoutMs: (args.timeoutSeconds ?? 600) * 1_000, signal: controller.signal });
754
+ process.stdout.write(`${JSON.stringify(result)}\n`);
755
+ if (result.mode !== 'ready')
756
+ process.exitCode = 3;
757
+ }
758
+ finally {
759
+ process.off('SIGINT', cancel);
760
+ process.off('SIGTERM', cancel);
761
+ }
671
762
  return;
672
763
  }
673
764
  if (args.prepareLocalUpdate) {
@@ -680,7 +771,8 @@ export async function runRsiSetup(argv = process.argv.slice(2)) {
680
771
  const { readRsiLocalCohort } = await import('./rsi-local-cohort.js');
681
772
  const sourceRepository = args.sourceRepository ?? (await readRsiLocalCohort({ dshHome: args.dshHome, profile: args.profile })).sourceRepository;
682
773
  const prepared = await prepareRsiLocalUpdate({ dshHome: args.dshHome, profile: args.profile, sourceRepository,
683
- ...(args.addMemoryLearning ? { rootExtension: 'memory-learning' } : {}), signal: controller.signal });
774
+ ...(args.addMemoryLearning ? { rootExtension: 'memory-learning' } : {}),
775
+ ...(args.dockerPath ? { dockerPath: args.dockerPath } : {}), signal: controller.signal });
684
776
  process.stdout.write(`${JSON.stringify({ mode: prepared.mode, root: prepared.root, profile: prepared.profile,
685
777
  sourceCommit: prepared.source.sourceCommit, version: prepared.cohort.version,
686
778
  packages: prepared.cohort.packages.length, receiptDigest: prepared.receiptDigest,
@@ -723,7 +815,10 @@ export async function runRsiSetup(argv = process.argv.slice(2)) {
723
815
  ? (await import('./rsi-native-install.js')).installNativeRsiOwnerDeployment
724
816
  : (await import('./rsi-install.js')).installRsiOwnerDeployment;
725
817
  const result = await install({ dshHome: args.dshHome, profile: args.profile,
726
- sourceRepository: args.sourceRepository, ackExistingAutomations: args.ackExistingAutomations, signal: controller.signal });
818
+ sourceRepository: args.sourceRepository, ackExistingAutomations: args.ackExistingAutomations, signal: controller.signal,
819
+ enableOrdinaryUseLearning: args.enableOrdinaryUseLearning === true,
820
+ ...(args.intakeProvider !== undefined ? { intakeProvider: args.intakeProvider } : {}),
821
+ ...(args.intakeModel !== undefined ? { intakeModel: args.intakeModel } : {}) });
727
822
  process.stdout.write(`${JSON.stringify(result)}\n`);
728
823
  process.stderr.write(result.mode === 'ready' ? (process.platform === 'darwin'
729
824
  ? '原生 macOS 学习已启动并通过就绪检查:持久记忆、新工具独立验证与动态采用。\n'
@@ -769,6 +864,25 @@ export async function runRsiSetup(argv = process.argv.slice(2)) {
769
864
  return { ...provisioned, sourceBuild: build.sourceBuild, creationBuild: nativeRsiCreationBuild(build),
770
865
  capabilities: ['native-memory-learning', 'verified-plugin-creation', 'dynamic-tool-adoption'] };
771
866
  }
867
+ // Linux prepares the schema 3 native runtime by default: no Docker
868
+ // CLI, daemon, socket or image is involved. An explicit --docker-path
869
+ // keeps the legacy image path available during migration coexistence.
870
+ if (process.platform === 'linux' && !args.dockerPath) {
871
+ const build = await prepareLinuxRsiRuntime({ dshHome: args.dshHome, profile: args.profile, source,
872
+ signal: controller.signal });
873
+ try {
874
+ const release = await prepareRsiReleaseBuildEnvironment({ dshHome: args.dshHome, profile: args.profile,
875
+ build, signal: controller.signal });
876
+ return { ...provisioned, sourceBuild: build, releaseBuild: release };
877
+ }
878
+ catch (error) {
879
+ controller.signal.throwIfAborted();
880
+ if (!args.optionalBuild || !(error instanceof RsiReleaseBuildUnavailableError))
881
+ throw error;
882
+ process.stderr.write(`自迭代发布构建环境未就绪:${error.message}。已保留源码、验证运行时与原生工具链。\n`);
883
+ return { ...provisioned, sourceBuild: build, releaseBuildUnavailable: error.message };
884
+ }
885
+ }
772
886
  const build = await prepareRsiBuildEnvironment({ dshHome: args.dshHome, profile: args.profile, source,
773
887
  dockerPath: args.dockerPath, signal: controller.signal });
774
888
  try {
@@ -786,7 +900,8 @@ export async function runRsiSetup(argv = process.argv.slice(2)) {
786
900
  }
787
901
  catch (error) {
788
902
  controller.signal.throwIfAborted();
789
- if (!args.optionalBuild || !(error instanceof RsiBuildUnavailableError))
903
+ if (!args.optionalBuild
904
+ || !(error instanceof RsiBuildUnavailableError || error instanceof LinuxRsiRuntimeUnavailableError))
790
905
  throw error;
791
906
  process.stderr.write(`自迭代构建环境未就绪:${error.message}。已保留源码准备结果。\n`);
792
907
  return { ...provisioned, buildUnavailable: error.message };