@capybara-hq/kernel 0.1.0-rc.111 → 0.1.0-rc.113

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 (38) hide show
  1. package/dist/automations/errors.js +1 -1
  2. package/dist/automations/events/acceptance.d.ts +7 -2
  3. package/dist/automations/events/acceptance.js +7 -2
  4. package/dist/catalog/marketplaces.service.d.ts +1 -1
  5. package/dist/conversations/conversation-ref.d.ts +58 -0
  6. package/dist/conversations/conversation-ref.js +103 -0
  7. package/dist/conversations/conversations.controller.d.ts +6 -0
  8. package/dist/conversations/conversations.controller.js +23 -6
  9. package/dist/conversations/conversations.service.d.ts +40 -1
  10. package/dist/conversations/conversations.service.js +163 -11
  11. package/dist/conversations/events.d.ts +9 -0
  12. package/dist/conversations/events.js +14 -0
  13. package/dist/conversations/permission-profiles.controller.d.ts +3 -0
  14. package/dist/conversations/permission-profiles.controller.js +3 -0
  15. package/dist/db/kernel-schema.d.ts +11 -0
  16. package/dist/errors.d.ts +8 -0
  17. package/dist/errors.js +8 -0
  18. package/dist/inbox/inbox-items.service.d.ts +5 -3
  19. package/dist/inbox/inbox-items.service.js +12 -4
  20. package/dist/log.d.ts +6 -0
  21. package/dist/log.js +47 -19
  22. package/dist/platform/ops/agent-skills.ops.js +6 -2
  23. package/dist/platform/ops/inbox.ops.js +6 -4
  24. package/dist/push/recipients.js +2 -2
  25. package/dist/push/texts.d.ts +8 -2
  26. package/dist/push/texts.js +4 -1
  27. package/dist/sandbox/review/classifier.js +3 -1
  28. package/dist/skills/invocable.controller.d.ts +4 -0
  29. package/dist/skills/invocable.controller.js +5 -1
  30. package/dist/skills/invoke.d.ts +68 -2
  31. package/dist/skills/invoke.js +128 -13
  32. package/dist/skills/skills.schemas.d.ts +7 -1
  33. package/dist/skills/skills.schemas.js +11 -2
  34. package/dist/themes/render-css.js +9 -2
  35. package/package.json +2 -2
  36. package/src/migrations/0196_conversation_events_compaction_summary_idx.sql +8 -0
  37. package/src/migrations/0197_inbox_item_localized_text.sql +8 -0
  38. package/src/migrations/0198_acceptance_prompt.sql +10 -0
@@ -969,6 +969,15 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
969
969
  projectFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
970
970
  path: z.ZodString;
971
971
  }, z.core.$strip>>>;
972
+ conversationRefs: z.ZodOptional<z.ZodArray<z.ZodObject<{
973
+ id: z.ZodString;
974
+ title: z.ZodNullable<z.ZodString>;
975
+ source: z.ZodEnum<{
976
+ excerpt: "excerpt";
977
+ summary: "summary";
978
+ }>;
979
+ upToSeq: z.ZodNumber;
980
+ }, z.core.$strip>>>;
972
981
  authorAccountId: z.ZodString;
