@pinet/slack-bridge 0.1.2 → 0.2.0

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/README.md +59 -32
  2. package/dist/broker/adapters/slack.d.ts +19 -1
  3. package/dist/broker/adapters/slack.js +111 -22
  4. package/dist/broker/client.d.ts +2 -1
  5. package/dist/broker/client.js +1 -0
  6. package/dist/broker/socket-server.js +18 -0
  7. package/dist/deploy-manifest.d.ts +5 -0
  8. package/dist/deploy-manifest.js +30 -1
  9. package/dist/follower-runtime.js +5 -1
  10. package/dist/helpers.d.ts +14 -0
  11. package/dist/helpers.js +45 -21
  12. package/dist/index.js +60 -0
  13. package/dist/pinet-commands.d.ts +6 -1
  14. package/dist/pinet-commands.js +166 -1
  15. package/dist/pinet-mesh-ops.d.ts +11 -0
  16. package/dist/pinet-mesh-ops.js +17 -0
  17. package/dist/pinet-tools.d.ts +47 -0
  18. package/dist/pinet-tools.js +496 -36
  19. package/dist/prompts/broker/tmux.md +2 -2
  20. package/dist/reaction-triggers.d.ts +1 -0
  21. package/dist/reaction-triggers.js +26 -15
  22. package/dist/runtime-agent-context.js +19 -0
  23. package/dist/runtime-mode.js +7 -1
  24. package/dist/single-player-runtime.js +22 -26
  25. package/dist/slack-access.d.ts +11 -0
  26. package/dist/slack-access.js +30 -0
  27. package/dist/slack-agents-command.d.ts +19 -0
  28. package/dist/slack-agents-command.js +90 -0
  29. package/dist/slack-export.d.ts +1 -1
  30. package/dist/slack-export.js +6 -4
  31. package/dist/slack-file-access.d.ts +34 -0
  32. package/dist/slack-file-access.js +209 -0
  33. package/dist/slack-message-context.d.ts +0 -1
  34. package/dist/slack-message-context.js +1 -6
  35. package/dist/slack-pinet-runtime-adapter.d.ts +4 -2
  36. package/dist/slack-pinet-runtime-adapter.js +12 -0
  37. package/dist/slack-tools.d.ts +6 -0
  38. package/dist/slack-tools.js +290 -36
  39. package/dist/slack-upload.d.ts +13 -1
  40. package/dist/slack-upload.js +29 -2
  41. package/dist/stale-slack-messages.d.ts +12 -0
  42. package/dist/stale-slack-messages.js +29 -0
  43. package/dist/subtree-broker-runtime.d.ts +109 -0
  44. package/dist/subtree-broker-runtime.js +558 -0
  45. package/manifest.yaml +9 -0
  46. package/package.json +9 -7
  47. package/skills/slack-bridge/SKILL.md +60 -1
