@skrr-ai/cli 0.1.162 → 0.1.163

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 (82) hide show
  1. package/dist/base-command.d.ts +5 -2
  2. package/dist/base-command.js +96 -39
  3. package/dist/commands/activity/list.d.ts +7 -0
  4. package/dist/commands/activity/list.js +17 -0
  5. package/dist/commands/activity/scan-older.d.ts +2 -2
  6. package/dist/commands/activity/scan-older.js +6 -5
  7. package/dist/commands/activity/show.d.ts +0 -2
  8. package/dist/commands/activity/show.js +21 -42
  9. package/dist/commands/agents/always-on/release-run.d.ts +3 -3
  10. package/dist/commands/agents/always-on/release-run.js +5 -6
  11. package/dist/commands/agents/mini-computer/app/reset.d.ts +1 -0
  12. package/dist/commands/agents/mini-computer/app/reset.js +5 -2
  13. package/dist/commands/agents/mini-computer/app/set.js +1 -1
  14. package/dist/commands/agents/mini-computer/show.js +4 -2
  15. package/dist/commands/agents/mini-computer/tasks-view.js +2 -2
  16. package/dist/commands/agents/triggers/replay.js +1 -1
  17. package/dist/commands/agents/triggers/runs.d.ts +2 -3
  18. package/dist/commands/agents/triggers/runs.js +4 -5
  19. package/dist/commands/apps/auto-apply.js +31 -10
  20. package/dist/commands/apps/check.js +8 -0
  21. package/dist/commands/apps/data/batch.js +16 -5
  22. package/dist/commands/apps/data/collections.js +1 -1
  23. package/dist/commands/apps/data/delete.js +12 -4
  24. package/dist/commands/apps/data/patch.js +11 -4
  25. package/dist/commands/apps/data/put.js +13 -6
  26. package/dist/commands/apps/data/query.js +3 -3
  27. package/dist/commands/apps/install.js +24 -7
  28. package/dist/commands/apps/installations/events.d.ts +1 -0
  29. package/dist/commands/apps/installations/events.js +63 -10
  30. package/dist/commands/apps/installations/show.js +26 -5
  31. package/dist/commands/apps/installations/snapshot.js +1 -1
  32. package/dist/commands/apps/installations/versions.js +25 -9
  33. package/dist/commands/apps/logs.js +4 -1
  34. package/dist/commands/apps/push.js +10 -2
  35. package/dist/commands/apps/reconsent.js +7 -1
  36. package/dist/commands/apps/rollback.js +2 -2
  37. package/dist/commands/apps/settings/set.js +81 -4
  38. package/dist/commands/apps/settings/show.js +38 -7
  39. package/dist/commands/duties/status.js +20 -15
  40. package/dist/commands/outbox/drop.js +21 -15
  41. package/dist/commands/outbox/list.d.ts +2 -1
  42. package/dist/commands/outbox/list.js +20 -11
  43. package/dist/commands/outbox/retry.d.ts +8 -11
  44. package/dist/commands/outbox/retry.js +135 -92
  45. package/dist/commands/spaces/create.js +1 -1
  46. package/dist/commands/tasks/comments/add.js +1 -1
  47. package/dist/commands/triggers/audit.js +3 -5
  48. package/dist/commands/triggers/fire-detail.js +7 -1
  49. package/dist/commands/triggers/replay.js +1 -1
  50. package/dist/commands/triggers/runs.d.ts +2 -4
  51. package/dist/commands/triggers/runs.js +3 -5
  52. package/dist/generated/agent-guides.json +19 -19
  53. package/dist/lib/agent-activity.d.ts +21 -1
  54. package/dist/lib/agent-activity.js +98 -29
  55. package/dist/lib/api-fetch.d.ts +2 -0
  56. package/dist/lib/api-fetch.js +5 -5
  57. package/dist/lib/appData.d.ts +43 -5
  58. package/dist/lib/appData.js +117 -25
  59. package/dist/lib/appInstallations.d.ts +5 -5
  60. package/dist/lib/appInstallations.js +211 -74
  61. package/dist/lib/appSettings.d.ts +2 -0
  62. package/dist/lib/appSettings.js +36 -3
  63. package/dist/lib/apps-command.d.ts +9 -0
  64. package/dist/lib/apps-command.js +191 -7
  65. package/dist/lib/appsCheck.js +29 -3
  66. package/dist/lib/appsFs.d.ts +1 -1
  67. package/dist/lib/json-output.d.ts +4 -0
  68. package/dist/lib/json-output.js +38 -0
  69. package/dist/lib/miniComputer.js +9 -2
  70. package/dist/lib/node-adapter.js +35 -2
  71. package/dist/lib/outbox.d.ts +20 -5
  72. package/dist/lib/outbox.js +233 -76
  73. package/dist/lib/rate-limit-retry.d.ts +3 -2
  74. package/dist/lib/rate-limit-retry.js +3 -2
  75. package/dist/lib/roles.d.ts +1 -1
  76. package/dist/lib/triggers.d.ts +3 -0
  77. package/dist/lib/triggers.js +10 -0
  78. package/dist/lib/widgetStaticScan.d.ts +3 -1
  79. package/dist/lib/widgetStaticScan.js +182 -47
  80. package/dist/node_modules/@skrr-ai/data-provider/index.js +10416 -9520
  81. package/oclif.manifest.json +137 -44
  82. package/package.json +4 -3