973
982
  sender: z.ZodOptional<z.ZodObject<{
974
983
  name: z.ZodString;
@@ -890,6 +890,20 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
890
890
  * body's list. Absent: none.
891
891
  */
892
892
  projectFiles: z.array(z.object({ path: z.string() })).optional(),
893
+ /**
894
+ * The referenced conversations (@ conversations spec §2): the quoted block of reference i is
895
+ * `content[1 + attachments.length + projectFiles.length + i]`, before the uploaded files'
896
+ * blocks. `title` is the title at send time (null: untitled), `source` what the block was
897
+ * built from, `upToSeq` the highest seq read. Deduplicated. Absent: none.
898
+ */
899
+ conversationRefs: z
900
+ .array(z.object({
901
+ id: z.string(),
902
+ title: z.string().nullable(),
903
+ source: z.enum(["summary", "excerpt"]),
904
+ upToSeq: z.number().int().nonnegative(),
905
+ }))
906
+ .optional(),
893
907
  authorAccountId: z.string(),
894
908
  /**
895
909
  * Who wrote the message, at send time (run context spec §3.2): display name and org role
@@ -19,6 +19,9 @@ export declare const FirstMessageBody: z.ZodObject<{
19
19
  projectFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
20
20
  path: z.ZodString;
21
21
  }, z.core.$strict>>>;
22
+ conversationRefs: z.ZodOptional<z.ZodArray<z.ZodObject<{
23
+ id: z.ZodString;
24
+ }, z.core.$strict>>>;
22
25
  model: z.ZodOptional<z.ZodObject<{
23
26
  provider: z.ZodString;
24
27
  model: z.ZodString;
@@ -52,6 +52,9 @@ let PermissionProfilesController = class PermissionProfilesController {
52
52
  ...(message.attachments !== undefined ? { attachments: message.attachments } : {}),
53
53
  ...(message.files !== undefined ? { files: message.files } : {}),
54
54
  ...(message.projectFiles !== undefined ? { projectFiles: message.projectFiles } : {}),
55
+ ...(message.conversationRefs !== undefined
56
+ ? { conversationRefs: message.conversationRefs }
57
+ : {}),
55
58
  ...(message.model !== undefined ? { model: message.model } : {}),
56
59
  ...(message.effort !== undefined ? { effort: message.effort } : {}),
57
60
  ...(message.skill !== undefined ? { skill: message.skill } : {}),
@@ -1778,8 +1778,19 @@ export interface InboxItemsTable {
1778
1778
  /** The posting extension; null for a kernel item. */
1779
1779
  plugin: NullableText;
1780
1780
  kind: string;
1781
+ /** The title as a single string; the English one when the post gave `{ zh, en }`. */
1781
1782
  title: string;
1782
1783
  body: ColumnType<string, string | undefined, string>;
1784
+ /** The post's `{ zh, en }` title as given; null when it gave a single string. */
1785
+ title_localized: ColumnType<{
1786
+ zh: string;
1787
+ en: string;
1788
+ } | null, string | null | undefined, string | null>;
1789
+ /** The post's `{ zh, en }` body as given; null when it gave a single string or none. */
1790
+ body_localized: ColumnType<{
1791
+ zh: string;
1792
+ en: string;
1793
+ } | null, string | null | undefined, string | null>;
1783
1794
  link: NullableText;
1784
1795
  actions: ColumnType<StoredInboxAction[], string | undefined, string>;
1785
1796
  dedupe_key: NullableText;
package/dist/errors.d.ts CHANGED
@@ -396,6 +396,14 @@ export declare const ERROR_CODES: {
396
396
  * `details: [{ path?, reason? }]`.
397
397
  */
398
398
  readonly "conversation.project_file_unavailable": 422;
399
+ /**
400
+ * A referenced conversation cannot be referenced (@ conversations spec §1): missing, deleted,
401
+ * another person's or org's, a sub-agent's or eval conversation, or its agent no longer visible,
402
+ * all alike; or it has no messages yet (`reason: "empty"`); `details: [{ id, reason? }]`.
403
+ */
404
+ readonly "conversation.reference_unavailable": 422;
405
+ /** A message references the conversation it is written in; `details: [{ id }]`. */
406
+ readonly "conversation.reference_self": 422;
399
407
  readonly "run.not_active": 409;
400
408
  /** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
401
409
  readonly "run.not_found": 404;
package/dist/errors.js CHANGED
@@ -396,6 +396,14 @@ export const ERROR_CODES = {
396
396
  * `details: [{ path?, reason? }]`.
397
397
  */
398
398
  "conversation.project_file_unavailable": 422,
399
+ /**
400
+ * A referenced conversation cannot be referenced (@ conversations spec §1): missing, deleted,
401
+ * another person's or org's, a sub-agent's or eval conversation, or its agent no longer visible,
402
+ * all alike; or it has no messages yet (`reason: "empty"`); `details: [{ id, reason? }]`.
403
+ */
404
+ "conversation.reference_unavailable": 422,
405
+ /** A message references the conversation it is written in; `details: [{ id }]`. */
406
+ "conversation.reference_self": 422,
399
407
  "run.not_active": 409,
400
408
  /** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
401
409
  "run.not_found": 404,
@@ -1,4 +1,4 @@
1
- import { type InboxPost, type LocalizedName } from "@capybara-hq/plugin-sdk";
1
+ import { type InboxPost, type LocalizedName, type LocalizedText } from "@capybara-hq/plugin-sdk";
2
2
  import type { StoredInboxAction } from "../db/kernel-schema.js";
3
3
  import { KernelDb } from "../infra/database/kernel-db.js";
4
4
  import { TransactionHost } from "../infra/database/transaction-host.js";
@@ -24,8 +24,10 @@ export interface PersonalInboxItemView {
24
24
  /** The plugin's display name (its name in both languages when it has none); null for the kernel. */
25
25
  pluginName: LocalizedName | null;
26
26
  kind: string;
27
- title: string;
28
- body: string;
27
+ /** As posted: a single string, or `{ zh, en }` the reader sees in their language. */
28
+ title: LocalizedText;
29
+ /** As posted, like `title` (`""`: none). */
30
+ body: LocalizedText;
29
31
  /** An in-app path; a plugin item's is one of the plugin's pages (`/p/<plugin>/…`). */
30
32
  link: string | null;
31
33
  actions: {
@@ -31,6 +31,10 @@ const kernelLinkOk = (link) => link.startsWith("/") &&
31
31
  !link.startsWith("//") &&
32
32
  link.length <= INBOX_LIMITS.linkChars &&
33
33
  !/[\\\p{Cc}]/u.test(link);
34
+ /** A posted text as one string: itself, or the English one of `{ zh, en }`. */
35
+ const single = (t) => (typeof t === "string" ? t : t.en);
36
+ /** A posted `{ zh, en }` text as its stored JSON (only the two languages); null for a string. */
37
+ const localized = (t) => typeof t === "string" ? null : JSON.stringify({ zh: t.zh, en: t.en });
34
38
  const notFound = () => new ApiError("inbox.item_not_found", "Inbox item not found");
35
39
  /**
36
40
  * Personal inbox items (`inbox_items`, collaboration spec §4.9): an item for one person in one
@@ -125,8 +129,10 @@ let InboxItemsService = class InboxItemsService {
125
129
  source: source.kind,
126
130
  plugin,
127
131
  kind: p.kind,
128
- title: p.title,
129
- body: p.body ?? "",
132
+ title: single(p.title),
133
+ body: p.body === undefined ? "" : single(p.body),
134
+ title_localized: localized(p.title),
135
+ body_localized: p.body === undefined ? null : localized(p.body),
130
136
  link: p.link ?? null,
131
137
  actions: JSON.stringify(actions),
132
138
  dedupe_key: dedupe,
@@ -253,6 +259,8 @@ let InboxItemsService = class InboxItemsService {
253
259
  "kind",
254
260
  "title",
255
261
  "body",
262
+ "title_localized",
263
+ "body_localized",
256
264
  "link",
257
265
  "actions",
258
266
  "detail",
@@ -274,8 +282,8 @@ let InboxItemsService = class InboxItemsService {
274
282
  plugin: r.plugin,
275
283
  pluginName: r.plugin === null ? null : (names.get(r.plugin) ?? null),
276
284
  kind: r.kind,
277
- title: r.title,
278
- body: r.body,
285
+ title: r.title_localized ?? r.title,
286
+ body: r.body_localized ?? r.body,
279
287
  link: r.link,
280
288
  actions: r.actions.map((a) => ({
281
289
  id: a.id,
package/dist/log.d.ts CHANGED
@@ -36,6 +36,10 @@ export interface KernelLogger extends Logger {
36
36
  */
37
37
  child(fields: Record<string, string>): KernelLogger;
38
38
  }
39
+ /** Counts the candidate comparisons a matcher makes (tests). */
40
+ export interface MatcherProbes {
41
+ count: number;
42
+ }
39
43
  /**
40
44
  * 用与 logger 相同的匹配器打码任意文本(工具结果等不经过日志的内容用):展开规则同 `addOrgSecrets`
41
45
  * (URL 形式的值另登记 `user:password@` 片段),只取长度 ≥ `minLength` 的值(默认 12,同组织来源密钥;
@@ -78,6 +82,8 @@ export interface LoggerOptions {
78
82
  orgSecretCapacity?: number;
79
83
  /** Called on every matcher rebuild (tests). */
80
84
  onMatcherBuild?: () => void;
85
+ /** Counts the candidate comparisons the matchers make (tests). */
86
+ matcherProbes?: MatcherProbes;
81
87
  }
82
88
  /**
83
89
  * Creates the kernel logger on pino. Each record is `{ time, level, msg, ...base, ...fields }` with
package/dist/log.js CHANGED
@@ -17,38 +17,66 @@ const ORG_SECRET_CAPACITY = 10_000;
17
17
  /** 匹配器按前缀分桶的前缀长度(不超过两种最短登记长度)。 */
18
18
  const PREFIX_LEN = MIN_SECRET_LEN;
19
19
  /**
20
- * 编译后的打码匹配器:按值的前 `PREFIX_LEN` 个字符分桶,桶内按长度降序。扫描字符串时每个位置查一次桶、
21
- * 记下最长命中的区间,重叠或相邻的区间合并后替换;开销与字符串长度成正比,与登记的密钥数基本无关。
20
+ * The compiled redaction matcher. Values are bucketed by their first `PREFIX_LEN` characters; inside a
21
+ * bucket, by length, one set per distinct length, longest first. At each position of the scanned
22
+ * string it looks up the bucket once and probes each of its lengths once (a set lookup of the slice of
23
+ * that length), keeping the longest hit; overlapping or adjacent hits merge and are replaced. The cost
24
+ * grows with the string's length and the number of distinct lengths in a bucket, never with the
25
+ * number of registered values: many secrets sharing a prefix (`sk-proj-`, `ghp_`) cost no more.
22
26
  */
23
- function compileMatcher(values) {
24
- const buckets = new Map();
27
+ function compileMatcher(values, probes) {
28
+ const byPrefix = new Map();
25
29
  for (const v of values) {
26
30
  const key = v.slice(0, PREFIX_LEN);
27
- const b = buckets.get(key);
28
- if (b)
29
- b.push(v);
31
+ let byLen = byPrefix.get(key);
32
+ if (!byLen) {
33
+ byLen = new Map();
34
+ byPrefix.set(key, byLen);
35
+ }
36
+ const set = byLen.get(v.length);
37
+ if (set)
38
+ set.add(v);
30
39
  else
31
- buckets.set(key, [v]);
40
+ byLen.set(v.length, new Set([v]));
32
41
  }
33
- if (buckets.size === 0)
42
+ if (byPrefix.size === 0)
34
43
  return (s) => s;
35
- for (const b of buckets.values())
36
- b.sort((a, c) => c.length - a.length);
44
+ const buckets = new Map();
45
+ for (const [key, byLen] of byPrefix) {
46
+ const lens = [...byLen.keys()].sort((a, c) => c - a);
47
+ buckets.set(key, { lens, sets: lens.map((l) => byLen.get(l)) });
48
+ }
49
+ const longest = (s, i) => {
50
+ const b = buckets.get(s.slice(i, i + PREFIX_LEN));
51
+ if (!b)
52
+ return 0;
53
+ const room = s.length - i;
54
+ for (let k = 0; k < b.lens.length; k++) {
55
+ const len = b.lens[k];
56
+ if (len > room)
57
+ continue;
58
+ if (probes)
59
+ probes.count++;
60
+ if (b.sets[k].has(s.slice(i, i + len)))
61
+ return len;
62
+ }
63
+ return 0;
64
+ };
37
65
  return (s) => {
38
66
  if (s.length < PREFIX_LEN)
39
67
  return s;
40
- // 每个位置都记下最长命中的区间 [i, i + len),不跳过(否则先开始的密钥会吞掉与之重叠的后一个密钥的开头,
41
- // 使后者剩余部分明文输出);重叠或相邻的区间合并后整段替换为一个 [REDACTED]。
68
+ // Record the longest hit [i, i + len) at every position without skipping ahead (skipping would
69
+ // let an earlier secret swallow the start of an overlapping later one and leave its rest in
70
+ // clear text); overlapping or adjacent hits merge into one [REDACTED].
42
71
  let out = "";
43
72
  let last = 0;
44
73
  let runStart = -1;
45
74
  let runEnd = -1;
46
75
  for (let i = 0; i <= s.length - PREFIX_LEN; i++) {
47
- const b = buckets.get(s.slice(i, i + PREFIX_LEN));
48
- const hit = b?.find((v) => s.startsWith(v, i));
49
- if (!hit)
76
+ const len = longest(s, i);
77
+ if (len === 0)
50
78
  continue;
51
- const end = i + hit.length;
79
+ const end = i + len;
52
80
  if (runStart >= 0 && i <= runEnd) {
53
81
  if (end > runEnd)
54
82
  runEnd = end;
@@ -220,7 +248,7 @@ export function createLogger(level = "info", opts = {}) {
220
248
  let deployMatcher;
221
249
  const redact = (s) => {
222
250
  if (!matcher) {
223
- matcher = compileMatcher(new Set([...secrets, ...orgSecrets]));
251
+ matcher = compileMatcher(new Set([...secrets, ...orgSecrets]), opts.matcherProbes);
224
252
  opts.onMatcherBuild?.();
225
253
  }
226
254
  return matcher(s);
@@ -228,7 +256,7 @@ export function createLogger(level = "info", opts = {}) {
228
256
  /** 顶层 msg 只按部署方密钥打码:组织来源的值不能遮蔽日志消息。 */
229
257
  const redactMsg = (s) => {
230
258
  if (!deployMatcher) {
231
- deployMatcher = compileMatcher(secrets);
259
+ deployMatcher = compileMatcher(secrets, opts.matcherProbes);
232
260
  opts.onMatcherBuild?.();
233
261
  }
234
262
  return deployMatcher(s);
@@ -205,11 +205,13 @@ let AgentSkillsOperations = class AgentSkillsOperations {
205
205
  }),
206
206
  defineOperation({
207
207
  id: "agents.invocable-skills",
208
- description: "List the skills a person can invoke with / on an agent (its effective skills: org, platform and its own), by name: id, name, source (platform, plugin, agent or project), state (manual for manual-only), description, version and the plugin. Optionally pass a conversation of yours with that agent to include its trial drafts and, for a conversation bound to a project, the project's skills as project:<name>.",
208
+ description: "List the skills a person can invoke with / on an agent (its effective skills: org, platform and its own), by name: id, name, source (platform, plugin, agent or project), state (manual for manual-only), description, version and the plugin. Optionally pass a conversation of yours with that agent to include its trial drafts and, for a conversation bound to a project, the project's skills as project:<name>; without a conversation, pass deviceId and project (a project of that device) to include that project's skills as last read in one of your conversations.",
209
209
  input: z
210
210
  .object({
211
211
  agentId: AgentId,
212
212
  conversationId: InvocableSkillsQuerySchema.shape.conversationId,
213
+ deviceId: InvocableSkillsQuerySchema.shape.deviceId,
214
+ project: InvocableSkillsQuerySchema.shape.project,
213
215
  })
214
216
  .strict(),
215
217
  example: { agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77" },
@@ -227,7 +229,9 @@ let AgentSkillsOperations = class AgentSkillsOperations {
227
229
  },
228
230
  ],
229
231
  run: async (input, ctx) => ({
230
- items: (await this.invoker.listFor(ctx.orgId, input.agentId, ctx.actorAccountId, input.conversationId)).map((s) => ({
232
+ items: (await this.invoker.listFor(ctx.orgId, input.agentId, ctx.actorAccountId, input.conversationId, input.deviceId !== undefined && input.project !== undefined
233
+ ? { deviceId: input.deviceId, project: input.project }
234
+ : undefined)).map((s) => ({
231
235
  id: s.id,
232
236
  name: s.name,
233
237
  source: s.source,
@@ -38,6 +38,8 @@ const NOT_FOUND = {
38
38
  const DECIDE_REQUEST_ON_WEB = "Decide it on the web, in the inbox.";
39
39
  const DISMISS_ORG = "Dismiss it with inbox.dismiss-notice once read.";
40
40
  const ADMIN_CONSOLE_PENDING = "Review it in the admin console (plugins, pending tab).";
41
+ /** A personal item's text in `lang`: a single string as is, else that language of `{ zh, en }`. */
42
+ const textIn = (t, lang) => typeof t === "string" ? t : t[lang];
41
43
  /** What a request asks for, by name (the plugin, the marketplace entry or the agent). */
42
44
  const requestName = (r) => r.item?.name ?? r.entry?.name ?? r.agent?.name ?? r.kind;
43
45
  const requester = (r) => r.requestedByName ?? "a deleted account";
@@ -140,7 +142,7 @@ function orgRow(i) {
140
142
  ...base,
141
143
  name: it.pluginName?.en ?? "Capybara",
142
144
  state: "open",
143
- summary: `${it.title}${it.body !== "" ? `: ${it.body}` : ""}`,
145
+ summary: `${textIn(it.title, "en")}${textIn(it.body, "en") !== "" ? `: ${textIn(it.body, "en")}` : ""}`,
144
146
  next: it.actions.length > 0
145
147
  ? "Its buttons are pressed by you on the web, in the inbox; dismiss it with inbox.item-dismiss once read."
146
148
  : "Dismiss it with inbox.item-dismiss once read.",
@@ -384,10 +386,10 @@ let InboxOperations = class InboxOperations {
384
386
  summary: async (input, ctx) => {
385
387
  const open = await orElse(() => this.items.listOpen(ctx.orgId, ctx.actorAccountId), []);
386
388
  const it = open.find((x) => x.id === input.id);
387
- const name = named(it === undefined ? input.id : it.title);
389
+ const name = (lang) => named(it === undefined ? input.id : textIn(it.title, lang));
388
390
  return {
389
- zh: `从你的收件箱移除「${name}」`,
390
- en: `Dismiss "${name}" from your inbox`,
391
+ zh: `从你的收件箱移除「${name("zh")}」`,
392
+ en: `Dismiss "${name("en")}" from your inbox`,
391
393
  };
392
394
  },
393
395
  run: async (input, ctx) => {
@@ -43,7 +43,7 @@ async function resolveInboxItem(db, itemId) {
43
43
  // org, which every later read filters by
44
44
  const item = await db
45
45
  .selectFrom("inbox_items")
46
- .select(["org_id", "account_id", "plugin", "title", "state", "expires_at"])
46
+ .select(["org_id", "account_id", "plugin", "title", "title_localized", "state", "expires_at"])
47
47
  .where("id", "=", itemId)
48
48
  .executeTakeFirst();
49
49
  if (!item || item.state !== "open" || item.expires_at.getTime() <= Date.now())
@@ -66,7 +66,7 @@ async function resolveInboxItem(db, itemId) {
66
66
  path: `/inbox?org=${encodeURIComponent(orgId)}#item=${encodeURIComponent(itemId)}`,
67
67
  threadId: "inbox",
68
68
  title,
69
- conversationTitle: item.title,
69
+ conversationTitle: item.title_localized ?? item.title,
70
70
  text: "inboxItem",
71
71
  };
72
72
  }
@@ -26,8 +26,14 @@ export interface ResolvedPush {
26
26
  zh: string;
27
27
  en: string;
28
28
  };
29
- /** Shown only with `push.previews: "titles"` (an inbox item's title). */
30
- conversationTitle: string | null;
29
+ /**
30
+ * Shown only with `push.previews: "titles"` (an inbox item's title; a localized one is shown in
31
+ * the registration's locale).
32
+ */
33
+ conversationTitle: string | {
34
+ zh: string;
35
+ en: string;
36
+ } | null;
31
37
  text: PushTextKey;
32
38
  }
33
39
  /**
@@ -34,7 +34,10 @@ function cut(s, max) {
34
34
  */
35
35
  export function renderPushMessage(r, locale, previews, origin) {
36
36
  const sentence = pushText(r.text, locale);
37
- const lead = previews === "titles" && r.conversationTitle ? r.conversationTitle : null;
37
+ const conversationTitle = r.conversationTitle === null || typeof r.conversationTitle === "string"
38
+ ? r.conversationTitle
39
+ : r.conversationTitle[locale];
40
+ const lead = previews === "titles" && conversationTitle ? conversationTitle : null;
38
41
  const body = lead === null ? sentence : `${lead}${locale === "zh" ? ":" : ": "}${sentence}`;
39
42
  return {
40
43
  title: cut(typeof r.title === "string" ? r.title : r.title[locale], PUSH_LIMITS.titleChars),
@@ -267,7 +267,9 @@ export const PERSON_MESSAGES_READ = 20;
267
267
  * referenced project files (`payload.projectFiles`, blocks `1 + attachments.length + i`: the
268
268
  * person's intent, worded by the kernel). The `@` resources' bodies (`payload.attachments`,
269
269
  * blocks `1 .. attachments.length`) are content read from a connector, not the person's
270
- * instructions, so they are skipped, like images, documents and uploaded files.
270
+ * instructions, so they are skipped, like images, documents and uploaded files. So are the
271
+ * referenced conversations' blocks (`payload.conversationRefs`, after the project file lines):
272
+ * quoted material, not the person's intent.
271
273
  */
272
274
  function textOfUserMessage(payload) {
273
275
  const p = payload;
@@ -4,6 +4,8 @@ import { type OrgContext } from "../orgs/org.guard.js";
4
4
  import { type InvocableSkill, SkillInvoker } from "./invoke.js";
5
5
  declare const ListQuery: z.ZodObject<{
6
6
  conversationId: z.ZodOptional<z.ZodString>;
7
+ deviceId: z.ZodOptional<z.ZodString>;
8
+ project: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
7
9
  }, z.core.$strict>;
8
10
  /**
9
11
  * The composer's `/` menu (phase D spec §4.5): `GET /api/v1/orgs/:orgId/agents/:agentId/
@@ -12,6 +14,8 @@ declare const ListQuery: z.ZodObject<{
12
14
  * (`agents.use`, human principals: invocations are sent from a conversation); an agent the caller
13
15
  * cannot use → 404 `agent.not_found`; a `conversationId` that is not the caller's conversation with
14
16
  * this agent → 404 `conversation.not_found` (with it, that conversation's trial drafts apply).
17
+ * Without a conversation, `deviceId` and `project` add the picked project's skills from its last
18
+ * known snapshot among the caller's own conversations.
15
19
  */
16
20
  export declare class InvocableSkillsController {
17
21
  private readonly invoker;
@@ -24,6 +24,8 @@ class InvocableSkillsQuery extends createZodDto(ListQuery, "InvocableSkillsQuery
24
24
  * (`agents.use`, human principals: invocations are sent from a conversation); an agent the caller
25
25
  * cannot use → 404 `agent.not_found`; a `conversationId` that is not the caller's conversation with
26
26
  * this agent → 404 `conversation.not_found` (with it, that conversation's trial drafts apply).
27
+ * Without a conversation, `deviceId` and `project` add the picked project's skills from its last
28
+ * known snapshot among the caller's own conversations.
27
29
  */
28
30
  let InvocableSkillsController = class InvocableSkillsController {
29
31
  invoker;
@@ -33,7 +35,9 @@ let InvocableSkillsController = class InvocableSkillsController {
33
35
  async list(principal, org, agentId, q) {
34
36
  const p = requireUser(principal);
35
37
  return {
36
- skills: await this.invoker.listFor(org.orgId, agentId, p.account.id, q.conversationId),
38
+ skills: await this.invoker.listFor(org.orgId, agentId, p.account.id, q.conversationId, q.deviceId !== undefined && q.project !== undefined
39
+ ? { deviceId: q.deviceId, project: q.project }
40
+ : undefined),
37
41
  };
38
42
  }
39
43
  };
@@ -94,6 +94,37 @@ export declare function projectInvocables(p: ProjectRootPayload | undefined): In
94
94
  * `project_root`'s skills; null when it is.
95
95
  */
96
96
  export declare function projectSkillBlocked(p: ProjectRootPayload | undefined, name: string): NotInvocableReason | null;
97
+ /** A conversation's project binding: the device and the project's name and root. */
98
+ export interface ProjectBinding {
99
+ deviceId: string;
100
+ name: string;
101
+ path: string;
102
+ }
103
+ /**
104
+ * The last known snapshot of a project (project skills before the first run, design §3.1): the
105
+ * newest usable `project_root` among the caller's own chat conversations bound to the same device,
106
+ * project name and root (each conversation's latest one). What a run of the same person read from
107
+ * that project; the device is never asked. Undefined when none is known.
108
+ */
109
+ export declare function latestKnownProjectRoot(db: KernelSchemaDb, a: {
110
+ orgId: string;
111
+ accountId: string;
112
+ binding: ProjectBinding;
113
+ }): Promise<ProjectRootPayload | undefined>;
114
+ /**
115
+ * The snapshot a conversation's project skills come from: its own latest `project_root`, or, when
116
+ * its runs never recorded one, the last known snapshot of its binding among its owner's
117
+ * conversations ({@link latestKnownProjectRoot}). `own` says which. Undefined when neither exists.
118
+ */
119
+ export declare function projectSnapshotOf(db: KernelSchemaDb, a: {
120
+ orgId: string;
121
+ conversationId: string;
122
+ },
123
+ /** The conversation's own latest `project_root` (default: read with `db`). */
124
+ ownLatest?: () => Promise<ProjectRootPayload | undefined>): Promise<{
125
+ payload: ProjectRootPayload;
126
+ own: boolean;
127
+ } | undefined>;
97
128
  /**
98
129
  * Whether the skill a queued invocation recorded is still one a person can invoke in this
99
130
  * conversation (phase D Task 9, checked again at dispatch): the same skill (by id) among the
@@ -120,7 +151,12 @@ export declare const forkLeadText: (name: string, agentType: string, args: strin
120
151
  export declare function projectSkillStub(a: {
121
152
  name: string;
122
153
  args: string;
123
- }, latest: ProjectRootPayload, bare: string): RenderedInvocation;
154
+ }, latest: ProjectRootPayload, bare: string,
155
+ /**
156
+ * Where `latest` comes from: `run`, this conversation's run start; `known`, the last known
157
+ * snapshot of the project from another conversation (no run of this one read it yet).
158
+ */
159
+ from?: "run" | "known"): RenderedInvocation;
124
160
  /** The warning recorded when a forked skill's `agent` does not resolve (spec §6.2). */
125
161
  export declare const forkAgentUnknownText: (name: string, agent: string) => string;
126
162
  /**
@@ -144,7 +180,21 @@ export declare class SkillInvoker {
144
180
  * then its trial drafts apply, and its latest usable `project_root` adds the project's skills
145
181
  * after the agent's ({@link projectInvocables}).
146
182
  */
147
- listFor(orgId: string, agentId: string, accountId: string, conversationId?: string): Promise<InvocableSkill[]>;
183
+ listFor(orgId: string, agentId: string, accountId: string, conversationId?: string,
184
+ /**
185
+ * Without `conversationId`: the new conversation's picked device project (design §3.2), whose
186
+ * last known snapshot adds the project's skills.
187
+ */
188
+ pick?: {
189
+ deviceId: string;
190
+ project: string;
191
+ }): Promise<InvocableSkill[]>;
192
+ /**
193
+ * The device project a new conversation picked, by device and name, or undefined when the device
194
+ * has no project of that name. Only its last known snapshot among the caller's own conversations
195
+ * is used, so nothing of someone else's device can be read through it.
196
+ */
197
+ private pickedBinding;
148
198
  /**
149
199
  * The agent's effective skills a person can invoke (`user` not false), sorted by name (code
150
200
  * point order), model-invocable and manual-only alike (spec §3.1).
@@ -174,6 +224,14 @@ export declare class SkillInvoker {
174
224
  * names the skill's directory ({@link knownSkillsRoot}). Null or absent: `/skills`.
175
225
  */
176
226
  deviceId?: string | null;
227
+ /**
228
+ * The first message of a conversation not created yet: the project it is created bound to, as
229
+ * the creation resolves it (its last known snapshot renders a project skill, design §3.3).
230
+ */
231
+ project?: {
232
+ name: string;
233
+ path: string;
234
+ };
177
235
  agent: AgentDefinition;
178
236
  name: string;
179
237
  args: string;
@@ -188,6 +246,14 @@ export declare class SkillInvoker {
188
246
  * the `Skill` tool.
189
247
  */
190
248
  private prepareProject;
249
+ /** {@link projectSnapshotOf}, the conversation's own latest read through the event log. */
250
+ private conversationSnapshot;
251
+ /**
252
+ * Where a send's project skill is rendered from (design §3.3): the conversation's own latest
253
+ * `project_root`, else the last known snapshot of its binding; for a conversation not created
254
+ * yet, the last known snapshot of the project it is created bound to.
255
+ */
256
+ private projectSnapshot;
191
257
  /**
192
258
  * The task of a fork invocation's sub-agent (spec §6.2), rendered at dispatch from the version
193
259
  * the person's message recorded (`skill.{id, source, version, arguments}`), never by name, so a