@getfamiliar/shared 0.1.11 → 0.1.13

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.
package/build/Schema.js CHANGED
@@ -50,16 +50,18 @@ export const CHATMESSAGES_NEW_CHANNEL = "chatmessages_new";
50
50
  */
51
51
  export const SCHEDULED_SUBAGENTS_CHANNEL = "scheduled_subagents_changed";
52
52
  /**
53
- * Topic regex used by the events check constraint and by the container
54
- * runtime when resolving handler files. One word, optionally followed
55
- * by any number of `:`-prefixed sub-topic words. Examples:
56
- * `mail`, `chat:cli`, `chat:telegram:group:reaction`.
53
+ * Topic regex used by the topic check constraints and by the container
54
+ * runtime when resolving handler files. One word (word characters and
55
+ * dashes), optionally followed by any number of `:`-prefixed sub-topic
56
+ * words. Examples: `mail`, `chat:cli`, `mail:extract-style`,
57
+ * `chat:telegram:group:reaction`.
57
58
  *
58
- * The container resolves a handler for topic `a:b:c` by walking the
59
- * chain `a/b/c/<basename>.md → a/b/<basename>.md → a/<basename>.md`
60
- * deepest-first and merging every existing layer (see HandlerFile.load).
59
+ * The topic is a handler's whole address: `a:b:c` names the single file
60
+ * `a/b/c.md` (or its folder form `a/b/c/index.md`). Events fall back up
61
+ * the chain (`a:b`, `a`) when that file is missing; everything else must
62
+ * match exactly (see `HandlerResolution.ts`).
61
63
  */
