omp-superagent 0.1.16 → 0.1.18

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 (47) hide show
  1. package/DESIGN.md +15 -12
  2. package/config.example.json +4 -1
  3. package/docs/OPERATIONS.en.md +119 -33
  4. package/docs/OPERATIONS.md +83 -23
  5. package/docs/design/execution.md +66 -17
  6. package/docs/design/messaging.md +134 -47
  7. package/docs/releases/0.1.17.md +10 -0
  8. package/docs/releases/0.1.18.md +10 -0
  9. package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
  10. package/gateway/bin/omp-gateway-darwin-x64 +0 -0
  11. package/gateway/bin/omp-gateway-linux-arm64 +0 -0
  12. package/gateway/bin/omp-gateway-linux-x64 +0 -0
  13. package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
  14. package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
  15. package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
  16. package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
  17. package/package.json +1 -1
  18. package/skills/head/SKILL.md +2 -2
  19. package/skills/head/references/routing.md +17 -6
  20. package/src/config/config.ts +15 -0
  21. package/src/contracts.ts +49 -4
  22. package/src/cron/cron-jobs.ts +135 -92
  23. package/src/cron/cron-pr-intake.ts +18 -11
  24. package/src/extension.ts +15 -5
  25. package/src/gateway/gateway-client.ts +3 -1
  26. package/src/lane/workflow.ts +12 -6
  27. package/src/managed-super-probe.ts +21 -15
  28. package/src/messaging/messenger-command-catalog.json +1 -1
  29. package/src/messaging/messenger-commands.ts +8 -3
  30. package/src/messaging/slack-context.ts +50 -0
  31. package/src/omp/superkit-skills.ts +15 -2
  32. package/src/pr/pr-intake-order.ts +62 -0
  33. package/src/pr/pr-intake-review.ts +49 -31
  34. package/src/pr/pr-intake-work.ts +3 -2
  35. package/src/routing/message-order.ts +22 -1
  36. package/src/routing/topic-request.ts +41 -0
  37. package/src/runtime/controller.ts +515 -191
  38. package/src/runtime/deferred-routing.ts +12 -4
  39. package/src/runtime/dm-timeline.ts +3 -3
  40. package/src/storage/deferred-routing.ts +25 -4
  41. package/src/storage/store.ts +389 -60
  42. package/src/worker/worker-checkout.ts +38 -4
  43. package/src/worker/worker-host.ts +114 -24
  44. package/src/worker/worker-ledger.ts +28 -9
  45. package/src/worker/worker-repository.ts +13 -0
  46. package/src/worker/worker-service.ts +74 -17
  47. package/src/worker/worker-wire.ts +3 -1