@@ -1,5 +1,11 @@
1
1
  import type { ResolvedCredential } from './credential-resolver';
2
2
  export type ActivityScope = 'user' | 'agent' | 'duty';
3
+ export declare const ACTIVITY_SOURCES: readonly ["trigger_fire", "duty_check", "task_execution", "direct_chat", "group_chat", "goal_planner_tick", "autonomous_run"];
4
+ export type ActivitySource = (typeof ACTIVITY_SOURCES)[number];
5
+ export declare const ACTIVITY_RUNTIMES: readonly ["selected", "bound", "not_bound", "unknown", "byo-machine", "hosted-machine", "hosted-job-machine", "dedicated-machine", "space-machine", "oversky-worker"];
6
+ export type ActivityRuntime = (typeof ACTIVITY_RUNTIMES)[number];
7
+ export declare const ACTIVITY_INITIATORS: readonly ["person", "automation", "agent", "system", "unknown"];
8
+ export type ActivityInitiator = (typeof ACTIVITY_INITIATORS)[number];
3
9
  export interface ActivitySourceRef {
4
10
  kind: string;
5
11
  keys: Record<string, string>;
@@ -38,6 +44,12 @@ export interface ActivityResponse {
38
44
  items: ActivityItem[];
39
45
  hasMore: boolean;
40
46
  nextCursor: string | null;
47
+ /** A bounded scan can continue, without proving another match exists. */
48
+ scanCursor?: string | null;
49
+ filterScan?: {
50
+ state: 'partial';
51
+ reason: string;
52
+ };
41
53
  ordering: string;
42
54
  coverage: Array<{
43
55
  source: string;
@@ -45,11 +57,19 @@ export interface ActivityResponse {
45
57
  reason?: string;
46
58
  }>;
47
59
  }
60
+ export declare function isPrintableActivityToken(value: string): boolean;
48
61
  /** The API authorizes each source; a source reference is never an access grant. */
49
62
  export declare function listAgentActivity(options: {
50
63
  scope: ActivityScope;
51
64
  agentId?: string;
52
65
  dutyId?: string;
66
+ source?: ActivitySource;
67
+ status?: string;
68
+ runtime?: ActivityRuntime;
69
+ initiator?: ActivityInitiator;
70
+ content?: string;
71
+ from?: string;
72
+ before?: string;
53
73
  limit?: number;
54
74
  cursor?: string;
55
75
  }, credential?: ResolvedCredential): Promise<ActivityResponse>;
@@ -68,7 +88,7 @@ export declare function runtimeCell(item: ActivityItem): string;
68
88
  /** The activity table, shared by the feed and the older-activity scans so the two never drift. */
69
89
  export declare function renderActivityItems(items: ActivityItem[], log: (line: string) => void): void;
70
90
  export declare function renderAgentActivity(response: ActivityResponse, log: (line: string) => void): void;
71
- export type ActivityScanSource = 'chat' | 'group-chat';
91
+ export type ActivityScanSource = 'chat' | 'group-chat' | 'task';
72
92
  export interface ActivityScanResponse {
73
93
  object: string;
74
94
  items: ActivityItem[];
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ACTIVITY_INITIATORS = exports.ACTIVITY_RUNTIMES = exports.ACTIVITY_SOURCES = void 0;
4
+ exports.isPrintableActivityToken = isPrintableActivityToken;
3
5
  exports.listAgentActivity = listAgentActivity;
4
6
  exports.sourceLabel = sourceLabel;
5
7
  exports.runtimeCell = runtimeCell;
@@ -14,6 +16,22 @@ exports.groupReplyUnavailable = groupReplyUnavailable;
14
16
  const api_fetch_1 = require("./api-fetch");
15
17
  const format_1 = require("./format");
16
18
  const search_display_1 = require("./search-display");
19
+ exports.ACTIVITY_SOURCES = [
20
+ 'trigger_fire', 'duty_check', 'task_execution', 'direct_chat',
21
+ 'group_chat', 'goal_planner_tick', 'autonomous_run',
22
+ ];
23
+ exports.ACTIVITY_RUNTIMES = [
24
+ 'selected', 'bound', 'not_bound', 'unknown', 'byo-machine', 'hosted-machine',
25
+ 'hosted-job-machine', 'dedicated-machine', 'space-machine', 'oversky-worker',
26
+ ];
27
+ exports.ACTIVITY_INITIATORS = ['person', 'automation', 'agent', 'system', 'unknown'];
28
+ /** Activity values can contain source-authored text. Never emit terminal control or bidi characters. */
29
+ function activityCell(value, placeholder = '-') {
30
+ return (0, search_display_1.searchDisplayText)((0, format_1.formatCell)(value, placeholder)).replace(/[\u061c\u200e\u200f]/g, '') || placeholder;
31
+ }
32
+ function isPrintableActivityToken(value) {
33
+ return (0, search_display_1.isPrintableSearchCursor)(value) && !/[\u061c\u200e\u200f]/.test(value);
34
+ }
17
35
  /** The API authorizes each source; a source reference is never an access grant. */
18
36
  function listAgentActivity(options, credential) {
19
37
  const query = new URLSearchParams({ scope: options.scope });
@@ -21,6 +39,20 @@ function listAgentActivity(options, credential) {
21
39
  query.set('agentId', options.agentId);
22
40
  if (options.dutyId)
23
41
  query.set('dutyId', options.dutyId);
42
+ if (options.source)
43
+ query.set('source', options.source);
44
+ if (options.status)
45
+ query.set('status', options.status);
46
+ if (options.runtime)
47
+ query.set('runtime', options.runtime);
48
+ if (options.initiator)
49
+ query.set('initiator', options.initiator);
50
+ if (options.content)
51
+ query.set('content', options.content);
52
+ if (options.from)
53
+ query.set('from', options.from);
54
+ if (options.before)
55
+ query.set('before', options.before);
24
56
  if (options.limit !== undefined)
25
57
  query.set('limit', String(options.limit));
26
58
  if (options.cursor)
@@ -34,7 +66,8 @@ function listAgentActivity(options, credential) {
34
66
  function sourceLabel(ref) {
35
67
  if (!ref?.keys || typeof ref.keys !== 'object')
36
68
  return 'unavailable';
37
- const pairs = Object.entries(ref.keys).map(([key, value]) => `${key}=${(0, format_1.formatCell)(value)}`);
69
+ const token = (value) => typeof value === 'string' && isPrintableActivityToken(value) ? value : '[unprintable]';
70
+ const pairs = Object.entries(ref.keys).map(([key, value]) => `${token(key)}=${token(value)}`);
38
71
  return pairs.length ? pairs.join(' ') : 'unavailable';
39
72
  }
40
73
  /**
@@ -45,9 +78,9 @@ function sourceLabel(ref) {
45
78
  */
46
79
  function runtimeCell(item) {
47
80
  const runtime = item.runtime;
48
- const parts = [(0, format_1.formatCell)(runtime?.state, 'unknown')];
81
+ const parts = [activityCell(runtime?.state, 'unknown')];
49
82
  if (runtime?.selectedMachineProduct)
50
- parts.push((0, format_1.formatCell)(runtime.selectedMachineProduct));
83
+ parts.push(activityCell(runtime.selectedMachineProduct));
51
84
  const considered = runtime?.considered;
52
85
  const weighed = Array.isArray(considered) ? considered.length : 0;
53
86
  if (weighed > 1 || (weighed === 1 && runtime?.state === 'not_bound')) {
@@ -55,19 +88,19 @@ function runtimeCell(item) {
55
88
  }
56
89
  const handoff = item.dispatch?.state;
57
90
  if (handoff && handoff !== 'unknown')
58
- parts.push(`hand-off ${(0, format_1.formatCell)(handoff)}`);
91
+ parts.push(`hand-off ${activityCell(handoff)}`);
59
92
  return parts.join(' · ');
60
93
  }
61
94
  /** The activity table, shared by the feed and the older-activity scans so the two never drift. */
62
95
  function renderActivityItems(items, log) {
63
96
  (0, format_1.renderTable)(items.map((item) => ({
64
- when: (0, format_1.localTime)(item.timestamp),
65
- source: (0, format_1.formatCell)(item.sourceKind),
66
- status: (0, format_1.formatCell)(item.status, 'unknown'),
67
- title: (0, format_1.formatCell)(item.title),
97
+ when: activityCell((0, format_1.localTime)(item.timestamp)),
98
+ source: activityCell(item.sourceKind),
99
+ status: activityCell(item.status, 'unknown'),
100
+ title: activityCell(item.title),
68
101
  reference: sourceLabel(item.sourceRef),
69
102
  runtime: runtimeCell(item),
70
- content: (0, format_1.formatCell)(item.content?.state, 'unknown'),
103
+ content: activityCell(item.content?.state, 'unknown'),
71
104
  })), [
72
105
  { key: 'when', header: 'WHEN' },
73
106
  { key: 'source', header: 'SOURCE' },
@@ -79,7 +112,7 @@ function renderActivityItems(items, log) {
79
112
  ], log);
80
113
  }
81
114
  function renderAgentActivity(response, log) {
82
- log(`Activity · ${response.scope}`);
115
+ log(`Activity · ${activityCell(response.scope, 'unknown')}`);
83
116
  const items = Array.isArray(response.items) ? response.items : [];
84
117
  if (items.length) {
85
118
  renderActivityItems(items, log);
@@ -91,13 +124,13 @@ function renderAgentActivity(response, log) {
91
124
  // no activity. Always print the server's coverage, even on an empty page.
92
125
  if (items.length) {
93
126
  log('');
94
- log('Detail: activity show --trigger <triggerId> --fire <occurrenceId>,');
95
- log(' or activity show --duty <dutyId>.');
127
+ log('Trigger Activity detail is unavailable: the original Trigger identity was not recorded.');
128
+ log('Duty trace: activity show --duty <dutyId> (independently authorized).');
96
129
  log('Task run content is not connected to Activity; open the Task for its authorized history.');
97
- log('Chat source: messages show <conversationId> <messageId> (subject to conversation access).');
130
+ log('Current chat: messages show <conversationId> <messageId> (independently authorized; Activity identity unverified).');
98
131
  log('Group reply: activity show --group-chat <groupChatId> --message <messageId>.');
99
- log('Older chat or group rows the feed does not page to: activity scan-older chat|group-chat.');
100
132
  }
133
+ log('Scan your older activity: activity scan-older chat|group-chat|task.');
101
134
  log('');
102
135
  const coverage = Array.isArray(response.coverage) ? response.coverage : [];
103
136
  if (!coverage.length)
@@ -105,22 +138,41 @@ function renderAgentActivity(response, log) {
105
138
  else {
106
139
  log('Coverage:');
107
140
  for (const item of coverage) {
108
- log(` ${(0, format_1.formatCell)(item.source)}: ${(0, format_1.formatCell)(item.state, 'unknown')}${item.reason ? ` (${(0, format_1.formatCell)(item.reason)})` : ''}`);
141
+ log(` ${activityCell(item.source)}: ${activityCell(item.state, 'unknown')}${item.reason ? ` (${activityCell(item.reason)})` : ''}`);
109
142
  }
110
143
  }
111
- if (response.hasMore && response.nextCursor) {
144
+ if (response.filterScan?.state === 'partial') {
145
+ log('');
146
+ log(`Filter scan: partial${response.filterScan.reason ? ` (${activityCell(response.filterScan.reason)})` : ''}`);
147
+ }
148
+ if (response.hasMore) {
112
149
  log('');
113
- log(`Next cursor: ${response.nextCursor}`);
114
- log('Pass this cursor with the same scope and filters to read the next page.');
150
+ if (!response.nextCursor) {
151
+ log('More activity may be available, but the server did not return a cursor.');
152
+ }
153
+ else if (typeof response.nextCursor !== 'string' || !isPrintableActivityToken(response.nextCursor)) {
154
+ log('The next cursor cannot be printed safely.');
155
+ }
156
+ else {
157
+ log(`Next cursor: ${response.nextCursor}`);
158
+ log('Pass this cursor with the same scope and filters to read the next page.');
159
+ }
115
160
  }
116
- else if (response.hasMore) {
161
+ else if (response.scanCursor) {
117
162
  log('');
118
- log('More activity may be available, but the server did not return a cursor.');
163
+ if (typeof response.scanCursor !== 'string' || !isPrintableActivityToken(response.scanCursor)) {
164
+ log('The scan cursor cannot be printed safely.');
165
+ }
166
+ else {
167
+ log(`Scan cursor: ${response.scanCursor}`);
168
+ log('Continue with the same filters to scan further; another match is not guaranteed.');
169
+ }
119
170
  }
120
171
  }
121
172
  const SCAN_OBJECT = {
122
173
  chat: 'personal_chat_activity_scan',
123
174
  'group-chat': 'group_chat_activity_scan',
175
+ task: 'personal_task_activity_scan',
124
176
  };
125
177
  const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
126
178
  /**
@@ -136,11 +188,22 @@ function scanOlderActivity(options, credential) {
136
188
  query.set('limit', String(options.limit));
137
189
  if (options.cursor)
138
190
  query.set('cursor', options.cursor);
139
- return options.source === 'chat'
140
- ? (0, api_fetch_1.apiFetch)(`/api/agent-activity/chat/scan-older?${query.toString()}`, { credential })
141
- : (0, api_fetch_1.apiFetch)(`/api/agent-activity/group-chat/scan-older?${query.toString()}`, {
191
+ // One literal path per source, on purpose. The route-parity check reads these paths from the
192
+ // source, and a `${options.source}` template resolves to `:param`, which matches none of the
193
+ // three routes and reports each as unreachable from the CLI.
194
+ if (options.source === 'chat') {
195
+ return (0, api_fetch_1.apiFetch)(`/api/agent-activity/chat/scan-older?${query.toString()}`, {
142
196
  credential,
143
197
  });
198
+ }
199
+ if (options.source === 'task') {
200
+ return (0, api_fetch_1.apiFetch)(`/api/agent-activity/task/scan-older?${query.toString()}`, {
201
+ credential,
202
+ });
203
+ }
204
+ return (0, api_fetch_1.apiFetch)(`/api/agent-activity/group-chat/scan-older?${query.toString()}`, {
205
+ credential,
206
+ });
144
207
  }
145
208
  /**
146
209
  * Accept a response only if it has the documented shape. A body that merely LOOKS empty (a proxy
@@ -150,6 +213,8 @@ function scanOlderActivity(options, credential) {
150
213
  function parseActivityScan(source, value) {
151
214
  if (!isRecord(value) || value.object !== SCAN_OBJECT[source])
152
215
  return null;
216
+ if (source === 'task' && value.ordering !== 'task_scan')
217
+ return null;
153
218
  if (!Array.isArray(value.items) || !value.items.every(isRecord))
154
219
  return null;
155
220
  if (!isRecord(value.coverage) || typeof value.coverage.state !== 'string')
@@ -159,14 +224,16 @@ function parseActivityScan(source, value) {
159
224
  return value;
160
225
  }
161
226
  function renderActivityScan(source, response, log) {
162
- const label = source === 'chat' ? 'chat' : 'group';
227
+ const label = source === 'chat' ? 'chat' : source === 'task' ? 'Task' : 'group';
163
228
  log(`Earlier ${label} activity`);
164
229
  if (response.items.length) {
165
230
  renderActivityItems(response.items, log);
166
231
  log('');
167
232
  log(source === 'chat'
168
- ? 'Chat source: messages show <conversationId> <messageId> (subject to conversation access).'
169
- : 'Group reply: activity show --group-chat <groupChatId> --message <messageId>.');
233
+ ? 'Current chat: messages show <conversationId> <messageId> (independently authorized; Activity identity unverified).'
234
+ : source === 'task'
235
+ ? 'Open the Task for its independently authorized history.'
236
+ : 'Group reply: activity show --group-chat <groupChatId> --message <messageId>.');
170
237
  }
171
238
  else {
172
239
  log(`No additional visible ${label} activity was found in this scan.`);
@@ -175,15 +242,17 @@ function renderActivityScan(source, response, log) {
175
242
  log('');
176
243
  log(source === 'chat'
177
244
  ? 'A scan is a separate, bounded read of older chat replies. Its cursor is not a global time order or a has-more signal, and some history may be unavailable.'
178
- : 'Groups are scanned separately, not in global time order. Some history may be unavailable.');
245
+ : source === 'task'
246
+ ? 'Personal Tasks are scanned separately, not in global time order. Some history may be unavailable.'
247
+ : 'Groups are scanned separately, not in global time order. Some history may be unavailable.');
179
248
  const coverage = response.coverage;
180
- log(`Coverage: ${(0, format_1.formatCell)(coverage.source, label)}: ${(0, format_1.formatCell)(coverage.state, 'unknown')}${coverage.reason ? ` (${(0, format_1.formatCell)(coverage.reason)})` : ''}`);
249
+ log(`Coverage: ${activityCell(coverage.source, label)}: ${activityCell(coverage.state, 'unknown')}${coverage.reason ? ` (${activityCell(coverage.reason)})` : ''}`);
181
250
  log('');
182
251
  const cursor = response.scanOlderCursor;
183
252
  if (!cursor) {
184
253
  log('The server returned no cursor, so this scan cannot be continued.');
185
254
  }
186
- else if (!(0, search_display_1.isPrintableSearchCursor)(cursor)) {
255
+ else if (!isPrintableActivityToken(cursor)) {
187
256
  log('The server returned a cursor that cannot be printed safely; read it with --json.');
188
257
  }
189
258
  else {
@@ -3,6 +3,8 @@ import { type DaemonBrokerFailure } from './daemonBroker';
3
3
  export interface ApiFetchOptions {
4
4
  method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
5
5
  body?: unknown;
6
+ /** Do not transparently resend or redirect this request after an ambiguous response. */
7
+ singleAttempt?: boolean;
6
8
  /** Override credential resolution — useful for tests. */
7
9
  credential?: ResolvedCredential;
8
10
  /** Exact admitted-session Memory history GET; never uses owner credentials. */
@@ -216,17 +216,17 @@ async function apiFetch(pathOrUrl, opts = {}) {
216
216
  const { response, retryAfterMs } = await (0, rate_limit_retry_1.fetchWithRateLimitRetry)(() => fetch(url, {
217
217
  method,
218
218
  headers: sent,
219
- ...(historyRead ? { redirect: 'error' } : (0, task_runtime_headers_1.taskRuntimeRedirectOptions)(sent)),
219
+ ...(historyRead || opts.singleAttempt ? { redirect: 'error' } : (0, task_runtime_headers_1.taskRuntimeRedirectOptions)(sent)),
220
220
  body,
221
221
  ...(opts.signal ? { signal: opts.signal } : {}),
222
- }), { method, headers: sent, signal: opts.signal });
222
+ }), { method, headers: sent, signal: opts.signal, ...(opts.singleAttempt ? { maxRetries: 0 } : {}) });
223
223
  lastRetryAfterMs = retryAfterMs;
224
224
  return response;
225
225
  };
226
226
  let lastRetryAfterMs;
227
227
  let res = await fetchWithCredential(cred);
228
228
  let brokerFailure = null;
229
- if (res.status === 401 && delegatedCli) {
229
+ if (!opts.singleAttempt && res.status === 401 && delegatedCli) {
230
230
  // Deliberately terminal on broker failure: an Agent whose daemon cannot
231
231
  // rotate its family must surface the 401, never fall through to
232
232
  // `ensureFreshCliCredential` and adopt the human's stored refresh family.
@@ -237,7 +237,7 @@ async function apiFetch(pathOrUrl, opts = {}) {
237
237
  res = await fetchWithCredential(cred);
238
238
  }
239
239
  }
240
- else if (res.status === 401 &&
240
+ else if (!opts.singleAttempt && res.status === 401 &&
241
241
  !historyRead &&
242
242
  (0, daemonBroker_1.isBrokeredHandoffToken)(cred.token) &&
243
243
  !isAuthEndpoint(pathOrUrl)) {
@@ -256,7 +256,7 @@ async function apiFetch(pathOrUrl, opts = {}) {
256
256
  res = await fetchWithCredential(cred);
257
257
  }
258
258
  }
259
- else if (res.status === 401 && !autonomousCredential && !isAuthEndpoint(pathOrUrl)) {
259
+ else if (!opts.singleAttempt && res.status === 401 && !autonomousCredential && !isAuthEndpoint(pathOrUrl)) {
260
260
  const fresh = await (0, refresh_1.ensureFreshCliCredential)({ credential: cred, force: true });
261
261
  if (fresh.refreshed && fresh.credential.token) {
262
262
  cred = fresh.credential;
@@ -1,9 +1,39 @@
1
+ /**
2
+ * `skrr apps data put | query`: what the commands that write and read an installed app's OWN documents, as the
3
+ * signed-in person, share. The domain lib of the person channel; the authoring loop's is `lib/apps.ts` and the
4
+ * installation commands' `lib/appInstallations.ts`.
5
+ *
6
+ * It builds no URL. Every call is a `dataService` function (`@skrr-ai/data-provider`: `putAppInstallationData`,
7
+ * `queryAppInstallationData`), which is what keeps this CLI and any other client on one route (and what
8
+ * `domain-api-parity.spec.ts` checks). What lives here is what a terminal needs around it:
9
+ *
10
+ * - where a document comes from (`--doc`, `--from-file`, `--stdin`: exactly one) and that it is a JSON OBJECT, said
11
+ * before anything is sent;
12
+ * - the `where` of a read, a JSON object of equalities on top-level fields (the store's own rule, refused by the
13
+ * server's parser if it is more);
14
+ * - what a refusal means in words, keyed by the contract's whole vocabulary (`APP_PERSON_DATA_REFUSALS`), and what a
15
+ * conflict (someone wrote first) means and the revision to retry from: an answer, never an error;
16
+ * - a document drawn for a terminal: its content is whatever the app's window, a webhook, an Agent or a person
17
+ * wrote, so it is DATA, and nothing a terminal would act on is printed raw (control characters, escapes and
18
+ * bidirectional overrides are written out as `\uXXXX`).
19
+ *
20
+ * NEVER PRINTED: who wrote a row. The server returns the KIND of writer (`app`, `agent`, `person`) and never an id.
21
+ */
22
+ import { APP_STORE_CURSOR_INVALID_REASON } from '@skrr-ai/data-provider';
1
23
  import type { AppInstallationDataCatalog, AppPersonDataRefusal, AppStoreConflict, AppStoreDocView, AppStoreQueryResult } from '@skrr-ai/data-provider';
2
24
  /** Why the input could not be used; never carries what was in it. */
3
25
  export declare class AppDataInputError extends Error {
4
26
  readonly code: 'APP_DATA_SOURCE' | 'APP_DATA_NOT_JSON' | 'APP_DATA_NOT_OBJECT' | 'APP_DATA_WHERE';
5
27
  constructor(code: 'APP_DATA_SOURCE' | 'APP_DATA_NOT_JSON' | 'APP_DATA_NOT_OBJECT' | 'APP_DATA_WHERE', message: string);
6
28
  }
29
+ /** A 2xx is not a receipt unless its body identifies the requested operation. */
30
+ export declare function assertAppDataWriteResult(value: unknown, target: {
31
+ verb: 'put' | 'patch' | 'delete';
32
+ id: string;
33
+ } | {
34
+ verb: 'batch';
35
+ writes: Array<Record<string, unknown>>;
36
+ }): void;
7
37
  /**
8
38
  * The document the person gave, from exactly one of `--doc`, `--from-file` and `--stdin`. A file is read the way the
9
39
  * authoring commands read one (a symbolic link is refused, never followed). The error names the problem and never
@@ -14,13 +44,17 @@ export declare function readDocumentInput(input: {
14
44
  fromFile?: string;
15
45
  stdin?: boolean;
16
46
  }): Promise<Record<string, unknown>>;
17
- /** The `--where` of a read: a JSON object. What it may hold is the server's parser's to say, once, for every client. */
47
+ /** Validate `--where` with the same parser the server uses. */
18
48
  export declare function readWhereInput(text: string): Record<string, string | number | boolean | null>;
19
49
  export type PersonDataFailure = {
20
50
  kind: 'refusal';
21
51
  code: AppPersonDataRefusal;
22
52
  status?: number;
23
53
  message?: string;
54
+ /** A state proven by the same authorized request, when a newer server provides it. */
55
+ reason?: 'installation_suspended' | typeof APP_STORE_CURSOR_INVALID_REASON;
56
+ /** Zero-based index of the batch operation, when the server can identify one. */
57
+ index?: number;
24
58
  retryAfterMs?: number;
25
59
  } | {
26
60
  kind: 'conflict';
@@ -42,12 +76,12 @@ export declare const PERSON_DATA_REFUSAL_CODES: Record<AppPersonDataRefusal, str
42
76
  export declare const PERSON_DATA_CONFLICT_CODES: Record<AppStoreConflict, string>;
43
77
  /** A refusal that says "that is not there for you" exits as an unknown app does; the rest exit 1. */
44
78
  export declare function personDataFailureExit(failure: PersonDataFailure): number;
45
- /** Can the same call work a moment later? A busy server and a rate limit can; the rest need something changed. */
79
+ /** Automatic retry is only advised when the refusal proves it is safe to retry. */
46
80
  export declare function personDataFailureRetryable(failure: PersonDataFailure): boolean;
47
- /** The words for a refusal. The server's own sentence, when it sent one, is added after ours and never replaces it. */
81
+ /** The words for a refusal. Keep specific server diagnostics alongside the general guidance. */
48
82
  export declare function describePersonDataRefusal(failure: Extract<PersonDataFailure, {
49
83
  kind: 'refusal';
50
- }>, bin: string): string;
84
+ }>, bin: string, operation?: 'query'): string;
51
85
  /**
52
86
  * What a conflict means and what to do. A conflict is an ANSWER: someone (the app's window, an Agent, another person)
53
87
  * wrote the document first, so read it again, merge, and retry with the revision it is at now. Nothing was written.
@@ -59,6 +93,10 @@ export declare function describePersonDataConflict(failure: Extract<PersonDataFa
59
93
  collection: string;
60
94
  id: string;
61
95
  verb?: 'put' | 'patch' | 'delete' | 'batch';
96
+ batchTargets?: Array<{
97
+ collection?: unknown;
98
+ id?: unknown;
99
+ }>;
62
100
  }, bin: string): string;
63
101
  /** The `set` of a patch (a JSON object of path -> value) and the `unset` paths. What a path may be is the server's parser's to say. */
64
102
  export declare function readPatchInput(input: {
@@ -92,7 +130,7 @@ export declare function formatDocument(doc: AppStoreDocView): string[];
92
130
  export declare function formatQueryResult(result: AppStoreQueryResult, target: {
93
131
  installation: string;
94
132
  collection: string;
95
- }, bin: string): string[];
133
+ }, _bin: string): string[];
96
134
  /** The limit the reference and this help text share, so a number is never typed twice. */
97
135
  export declare const PERSON_DATA_QUERY_LIMIT_MAX: 200;
98
136
  /**