@@ -0,0 +1,12 @@
1
+ export declare const STALE_SLACK_MESSAGE_MAX_AGE_MS: number;
2
+ export interface SlackMessageStalenessInput {
3
+ source: string;
4
+ timestamp: string;
5
+ }
6
+ export interface SlackMessageStalenessOptions {
7
+ nowMs?: number;
8
+ maxAgeMs?: number;
9
+ }
10
+ export declare function parseSlackTimestampMs(timestamp: string): number | null;
11
+ export declare function getSlackMessageAgeMs(input: SlackMessageStalenessInput, options?: SlackMessageStalenessOptions): number | null;
12
+ export declare function isStaleSlackMessage(input: SlackMessageStalenessInput, options?: SlackMessageStalenessOptions): boolean;
@@ -0,0 +1,29 @@
1
+ export const STALE_SLACK_MESSAGE_MAX_AGE_MS = 15 * 60 * 1000;
2
+ // Slack message ts values are epoch seconds. Treat tiny test/sentinel values as
3
+ // ambiguous rather than stale so only plausible Slack-origin event timestamps
4
+ // are skipped.
5
+ const MIN_PLAUSIBLE_SLACK_TIMESTAMP_SECONDS = 1_000_000_000;
6
+ export function parseSlackTimestampMs(timestamp) {
7
+ const seconds = Number(timestamp);
8
+ if (!Number.isFinite(seconds) || seconds < MIN_PLAUSIBLE_SLACK_TIMESTAMP_SECONDS) {
9
+ return null;
10
+ }
11
+ return Math.trunc(seconds * 1000);
12
+ }
13
+ export function getSlackMessageAgeMs(input, options = {}) {
14
+ if (input.source !== "slack") {
15
+ return null;
16
+ }
17
+ const timestampMs = parseSlackTimestampMs(input.timestamp);
18
+ if (timestampMs === null) {
19
+ return null;
20
+ }
21
+ return (options.nowMs ?? Date.now()) - timestampMs;
22
+ }
23
+ export function isStaleSlackMessage(input, options = {}) {
24
+ const ageMs = getSlackMessageAgeMs(input, options);
25
+ if (ageMs === null) {
26
+ return false;
27
+ }
28
+ return ageMs > (options.maxAgeMs ?? STALE_SLACK_MESSAGE_MAX_AGE_MS);
29
+ }
@@ -0,0 +1,109 @@
1
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import type { PinetReadOptions, PinetReadResult } from "@pinet/pinet-core/pinet-read-formatting";
3
+ import { type InboxMessage, type PinetControlCommand, type PinetRemoteControlRequestResult, type SlackBridgeSettings } from "./helpers.js";
4
+ export interface SubtreeBrokerPaths {
5
+ rootDir: string;
6
+ socketPath: string;
7
+ dbPath: string;
8
+ lockPath: string;
9
+ }
10
+ export interface SubtreeWorkerRecord {
11
+ launchId: string;
12
+ sessionName: string;
13
+ repoPath: string;
14
+ role: string;
15
+ laneId: string | null;
16
+ agentId: string | null;
17
+ startedAt: string;
18
+ monitorCommand: string;
19
+ }
20
+ export interface SubtreeBrokerStatus {
21
+ active: boolean;
22
+ selfAgentId: string | null;
23
+ startedAt: string | null;
24
+ paths: SubtreeBrokerPaths | null;
25
+ childLaunchEnv: Record<string, string>;
26
+ childLaunchHint: string | null;
27
+ childCount: number;
28
+ spawnedWorkers: SubtreeWorkerRecord[];
29
+ }
30
+ export interface SubtreeAgentRecord {
31
+ emoji: string;
32
+ name: string;
33
+ id: string;
34
+ pid?: number;
35
+ status: "working" | "idle";
36
+ metadata: Record<string, unknown> | null;
37
+ lastHeartbeat: string;
38
+ lastSeen?: string;
39
+ disconnectedAt?: string | null;
40
+ resumableUntil?: string | null;
41
+ outboundCount?: number;
42
+ pendingInboxCount?: number;
43
+ parentAgentId?: string | null;
44
+ rootAgentId?: string | null;
45
+ treeDepth?: number;
46
+ supervisionState?: string;
47
+ subtreeRole?: string | null;
48
+ laneId?: string | null;
49
+ }
50
+ export interface SubtreeSpawnInput {
51
+ task: string;
52
+ repo: string;
53
+ role?: string;
54
+ laneId?: string;
55
+ waitForRegistrationMs?: number;
56
+ }
57
+ export interface SubtreeSpawnResult {
58
+ status: "started";
59
+ launchId: string;
60
+ sessionName: string;
61
+ repoPath: string;
62
+ role: string;
63
+ laneId: string | null;
64
+ agentId: string;
65
+ agentName: string;
66
+ messageId: number;
67
+ threadId: string;
68
+ monitorCommand: string;
69
+ socketPath: string;
70
+ dbPath: string;
71
+ childLaunchEnv: Record<string, string>;
72
+ }
73
+ export interface SubtreeBrokerRuntimeDeps {
74
+ cwd: string;
75
+ getSettings: () => SlackBridgeSettings;
76
+ getAgentStableId: () => string;
77
+ getCentralAgentId: () => string | null;
78
+ getAgentIdentity: () => {
79
+ name: string;
80
+ emoji: string;
81
+ };
82
+ getAgentMetadata: (role: "broker" | "worker") => Promise<Record<string, unknown>>;
83
+ getMeshRoleFromMetadata: (metadata: Record<string, unknown> | undefined, fallback?: "broker" | "worker") => "broker" | "worker";
84
+ pushInboxMessages: (messages: InboxMessage[]) => void;
85
+ updateBadge: () => void;
86
+ maybeDrainInboxIfIdle: (ctx: ExtensionContext) => boolean;
87
+ requestRemoteControl: (command: PinetControlCommand, ctx: ExtensionContext) => PinetRemoteControlRequestResult;
88
+ runRemoteControl: (command: PinetControlCommand, ctx: ExtensionContext) => void;
89
+ formatError: (error: unknown) => string;
90
+ }
91
+ export interface SubtreeBrokerRuntime {
92
+ start: (ctx: ExtensionContext) => Promise<SubtreeBrokerStatus>;
93
+ stop: (options?: {
94
+ releaseIdentity?: boolean;
95
+ stopChildren?: boolean;
96
+ }) => Promise<void>;
97
+ getStatus: () => SubtreeBrokerStatus;
98
+ readInbox: (options?: PinetReadOptions) => PinetReadResult | null;
99
+ sendMessage: (target: string, body: string, metadata?: Record<string, unknown>) => Promise<{
100
+ messageId: number;
101
+ target: string;
102
+ threadId: string;
103
+ } | null>;
104
+ listAgents: (includeGhosts?: boolean) => SubtreeAgentRecord[] | null;
105
+ spawnWorker: (ctx: ExtensionContext, input: SubtreeSpawnInput) => Promise<SubtreeSpawnResult>;
106
+ isActive: () => boolean;
107
+ }
108
+ export declare function buildSubtreeBrokerPaths(stableId: string): SubtreeBrokerPaths;
109
+ export declare function createSubtreeBrokerRuntime(deps: SubtreeBrokerRuntimeDeps): SubtreeBrokerRuntime;