@skrr-ai/cli 0.1.202 → 0.1.206

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 (71) hide show
  1. package/bin/dev-fallback.js +47 -29
  2. package/bin/dev.cjs +6 -0
  3. package/dist/base-command.js +1 -1
  4. package/dist/commands/agent/message/context.d.ts +3 -0
  5. package/dist/commands/agent/message/context.js +33 -1
  6. package/dist/commands/agent/message/no-reply.d.ts +17 -0
  7. package/dist/commands/agent/message/no-reply.js +54 -0
  8. package/dist/commands/agent/message/retract.d.ts +24 -0
  9. package/dist/commands/agent/message/retract.js +167 -0
  10. package/dist/commands/agent/message/send.d.ts +53 -3
  11. package/dist/commands/agent/message/send.js +148 -4
  12. package/dist/commands/agents/chat.d.ts +12 -0
  13. package/dist/commands/agents/chat.js +258 -25
  14. package/dist/commands/agents/manager/status.d.ts +9 -0
  15. package/dist/commands/agents/manager/status.js +84 -0
  16. package/dist/commands/agents/queue/clear.d.ts +13 -0
  17. package/dist/commands/agents/queue/clear.js +31 -0
  18. package/dist/commands/agents/queue/list.d.ts +10 -0
  19. package/dist/commands/agents/queue/list.js +34 -0
  20. package/dist/commands/agents/queue/move.d.ts +16 -0
  21. package/dist/commands/agents/queue/move.js +33 -0
  22. package/dist/commands/agents/queue/pause.d.ts +7 -0
  23. package/dist/commands/agents/queue/pause.js +24 -0
  24. package/dist/commands/agents/queue/resume.d.ts +7 -0
  25. package/dist/commands/agents/queue/resume.js +24 -0
  26. package/dist/commands/agents/queue/steer.d.ts +14 -0
  27. package/dist/commands/agents/queue/steer.js +38 -0
  28. package/dist/commands/agents/queue/withdraw.d.ts +10 -0
  29. package/dist/commands/agents/queue/withdraw.js +27 -0
  30. package/dist/commands/agents/supervision.d.ts +1 -0
  31. package/dist/commands/agents/supervision.js +28 -9
  32. package/dist/commands/convos/transcript.d.ts +48 -0
  33. package/dist/commands/convos/transcript.js +461 -0
  34. package/dist/commands/duties/advance-next.d.ts +17 -0
  35. package/dist/commands/duties/advance-next.js +122 -0
  36. package/dist/commands/duties/pack/plan.js +45 -0
  37. package/dist/commands/duties/preflight.d.ts +1 -0
  38. package/dist/commands/duties/preflight.js +18 -2
  39. package/dist/commands/spaces/auto-executor/preview.js +6 -2
  40. package/dist/commands/spaces/charter/revise.d.ts +16 -0
  41. package/dist/commands/spaces/charter/revise.js +84 -0
  42. package/dist/commands/spaces/skills/propose.d.ts +1 -0
  43. package/dist/commands/spaces/skills/propose.js +5 -0
  44. package/dist/commands/tasks/create.js +16 -1
  45. package/dist/commands/tasks/result/show.js +6 -3
  46. package/dist/commands/tasks/start.d.ts +3 -0
  47. package/dist/commands/tasks/start.js +12 -1
  48. package/dist/commands/triggers/capabilities.js +14 -4
  49. package/dist/generated/agent-guides.json +258 -24
  50. package/dist/lib/agent-chat-queue-command.d.ts +29 -0
  51. package/dist/lib/agent-chat-queue-command.js +75 -0
  52. package/dist/lib/agent-chat-queue.d.ts +77 -0
  53. package/dist/lib/agent-chat-queue.js +245 -0
  54. package/dist/lib/agent-chat-start.d.ts +101 -0
  55. package/dist/lib/agent-chat-start.js +151 -6
  56. package/dist/lib/duties.d.ts +5 -1
  57. package/dist/lib/duties.js +16 -5
  58. package/dist/lib/duty-product.js +6 -0
  59. package/dist/lib/input-queue.d.ts +18 -0
  60. package/dist/lib/input-queue.js +59 -0
  61. package/dist/lib/message-intent.d.ts +26 -3
  62. package/dist/lib/message-intent.js +7 -1
  63. package/dist/lib/task-runtime-headers.d.ts +5 -0
  64. package/dist/lib/task-runtime-headers.js +28 -8
  65. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.d.ts +16 -15
  66. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.js +0 -22
  67. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.d.ts +16 -15
  68. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.js +0 -22
  69. package/dist/node_modules/@skrr-ai/data-provider/index.js +11690 -11370
  70. package/oclif.manifest.json +1635 -332
  71. package/package.json +10 -4
