@bridgebrew/sessions 0.0.23 → 0.0.27

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.
@@ -51,6 +51,20 @@ const unquote = (name: string | undefined) => {
51
51
  return new TextDecoder().decode(new Uint8Array(bytes));
52
52
  };
53
53
 
54
+ /** The path of a file whose diff has no `---`/`+++` lines (a binary file, a mode change): its rename's target, else its
55
+ * `diff --git` line's `b/` side, quoted, or unquoted and split where both sides name the same file (a space is in it). */
56
+ const gitLinePath = (lines: string[]) => {
57
+ const renamed = lines.find((line) => line.startsWith('rename to '));
58
+ if (renamed) return unquote(renamed.slice('rename to '.length));
59
+ const rest = lines[0]!.slice('diff --git '.length);
60
+ const quoted = /"(?:[^"\\]|\\.)*"$/.exec(rest)?.[0];
61
+ if (quoted) return unquote(quoted)?.replace(/^b\//, '');
62
+ const half = (rest.length - 1) / 2;
63
+ if (Number.isInteger(half) && rest.startsWith('a/') && rest.slice(half + 1).startsWith('b/') && rest.slice(2, half) === rest.slice(half + 3))
64
+ return rest.slice(half + 3);
65
+ return /^a\/(.*) b\//.exec(rest)?.[1];
66
+ };
67
+
54
68
  /** A `git diff` cut per file: its path (the new one, the old one for a deletion), its lines from its first hunk, and
55
69
  * its added and removed line counts. */
56
70
  export const diffFiles = (diff: string) =>
