@skrr-ai/cli 0.1.143 → 0.1.145

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 (102) hide show
  1. package/README.md +13 -0
  2. package/dist/commands/agenda/plan.d.ts +7 -0
  3. package/dist/commands/agenda/plan.js +17 -0
  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 +70 -0
  8. package/dist/commands/agent/message/decline.d.ts +17 -0
  9. package/dist/commands/agent/message/decline.js +70 -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/delete.d.ts +45 -0
  13. package/dist/commands/agents/delete.js +139 -2
  14. package/dist/commands/agents/plan-day.d.ts +50 -7
  15. package/dist/commands/agents/plan-day.js +293 -65
  16. package/dist/commands/agents/proactive-audit.d.ts +22 -0
  17. package/dist/commands/agents/proactive-audit.js +86 -0
  18. package/dist/commands/agents/schedule-overview.d.ts +7 -0
  19. package/dist/commands/agents/schedule-overview.js +49 -5
  20. package/dist/commands/agents/schedule-trace.js +42 -21
  21. package/dist/commands/agents/spawn.d.ts +78 -1
  22. package/dist/commands/agents/spawn.js +262 -6
  23. package/dist/commands/agents/todos/list.d.ts +5 -0
  24. package/dist/commands/agents/todos/list.js +19 -5
  25. package/dist/commands/agents/triggers/create.js +1 -1
  26. package/dist/commands/agents/triggers/update.js +1 -1
  27. package/dist/commands/agents/upcoming.d.ts +1 -0
  28. package/dist/commands/agents/upcoming.js +18 -7
  29. package/dist/commands/commitments/create.js +14 -4
  30. package/dist/commands/commitments/preflight.js +14 -3
  31. package/dist/commands/commitments/update.js +1 -1
  32. package/dist/commands/initiatives/worker/deactivate.d.ts +23 -0
  33. package/dist/commands/initiatives/worker/deactivate.js +78 -0
  34. package/dist/commands/login.js +8 -2
  35. package/dist/commands/logout.d.ts +20 -0
  36. package/dist/commands/logout.js +110 -5
  37. package/dist/commands/memory/maintain.js +16 -2
  38. package/dist/commands/spaces/delete.js +6 -1
  39. package/dist/commands/spaces/workflow-templates/insert.js +4 -0
  40. package/dist/commands/spaces/workflows/archive.js +6 -1
  41. package/dist/commands/spaces/workflows/publish.js +3 -1
  42. package/dist/commands/spaces/workflows/run.d.ts +1 -0
  43. package/dist/commands/spaces/workflows/run.js +17 -1
  44. package/dist/commands/spaces/workflows/triggers/create.js +3 -1
  45. package/dist/commands/store/show.js +22 -0
  46. package/dist/commands/tasks/workflow-context.js +3 -1
  47. package/dist/commands/triggers/capabilities.js +17 -1
  48. package/dist/commands/triggers/create.d.ts +2 -0
  49. package/dist/commands/triggers/create.js +23 -7
  50. package/dist/commands/triggers/fire-detail.js +12 -3
  51. package/dist/commands/triggers/list.d.ts +1 -0
  52. package/dist/commands/triggers/list.js +13 -1
  53. package/dist/commands/triggers/preflight.js +18 -0
  54. package/dist/commands/triggers/prune.js +9 -5
  55. package/dist/commands/triggers/update.js +13 -4
  56. package/dist/generated/agent-guides.json +35 -35
  57. package/dist/lib/agent-proactive-baseline.js +7 -1
  58. package/dist/lib/agentic-stream.d.ts +7 -0
  59. package/dist/lib/agentic-stream.js +22 -0
  60. package/dist/lib/commitments.d.ts +16 -9
  61. package/dist/lib/commitments.js +78 -5
  62. package/dist/lib/compasses.js +1 -1
  63. package/dist/lib/daemon-setup.js +9 -3
  64. package/dist/lib/daemonBroker.d.ts +7 -0
  65. package/dist/lib/daemonBroker.js +5 -0
  66. package/dist/lib/daemonHandoff.d.ts +2 -0
  67. package/dist/lib/daemonHandoff.js +10 -1
  68. package/dist/lib/daemonIslandProfile.d.ts +19 -0
  69. package/dist/lib/daemonIslandProfile.js +41 -0
  70. package/dist/lib/dedicated-power.js +10 -3
  71. package/dist/lib/format.d.ts +47 -0
  72. package/dist/lib/format.js +136 -1
  73. package/dist/lib/initiatives-worker.d.ts +25 -0
  74. package/dist/lib/initiatives-worker.js +13 -0
  75. package/dist/lib/login.d.ts +7 -0
  76. package/dist/lib/login.js +5 -0
  77. package/dist/lib/planOutcome.d.ts +51 -0
  78. package/dist/lib/planOutcome.js +88 -0
  79. package/dist/lib/proactive-audit.d.ts +52 -0
  80. package/dist/lib/proactive-audit.js +67 -0
  81. package/dist/lib/proactiveApi.d.ts +71 -0
  82. package/dist/lib/proactiveApi.js +10 -1
  83. package/dist/lib/refresh.d.ts +20 -6
  84. package/dist/lib/refresh.js +27 -9
  85. package/dist/lib/roles.d.ts +1 -1
  86. package/dist/lib/schedule.d.ts +214 -10
  87. package/dist/lib/schedule.js +317 -21
  88. package/dist/lib/triggers.d.ts +139 -3
  89. package/dist/lib/triggers.js +382 -18
  90. package/dist/lib/workflow-node-control.js +8 -0
  91. package/dist/lib/workflow-run-view.js +9 -0
  92. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.d.ts +1 -1
  93. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.js +2 -0
  94. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refresh.d.ts +22 -0
  95. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refresh.js +15 -4
  96. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.d.ts +1 -1
  97. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.js +1 -1
  98. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refresh.d.ts +22 -0
  99. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refresh.js +22 -4
  100. package/dist/node_modules/@skrr-ai/data-provider/index.js +5252 -5211
  101. package/oclif.manifest.json +526 -29
  102. package/package.json +1 -1