62
- export const TOPIC_PATTERN = "^\\w+(:\\w+)*$";
64
+ export const TOPIC_PATTERN = "^[\\w-]+(:[\\w-]+)*$";
63
65
  export const SCHEMA_SQL = `
64
66
  -- Drop legacy single-table artifacts from before the events/agentruns
65
67
  -- split. Safe no-ops on fresh databases. The current schema reuses the
@@ -105,10 +107,13 @@ ALTER TABLE events ADD COLUMN IF NOT EXISTS preferred_chat_channel_id text;
105
107
  -- emitter's framing without the EventWatcher having to reach into the
106
108
  -- payload schema.
107
109
  ALTER TABLE events ADD COLUMN IF NOT EXISTS prompt text;
108
- -- Optional override for the root agentrun's handler. When NULL the
109
- -- input-event watcher falls back to 'index' — same behaviour as
110
- -- before this column existed. Set by the emitter on NewEvent.
111
- ALTER TABLE events ADD COLUMN IF NOT EXISTS start_handler text;
110
+ -- The topic is the handler's whole address now; the separate start
111
+ -- handler basename is gone.
112
+ ALTER TABLE events DROP COLUMN IF EXISTS start_handler;
113
+ -- When true the topic must name an existing handler file exactly; when
114
+ -- false (world events) handler resolution falls back up the topic chain.
115
+ -- Copied onto the root agentrun by the input-event watcher.
116
+ ALTER TABLE events ADD COLUMN IF NOT EXISTS is_exact_topic boolean NOT NULL DEFAULT false;
112
117
  -- Privileged events originate from a trusted user-input source (operator
113
118
  -- at the local terminal via cli-chat, operator on Telegram). The flag
114
119
  -- propagates verbatim to the root agentrun and to every child agentrun
@@ -133,7 +138,6 @@ CREATE TABLE IF NOT EXISTS agentruns (
133
138
  event_id bigint NOT NULL REFERENCES events(id) ON DELETE CASCADE,
134
139
  parent_agentrun_id bigint REFERENCES agentruns(id) ON DELETE CASCADE,
135
140
  topic text NOT NULL,
136
- handler text NOT NULL,
137
141
  priority smallint NOT NULL DEFAULT 50,
138
142
  state text NOT NULL DEFAULT 'pending',
139
143
  prompt text,
@@ -150,6 +154,11 @@ CREATE TABLE IF NOT EXISTS agentruns (
150
154
  -- Forward-compat ALTER for databases created before result_text landed.
151
155
  -- Safe no-op on fresh databases where the column already exists.
152
156
  ALTER TABLE agentruns ADD COLUMN IF NOT EXISTS result_text text;
157
+ -- The topic is the handler's whole address; the basename column is gone.
158
+ ALTER TABLE agentruns DROP COLUMN IF EXISTS handler;
159
+ -- Whether handler resolution must match the topic exactly. Root
160
+ -- agentruns copy the event's flag; spawned children are always exact.
161
+ ALTER TABLE agentruns ADD COLUMN IF NOT EXISTS is_exact_topic boolean NOT NULL DEFAULT true;
153
162
  -- Inherited from the originating event (root agentrun) or parent
154
163
  -- agentrun (children spawned via schedule_subagent / start_subagent). See
155
164
  -- the matching ALTER on the events table for the trust-model rationale.
@@ -452,7 +461,6 @@ CREATE TABLE IF NOT EXISTS scheduled_subagents (
452
461
  key text PRIMARY KEY,
453
462
  fire_at timestamptz NOT NULL,
454
463
  topic text NOT NULL,
455
- handler text NOT NULL,
456
464
  prompt text,
457
465
  payload jsonb NOT NULL DEFAULT '{}'::jsonb,
458
466
  priority smallint NOT NULL DEFAULT 50,
@@ -461,6 +469,12 @@ CREATE TABLE IF NOT EXISTS scheduled_subagents (
461
469
  CONSTRAINT scheduled_subagents_topic_format CHECK (topic ~ '${TOPIC_PATTERN}')
462
470
  );
463
471
 
472
+ -- The topic is the handler's whole address; the basename column is gone.
473
+ ALTER TABLE scheduled_subagents DROP COLUMN IF EXISTS handler;
474
+ -- Re-add the topic CHECK so a widened TOPIC_PATTERN reaches existing tables.
475
+ ALTER TABLE scheduled_subagents DROP CONSTRAINT IF EXISTS scheduled_subagents_topic_format;
476
+ ALTER TABLE scheduled_subagents ADD CONSTRAINT scheduled_subagents_topic_format CHECK (topic ~ '${TOPIC_PATTERN}');
477
+
464
478
  CREATE INDEX IF NOT EXISTS scheduled_subagents_fire_at_idx
465
479
  ON scheduled_subagents (fire_at);
466
480
 
package/build/index.d.ts CHANGED
@@ -4,14 +4,15 @@ export { BASTION_TOKEN_HEADER } from "./BastionAuth.js";
4
4
  export { buildCalendarEventId, type CalendarApi, type CalendarAttachmentMeta, type CalendarAttendee, type CalendarChangePayload, type CalendarEventRow, type CalendarEventType, type CalendarImportance, type CalendarProvider, type CalendarResponseStatus, type CalendarRow, type CalendarSensitivity, type CalendarShowAs, type CalendarType, type CreateEventInput, type FindEventsQuery, type NewCalendarEvent, parseCalendarEventId, type UpdateEventInput, type UpsertCalendarInput, } from "./Calendar.js";
5
5
  export type { ChatFilter, ChatMessage, ChatRole, NewChatMessage } from "./ChatMessage.js";
6
6
  export { type ChatHandler, ChatMessageBus, type ChatUnsubscribe } from "./ChatMessageBus.js";
7
- export type { ConfigService } from "./Config.js";
7
+ export { type ConfigService, DEFAULT_WRITABLE_PATHS } from "./Config.js";
8
8
  export type { ContainerToolInfo } from "./ContainerTool.js";
9
9
  export { type ParsedCron, parseCron } from "./CronExpression.js";
10
10
  export type { EventFile, EventFilter, EventPatch, EventRow, EventState, NewEvent, } from "./Event.js";
11
11
  export { EVENT_PRIORITY } from "./Event.js";
12
12
  export { DuplicateIdempotencyKeyError, EventBus } from "./EventBus.js";
13
13
  export { estimateTokens } from "./estimateTokens.js";
14
- export { HandlerCatalog, type HandlerPath, isUnderSkillsFolder } from "./HandlerCatalog.js";
14
+ export { HandlerCatalog, type HandlerPath, type ResolvedHandler } from "./HandlerCatalog.js";
15
+ export { type HandlerResolution, type HandlerResolutionOptions, handlerCandidateLevels, resolveHandlerPath, topicFromHandlerPath, twinHandlerPath, } from "./HandlerResolution.js";
15
16
  export type { InferenceEventRow, InferenceOutcome, NewInferenceEvent, } from "./InferenceEvent.js";
16
17
  export { InferenceEventBus } from "./InferenceEventBus.js";
17
18
  export { type CreateLoggerOptions, createLogger, jsonStdoutStream, type Logger, type LogLevel, type LogStream, prettyStdoutStream, } from "./logging/Logger.js";
@@ -22,7 +23,7 @@ export { renderMarkdownToHtml } from "./markdownHtml.js";
22
23
  export { escapeTableCell, markdownTable, writeMarkdown } from "./markdownOutput.js";
23
24
  export { renderMarkdown } from "./markdownTerminal.js";
24
25
  export { matchesAnyGlob, matchesGlob } from "./PathGlob.js";
25
- export type { AnyCommandDef, EmitHandle, EmitOptions, HostContext, McpClient, McpInfo, PluginHostManifest, PluginManifest, PluginTool, PluginToolCallContext, PromptAppender, PromptPlaceholderRegistration, } from "./Plugin.js";
26
+ export type { AnyCommandDef, EmitHandle, EmitOptions, EmittedEventDescriptor, HostContext, McpClient, McpInfo, PluginHostManifest, PluginManifest, PluginTool, PluginToolCallContext, PromptAppender, PromptPlaceholderRegistration, } from "./Plugin.js";
26
27
  export { DaemonStoppedError, definePlugin } from "./Plugin.js";
27
28
  export { type NotificationHandler, POSTGRES_DB, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, PostgresConnection, type PostgresConnectionConfig, } from "./PostgresConnection.js";
28
29
  export { CACHE_MARKER_PLACEHOLDER, CORE_PROMPT_PLACEHOLDERS, isCorePromptPlaceholder, PROMPT_PLACEHOLDER_NAME_PATTERN, PROMPT_TEMPLATE_FILE, PromptPlaceholderConflictError, type PromptPlaceholderDefinition, type PromptPlaceholderKind, } from "./PromptPlaceholders.js";
package/build/index.js CHANGED
@@ -2,11 +2,13 @@ export { AgentRunBus } from "./AgentRunBus.js";
2
2
  export { BASTION_TOKEN_HEADER } from "./BastionAuth.js";
3
3
  export { buildCalendarEventId, parseCalendarEventId, } from "./Calendar.js";
4
4
  export { ChatMessageBus } from "./ChatMessageBus.js";
5
+ export { DEFAULT_WRITABLE_PATHS } from "./Config.js";
5
6
  export { parseCron } from "./CronExpression.js";
6
7
  export { EVENT_PRIORITY } from "./Event.js";
7
8
  export { DuplicateIdempotencyKeyError, EventBus } from "./EventBus.js";
8
9
  export { estimateTokens } from "./estimateTokens.js";
9
- export { HandlerCatalog, isUnderSkillsFolder } from "./HandlerCatalog.js";
10
+ export { HandlerCatalog } from "./HandlerCatalog.js";
11
+ export { handlerCandidateLevels, resolveHandlerPath, topicFromHandlerPath, twinHandlerPath, } from "./HandlerResolution.js";
10
12
  export { InferenceEventBus } from "./InferenceEventBus.js";
11
13
  export { createLogger, jsonStdoutStream, prettyStdoutStream, } from "./logging/Logger.js";
12
14
  export { buildMailId, parseMailId, } from "./Mail.js";
@@ -33,7 +33,7 @@ export class MockAgentRunBus {
33
33
  eventId: run.eventId,
34
34
  parentAgentrunId: run.parentAgentrunId ?? null,
35
35
  topic: run.topic,
36
- handler: run.handler,
36
+ isExactTopic: run.isExactTopic ?? true,
37
37
  priority: run.priority ?? 50,
38
38
  state: run.state ?? "pending",
39
39
  prompt: run.prompt ?? null,
@@ -29,7 +29,7 @@ export class MockEventBus {
29
29
  isChat: event.isChat === true,
30
30
  preferredChatChannelId: event.preferredChatChannelId ?? null,
31
31
  prompt: event.prompt ?? null,
32
- startHandler: event.startHandler ?? null,
32
+ isExactTopic: event.isExactTopic ?? false,
33
33
  privileged: event.privileged === true,
34
34
  outputChatOnFailure: event.outputChatOnFailure === true,
35
35
  createdAt: now,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@getfamiliar/shared",
3
3
  "type": "module",
4
- "version": "0.1.11",
4
+ "version": "0.1.13",
5
5
  "description": "Familiar — shared types and bus-state client between host and container.",
6
6
  "publishConfig": {
7
7
  "access": "public"