@@ -60,13 +74,19 @@ export const diffFiles = (diff: string) =>
60
74
  .map((chunk) => {
61
75
  const lines = chunk.replace(/\n$/, '').split('\n');
62
76
  const side = (prefix: string) => {
63
- const name = unquote(lines.find((line) => line.startsWith(prefix))?.slice(prefix.length));
77
+ // Git ends a name holding a space with a tab, outside its quotes: dropped before reading it (#197).
78
+ const name = unquote(
79
+ lines
80
+ .find((line) => line.startsWith(prefix))
81
+ ?.slice(prefix.length)
82
+ .replace(/\t$/, ''),
83
+ );
64
84
  return name && name !== '/dev/null' ? name.replace(/^[ab]\//, '') : undefined;
65
85
  };
66
86
  const hunk = lines.findIndex((line) => line.startsWith('@@'));
67
87
  const body = hunk < 0 ? lines.slice(1) : lines.slice(hunk);
68
88
  return {
69
- path: side('+++ ') ?? side('--- ') ?? /^diff --git a\/(.*) b\//.exec(lines[0]!)?.[1] ?? '',
89
+ path: side('+++ ') ?? side('--- ') ?? gitLinePath(lines) ?? '',
70
90
  lines: body,
71
91
  added: body.filter((line) => line[0] === '+').length,
72
92
  removed: body.filter((line) => line[0] === '-').length,
package/delegations.ts CHANGED
@@ -578,30 +578,36 @@ const viewOf = (each: Delegation) => ({
578
578
  });
579
579
 
580
580
  const flag = z.boolean().optional();
581
+ /** An optional field an agent may send blank (`""`): blank is left out, so it takes its default (#199). */
582
+ const optional = <T extends z.ZodType>(schema: T) =>
583
+ z.preprocess(
584
+ (value) => (typeof value === 'string' && value.trim() === '' ? undefined : value),
585
+ schema.optional(),
586
+ );
581
587
  const delegateBody = z.strictObject({
582
588
  from: z.string().min(1),
583
589
  prompt: z.string().trim().min(1).max(PROMPT_MAX),
584
- title: z.string().trim().min(1).max(200).optional(),
585
- role: z.enum(ROLES).optional(),
590
+ title: optional(z.string().trim().min(1).max(200)),
591
+ role: optional(z.enum(ROLES)),
586
592
  target: z
587
593
  .strictObject({
588
- profile: z.string().min(1).optional(),
589
- model: z.string().min(1).optional(),
590
- effort: z.string().min(1).optional(),
594
+ profile: optional(z.string().min(1)),
595
+ model: optional(z.string().min(1)),
596
+ effort: optional(z.string().min(1)),
591
597
  options: z.strictObject({ plan: flag, auto: flag }).optional(),
592
- project: z.string().min(1).optional(),
598
+ project: optional(z.string().min(1)),
593
599
  })
594
600
  .optional(),
595
- mode: z.string().min(1).optional(),
596
- interaction: z.enum(['default', 'plan']).optional(),
597
- isolation: z.enum(['shared', 'worktree']).optional(),
601
+ mode: optional(z.string().min(1)),
602
+ interaction: optional(z.enum(['default', 'plan'])),
603
+ isolation: optional(z.enum(['shared', 'worktree'])),
598
604
  worktree: z
599
605
  .strictObject({
600
606
  plugins: z.array(z.string().min(1)).min(1).max(50),
601
- branch: z.string().trim().min(1).max(100).optional(),
607
+ branch: optional(z.string().trim().min(1).max(100)),
602
608
  })
603
609
  .optional(),
604
- wait: z.enum(['async', 'wait']).optional(),
610
+ wait: optional(z.enum(['async', 'wait'])),
605
611
  timeoutMs: z.number().int().min(0).optional(),
606
612
  clientRequestId: z.string().min(1).max(200),
607
613
  });
@@ -1814,6 +1820,9 @@ export function createDelegations<V extends Value>({
1814
1820
  * before it. */
1815
1821
  const check = (id: string) =>
1816
1822
  serial(id, async () => {
1823
+ // After its writes asked before: the record of the turn that just ended (`lastTurn`) lands before its delegation
1824
+ // ends, so a delegation never ends on a child whose turn shows no end yet.
1825
+ await written(id);
1817
1826
  if (running.has(id)) return;
1818
1827
  const found = await get(id);
1819
1828
  const parent = found?.value.parent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bridgebrew/sessions",
3
- "version": "0.0.23",
3
+ "version": "0.0.27",
4
4
  "license": "MIT",
5
5
  "description": "Conversations with agents, in the workspace or in a project, through the Profile.",
6
6
  "keywords": [
@@ -1027,6 +1027,6 @@
1027
1027
  },
1028
1028
  "releaseStage": "dev",
1029
1029
  "engines": {
1030
- "bridge": ">=0.0.1-nightly.20261117.1"
1030
+ "bridge": ">=0.0.1-nightly.20261118.1"
1031
1031
  }
1032
1032
  }
package/server.ts CHANGED
@@ -728,10 +728,16 @@ const modeBody = z.strictObject({
728
728
  harness: z.string().min(1).optional(),
729
729
  });
730
730
  const effortBody = z.strictObject({ effort: z.string().min(1) });
731
+ /** A message's text as the agent gets it: blank is empty, a slash command is trimmed as it always was, any other text
732
+ * keeps its own whitespace (an indented snippet's first line stays indented, #200). */
733
+ const messageText = (text: string) => {
734
+ const trimmed = text.trim();
735
+ return !trimmed || trimmed.startsWith('/') ? trimmed : text;
736
+ };
731
737
  /** A message: its text, its images; one of them at least. */
732
738
  const turnBody = z
733
739
  .strictObject({
734
- text: z.string().trim(),
740
+ text: z.string().transform(messageText),
735
741
  attachments: z.array(attachment).max(ATTACHMENTS_MAX).optional(),
736
742
  // Bridge's own words (the host telling the agent how a change it asked for went), never the user's.
737
743
  from: z.literal('bridge').optional(),
@@ -4581,9 +4587,15 @@ export async function apply(ctx: Context, config?: unknown) {
4581
4587
 
4582
4588
  // Scheduled prompts (`sessions.prompt`): the scheduler's tasks own the schedule and call this action with a session
4583
4589
  // and a prompt. A run starts a turn or waits in the queue, marked with its task.
4590
+ // Required (blank is missing), kept as written: `messageText`.
4591
+ const scheduledPrompt = z
4592
+ .string()
4593
+ .max(PROMPT_MAX)
4594
+ .refine((text) => text.trim() !== '', 'is required')
4595
+ .transform(messageText);
4584
4596
  const promptInput = z.strictObject({
4585
4597
  session: z.string().min(1),
4586
- prompt: z.string().trim().min(1).max(PROMPT_MAX),
4598
+ prompt: scheduledPrompt,
4587
4599
  });
4588
4600
  /** A refused action input, named by its first wrong field (`prompt: is required`), so the form says it under it. */
4589
4601
  const inputRefusal = (error: z.ZodError) => {
@@ -4621,7 +4633,7 @@ export async function apply(ctx: Context, config?: unknown) {
4621
4633
  effort: z.string().trim().min(1).optional(),
4622
4634
  mode: z.string().trim().min(1).optional(),
4623
4635
  title: z.string().trim().max(200).optional(),
4624
- prompt: z.string().trim().min(1).max(PROMPT_MAX),
4636
+ prompt: scheduledPrompt,
4625
4637
  });
4626
4638
  const parseStart = (input: unknown) => {
4627
4639
  const parsed = startInput.safeParse(input);