package/README.md CHANGED
@@ -679,6 +679,19 @@ sky agents plan-day <agent-id> --regenerate "prioritize the Q2 launch" \
679
679
  --hours-start 09:00 --hours-end 17:00 # a fresh plan with a working-hours window
680
680
  ```
681
681
 
682
+ Generating a plan can take minutes, and the request that started it can end (a
683
+ gateway timeout) while the server keeps going. The server records each request
684
+ per agent-day, so `plan-day` and `schedule-trace` report what it knows: that a
685
+ plan is being generated (and since when), that the last attempt failed (and
686
+ why), or that a request went quiet and may have been interrupted. While a plan
687
+ is being generated, `--approve`, `--dismiss` and `--regenerate` are refused and
688
+ a bare `plan-day` waits for it instead of starting a second one.
689
+
690
+ A plan takes about a minute, longer than the edge lets one request wait. `plan-day`
691
+ therefore sends `Prefer: respond-async`: once the server has claimed the day it
692
+ answers 202 with the request it recorded and keeps planning, and the command
693
+ follows that request until it succeeds, fails (with the reason) or goes quiet.
694
+
682
695
  ### `sky agents schedule-overview <id>` — full-visibility view
683
696
 
684
697
  One call for everything an agent needs when it wakes to think: its
@@ -1,4 +1,11 @@
1
1
  import { BaseCommand } from '../../base-command';
2
+ /**
3
+ * The first thing a following terminal says after the runtime line. The turn is
4
+ * accepted but the worker takes about thirty seconds to start it, and until the
5
+ * stream reports `run.started` nothing else prints, which reads as a hang
6
+ * (OSK-22554). Names the cloud worker when that is where the turn is queued.
7
+ */
8
+ export declare function describeQueuedProgress(runtime: unknown): string;
2
9
  /**
3
10
  * `skrr agenda plan <agent-id>` — kick off a one-shot Agenda Planning turn
4
11
  * for an agent. The server-side controller resolves the agent's persistent
@@ -1,11 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.describeQueuedProgress = describeQueuedProgress;
3
4
  const core_1 = require("@oclif/core");
4
5
  const data_provider_1 = require("@skrr-ai/data-provider");
5
6
  const base_command_1 = require("../../base-command");
6
7
  const api_fetch_1 = require("../../lib/api-fetch");
7
8
  const agentic_stream_1 = require("../../lib/agentic-stream");
8
9
  const chat_1 = require("../agents/chat");
10
+ /**
11
+ * The first thing a following terminal says after the runtime line. The turn is
12
+ * accepted but the worker takes about thirty seconds to start it, and until the
13
+ * stream reports `run.started` nothing else prints, which reads as a hang
14
+ * (OSK-22554). Names the cloud worker when that is where the turn is queued.
15
+ */
16
+ function describeQueuedProgress(runtime) {
17
+ const plan = runtime && typeof runtime === 'object'
18
+ ? runtime.executionPlan
19
+ : null;
20
+ const selected = plan && typeof plan === 'object' ? plan.selectedKind : null;
21
+ return selected === 'agent-worker'
22
+ ? 'Queued on the cloud worker, starting…'
23
+ : 'Queued, waiting for the agent runtime to start…';
24
+ }
9
25
  function describeRuntime(runtime) {
10
26
  if (typeof runtime === 'string')
11
27
  return runtime;
@@ -86,6 +102,7 @@ class AgendaPlan extends base_command_1.BaseCommand {
86
102
  this.log('The turn is running detached. It may wait for permission; inspect it in the app or conversation ' + response.conversationId + '.');
87
103
  return;
88
104
  }
105
+ this.log(describeQueuedProgress(response.runtime));
89
106
  const readMessages = async () => {
90
107
  const messages = await data_provider_1.dataService.getMessagesByConvoId(response.conversationId);
91
108
  return Array.isArray(messages) ? messages : [];
@@ -17,7 +17,9 @@ const base_command_1 = require("../../../base-command");
17
17
  * agenda MCP server's hardened defaults (`DEFAULT_SCHEDULE_MAX_FIRES_PER_DAY`).
18
18
  */
19
19
  class AgendaTriggerCreate extends base_command_1.BaseCommand {
20
- static description = 'Register a future automatic agent run via the AgentTrigger subsystem. Mirrors the agenda_create_trigger MCP tool.';
20
+ static description = 'Register a future automatic agent run via the AgentTrigger subsystem. Mirrors the agenda_create_trigger MCP tool. ' +
21
+ 'Every run is a model turn. For a daily time, a one-time run or a deterministic action with no model turn ' +
22
+ '(for example creating a task), use `skrr triggers create`.';
21
23
  static examples = [
22
24
  "<%= config.bin %> agenda trigger create <agent-id> --kind schedule --cron '0 9 * * MON' --label 'Weekly briefing' --prompt 'Summarize last week and plan this week.'",
23
25
  "<%= config.bin %> agenda trigger create <agent-id> --kind self_scheduled --delay-minutes 240 --label 'Follow up' --prompt 'Check back on the Q2 launch task.'",
@@ -45,7 +47,7 @@ class AgendaTriggerCreate extends base_command_1.BaseCommand {
45
47
  description: "5-field cron expression — required when --kind=schedule (e.g. '0 9 * * MON')",
46
48
  }),
47
49
  timezone: core_1.Flags.string({
48
- description: 'IANA timezone for the cron (defaults to UTC). Only used with --kind=schedule.',
50
+ description: 'IANA timezone the cron is read in, for example America/Los_Angeles. Defaults to UTC, so "0 9 * * *" is 09:00 UTC when this is left out. Only used with --kind=schedule.',
49
51
  }),
50
52
  'delay-minutes': core_1.Flags.integer({
51
53
  description: 'Minutes from now to fire — required when --kind=self_scheduled. ' +
@@ -104,16 +104,16 @@ class AgendaTriggerList extends base_command_1.BaseCommand {
104
104
  return;
105
105
  }
106
106
  const rows = items.map((t) => {
107
- const next = t.schedule?.nextRunAt ??
108
- t.selfScheduled?.nextRunAt ??
109
- (0, triggers_1.onceDueAt)(t) ??
110
- '-';
107
+ // The same answer `triggers list` gives: a disabled trigger has no next run (its stored
108
+ // `nextRunAt` is where it WOULD run), so one list no longer says it will run while the other
109
+ // says it will not (OSK-22493).
110
+ const next = (0, triggers_1.nextRunLabel)(t);
111
111
  const fires = t.audit?.fireCount ?? 0;
112
112
  return {
113
113
  id: String(t.id ?? '-'),
114
114
  kind: String(t.kind ?? '-'),
115
115
  enabled: t.enabled === false ? 'no' : 'yes',
116
- label: String(t.label ?? '-').slice(0, 40),
116
+ label: String(t.label ?? '-'),
117
117
  next: String(next).slice(0, 25),
118
118
  fires: String(fires),
119
119
  source: (0, agent_trigger_listing_1.sourceLabel)(t, isUnconfirmedTurnCapture(t)),
@@ -123,8 +123,8 @@ class AgendaTriggerList extends base_command_1.BaseCommand {
123
123
  { key: 'id', header: 'TRIGGER ID' },
124
124
  { key: 'kind', header: 'KIND' },
125
125
  { key: 'enabled', header: 'ON' },
126
- { key: 'label', header: 'LABEL' },
127
- { key: 'next', header: 'NEXT RUN' },
126
+ { key: 'label', header: 'LABEL', maxWidth: 40, truncate: 'middle' },
127
+ { key: 'next', header: 'NEXT/LAST' },
128
128
  { key: 'fires', header: 'FIRES' },
129
129
  { key: 'source', header: 'SOURCE' },
130
130
  ], (line) => this.log(line));
@@ -0,0 +1,17 @@
1
+ import { BaseCommand } from '../../../base-command';
2
+ /**
3
+ * Approve an Agent's message that is waiting for your approval, and deliver it
4
+ * Only a person can decide: the server refuses an Agent or automation credential (OSK-22364).
5
+ */
6
+ export default class AgentMessageApprove extends BaseCommand {
7
+ static description: string;
8
+ static examples: string[];
9
+ static args: {
10
+ intent: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
11
+ };
12
+ static flags: {
13
+ agent: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ };
16
+ run(): Promise<void>;
17
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const data_provider_1 = require("@skrr-ai/data-provider");
5
+ const base_command_1 = require("../../../base-command");
6
+ const agent_resolver_1 = require("../../../lib/agent-resolver");
7
+ const message_intent_1 = require("../../../lib/message-intent");
8
+ /**
9
+ * Approve an Agent's message that is waiting for your approval, and deliver it
10
+ * Only a person can decide: the server refuses an Agent or automation credential (OSK-22364).
11
+ */
12
+ class AgentMessageApprove extends base_command_1.BaseCommand {
13
+ static description = "Approve an Agent's message that is waiting for your approval, and deliver it";
14
+ static examples = [
15
+ '<%= config.bin %> agent message pending --agent <agent-id>',
16
+ '<%= config.bin %> agent message approve <intent-id> --agent <agent-id>',
17
+ ];
18
+ static args = {
19
+ intent: core_1.Args.string({ description: 'Intent ID from `agent message pending`', required: true }),
20
+ };
21
+ static flags = {
22
+ agent: core_1.Flags.string({ description: 'Agent ID', required: false }),
23
+ json: core_1.Flags.boolean({ description: 'Output as JSON' }),
24
+ };
25
+ async run() {
26
+ const { args, flags } = await this.parse(AgentMessageApprove);
27
+ const sessionContext = (0, message_intent_1.resolveMessageCommandSessionContext)({
28
+ requireHumanAuth: () => this.requireAuth(),
29
+ });
30
+ if (sessionContext) {
31
+ this.failWithCliError({
32
+ message: 'Only a person can see and decide on messages waiting for approval, not an Agent session.',
33
+ code: 'HUMAN_APPROVAL_REQUIRED',
34
+ exit: 2,
35
+ retryable: false,
36
+ });
37
+ }
38
+ let agentId;
39
+ try {
40
+ const explicitAgentId = (0, agent_resolver_1.mergeExplicitAgentInputs)([{ label: '--agent', value: flags.agent }]);
41
+ agentId = (await (0, agent_resolver_1.resolveAgentIdentity)(explicitAgentId)).id;
42
+ }
43
+ catch (error) {
44
+ const failure = (0, agent_resolver_1.agentResolutionFailure)(error);
45
+ this.failWithCliError({
46
+ message: failure.message,
47
+ code: failure.code,
48
+ exit: 2,
49
+ retryable: false,
50
+ details: failure.suggestion ? { suggestion: failure.suggestion } : undefined,
51
+ });
52
+ }
53
+ try {
54
+ const result = await data_provider_1.dataService.decideAgentDmIntent(agentId, args.intent, 'approve');
55
+ if (flags.json) {
56
+ this.printJsonResult(result);
57
+ return;
58
+ }
59
+ if (result.duplicate) {
60
+ this.log(`Nothing to do: that message is already ${result.status}.`);
61
+ return;
62
+ }
63
+ this.log(`Approved: ${result.intentId} is now ${result.status}${result.reason ? ` (${result.reason})` : ''}.`);
64
+ }
65
+ catch (error) {
66
+ this.handleApiError(error);
67
+ }
68
+ }
69
+ }
70
+ exports.default = AgentMessageApprove;
@@ -0,0 +1,17 @@
1
+ import { BaseCommand } from '../../../base-command';
2
+ /**
3
+ * Decline an Agent's message that is waiting for your approval, and cancel it
4
+ * Only a person can decide: the server refuses an Agent or automation credential (OSK-22364).
5
+ */
6
+ export default class AgentMessageDecline extends BaseCommand {
7
+ static description: string;
8
+ static examples: string[];
9
+ static args: {
10
+ intent: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
11
+ };
12
+ static flags: {
13
+ agent: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ };
16
+ run(): Promise<void>;
17
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const data_provider_1 = require("@skrr-ai/data-provider");
5
+ const base_command_1 = require("../../../base-command");
6
+ const agent_resolver_1 = require("../../../lib/agent-resolver");
7
+ const message_intent_1 = require("../../../lib/message-intent");
8
+ /**
9
+ * Decline an Agent's message that is waiting for your approval, and cancel it
10
+ * Only a person can decide: the server refuses an Agent or automation credential (OSK-22364).
11
+ */
12
+ class AgentMessageDecline extends base_command_1.BaseCommand {
13
+ static description = "Decline an Agent's message that is waiting for your approval, and cancel it";
14
+ static examples = [
15
+ '<%= config.bin %> agent message pending --agent <agent-id>',
16
+ '<%= config.bin %> agent message decline <intent-id> --agent <agent-id>',
17
+ ];
18
+ static args = {
19
+ intent: core_1.Args.string({ description: 'Intent ID from `agent message pending`', required: true }),
20
+ };
21
+ static flags = {
22
+ agent: core_1.Flags.string({ description: 'Agent ID', required: false }),
23
+ json: core_1.Flags.boolean({ description: 'Output as JSON' }),
24
+ };
25
+ async run() {
26
+ const { args, flags } = await this.parse(AgentMessageDecline);
27
+ const sessionContext = (0, message_intent_1.resolveMessageCommandSessionContext)({
28
+ requireHumanAuth: () => this.requireAuth(),
29
+ });
30
+ if (sessionContext) {
31
+ this.failWithCliError({
32
+ message: 'Only a person can see and decide on messages waiting for approval, not an Agent session.',
33
+ code: 'HUMAN_APPROVAL_REQUIRED',
34
+ exit: 2,
35
+ retryable: false,
36
+ });
37
+ }
38
+ let agentId;
39
+ try {
40
+ const explicitAgentId = (0, agent_resolver_1.mergeExplicitAgentInputs)([{ label: '--agent', value: flags.agent }]);
41
+ agentId = (await (0, agent_resolver_1.resolveAgentIdentity)(explicitAgentId)).id;
42
+ }
43
+ catch (error) {
44
+ const failure = (0, agent_resolver_1.agentResolutionFailure)(error);
45
+ this.failWithCliError({
46
+ message: failure.message,
47
+ code: failure.code,
48
+ exit: 2,
49
+ retryable: false,
50
+ details: failure.suggestion ? { suggestion: failure.suggestion } : undefined,
51
+ });
52
+ }
53
+ try {
54
+ const result = await data_provider_1.dataService.decideAgentDmIntent(agentId, args.intent, 'decline');
55
+ if (flags.json) {
56
+ this.printJsonResult(result);
57
+ return;
58
+ }
59
+ if (result.duplicate) {
60
+ this.log(`Nothing to do: that message is already ${result.status}.`);
61
+ return;
62
+ }
63
+ this.log(`Declined: ${result.intentId} is now ${result.status}${result.reason ? ` (${result.reason})` : ''}.`);
64
+ }
65
+ catch (error) {
66
+ this.handleApiError(error);
67
+ }
68
+ }
69
+ }
70
+ exports.default = AgentMessageDecline;
@@ -0,0 +1,18 @@
1
+ import { BaseCommand } from '../../../base-command';
2
+ /**
3
+ * The owner's view of an Agent's own messages that are waiting on `ask_first`. Without this the
4
+ * Gateway held them and told nobody (OSK-22364): `skrr agent message send` answered
5
+ * `approval_required`, and the message expired six hours later.
6
+ */
7
+ export default class AgentMessagePending extends BaseCommand {
8
+ static description: string;
9
+ static examples: string[];
10
+ static args: {
11
+ agent: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
12
+ };
13
+ static flags: {
14
+ agent: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ };
17
+ run(): Promise<void>;
18
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const data_provider_1 = require("@skrr-ai/data-provider");
5
+ const base_command_1 = require("../../../base-command");
6
+ const agent_resolver_1 = require("../../../lib/agent-resolver");
7
+ const message_intent_1 = require("../../../lib/message-intent");
8
+ /**
9
+ * The owner's view of an Agent's own messages that are waiting on `ask_first`. Without this the
10
+ * Gateway held them and told nobody (OSK-22364): `skrr agent message send` answered
11
+ * `approval_required`, and the message expired six hours later.
12
+ */
13
+ class AgentMessagePending extends base_command_1.BaseCommand {
14
+ static description = "List an Agent's own messages that are waiting for your approval because it is set to ask first";
15
+ static examples = [
16
+ '<%= config.bin %> agent message pending --agent <agent-id>',
17
+ '<%= config.bin %> agent message approve <intent-id> --agent <agent-id>',
18
+ ];
19
+ static args = {
20
+ agent: core_1.Args.string({ description: 'Agent ID', required: false, ignoreStdin: true }),
21
+ };
22
+ static flags = {
23
+ agent: core_1.Flags.string({ description: 'Agent ID' }),
24
+ json: core_1.Flags.boolean({ description: 'Output as JSON' }),
25
+ };
26
+ async run() {
27
+ const { args, flags } = await this.parse(AgentMessagePending);
28
+ const sessionContext = (0, message_intent_1.resolveMessageCommandSessionContext)({
29
+ requireHumanAuth: () => this.requireAuth(),
30
+ });
31
+ if (sessionContext) {
32
+ this.failWithCliError({
33
+ message: 'Only a person can see and decide on messages waiting for approval, not an Agent session.',
34
+ code: 'HUMAN_APPROVAL_REQUIRED',
35
+ exit: 2,
36
+ retryable: false,
37
+ });
38
+ }
39
+ let agentId;
40
+ try {
41
+ const explicitAgentId = (0, agent_resolver_1.mergeExplicitAgentInputs)([
42
+ { label: 'agent argument', value: args.agent },
43
+ { label: '--agent', value: flags.agent },
44
+ ]);
45
+ agentId = (await (0, agent_resolver_1.resolveAgentIdentity)(explicitAgentId)).id;
46
+ }
47
+ catch (error) {
48
+ const failure = (0, agent_resolver_1.agentResolutionFailure)(error);
49
+ this.failWithCliError({
50
+ message: failure.message,
51
+ code: failure.code,
52
+ exit: 2,
53
+ retryable: false,
54
+ details: failure.suggestion ? { suggestion: failure.suggestion } : undefined,
55
+ });
56
+ }
57
+ try {
58
+ const result = await data_provider_1.dataService.listAgentDmPendingIntents(agentId);
59
+ if (flags.json) {
60
+ this.printJsonResult(result);
61
+ return;
62
+ }
63
+ if (!result.items.length) {
64
+ this.log('Nothing is waiting for your approval.');
65
+ return;
66
+ }
67
+ for (const item of result.items) {
68
+ const expires = item.expiresAt ? ` · expires ${item.expiresAt}` : '';
69
+ this.log(`${item.intentId} [${item.kind ?? 'message'}]${expires}`);
70
+ this.log(` ${item.preview}`);
71
+ }
72
+ this.log(`\nApprove one with: skrr agent message approve <intent-id> --agent ${agentId} (or decline).`);
73
+ }
74
+ catch (error) {
75
+ this.handleApiError(error);
76
+ }
77
+ }
78
+ }
79
+ exports.default = AgentMessagePending;
@@ -22,6 +22,43 @@ export declare function agentErasureReport(response: DeleteAgentResponse | undef
22
22
  * (OSK-22342).
23
23
  */
24
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;
25
62
  export default class AgentsDelete extends BaseCommand {
26
63
  static description: string;
27
64
  static examples: string[];
@@ -30,11 +67,19 @@ export default class AgentsDelete extends BaseCommand {
30
67
  };
31
68
  static flags: {
32
69
  yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
70
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
33
71
  };
34
72
  /**
35
73
  * Which of the two the request is about to do, so the prompt can say so. A
36
74
  * failed read is not a reason to refuse: the delete reports its own error.
37
75
  */
38
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;
39
84
  run(): Promise<void>;
40
85
  }
@@ -1,12 +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;
6
7
  exports.agentRetainedReport = agentRetainedReport;
8
+ exports.isDeleteInProgressRefusal = isDeleteInProgressRefusal;
9
+ exports.waitForAgentGone = waitForAgentGone;
10
+ exports.agentDeletionSettledReport = agentDeletionSettledReport;
11
+ exports.agentDeletionUnsettledMessage = agentDeletionUnsettledMessage;
7
12
  const core_1 = require("@oclif/core");
8
13
  const data_provider_1 = require("@skrr-ai/data-provider");
9
14
  const base_command_1 = require("../../base-command");
15
+ const http_error_1 = require("../../lib/http-error");
10
16
  const prompt_1 = require("../../lib/prompt");
11
17
  /**
12
18
  * The confirmation question. Deleting an agent installed from the store only
@@ -74,17 +80,80 @@ function agentRetainedReport(response, bin = 'skrr') {
74
80
  ` Archive or reassign them with \`${bin} goals archive <goal-id>\` and \`${bin} tasks\`.`,
