@skrr-ai/cli 0.1.142 → 0.1.144

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 (156) hide show
  1. package/README.md +8 -0
  2. package/dist/base-command.d.ts +4 -2
  3. package/dist/base-command.js +46 -13
  4. package/dist/commands/agenda/trigger/create.js +4 -2
  5. package/dist/commands/agenda/trigger/list.js +7 -7
  6. package/dist/commands/agent/message/approve.d.ts +17 -0
  7. package/dist/commands/agent/message/approve.js +72 -0
  8. package/dist/commands/agent/message/decline.d.ts +17 -0
  9. package/dist/commands/agent/message/decline.js +72 -0
  10. package/dist/commands/agent/message/pending.d.ts +18 -0
  11. package/dist/commands/agent/message/pending.js +79 -0
  12. package/dist/commands/agents/always-on/disable.js +9 -1
  13. package/dist/commands/agents/always-on/enable.js +9 -1
  14. package/dist/commands/agents/always-on/status.js +14 -1
  15. package/dist/commands/agents/create.js +10 -1
  16. package/dist/commands/agents/delete.d.ts +51 -0
  17. package/dist/commands/agents/delete.js +163 -2
  18. package/dist/commands/agents/intuitions/list.js +1 -1
  19. package/dist/commands/agents/plan-day.d.ts +39 -7
  20. package/dist/commands/agents/plan-day.js +254 -65
  21. package/dist/commands/agents/proactive-audit.d.ts +22 -0
  22. package/dist/commands/agents/proactive-audit.js +86 -0
  23. package/dist/commands/agents/schedule-overview.d.ts +7 -0
  24. package/dist/commands/agents/schedule-overview.js +43 -5
  25. package/dist/commands/agents/schedule-trace.js +30 -19
  26. package/dist/commands/agents/spawn.d.ts +51 -0
  27. package/dist/commands/agents/spawn.js +212 -9
  28. package/dist/commands/agents/todos/cancel.js +3 -0
  29. package/dist/commands/agents/todos/edit.js +1 -1
  30. package/dist/commands/agents/todos/list.d.ts +5 -0
  31. package/dist/commands/agents/todos/list.js +19 -5
  32. package/dist/commands/agents/triggers/create.js +1 -1
  33. package/dist/commands/agents/triggers/policy.js +7 -0
  34. package/dist/commands/agents/triggers/update.js +1 -1
  35. package/dist/commands/commitments/create.js +13 -3
  36. package/dist/commands/commitments/preflight.js +31 -5
  37. package/dist/commands/daemon/index.js +1 -0
  38. package/dist/commands/daemon/logs.d.ts +8 -1
  39. package/dist/commands/daemon/logs.js +32 -22
  40. package/dist/commands/daemon/profile.d.ts +15 -0
  41. package/dist/commands/daemon/profile.js +51 -0
  42. package/dist/commands/goals/briefing/status.js +1 -1
  43. package/dist/commands/initiatives/worker/deactivate.d.ts +23 -0
  44. package/dist/commands/initiatives/worker/deactivate.js +78 -0
  45. package/dist/commands/login.js +8 -2
  46. package/dist/commands/logout.d.ts +20 -0
  47. package/dist/commands/logout.js +110 -5
  48. package/dist/commands/machines/profiles/disconnect.d.ts +23 -0
  49. package/dist/commands/machines/profiles/disconnect.js +102 -0
  50. package/dist/commands/machines/profiles/index.d.ts +15 -0
  51. package/dist/commands/machines/profiles/index.js +33 -0
  52. package/dist/commands/machines/profiles/label.d.ts +24 -0
  53. package/dist/commands/machines/profiles/label.js +85 -0
  54. package/dist/commands/machines/profiles/list.d.ts +16 -0
  55. package/dist/commands/machines/profiles/list.js +87 -0
  56. package/dist/commands/memory/maintain.js +16 -2
  57. package/dist/commands/profiles/list.js +17 -2
  58. package/dist/commands/spaces/delete.js +6 -1
  59. package/dist/commands/spaces/workflows/archive.js +6 -1
  60. package/dist/commands/spaces/workflows/publish.js +3 -1
  61. package/dist/commands/spaces/workflows/run.d.ts +1 -0
  62. package/dist/commands/spaces/workflows/run.js +17 -1
  63. package/dist/commands/spaces/workflows/triggers/create.js +3 -1
  64. package/dist/commands/tasks/workflow-context.js +3 -1
  65. package/dist/commands/triggers/authorization.js +1 -1
  66. package/dist/commands/triggers/capabilities.js +17 -1
  67. package/dist/commands/triggers/create.d.ts +2 -0
  68. package/dist/commands/triggers/create.js +23 -7
  69. package/dist/commands/triggers/fire-detail.js +12 -3
  70. package/dist/commands/triggers/list.d.ts +1 -0
  71. package/dist/commands/triggers/list.js +13 -1
  72. package/dist/commands/triggers/preflight.js +18 -0
  73. package/dist/commands/triggers/prune.js +9 -5
  74. package/dist/commands/triggers/update.js +13 -4
  75. package/dist/generated/agent-guides.json +35 -35
  76. package/dist/lib/agent-guides.js +1 -1
  77. package/dist/lib/agent-proactive-baseline.d.ts +6 -0
  78. package/dist/lib/agent-proactive-baseline.js +32 -3
  79. package/dist/lib/always-on-command-result.d.ts +18 -0
  80. package/dist/lib/always-on-command-result.js +52 -0
  81. package/dist/lib/always-on-runtime.d.ts +31 -0
  82. package/dist/lib/always-on-runtime.js +39 -0
  83. package/dist/lib/auth-diagnostics.d.ts +10 -1
  84. package/dist/lib/auth-diagnostics.js +16 -8
  85. package/dist/lib/commitments.d.ts +16 -9
  86. package/dist/lib/commitments.js +65 -4
  87. package/dist/lib/compasses.js +5 -0
  88. package/dist/lib/daemon-binding.js +6 -3
  89. package/dist/lib/daemon-command-hint.d.ts +10 -5
  90. package/dist/lib/daemon-command-hint.js +11 -6
  91. package/dist/lib/daemon-setup.js +9 -3
  92. package/dist/lib/daemonBroker.d.ts +7 -0
  93. package/dist/lib/daemonBroker.js +5 -0
  94. package/dist/lib/daemonHandoff.d.ts +2 -0
  95. package/dist/lib/daemonHandoff.js +16 -3
  96. package/dist/lib/daemonIslandProfile.d.ts +19 -0
  97. package/dist/lib/daemonIslandProfile.js +41 -0
  98. package/dist/lib/drain-stdio.d.ts +22 -0
  99. package/dist/lib/drain-stdio.js +46 -0
  100. package/dist/lib/format.d.ts +32 -0
  101. package/dist/lib/format.js +105 -1
  102. package/dist/lib/initiatives-worker.d.ts +25 -0
  103. package/dist/lib/initiatives-worker.js +13 -0
  104. package/dist/lib/keychain.d.ts +22 -1
  105. package/dist/lib/keychain.js +40 -1
  106. package/dist/lib/local-daemon-readiness.js +4 -6
  107. package/dist/lib/local-skills.js +4 -1
  108. package/dist/lib/login.d.ts +7 -0
  109. package/dist/lib/login.js +5 -0
  110. package/dist/lib/machines.d.ts +68 -0
  111. package/dist/lib/machines.js +67 -0
  112. package/dist/lib/proactive-audit.d.ts +52 -0
  113. package/dist/lib/proactive-audit.js +67 -0
  114. package/dist/lib/proactiveApi.d.ts +23 -0
  115. package/dist/lib/refresh.d.ts +20 -6
  116. package/dist/lib/refresh.js +27 -9
  117. package/dist/lib/roles.d.ts +1 -1
  118. package/dist/lib/runtime-start-verification.js +3 -6
  119. package/dist/lib/schedule.d.ts +189 -9
  120. package/dist/lib/schedule.js +283 -22
  121. package/dist/lib/triggers.d.ts +134 -3
  122. package/dist/lib/triggers.js +370 -17
  123. package/dist/lib/workflow-node-control.js +8 -0
  124. package/dist/lib/workflow-run-view.js +9 -0
  125. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/configRoot.d.ts +12 -0
  126. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/configRoot.js +10 -2
  127. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/deviceIdentityBridge.d.ts +8 -0
  128. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/deviceIdentityBridge.js +22 -0
  129. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/executorStopReceiptV2.d.ts +133 -0
  130. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/executorStopReceiptV2.js +180 -0
  131. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.d.ts +5 -3
  132. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.js +50 -0
  133. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profilePorts.d.ts +137 -0
  134. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profilePorts.js +328 -0
  135. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profileSelection.d.ts +63 -0
  136. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profileSelection.js +174 -0
  137. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refresh.d.ts +22 -0
  138. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refresh.js +15 -4
  139. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/configRoot.d.ts +12 -0
  140. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/configRoot.js +14 -0
  141. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/deviceIdentityBridge.d.ts +8 -0
  142. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/deviceIdentityBridge.js +27 -0
  143. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/executorStopReceiptV2.d.ts +133 -0
  144. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/executorStopReceiptV2.js +183 -0
  145. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.d.ts +5 -3
  146. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.js +11 -3
  147. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profilePorts.d.ts +137 -0
  148. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profilePorts.js +333 -0
  149. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profileSelection.d.ts +63 -0
  150. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profileSelection.js +212 -0
  151. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refresh.d.ts +22 -0
  152. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refresh.js +22 -4
  153. package/dist/node_modules/@skrr-ai/auth-core/package.json +11 -1
  154. package/dist/node_modules/@skrr-ai/data-provider/index.js +7446 -7378
  155. package/oclif.manifest.json +844 -47
  156. package/package.json +1 -1