@@ -10,6 +10,7 @@ interface DrainActions {
10
10
  readonly stopped: () => boolean;
11
11
  readonly fenced: () => boolean;
12
12
  readonly recovery: (input: Inbound) => RecoveryControl | null;
13
+ readonly awaitingReceipt: (input: Inbound) => boolean;
13
14
  readonly admit: (id: string) => Promise<void>;
14
15
  readonly report: (error: unknown) => void;
15
16
  readonly background: (task: Promise<void>) => void;
@@ -32,8 +33,9 @@ export class DeferredRoutingDrain {
32
33
  this.drain(conversation);
33
34
  }
34
35
 
35
- retrying(conversation: string): boolean {
36
- return this.retry.has(conversation);
36
+ blocked(conversation: string): boolean {
37
+ const head = this.queue.head(conversation);
38
+ return this.retry.has(conversation) || head !== null && this.awaitingReceipt(head);
37
39
  }
38
40
 
39
41
  resume(): void {
@@ -49,10 +51,16 @@ export class DeferredRoutingDrain {
49
51
  return this.actions.stopped() || this.actions.fenced();
50
52
  }
51
53
 
54
+ private awaitingReceipt(id: string): boolean {
55
+ const input = this.queue.input(id);
56
+ return input !== null && this.actions.awaitingReceipt(input);
57
+ }
58
+
52
59
  private next(conversation: string, head: string, failed: ReadonlySet<string>): string | null {
53
60
  const retry = this.retry.get(conversation);
54
- const headReady = (!retry || retry.at <= Date.now()) && !failed.has(head);
55
- const includeBare = !headReady && retry !== undefined;
61
+ const awaitingReceipt = this.awaitingReceipt(head);
62
+ const headReady = !awaitingReceipt && (!retry || retry.at <= Date.now()) && !failed.has(head);
63
+ const includeBare = !headReady && (awaitingReceipt || retry !== undefined);
56
64
  // A persisted exact stop can bypass a blocked history read so work from
57
65
  // another conversation cannot resume the target lane out of order.
58
66
  for (const input of this.queue.priority(conversation, includeBare)) {
@@ -37,7 +37,7 @@ export class DmTimeline {
37
37
  constructor(private readonly store: Pick<StorePort, "getMeta" | "admittedMessageIds" | "input">) {}
38
38
 
39
39
  admit(input: Inbound, eventId: string | null, commandBlocked: boolean): { input: Inbound; metadata: Record<string, string> } {
40
- if (input.route.platform === "slack") return this.slackDmAdmission(input);
40
+ if (input.route.platform === "slack") return this.slackDmAdmission(input, commandBlocked);
41
41
  let metadata: Record<string, string> = {};
42
42
  if (eventId === null) throw new Error("Cannot order this DM input");
43
43
  const physical = physicalRoute(input.route);
@@ -118,9 +118,9 @@ export class DmTimeline {
118
118
  return latest;
119
119
  }
120
120
 
121
- private slackDmAdmission(input: Inbound): { input: Inbound; metadata: Record<string, string> } {
121
+ private slackDmAdmission(input: Inbound, commandBlocked: boolean): { input: Inbound; metadata: Record<string, string> } {
122
122
  const physical = physicalRoute(input.route);
123
- const command = input.text.trim();
123
+ const command = commandBlocked ? "" : input.text.trim();
124
124
  const control = /^\/new(?:\s|$)/.test(command) || command === "/main";
125
125
  const anchorMessageId = input.messageId === null ? this.slackAnchor(input) : undefined;
126
126
  let metadata: Record<string, string> = {};
@@ -2,6 +2,7 @@ import type { Database } from "bun:sqlite";
2
2
  import { deferredRecoveryCandidate, physicalRouteKey, routingConversation, type DeferredRoutingPort, type Inbound, type Lane } from "../contracts";
3
3
 
4
4
  const LEGACY_QUEUE = "intake:deferred-routing";
5
+ const SLACK_CHOICE_CLOCK = "intake:slack-choice-clock";
5
6
  const SCHEMA = `
6
7
  CREATE TABLE IF NOT EXISTS deferred_routing (
7
8
  sequence INTEGER PRIMARY KEY AUTOINCREMENT, id TEXT NOT NULL UNIQUE,
@@ -34,9 +35,12 @@ interface IdRow { readonly id: string }
34
35
  export interface DeferredChoiceRow {
35
36
  readonly id: string;
36
37
  readonly text: string;
38
+ readonly routingText: string | null;
39
+ readonly verifiedSlackBody: 0 | 1;
37
40
  readonly messageId: string | null;
38
41
  readonly replyId: string | null;
39
42
  readonly authoredAt: number;
43
+ readonly attached: 0 | 1;
40
44
  }
41
45
 
42
46
  export class DeferredRoutingQueue implements DeferredRoutingPort {
@@ -44,6 +48,18 @@ export class DeferredRoutingQueue implements DeferredRoutingPort {
44
48
  private readonly reconcileInbound: (existing: Inbound, incoming: Inbound) => Inbound | null) {
45
49
  this.db.transaction(() => {
46
50
  this.db.run(SCHEMA);
51
+ if (!this.db.query("SELECT 1 FROM metadata WHERE key = ?").get(SLACK_CHOICE_CLOCK)) {
52
+ // Older HEADs saved fractional Slack times in the payload but left the
53
+ // choice index null. Recover pending messages before the drain starts.
54
+ this.db.run(`UPDATE deferred_routing
55
+ SET choice_at = json_extract(data, '$.receivedAt')
56
+ WHERE choice_at IS NULL AND message_id IS NOT NULL
57
+ AND json_extract(data, '$.route.platform') = 'slack'
58
+ AND json_type(data, '$.pickerSelection') IS NULL
59
+ AND json_type(data, '$.receivedAt') = 'real'
60
+ AND abs(json_extract(data, '$.receivedAt')) <= 9007199254740991`);
61
+ this.db.run("INSERT INTO metadata (key, value) VALUES (?, 'true')", [SLACK_CHOICE_CLOCK]);
62
+ }
47
63
  const legacy = this.db.query<{ value: string }, [string]>("SELECT value FROM metadata WHERE key = ?").get(LEGACY_QUEUE);
48
64
  if (!legacy) return;
49
65
  const queue: readonly Inbound[] = JSON.parse(legacy.value);
@@ -56,7 +72,8 @@ export class DeferredRoutingQueue implements DeferredRoutingPort {
56
72
  enqueue(input: Inbound): void {
57
73
  const candidate = deferredRecoveryCandidate(input.text);
58
74
  const choiceAt = !input.pickerSelection && (typeof input.messageId === "string" || typeof input.interactionId === "string")
59
- && Number.isSafeInteger(input.receivedAt) ? input.receivedAt : null;
75
+ && Number.isSafeInteger(input.route.platform === "slack" ? Math.trunc(input.receivedAt) : input.receivedAt)
76
+ ? input.receivedAt : null;
60
77
  this.db.query(`INSERT INTO deferred_routing
61
78
  (id, conversation, physical_route, message_id, priority, stop_lane, choice_at, data)
62
79
  VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(
@@ -104,7 +121,7 @@ export class DeferredRoutingQueue implements DeferredRoutingPort {
104
121
  }
105
122
 
106
123
  *earlierLaneStops(lane: Pick<Lane, "id" | "route">, beforeId: string): Iterable<Inbound> {
107
- // A bare stop binds only by its exact Discord thread route. Named stops
124
+ // A bare stop binds only by its exact physical work thread. Named stops
108
125
  // can come from any conversation but need not read other lanes' candidates.
109
126
  const rows = this.db.query<DataRow, [string, string, string]>(`
110
127
  SELECT data, sequence FROM deferred_routing INDEXED BY deferred_routing_named_stop WHERE stop_lane = ?2 AND ${EARLIER}
@@ -134,8 +151,12 @@ export class DeferredRoutingQueue implements DeferredRoutingPort {
134
151
 
135
152
  choices(input: Pick<Inbound, "id" | "route" | "receivedAt">, deadline: number): Iterable<DeferredChoiceRow> {
136
153
  return this.db.query<DeferredChoiceRow, [string, number, number, string]>(`
137
- SELECT id, json_extract(data, '$.text') AS text, message_id AS messageId,
138
- json_extract(data, '$.reply.messageId') AS replyId, choice_at AS authoredAt
154
+ SELECT id, json_extract(data, '$.text') AS text, json_extract(data, '$.routingText') AS routingText,
155
+ json_type(data, '$.slackVerifiedRoutingBody') IS 'true' AS verifiedSlackBody, message_id AS messageId,
156
+ json_extract(data, '$.reply.messageId') AS replyId, choice_at AS authoredAt,
157
+ coalesce(json_extract(data, '$.unresolvedReply'), 0)
158
+ OR json_type(data, '$.attachments') IS NOT 'array'
159
+ OR json_array_length(data, '$.attachments') > 0 AS attached
139
160
  FROM deferred_routing INDEXED BY deferred_routing_choice
140
161
  WHERE physical_route = ? AND choice_at BETWEEN ? AND ? AND id <> ?
141
162
  `).iterate(physicalRouteKey(input.route), input.receivedAt, deadline, input.id);