75
81
  ];
76
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
+ }
77
142
  class AgentsDelete extends base_command_1.BaseCommand {
78
143
  static description = 'Delete an agent you created (irreversible), or uninstall one installed from the store (reinstalling restores it)';
79
144
  static examples = [
80
145
  '<%= config.bin %> agents delete <agent-id>',
81
146
  '<%= config.bin %> agents delete <agent-id> --yes',
147
+ '<%= config.bin %> agents delete <agent-id> --yes --json',
82
148
  ];
83
149
  static args = {
84
150
  id: core_1.Args.string({ description: 'Agent ID', required: true, ignoreStdin: true }),
85
151
  };
86
152
  static flags = {
87
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
+ }),
88
157
  };
89
158
  /**
90
159
  * Which of the two the request is about to do, so the prompt can say so. A
@@ -98,6 +167,58 @@ class AgentsDelete extends base_command_1.BaseCommand {
98
167
  return null;
99
168
  }
100
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
+ }
101
222
  async run() {
102
223
  this.requireAuth();
103
224
  const { args, flags } = await this.parse(AgentsDelete);
@@ -114,15 +235,31 @@ class AgentsDelete extends base_command_1.BaseCommand {
114
235
  throw err;
115
236
  }
116
237
  if (!ok) {
117
- this.log('Cancelled.');
238
+ if (flags.json)
239
+ this.printJsonResult({ agentId: args.id, cancelled: true }, { ok: false });
240
+ else
241
+ this.log('Cancelled.');
118
242
  return;
119
243
  }
120
244
  let response;
245
+ let alreadyRunning = false;
121
246
  try {
122
247
  response = await data_provider_1.dataService.deleteAgent({ agent_id: args.id });
123
248
  }
124
249
  catch (err) {
125
- 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;
126
263
  }
127
264
  this.log(agentRemovalReport(args.id, response));
128
265
  for (const line of agentErasureReport(response))