@@ -16,6 +16,49 @@ export declare function agentRemovalReport(agentId: string, response: DeleteAgen
16
16
  * nothing (an older server, or an uninstall, which erases nothing).
17
17
  */
18
18
  export declare function agentErasureReport(response: DeleteAgentResponse | undefined): string[];
19
+ /**
20
+ * What stays behind: Goals the Agent owned and open Tasks assigned to it. They are the owner's own
21
+ * work, so deleting the Agent does not remove them, and until now the receipt never said so
22
+ * (OSK-22342).
23
+ */
24
+ export declare function agentRetainedReport(response: DeleteAgentResponse | undefined, bin?: string): string[];
25
+ /**
26
+ * How long to keep reading an agent whose deletion the server accepted but had not finished. The
27
+ * slowest deletions seen under load ran a little over two minutes in all, and the server answers
28
+ * the request about 45 s in.
29
+ */
30
+ export declare const DELETION_SETTLE_TIMEOUT_MS = 180000;
31
+ /**
32
+ * `409 AGENT_DELETE_IN_PROGRESS`: another request holds the delete lease for this agent. That is the
33
+ * deletion this command is after, running (or abandoned and not yet expired), not a failure to
34
+ * delete.
35
+ */
36
+ export declare function isDeleteInProgressRefusal(err: unknown): boolean;
37
+ export type DeletionSettlement = {
38
+ /**
39
+ * - `gone` — the agent now reads as not found.
40
+ * - `present` — it still reads, so the deletion has not committed (or failed).
41
+ * - `unreadable` — it could not be read at all in the time given.
42
+ */
43
+ state: 'gone' | 'present' | 'unreadable';
44
+ waitedMs: number;
45
+ };
46
+ /**
47
+ * Reads the agent until it is not found, or until `timeoutMs` has passed. A failed read is not
48
+ * a verdict: the server may be busy, which is why the deletion is slow, so it is tried again.
49
+ */
50
+ export declare function waitForAgentGone(agentId: string, options?: {
51
+ timeoutMs?: number;
52
+ intervalMs?: number;
53
+ read?: (agentId: string) => Promise<unknown>;
54
+ sleep?: (ms: number) => Promise<void>;
55
+ now?: () => number;
56
+ onWait?: (waitedMs: number) => void;
57
+ }): Promise<DeletionSettlement>;
58
+ /** What to print once a deletion that outlived its request is seen to be finished. */
59
+ export declare function agentDeletionSettledReport(agentId: string, waitedMs: number): string[];
60
+ /** What to say when the agent still reads after the wait. */
61
+ export declare function agentDeletionUnsettledMessage(agentId: string, waitedMs: number, bin?: string): string;
19
62
  export default class AgentsDelete extends BaseCommand {
20
63
  static description: string;
21
64
  static examples: string[];
@@ -24,11 +67,19 @@ export default class AgentsDelete extends BaseCommand {
24
67
  };
25
68
  static flags: {
26
69
  yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
70
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
27
71
  };
28
72
  /**
29
73
  * Which of the two the request is about to do, so the prompt can say so. A
30
74
  * failed read is not a reason to refuse: the delete reports its own error.
31
75
  */
32
76
  private predictRemoval;
77
+ /**
78
+ * The server did not finish the deletion inside the time a request may wait (it answered `202`),
79
+ * or another request already holds this agent's delete lease. Either way a deletion is running
80
+ * that this command did not see finish, so read the agent until it is gone instead of reporting
81
+ * the hold as a failure of a delete that is succeeding (OSK-21713, OSK-21788).
82
+ */
83
+ private settleRunningDeletion;
33
84
  run(): Promise<void>;
34
85
  }
@@ -1,11 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DELETION_SETTLE_TIMEOUT_MS = void 0;
3
4
  exports.agentRemovalQuestion = agentRemovalQuestion;
4
5
  exports.agentRemovalReport = agentRemovalReport;
5
6
  exports.agentErasureReport = agentErasureReport;
7
+ exports.agentRetainedReport = agentRetainedReport;
8
+ exports.isDeleteInProgressRefusal = isDeleteInProgressRefusal;
9
+ exports.waitForAgentGone = waitForAgentGone;
10
+ exports.agentDeletionSettledReport = agentDeletionSettledReport;
11
+ exports.agentDeletionUnsettledMessage = agentDeletionUnsettledMessage;
6
12
  const core_1 = require("@oclif/core");
7
13
  const data_provider_1 = require("@skrr-ai/data-provider");
8
14
  const base_command_1 = require("../../base-command");
15
+ const http_error_1 = require("../../lib/http-error");
9
16
  const prompt_1 = require("../../lib/prompt");
10
17
  /**
11
18
  * The confirmation question. Deleting an agent installed from the store only
@@ -52,17 +59,101 @@ function agentErasureReport(response) {
52
59
  const erasure = response && 'erasure' in response ? response.erasure : undefined;
53
60
  return (0, data_provider_1.describePersonalContextErasure)(erasure)?.lines ?? [];
54
61
  }
62
+ /**
63
+ * What stays behind: Goals the Agent owned and open Tasks assigned to it. They are the owner's own
64
+ * work, so deleting the Agent does not remove them, and until now the receipt never said so
65
+ * (OSK-22342).
66
+ */
67
+ function agentRetainedReport(response, bin = 'skrr') {
68
+ if ((0, data_provider_1.agentRemovalKind)(response) !== 'deleted')
69
+ return [];
70
+ const retained = response && 'retained' in response ? response.retained : undefined;
71
+ if (!retained || (retained.goals <= 0 && retained.openTasks <= 0))
72
+ return [];
73
+ const noun = (count, word) => `${count} ${word}${count === 1 ? '' : 's'}`;
74
+ const parts = [
75
+ ...(retained.goals > 0 ? [noun(retained.goals, 'goal')] : []),
76
+ ...(retained.openTasks > 0 ? [noun(retained.openTasks, 'open task')] : []),
77
+ ];
78
+ return [
79
+ `Left in place: ${parts.join(' and ')} that this agent owned or was assigned. They are yours, so deleting the agent did not remove them, and they still name it.`,
80
+ ` Archive or reassign them with \`${bin} goals archive <goal-id>\` and \`${bin} tasks\`.`,
81
+ ];
82
+ }
83
+ /**
84
+ * How long to keep reading an agent whose deletion the server accepted but had not finished. The
85
+ * slowest deletions seen under load ran a little over two minutes in all, and the server answers
86
+ * the request about 45 s in.
87
+ */
88
+ exports.DELETION_SETTLE_TIMEOUT_MS = 180_000;
89
+ const DELETION_SETTLE_INTERVAL_MS = 3_000;
90
+ /**
91
+ * `409 AGENT_DELETE_IN_PROGRESS`: another request holds the delete lease for this agent. That is the
92
+ * deletion this command is after, running (or abandoned and not yet expired), not a failure to
93
+ * delete.
94
+ */
95
+ function isDeleteInProgressRefusal(err) {
96
+ return (0, http_error_1.httpBodyOf)(err)?.code === 'AGENT_DELETE_IN_PROGRESS';
97
+ }
98
+ /**
99
+ * Reads the agent until it is not found, or until `timeoutMs` has passed. A failed read is not
100
+ * a verdict: the server may be busy, which is why the deletion is slow, so it is tried again.
101
+ */
102
+ async function waitForAgentGone(agentId, options = {}) {
103
+ const timeoutMs = options.timeoutMs ?? exports.DELETION_SETTLE_TIMEOUT_MS;
104
+ const intervalMs = options.intervalMs ?? DELETION_SETTLE_INTERVAL_MS;
105
+ const read = options.read ?? ((id) => data_provider_1.dataService.getAgentById({ agent_id: id }));
106
+ const sleep = options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
107
+ const now = options.now ?? Date.now;
108
+ const startedAt = now();
109
+ let state = 'unreadable';
110
+ for (;;) {
111
+ try {
112
+ await read(agentId);
113
+ state = 'present';
114
+ }
115
+ catch (err) {
116
+ if ((0, http_error_1.isHttpNotFound)(err))
117
+ return { state: 'gone', waitedMs: now() - startedAt };
118
+ }
119
+ const waitedMs = now() - startedAt;
120
+ if (waitedMs >= timeoutMs)
121
+ return { state, waitedMs };
122
+ options.onWait?.(waitedMs);
123
+ await sleep(Math.min(intervalMs, timeoutMs - waitedMs));
124
+ }
125
+ }
126
+ /** What to print once a deletion that outlived its request is seen to be finished. */
127
+ function agentDeletionSettledReport(agentId, waitedMs) {
128
+ return [
129
+ `Deleted agent ${agentId}`,
130
+ `The deletion finished ${Math.round(waitedMs / 1000)}s after the server answered the request, so no erasure receipt came back with it.`,
131
+ 'Personal Context erasure: not confirmed. The agent is gone; that does not confirm that data derived from it has been erased.',
132
+ ];
133
+ }
134
+ /** What to say when the agent still reads after the wait. */
135
+ function agentDeletionUnsettledMessage(agentId, waitedMs, bin = 'skrr') {
136
+ return [
137
+ `Agent ${agentId} is still there after ${Math.round(waitedMs / 1000)}s. The server has not finished deleting it: a deletion may still be running, or an earlier one's hold may not have expired yet.`,
138
+ `Read it with \`${bin} agents show ${agentId}\`; it reads as not found once it is gone.`,
139
+ `Running \`${bin} agents delete ${agentId}\` again is safe: while the first deletion is running it is refused as already in progress, and if the first one failed it starts a new attempt.`,
140
+ ].join('\n');
141
+ }
55
142
  class AgentsDelete extends base_command_1.BaseCommand {
56
143
  static description = 'Delete an agent you created (irreversible), or uninstall one installed from the store (reinstalling restores it)';
57
144
  static examples = [
58
145
  '<%= config.bin %> agents delete <agent-id>',
59
146
  '<%= config.bin %> agents delete <agent-id> --yes',
147
+ '<%= config.bin %> agents delete <agent-id> --yes --json',
60
148
  ];
61
149
  static args = {
62
150
  id: core_1.Args.string({ description: 'Agent ID', required: true, ignoreStdin: true }),
63
151
  };
64
152
  static flags = {
65
153
  yes: core_1.Flags.boolean({ char: 'y', description: 'Skip confirmation prompt' }),
154
+ json: core_1.Flags.boolean({
155
+ description: "Output the receipt as JSON: what was done (`removal`) and the server's own erasure and retained-work report. Pair with --yes in scripts.",
156
+ }),
66
157
  };
67
158
  /**
68
159
  * Which of the two the request is about to do, so the prompt can say so. A
@@ -76,6 +167,58 @@ class AgentsDelete extends base_command_1.BaseCommand {
76
167
  return null;
77
168
  }
78
169
  }
170
+ /**
171
+ * The server did not finish the deletion inside the time a request may wait (it answered `202`),
172
+ * or another request already holds this agent's delete lease. Either way a deletion is running
173
+ * that this command did not see finish, so read the agent until it is gone instead of reporting
174
+ * the hold as a failure of a delete that is succeeding (OSK-21713, OSK-21788).
175
+ */
176
+ async settleRunningDeletion(agentId, alreadyRunning, json) {
177
+ if (!json) {
178
+ this.log(alreadyRunning
179
+ ? `A deletion of agent ${agentId} is already running on the server. Waiting for it to finish...`
180
+ : `Deleting agent ${agentId} is taking longer than a request may wait, so it continues on the server. Waiting for it to finish...`);
181
+ }
182
+ let lastReported = 0;
183
+ const settled = await waitForAgentGone(agentId, {
184
+ onWait: (waitedMs) => {
185
+ if (json || waitedMs - lastReported < 30_000)
186
+ return;
187
+ lastReported = waitedMs;
188
+ this.log(`Still deleting after ${Math.round(waitedMs / 1000)}s...`);
189
+ },
190
+ });
191
+ if (settled.state === 'gone') {
192
+ if (json) {
193
+ // No erasure object: the receipt belonged to the request that started the deletion, which
194
+ // had already been answered. A script must not read its absence as erased.
195
+ this.printJsonResult({
196
+ agentId,
197
+ removal: 'deleted',
198
+ deletion: 'finished_after_response',
199
+ waitedMs: settled.waitedMs,
200
+ erasureReceipt: 'unavailable',
201
+ });
202
+ return;
203
+ }
204
+ for (const line of agentDeletionSettledReport(agentId, settled.waitedMs))
205
+ this.log(line);
206
+ return;
207
+ }
208
+ if (json) {
209
+ this.printJsonResult({
210
+ agentId,
211
+ removal: null,
212
+ deletion: 'running',
213
+ agentReadable: settled.state === 'present',
214
+ waitedMs: settled.waitedMs,
215
+ }, { ok: false });
216
+ this.exit(1);
217
+ }
218
+ this.error(agentDeletionUnsettledMessage(agentId, settled.waitedMs, this.config.bin), {
219
+ exit: 1,
220
+ });
221
+ }
79
222
  async run() {
80
223
  this.requireAuth();
81
224
  const { args, flags } = await this.parse(AgentsDelete);
@@ -92,19 +235,37 @@ class AgentsDelete extends base_command_1.BaseCommand {
92
235
  throw err;
93
236
  }
94
237
  if (!ok) {
95
- this.log('Cancelled.');
238
+ if (flags.json)
239
+ this.printJsonResult({ agentId: args.id, cancelled: true }, { ok: false });
240
+ else
241
+ this.log('Cancelled.');
96
242
  return;
97
243
  }
98
244
  let response;
245
+ let alreadyRunning = false;
99
246
  try {
100
247
  response = await data_provider_1.dataService.deleteAgent({ agent_id: args.id });
101
248
  }
102
249
  catch (err) {
103
- this.handleApiError(err);
250
+ if (!isDeleteInProgressRefusal(err))
251
+ this.handleApiError(err);
252
+ alreadyRunning = true;
253
+ }
254
+ if (alreadyRunning || (0, data_provider_1.agentDeletionPending)(response)) {
255
+ await this.settleRunningDeletion(args.id, alreadyRunning, Boolean(flags.json));
256
+ return;
257
+ }
258
+ if (flags.json) {
259
+ // The server's own report, unabridged: a script needs the erasure state and the retained
260
+ // work as data, not as the sentences a person reads below.
261
+ this.printJsonResult({ agentId: args.id, removal: (0, data_provider_1.agentRemovalKind)(response), ...response });
262
+ return;
104
263
  }
105
264
  this.log(agentRemovalReport(args.id, response));
106
265
  for (const line of agentErasureReport(response))
107
266
  this.log(line);
267
+ for (const line of agentRetainedReport(response, this.config.bin))
268
+ this.log(line);
108
269
  }
109
270
  }
110
271
  exports.default = AgentsDelete;
@@ -21,7 +21,7 @@ class AgentsIntuitionsList extends base_command_1.BaseCommand {
21
21
  this.log(`No active intuitions. Run skrr agents intuitions generate ${args.agentId} to look for suggestions.`);
22
22
  }
23
23
  else {
24
- this.log(JSON.stringify(intuitions, null, 2));
24
+ this.printJsonResult(intuitions);
25
25
  }
26
26
  this.printAgentUrl(args.agentId);
27
27
  }