@@ -118,44 +118,61 @@ function resolveSourceSpecifier(fileSystem, fromDirectory, specifier) {
118
118
  * that starts resolving later changes the digest, which is the correct verdict.
119
119
  */
120
120
  function commandClosureDigest(fileSystem, sourceRoot, entrySource) {
121
- const seen = new Set();
122
- const unresolved = [];
123
- const pending = [path.resolve(entrySource)];
124
- while (pending.length) {
125
- const current = pending.pop();
126
- if (seen.has(current)) continue;
127
- seen.add(current);
128
- let text;
121
+ return createCommandClosureDigest(fileSystem, sourceRoot)(entrySource);
122
+ }
123
+
124
+ // Reuse source reads and import resolution across commands in one manifest.
125
+ // Runtime lookups create a fresh reader for each freshness check.
126
+ function createCommandClosureDigest(fileSystem, sourceRoot) {
127
+ const sources = new Map();
128
+ function readSource(file) {
129
+ if (sources.has(file)) return sources.get(file);
130
+ const source = { bytes: null, dependencies: [], unresolved: [] };
131
+ sources.set(file, source);
129
132
  try {
130
- text = fileSystem.readFileSync(current, 'utf8');
133
+ source.bytes = fileSystem.readFileSync(file);
131
134
  } catch {
132
- continue;
135
+ return source;
133
136
  }
134
- for (const specifier of relativeSpecifiers(text)) {
135
- const resolved = resolveSourceSpecifier(fileSystem, path.dirname(current), specifier);
137
+ for (const specifier of relativeSpecifiers(source.bytes.toString('utf8'))) {
138
+ const resolved = resolveSourceSpecifier(fileSystem, path.dirname(file), specifier);
136
139
  if (resolved) {
137
- if (!seen.has(resolved)) pending.push(resolved);
140
+ source.dependencies.push(resolved);
138
141
  } else {
139
- unresolved.push(`${path.relative(sourceRoot, current)}:${specifier}`);
142
+ source.unresolved.push(`${path.relative(sourceRoot, file)}:${specifier}`);
140
143
  }
141
144
  }
145
+ return source;
142
146
  }
143
- const hash = crypto.createHash('sha256');
144
- for (const file of [...seen].sort()) {
145
- hash.update(path.relative(sourceRoot, file).split(path.sep).join('/'));
146
- hash.update('\0');
147
- try {
148
- hash.update(fileSystem.readFileSync(file));
149
- } catch {
150
- hash.update('<unreadable>');
147
+
148
+ return (entrySource) => {
149
+ const seen = new Set();
150
+ const unresolved = [];
151
+ const pending = [path.resolve(entrySource)];
152
+ while (pending.length) {
153
+ const current = pending.pop();
154
+ if (seen.has(current)) continue;
155
+ seen.add(current);
156
+ const { dependencies, unresolved: misses } = readSource(current);
157
+ unresolved.push(...misses);
158
+ for (const dependency of dependencies) {
159
+ if (!seen.has(dependency)) pending.push(dependency);
160
+ }
151
161
  }
152
- hash.update('\0');
153
- }
154
- for (const miss of unresolved.sort()) {
155
- hash.update(miss.split(path.sep).join('/'));
156
- hash.update('\0');
157
- }
158
- return hash.digest('hex');
162
+
163
+ const hash = crypto.createHash('sha256');
164
+ for (const file of [...seen].sort()) {
165
+ hash.update(path.relative(sourceRoot, file).split(path.sep).join('/'));
166
+ hash.update('\0');
167
+ hash.update(sources.get(file).bytes ?? '<unreadable>');
168
+ hash.update('\0');
169
+ }
170
+ for (const miss of unresolved.sort()) {
171
+ hash.update(miss.split(path.sep).join('/'));
172
+ hash.update('\0');
173
+ }
174
+ return hash.digest('hex');
175
+ };
159
176
  }
160
177
 
161
178
  function findAlternateCli({
@@ -386,6 +403,7 @@ function missingLocalCommandBuild({ cliRoot, argv, fileSystem = fs, verifySource
386
403
  module.exports = {
387
404
  COMMAND_BUILD_MANIFEST,
388
405
  commandClosureDigest,
406
+ createCommandClosureDigest,
389
407
  findAlternateCli,
390
408
  missingLocalCommandBuild,
391
409
  sourceTreeDigest,
package/bin/dev.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  'use strict';
2
3
 
3
4
  // Load the same commands, flags and hooks as the shipped CLI, directly from the
@@ -7,6 +8,11 @@ const { Plugin, settings, run } = require('@oclif/core');
7
8
 
8
9
  async function main(argv) {
9
10
  const root = path.resolve(__dirname, '..');
11
+ // Resolve the TypeScript loader from the CLI checkout. A managed session
12
+ // can start in an unrelated project's directory with its own tsconfig.
13
+ process.env.TSX_TSCONFIG_PATH = path.join(root, 'tsconfig.json');
14
+ await import('tsx');
15
+ process.env.OCLIF_SKIP_NEW_VERSION_CHECK = '1';
10
16
  const pjson = require('../package.json');
11
17
  settings.enableAutoTranspile = true;
12
18
  const source = new Plugin({ root, isRoot: true, ignoreManifest: true, errorOnManifestCreate: true });
@@ -331,7 +331,7 @@ class BaseCommand extends core_1.Command {
331
331
  }
332
332
  jsonOperationError(value) {
333
333
  return this.jsonOperationContext
334
- ? this.jsonOperationResult(value, { outcome: 'failed', writeState: 'unknown' })
334
+ ? this.jsonOperationResult(value, { outcome: 'failed' })
335
335
  : value;
336
336
  }
337
337
  cliConfig;
@@ -14,6 +14,9 @@ export default class AgentMessageContext extends BaseCommand {
14
14
  agent: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
15
  task: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
16
  run: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ conversation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ limit: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ before: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
20
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
21
  };
19
22
  run(): Promise<void>;
@@ -12,9 +12,11 @@ const message_intent_1 = require("../../../lib/message-intent");
12
12
  * it never returns a schedule or tells the model that it must send a message.
13
13
  */
14
14
  class AgentMessageContext extends base_command_1.BaseCommand {
15
- static description = 'Show recent Agent Updates and user-engagement observations for adaptive communication judgment';
15
+ static description = "Show what the owner saw in a conversation with the Agent (its replies, its messages, the platform's and the owner's), how far they read, what they said since, and recent Agent Updates, as observations for communication judgment";
16
16
  static examples = [
17
17
  '<%= config.bin %> agent message context --agent <agent-id>',
18
+ '<%= config.bin %> agent message context --agent <agent-id> --conversation <conversation-id>',
19
+ '<%= config.bin %> agent message context --agent <agent-id> --limit 20 --before <cursor>',
18
20
  '<%= config.bin %> agent message context --agent <agent-id> --task <task-id>',
19
21
  ];
20
22
  static args = {
@@ -26,6 +28,17 @@ class AgentMessageContext extends base_command_1.BaseCommand {
26
28
  run: core_1.Flags.string({
27
29
  description: 'Optional run context to narrow recent updates (refused inside a daemon session — the session path is already bound to its own run)',
28
30
  }),
31
+ conversation: core_1.Flags.string({
32
+ description: `Conversation to read: \`${data_provider_1.AGENT_COMMUNICATION_CONTEXT_MAIN_CONVERSATION}\` (the default) or a conversation id of yours with this Agent. Refused inside a daemon session, which reads the conversation its turn belongs to`,
33
+ }),
34
+ limit: core_1.Flags.integer({
35
+ description: `Timeline entries to return (1-${data_provider_1.AGENT_COMMUNICATION_CONTEXT_MAX_LIMIT})`,
36
+ min: 1,
37
+ max: data_provider_1.AGENT_COMMUNICATION_CONTEXT_MAX_LIMIT,
38
+ }),
39
+ before: core_1.Flags.string({
40
+ description: 'Read the page before this cursor (`timeline.before` of an earlier answer)',
41
+ }),
29
42
  json: core_1.Flags.boolean({
30
43
  description: 'Accepted for consistency; this command always outputs JSON',
31
44
  }),
@@ -75,9 +88,25 @@ class AgentMessageContext extends base_command_1.BaseCommand {
75
88
  },
76
89
  });
77
90
  }
91
+ // Same reason as --run: the session's conversation comes from its claim.
92
+ if (flags.conversation !== undefined) {
93
+ this.failWithCliError({
94
+ message: '--conversation cannot be chosen inside a daemon session: the session reads the conversation its turn belongs to.',
95
+ code: 'CONVERSATION_CONTEXT_UNSUPPORTED_IN_SESSION',
96
+ exit: 2,
97
+ retryable: false,
98
+ details: {
99
+ suggestion: 'Drop --conversation (the context already reads the conversation your next message lands in), or call the command outside a daemon session.',
100
+ },
101
+ });
102
+ }
78
103
  const params = new URLSearchParams();
79
104
  if (flags.task)
80
105
  params.set('taskId', flags.task);
106
+ if (flags.limit !== undefined)
107
+ params.set('limit', String(flags.limit));
108
+ if (flags.before)
109
+ params.set('before', flags.before);
81
110
  const query = params.size ? `?${params.toString()}` : '';
82
111
  const result = await (0, api_fetch_1.apiFetch)(`/api/agentic/sessions/${encodeURIComponent(sessionContext.sessionId)}/message-context${query}`, { credential: (0, message_intent_1.sessionCredential)(sessionContext.token) });
83
112
  this.log(JSON.stringify(result, null, 2));
@@ -89,6 +118,9 @@ class AgentMessageContext extends base_command_1.BaseCommand {
89
118
  const result = await data_provider_1.dataService.getAgentAdaptiveCommunicationContext(agentId, {
90
119
  taskId: flags.task,
91
120
  runId: flags.run,
121
+ ...(flags.conversation !== undefined ? { conversation: flags.conversation } : {}),
122
+ ...(flags.limit !== undefined ? { limit: flags.limit } : {}),
123
+ ...(flags.before ? { before: flags.before } : {}),
92
124
  });
93
125
  this.log(JSON.stringify(result, null, 2));
94
126
  }
@@ -0,0 +1,17 @@
1
+ import { BaseCommand } from '../../../base-command';
2
+ /**
3
+ * Declare that the running interactive turn needs no message in Main Chat: the person only
4
+ * acknowledged something, or the work speaks for itself. The server records it on the turn
5
+ * (`declared_silent`), and the turn's marker still shows that the turn happened.
6
+ *
7
+ * Only inside a daemon session, for that session's own running turn: the server proves the
8
+ * turn from the session token, exactly as it does for a send.
9
+ */
10
+ export default class AgentMessageNoReply extends BaseCommand {
11
+ static description: string;
12
+ static examples: string[];
13
+ static flags: {
14
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ };
16
+ run(): Promise<void>;
17
+ }
@@ -0,0 +1,54 @@
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 api_fetch_1 = require("../../../lib/api-fetch");
7
+ const message_intent_1 = require("../../../lib/message-intent");
8
+ /**
9
+ * Declare that the running interactive turn needs no message in Main Chat: the person only
10
+ * acknowledged something, or the work speaks for itself. The server records it on the turn
11
+ * (`declared_silent`), and the turn's marker still shows that the turn happened.
12
+ *
13
+ * Only inside a daemon session, for that session's own running turn: the server proves the
14
+ * turn from the session token, exactly as it does for a send.
15
+ */
16
+ class AgentMessageNoReply extends base_command_1.BaseCommand {
17
+ static description = 'Declare that this interactive turn needs no message in Main Chat (recorded on the turn; Main Chat does not act on it yet). Only inside a daemon session, for its own running turn';
18
+ static examples = ['<%= config.bin %> agent message no-reply'];
19
+ static flags = {
20
+ json: core_1.Flags.boolean({
21
+ description: 'Accepted for consistency; this command always outputs JSON',
22
+ }),
23
+ };
24
+ async run() {
25
+ await this.parse(AgentMessageNoReply);
26
+ const sessionContext = (0, message_intent_1.resolveMessageCommandSessionContext)({
27
+ // A person has no turn to declare: only a session can.
28
+ requireHumanAuth: () => undefined,
29
+ });
30
+ if (!sessionContext?.sessionId) {
31
+ this.failWithCliError({
32
+ message: '`agent message no-reply` declares something about a running turn, so it only works inside a daemon session.',
33
+ code: 'NO_REPLY_REQUIRES_SESSION',
34
+ exit: 2,
35
+ retryable: false,
36
+ details: {
37
+ suggestion: 'Run it from the interactive session whose turn it is; outside one there is no turn to declare.',
38
+ },
39
+ });
40
+ }
41
+ try {
42
+ const result = await (0, api_fetch_1.apiFetch)(`/api/agentic/sessions/${encodeURIComponent(sessionContext.sessionId)}/turn-disposition`, {
43
+ method: 'POST',
44
+ credential: (0, message_intent_1.sessionCredential)(sessionContext.token),
45
+ body: { disposition: data_provider_1.TURN_REPLY_DISPOSITIONS[0] },
46
+ });
47
+ this.log(JSON.stringify(result, null, 2));
48
+ }
49
+ catch (error) {
50
+ this.handleApiError(error);
51
+ }
52
+ }
53
+ }
54
+ exports.default = AgentMessageNoReply;
@@ -0,0 +1,24 @@
1
+ import { BaseCommand } from '../../../base-command';
2
+ import { type CanonicalMessageIntentResponse } from '../../../lib/message-intent';
3
+ /**
4
+ * Withdraw a message this Agent sent its owner (C10). Nothing is sent: the server marks the
5
+ * message retracted after proving, through the session, that this Agent sent it. The message
6
+ * stays in the conversation as a placeholder and in the audit.
7
+ *
8
+ * Only inside an Agent session: a person at a terminal has no Agent message of their own to
9
+ * withdraw. To correct a message instead, send the correction with `send --supersedes`.
10
+ */
11
+ export default class AgentMessageRetract extends BaseCommand {
12
+ static description: string;
13
+ static examples: string[];
14
+ static args: {
15
+ messageId: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
16
+ };
17
+ static flags: {
18
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
19
+ };
20
+ run(): Promise<void>;
21
+ }
22
+ /** The key of withdrawing one message from one session; ids are hashed so the key stays short. */
23
+ export declare function retractIdempotencyKey(sessionId: string, messageId: string): string;
24
+ export declare function describeRetraction(messageId: string, result: Pick<CanonicalMessageIntentResponse, 'status' | 'reason'>): string;
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.retractIdempotencyKey = retractIdempotencyKey;
37
+ exports.describeRetraction = describeRetraction;
38
+ const crypto = __importStar(require("node:crypto"));
39
+ const core_1 = require("@oclif/core");
40
+ const data_provider_1 = require("@skrr-ai/data-provider");
41
+ const base_command_1 = require("../../../base-command");
42
+ const agent_resolver_1 = require("../../../lib/agent-resolver");
43
+ const message_intent_1 = require("../../../lib/message-intent");
44
+ /**
45
+ * Withdraw a message this Agent sent its owner (C10). Nothing is sent: the server marks the
46
+ * message retracted after proving, through the session, that this Agent sent it. The message
47
+ * stays in the conversation as a placeholder and in the audit.
48
+ *
49
+ * Only inside an Agent session: a person at a terminal has no Agent message of their own to
50
+ * withdraw. To correct a message instead, send the correction with `send --supersedes`.
51
+ */
52
+ class AgentMessageRetract extends base_command_1.BaseCommand {
53
+ static description = 'Withdraw a message this Agent sent in the owner’s chat. Nothing new is sent; the message is shown as withdrawn. Only inside an Agent session, for its own messages';
54
+ static examples = [
55
+ '<%= config.bin %> agent message retract <message-id>',
56
+ '<%= config.bin %> agent message retract <message-id> --json',
57
+ ];
58
+ static args = {
59
+ messageId: core_1.Args.string({
60
+ description: 'The messageId of the message to withdraw (printed by `agent message send`, and in `agent message context`)',
61
+ required: true,
62
+ ignoreStdin: true,
63
+ }),
64
+ };
65
+ static flags = {
66
+ json: core_1.Flags.boolean({ description: 'Print the server’s answer as JSON' }),
67
+ };
68
+ async run() {
69
+ const { args, flags } = await this.parse(AgentMessageRetract);
70
+ const parsed = (0, data_provider_1.parseMessageOperation)({ kind: 'retract', targetMessageId: args.messageId });
71
+ if (!parsed.ok) {
72
+ this.failWithCliError({
73
+ message: parsed.reason,
74
+ code: 'INVALID_MESSAGE_OPERATION',
75
+ exit: 1,
76
+ retryable: false,
77
+ });
78
+ }
79
+ let sessionContext;
80
+ try {
81
+ sessionContext = (0, message_intent_1.resolveMessageCommandSessionContext)({
82
+ // A person has no Agent message to withdraw: only the Agent's session can.
83
+ requireHumanAuth: () => undefined,
84
+ });
85
+ }
86
+ catch (error) {
87
+ this.failWithCliError({
88
+ message: error.message,
89
+ code: error.code || 'MESSAGE_INTENT_ERROR',
90
+ exit: 2,
91
+ retryable: false,
92
+ });
93
+ }
94
+ if (!sessionContext?.sessionId) {
95
+ this.failWithCliError({
96
+ message: '`agent message retract` withdraws one of the Agent’s own messages, so it only works inside that Agent’s session.',
97
+ code: 'MESSAGE_OPERATION_REQUIRES_SESSION',
98
+ exit: 2,
99
+ retryable: false,
100
+ details: {
101
+ suggestion: 'Run it from the session of the Agent that sent the message. Outside one there is no Agent to withdraw it as.',
102
+ },
103
+ });
104
+ }
105
+ let agentId;
106
+ try {
107
+ agentId = (0, agent_resolver_1.resolveSessionAgentIdentity)().id;
108
+ }
109
+ catch (error) {
110
+ const failure = (0, agent_resolver_1.agentResolutionFailure)(error);
111
+ this.failWithCliError({
112
+ message: failure.message,
113
+ code: failure.code,
114
+ exit: 2,
115
+ retryable: false,
116
+ details: { suggestion: failure.suggestion },
117
+ });
118
+ }
119
+ const targetMessageId = parsed.ok && parsed.value.kind === 'retract' ? parsed.value.targetMessageId : '';
120
+ const request = (0, message_intent_1.canonicalAppOwnerDmRequest)({
121
+ agentId: agentId,
122
+ text: '',
123
+ // One withdrawal per message per session: a retry replays it.
124
+ idempotencyKey: retractIdempotencyKey(sessionContext.sessionId, targetMessageId),
125
+ operation: { kind: 'retract', targetMessageId },
126
+ });
127
+ let result;
128
+ try {
129
+ result = await (0, message_intent_1.submitSessionMessageIntent)({ context: sessionContext, request });
130
+ }
131
+ catch (error) {
132
+ if (error instanceof Error && error.name === 'MessageIntentCliError') {
133
+ this.failWithCliError({
134
+ message: error.message,
135
+ code: error.code || 'MESSAGE_INTENT_ERROR',
136
+ exit: 2,
137
+ retryable: false,
138
+ });
139
+ }
140
+ this.handleApiError(error);
141
+ }
142
+ if (flags.json) {
143
+ this.log(JSON.stringify(result, null, 2));
144
+ return;
145
+ }
146
+ this.log(describeRetraction(targetMessageId, result));
147
+ }
148
+ }
149
+ exports.default = AgentMessageRetract;
150
+ /** The key of withdrawing one message from one session; ids are hashed so the key stays short. */
151
+ function retractIdempotencyKey(sessionId, messageId) {
152
+ const digest = crypto
153
+ .createHash('sha256')
154
+ .update(JSON.stringify(['retract', sessionId, messageId]))
155
+ .digest('hex')
156
+ .slice(0, 32);
157
+ return `cli:agent-message-retract:${digest}`;
158
+ }
159
+ function describeRetraction(messageId, result) {
160
+ if (result.status === 'retracted') {
161
+ return `Withdrew message ${messageId}. The person sees that it was withdrawn.`;
162
+ }
163
+ if (result.status === 'duplicate') {
164
+ return `Message ${messageId} was already withdrawn by this request; nothing changed.`;
165
+ }
166
+ return `Message ${messageId} was not withdrawn: ${result.status || 'unknown'}${result.reason ? ` (${result.reason})` : ''}.`;
167
+ }
@@ -1,7 +1,7 @@
1
- import { type EntityEmbed } from '@skrr-ai/data-provider';
1
+ import { dataService, type EntityEmbed, type MessageOperation } from '@skrr-ai/data-provider';
2
2
  import { BaseCommand } from '../../../base-command';
3
3
  import { type ResolvedAgentIdentity } from '../../../lib/agent-resolver';
4
- import { type CanonicalMessageDestination, type CanonicalMessageIntentRequest, type CanonicalMessageIntentResponse, type CommunicationPresentation, type OneVoiceOutcome } from '../../../lib/message-intent';
4
+ import { type CanonicalDestinationKind, type CanonicalMessageDestination, type CanonicalMessageIntentRequest, type CanonicalMessageIntentResponse, type CommunicationPresentation, type MessageOperationOutcome, type OneVoiceOutcome } from '../../../lib/message-intent';
5
5
  import { type WireEmbedRejection } from '../../../lib/entity-embeds';
6
6
  /**
7
7
  * A reading-comfort prompt, not a protocol limit. The Gateway deliberately
@@ -51,6 +51,12 @@ export type CanonicalIntentEnvelope = {
51
51
  */
52
52
  embeds?: EntityEmbed[];
53
53
  embedRejections?: WireEmbedRejection[];
54
+ /** C10: the app message this send became, which a later correction or withdrawal names. */
55
+ messageId?: string;
56
+ /** C10: the operation this send asked for, and what the server did with it. */
57
+ operation?: MessageOperation & {
58
+ outcome?: MessageOperationOutcome;
59
+ };
54
60
  intent: {
55
61
  id: string | null;
56
62
  status: NonNullable<CanonicalMessageIntentResponse['status']> | 'delivered' | 'submitted';
@@ -105,6 +111,8 @@ export default class AgentMessageSend extends BaseCommand {
105
111
  'thread-ts': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
106
112
  'thread-root': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
107
113
  'from-json': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
114
+ supersedes: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
115
+ 'status-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
108
116
  'idempotency-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
109
117
  kind: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
110
118
  phase: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -231,7 +239,13 @@ export declare function normalizeIntentPayload({ agentId, jsonBody, merged, }: {
231
239
  jsonBody: Record<string, unknown>;
232
240
  merged: Record<string, unknown>;
233
241
  }): NormalizedIntentPayload;
234
- export declare function generateIdempotencyKey(agentId: string, payload: Pick<NormalizedIntentPayload, 'destination' | 'content' | 'presentation' | 'context' | 'threadRootMessageId'>): string;
242
+ export declare function generateIdempotencyKey(agentId: string, payload: Pick<NormalizedIntentPayload, 'destination' | 'content' | 'presentation' | 'context' | 'threadRootMessageId'>, operation?: MessageOperation): string;
243
+ /**
244
+ * The app message a person's owner-DM send became, as the session path names it (`messageId`),
245
+ * so the text output says `Message id: …` on this path too. Only a send that reached the chat
246
+ * names one.
247
+ */
248
+ export declare function legacyDmMessageId(result: Awaited<ReturnType<typeof dataService.sendAgentDmMessage>>): string | undefined;
235
249
  export declare function buildEnvelope(input: {
236
250
  ok: boolean;
237
251
  principalKind: PrincipalKind;
@@ -251,6 +265,8 @@ export declare function buildEnvelope(input: {
251
265
  /** What the server applied to `presentation`; shown instead of the request when it differs. */
252
266
  appliedPresentation?: Pick<CommunicationPresentation, 'kind' | 'attention' | 'attentionRequested'>;
253
267
  notificationPolicy?: 'normal' | 'silent';
268
+ messageId?: string;
269
+ operation?: CanonicalIntentEnvelope['operation'];
254
270
  intent: CanonicalIntentEnvelope['intent'];
255
271
  }): CanonicalIntentEnvelope;
256
272
  /**
@@ -263,4 +279,38 @@ export declare function buildEnvelope(input: {
263
279
  */
264
280
  export declare function withAppliedAttention(declared: CommunicationPresentation, applied?: Pick<CommunicationPresentation, 'kind' | 'attention' | 'attentionRequested'>): CommunicationPresentation;
265
281
  export declare function formatEnvelope(envelope: CanonicalIntentEnvelope): string;
282
+ /**
283
+ * The message id a later correction names, and what this send did to an earlier message (C10).
284
+ * A send whose mark did not land is said to have gone out WITHOUT replacing anything: the exit
285
+ * code cannot say it, because the message itself was delivered.
286
+ */
287
+ export declare function describeMessageOperation(envelope: CanonicalIntentEnvelope): string;
288
+ /**
289
+ * The operation a send asks for, from `--supersedes`, `--status-key` or a JSON body's
290
+ * `operation`. One source only: two that disagree are refused rather than one silently winning.
291
+ * A retraction is not a send (`agent message retract`).
292
+ */
293
+ export declare function resolveSendOperation({ supersedes, statusKey, jsonOperation, }: {
294
+ supersedes?: string;
295
+ statusKey?: string;
296
+ jsonOperation?: unknown;
297
+ }): {
298
+ operation?: MessageOperation;
299
+ } | {
300
+ error: string;
301
+ };
302
+ /**
303
+ * Why a send cannot carry an operation here, or null. Only an Agent's own session can name its
304
+ * own message (the server proves it through the session), only an owner DM can be named, and a
305
+ * sequence would leave unclear which part replaces the earlier message.
306
+ */
307
+ export declare function sendOperationUnsupported({ destinationKind, inSession, partCount, }: {
308
+ destinationKind: CanonicalDestinationKind;
309
+ inSession: boolean;
310
+ partCount: number;
311
+ }): {
312
+ message: string;
313
+ code: string;
314
+ exit: number;
315
+ } | null;
266
316
  export {};