@@ -12,7 +12,13 @@ import { BaseCommand } from '../../base-command';
12
12
  *
13
13
  * A proposal is a DRAFT — nothing is scheduled until `--approve`. Re-running the
14
14
  * bare command recovers the pending proposal rather than regenerating it (mirrors
15
- * the board, which recovers a pending plan into the review modal).
15
+ * the board, which recovers a pending plan into the review modal). With NO
16
+ * pending plan the bare command starts a real planner run, and says so before it
17
+ * does; `--regenerate` is the explicit way to replace a pending plan.
18
+ *
19
+ * Times are shown in the plan's own timezone, named. A plan is proposed in
20
+ * `--timezone`, or this machine's zone: the same default `schedule-trace` and
21
+ * `todos list` use, so one agent-day is one zone across the commands.
16
22
  */
17
23
  export default class AgentsPlanDay extends BaseCommand {
18
24
  static description: string;
@@ -41,18 +47,44 @@ export default class AgentsPlanDay extends BaseCommand {
41
47
  * --json` did when the transport handed back an unparseable body (OSK-2803).
42
48
  */
43
49
  private requireProposal;
44
- /** `{proposal}` envelope reader that survives a body-less response. */
45
- private fetchPending;
50
+ /**
51
+ * `{proposal, planRequest}` envelope reader that survives a body-less response.
52
+ *
53
+ * `planRequest` is the server's own record of whether a plan is being
54
+ * generated, failed, or went quiet. It is what lets this command answer from
55
+ * the server's side instead of guessing from a timeout.
56
+ */
57
+ private fetchPendingState;
58
+ /** Refuse an action on the draft while its replacement is being generated. */
59
+ private refuseWhileGenerating;
46
60
  private workingHoursOverride;
47
61
  /**
48
62
  * Gateway failures can interrupt a response after the planner started.
49
- * Check the durable draft before suggesting another billable request; a
63
+ * Check the server's record before suggesting another billable request; a
50
64
  * 502 can also mean the planner never started, so do not assert that it did.
51
65
  */
52
66
  private static readonly TIMEOUT_STATUSES;
53
- /** Bounded, honest recovery poll. A daemon-run plan lands in ~2-4 minutes. */
54
- private static readonly RECOVERY_ATTEMPTS;
55
- private static readonly RECOVERY_INTERVAL_MS;
67
+ private static readonly POLL_INTERVAL_MS;
68
+ /** Without a plan-request record (older server) the wait is the old, bounded guess. */
69
+ private static readonly LEGACY_POLL_ATTEMPTS;
70
+ /** The longest a planner may run is ~12 min; wait that plus a margin, never forever. */
71
+ private static readonly MAX_WAIT_MS;
72
+ /** A finished request's draft can lag a replica read; allow a few polls for it. */
73
+ private static readonly DRAFT_LAG_POLLS;
74
+ /**
75
+ * Wait for a plan request to settle, reading the server's record each time.
76
+ *
77
+ * `target` says which request matters:
78
+ * - `existing`: one we found running, and want the result of.
79
+ * - `ours`: the request our POST started, whose response was lost. We only
80
+ * know the id of whatever was on record BEFORE posting, so a record that is
81
+ * missing or unchanged means the server never saw our request start.
82
+ *
83
+ * Returns instead of throwing for the three "no draft" endings so the caller
84
+ * decides what each means; a request that FAILED throws with the reason,
85
+ * because that is the one answer the person has been missing.
86
+ */
87
+ private awaitPlanRequest;
56
88
  /**
57
89
  * After a timed-out propose, collect the draft the server persisted anyway.
58
90
  * Returns null when the failure was not a timeout, or when nothing landed —