@agimon-ai/po-template-advanced 0.0.0-alpha.2 → 0.0.0-alpha.21

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.
@@ -3,8 +3,8 @@ import { View } from "react-native-unistyles/components/native/View";
3
3
  import { Text } from "react-native-unistyles/components/native/Text";
4
4
  import { ScrollView } from "react-native-unistyles/components/native/ScrollView";
5
5
  import { Pressable } from "react-native-unistyles/components/native/Pressable";
6
- import { AlertIcon, BranchIcon, Button, EmptyState, FolderIcon, Input, KebabIcon, PlusIcon, Sheet, SheetBody, SheetContent, SheetHeader, SheetTitle, Spinner, fontOf } from "@agimon-ai/po-native-components";
7
- import { useState } from "react";
6
+ import { ActivityIcon, AlertIcon, Badge, BranchIcon, Button, EmptyState, FolderIcon, ForkIcon, Input, KebabIcon, Label, ListRow, PlusIcon, Sheet, SheetBody, SheetContent, SheetHeader, SheetTitle, Spinner, UsersIcon, fontOf } from "@agimon-ai/po-native-components";
7
+ import { useEffect, useState } from "react";
8
8
  import { StyleSheet } from "react-native-unistyles";
9
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
10
  //#region src/extensions/(frontend)/template/_components/AdvancedSessionMenus.native.tsx
@@ -239,6 +239,221 @@ function WorkspaceMenuSheet({ workspace, actions, onClose }) {
239
239
  })] }) })
240
240
  });
241
241
  }
242
+ const SUGGESTION_DEBOUNCE_MS = 120;
243
+ const TRAILING_SEPARATORS = /\/+$/u;
244
+ function folderName(path) {
245
+ const trimmed = path.trim().replace(TRAILING_SEPARATORS, "");
246
+ return trimmed.slice(trimmed.lastIndexOf("/") + 1) || trimmed;
247
+ }
248
+ /** The cockpit's folder browser, in place: up, into a child, or use the current folder. */
249
+ function FolderBrowser({ start, listDirectory, onSelect }) {
250
+ const [target, setTarget] = useState(start);
251
+ const [listing, setListing] = useState(null);
252
+ const [error, setError] = useState("");
253
+ useEffect(() => {
254
+ let stale = false;
255
+ listDirectory(target).then((result) => {
256
+ if (stale) return;
257
+ if ("error" in result) setError(result.error);
258
+ else {
259
+ setError("");
260
+ setListing(result);
261
+ }
262
+ });
263
+ return () => {
264
+ stale = true;
265
+ };
266
+ }, [target, listDirectory]);
267
+ const parent = listing?.parent;
268
+ return /* @__PURE__ */ jsxs(View, {
269
+ style: styles$1.list,
270
+ children: [
271
+ /* @__PURE__ */ jsxs(View, {
272
+ style: styles$1.browserHead,
273
+ children: [/* @__PURE__ */ jsx(Text, {
274
+ style: styles$1.path,
275
+ numberOfLines: 1,
276
+ ellipsizeMode: "head",
277
+ children: listing?.path ?? "Loading…"
278
+ }), /* @__PURE__ */ jsx(Button, {
279
+ size: "sm",
280
+ disabled: listing === null,
281
+ onPress: () => listing !== null && onSelect(listing.path),
282
+ children: "Use this folder"
283
+ })]
284
+ }),
285
+ error ? /* @__PURE__ */ jsx(Text, {
286
+ style: [styles$1.error, styles$1.inset],
287
+ accessibilityRole: "alert",
288
+ children: error
289
+ }) : null,
290
+ parent === void 0 ? null : /* @__PURE__ */ jsx(ListRow, {
291
+ title: "Parent folder",
292
+ disclosure: false,
293
+ onPress: () => setTarget(parent),
294
+ style: styles$1.divider
295
+ }),
296
+ listing?.directories.length === 0 ? /* @__PURE__ */ jsx(Text, {
297
+ style: [styles$1.meta, styles$1.inset],
298
+ children: "No folders here"
299
+ }) : null,
300
+ listing?.directories.map((directory) => /* @__PURE__ */ jsx(ListRow, {
301
+ title: folderName(directory),
302
+ leading: /* @__PURE__ */ jsx(FolderIcon, {
303
+ size: 16,
304
+ color: "dim"
305
+ }),
306
+ onPress: () => setTarget(directory),
307
+ style: styles$1.divider
308
+ }, directory))
309
+ ]
310
+ });
311
+ }
312
+ /** The cockpit's add-workspace dialog as a sheet: a name, a folder, or both; a name alone gets a new folder. */
313
+ function AddWorkspaceSheet({ open, actions, onClose }) {
314
+ const [name, setName] = useState("");
315
+ const [nameEdited, setNameEdited] = useState(false);
316
+ const [path, setPath] = useState("");
317
+ const [browsing, setBrowsing] = useState(false);
318
+ const [suggestions, setSuggestions] = useState([]);
319
+ const [busy, setBusy] = useState(false);
320
+ const [error, setError] = useState("");
321
+ const { searchDirectories } = actions;
322
+ const shownName = nameEdited ? name : folderName(path);
323
+ const trimmedPath = path.trim().replace(TRAILING_SEPARATORS, "") || (path.trim() === "" ? "" : "/");
324
+ const canSubmit = !busy && (trimmedPath !== "" || shownName.trim() !== "");
325
+ useEffect(() => {
326
+ const typed = path.trim();
327
+ if (typed === "") return;
328
+ let stale = false;
329
+ const timer = setTimeout(async () => {
330
+ const found = await searchDirectories(typed);
331
+ if (!stale) setSuggestions(found.filter((directory) => directory !== typed));
332
+ }, SUGGESTION_DEBOUNCE_MS);
333
+ return () => {
334
+ stale = true;
335
+ clearTimeout(timer);
336
+ };
337
+ }, [path, searchDirectories]);
338
+ const changePath = (next) => {
339
+ setPath(next);
340
+ if (next.trim() === "") setSuggestions([]);
341
+ };
342
+ const finish = () => {
343
+ setName("");
344
+ setNameEdited(false);
345
+ setPath("");
346
+ setBrowsing(false);
347
+ setSuggestions([]);
348
+ setError("");
349
+ onClose();
350
+ };
351
+ const submit = async () => {
352
+ if (!canSubmit) return;
353
+ setBusy(true);
354
+ setError("");
355
+ const result = await actions.addWorkspace({
356
+ name: shownName.trim(),
357
+ ...trimmedPath === "" ? {} : { path: trimmedPath }
358
+ });
359
+ setBusy(false);
360
+ if (result === void 0) finish();
361
+ else setError(result.error);
362
+ };
363
+ return /* @__PURE__ */ jsx(Sheet, {
364
+ open,
365
+ onOpenChange: (next) => !next && !busy && finish(),
366
+ children: /* @__PURE__ */ jsxs(SheetContent, { children: [/* @__PURE__ */ jsx(SheetHeader, { children: /* @__PURE__ */ jsx(SheetTitle, { children: "Add workspace" }) }), /* @__PURE__ */ jsxs(SheetBody, {
367
+ style: styles$1.body,
368
+ children: [
369
+ /* @__PURE__ */ jsxs(View, {
370
+ style: styles$1.field,
371
+ children: [/* @__PURE__ */ jsx(Label, { children: "Name" }), /* @__PURE__ */ jsx(Input, {
372
+ value: shownName,
373
+ onChangeText: (next) => {
374
+ setNameEdited(true);
375
+ setName(next);
376
+ },
377
+ placeholder: "my-project",
378
+ autoCapitalize: "none",
379
+ autoCorrect: false,
380
+ accessibilityLabel: "Workspace name"
381
+ })]
382
+ }),
383
+ /* @__PURE__ */ jsxs(View, {
384
+ style: styles$1.field,
385
+ children: [
386
+ /* @__PURE__ */ jsx(Label, { children: "Folder" }),
387
+ /* @__PURE__ */ jsx(Text, {
388
+ style: styles$1.meta,
389
+ children: "Optional. Type a path or browse."
390
+ }),
391
+ /* @__PURE__ */ jsxs(View, {
392
+ style: styles$1.pathRow,
393
+ children: [/* @__PURE__ */ jsx(Input, {
394
+ value: path,
395
+ onChangeText: changePath,
396
+ placeholder: "~/workspace/my-project",
397
+ autoCapitalize: "none",
398
+ autoCorrect: false,
399
+ accessibilityLabel: "Workspace folder",
400
+ style: styles$1.pathInput
401
+ }), /* @__PURE__ */ jsx(Button, {
402
+ variant: browsing ? "subtle" : "outline",
403
+ accessibilityState: { selected: browsing },
404
+ onPress: () => setBrowsing((current) => !current),
405
+ children: "Browse"
406
+ })]
407
+ })
408
+ ]
409
+ }),
410
+ browsing ? /* @__PURE__ */ jsx(FolderBrowser, {
411
+ ...trimmedPath.startsWith("/") ? { start: trimmedPath } : {},
412
+ listDirectory: actions.listDirectory,
413
+ onSelect: (selected) => {
414
+ changePath(selected);
415
+ setBrowsing(false);
416
+ }
417
+ }) : suggestions.length > 0 ? /* @__PURE__ */ jsx(View, {
418
+ style: styles$1.list,
419
+ accessibilityLabel: "Matching folders",
420
+ children: suggestions.map((directory, index) => /* @__PURE__ */ jsx(ListRow, {
421
+ title: /* @__PURE__ */ jsx(Text, {
422
+ style: styles$1.path,
423
+ numberOfLines: 1,
424
+ ellipsizeMode: "head",
425
+ children: directory
426
+ }),
427
+ disclosure: false,
428
+ onPress: () => changePath(`${directory}/`),
429
+ style: index > 0 && styles$1.divider
430
+ }, directory))
431
+ }) : null,
432
+ trimmedPath === "" && shownName.trim() !== "" ? /* @__PURE__ */ jsxs(Text, {
433
+ style: styles$1.meta,
434
+ children: ["Creates ", /* @__PURE__ */ jsxs(Text, {
435
+ style: styles$1.mono,
436
+ children: ["~/.po/workspace/", shownName.trim()]
437
+ })]
438
+ }) : null,
439
+ error ? /* @__PURE__ */ jsx(Text, {
440
+ style: styles$1.error,
441
+ accessibilityRole: "alert",
442
+ children: error
443
+ }) : null,
444
+ /* @__PURE__ */ jsx(Button, {
445
+ variant: "primary",
446
+ size: "lg",
447
+ disabled: !canSubmit,
448
+ loading: busy,
449
+ loadingLabel: "Adding",
450
+ onPress: () => void submit(),
451
+ children: "Add workspace"
452
+ })
453
+ ]
454
+ })] })
455
+ });
456
+ }
242
457
  const styles$1 = StyleSheet.create((theme) => {
243
458
  const sans = fontOf(theme.fontFamily.sans);
244
459
  const text = (size, color) => ({
@@ -272,6 +487,40 @@ const styles$1 = StyleSheet.create((theme) => {
272
487
  borderTopColor: theme.colors["border-soft"],
273
488
  uni__dependencies: [0]
274
489
  },
490
+ field: {
491
+ gap: theme.spacing(1.5),
492
+ uni__dependencies: [0]
493
+ },
494
+ pathRow: {
495
+ flexDirection: "row",
496
+ alignItems: "center",
497
+ gap: theme.spacing(2),
498
+ uni__dependencies: [0]
499
+ },
500
+ pathInput: {
501
+ flex: 1,
502
+ minWidth: 0
503
+ },
504
+ browserHead: {
505
+ flexDirection: "row",
506
+ alignItems: "center",
507
+ gap: theme.spacing(2),
508
+ paddingHorizontal: theme.spacing(4),
509
+ paddingVertical: theme.spacing(2),
510
+ uni__dependencies: [0]
511
+ },
512
+ path: {
513
+ ...text("sm", theme.colors.dim),
514
+ fontFamily: fontOf(theme.fontFamily.mono),
515
+ flexShrink: 1,
516
+ flexGrow: 1,
517
+ uni__dependencies: [0]
518
+ },
519
+ inset: {
520
+ paddingHorizontal: theme.spacing(4),
521
+ paddingBottom: theme.spacing(2),
522
+ uni__dependencies: [0]
523
+ },
275
524
  pressed: {
276
525
  backgroundColor: theme.colors["tint-green"],
277
526
  uni__dependencies: [0]
@@ -326,7 +575,8 @@ function IconButton({ label, onPress, children }) {
326
575
  function SessionCard({ session, onOpen, onMenu }) {
327
576
  const tone = statusTone(session.status);
328
577
  const name = session.name || "Untitled";
329
- return /* @__PURE__ */ jsxs(Pressable, {
578
+ const markColor = session.active ? "green" : "faint";
579
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Pressable, {
330
580
  accessibilityRole: "button",
331
581
  accessibilityLabel: `Open ${name}`,
332
582
  onPress: () => onOpen(session.id),
@@ -350,35 +600,42 @@ function SessionCard({ session, onOpen, onMenu }) {
350
600
  }) : null,
351
601
  /* @__PURE__ */ jsxs(View, {
352
602
  style: styles.cardText,
353
- children: [/* @__PURE__ */ jsx(Text, {
354
- style: styles.name,
355
- numberOfLines: 2,
356
- children: name
603
+ children: [/* @__PURE__ */ jsxs(View, {
604
+ style: styles.nameRow,
605
+ children: [session.nested && session.provenance === "workflow-session" ? /* @__PURE__ */ jsx(ActivityIcon, {
606
+ size: 13,
607
+ color: markColor,
608
+ accessibilityLabel: "workflow session"
609
+ }) : session.nested && session.provenance ? /* @__PURE__ */ jsx(ForkIcon, {
610
+ size: 13,
611
+ color: markColor,
612
+ accessibilityLabel: session.provenance === "worktree" ? "automatic per-conversation worktree" : session.provenance
613
+ }) : null, /* @__PURE__ */ jsx(Text, {
614
+ style: styles.name,
615
+ numberOfLines: 2,
616
+ children: name
617
+ })]
357
618
  }), /* @__PURE__ */ jsxs(View, {
358
619
  style: styles.statusRow,
359
- children: [
360
- session.restarting ? /* @__PURE__ */ jsx(Spinner, {
361
- size: "small",
362
- color: "dim",
363
- label: "Restarting"
364
- }) : null,
365
- session.awaitingInput ? /* @__PURE__ */ jsx(AlertIcon, {
366
- size: 12,
367
- color: "magenta",
368
- accessibilityLabel: "Waiting for your input"
369
- }) : tone === "running" ? /* @__PURE__ */ jsx(Spinner, {
370
- size: "small",
371
- color: "yellow"
372
- }) : tone === "failed" ? /* @__PURE__ */ jsx(AlertIcon, {
373
- size: 12,
374
- color: "red"
375
- }) : null,
376
- /* @__PURE__ */ jsx(Text, {
377
- style: styles.status(tone),
378
- numberOfLines: 1,
379
- children: session.status
380
- })
381
- ]
620
+ children: [session.restarting ? /* @__PURE__ */ jsx(Spinner, {
621
+ size: "small",
622
+ color: "dim",
623
+ label: "Restarting"
624
+ }) : session.awaitingInput ? /* @__PURE__ */ jsx(AlertIcon, {
625
+ size: 12,
626
+ color: "magenta",
627
+ accessibilityLabel: "Waiting for your input"
628
+ }) : tone === "running" ? /* @__PURE__ */ jsx(Spinner, {
629
+ size: "small",
630
+ color: "yellow"
631
+ }) : tone === "failed" ? /* @__PURE__ */ jsx(AlertIcon, {
632
+ size: 12,
633
+ color: "red"
634
+ }) : null, /* @__PURE__ */ jsx(Text, {
635
+ style: styles.status(tone),
636
+ numberOfLines: 1,
637
+ children: session.status
638
+ })]
382
639
  })]
383
640
  }),
384
641
  /* @__PURE__ */ jsx(IconButton, {
@@ -409,28 +666,46 @@ function SessionCard({ session, onOpen, onMenu }) {
409
666
  }) : null
410
667
  ]
411
668
  }) : null,
412
- session.pendingSetups.map((setup) => /* @__PURE__ */ jsxs(View, {
413
- style: [styles.setup, session.profile && styles.underAvatar],
414
- children: [/* @__PURE__ */ jsxs(Text, {
415
- style: styles.setupStatus(setup.failed),
416
- numberOfLines: 2,
417
- children: [
418
- setup.name,
419
- " · ",
420
- setup.status
421
- ]
422
- }), setup.recovery ? /* @__PURE__ */ jsx(Text, {
423
- style: styles.recovery,
424
- children: setup.recovery
425
- }) : null]
426
- }, setup.id)),
669
+ session.groups !== void 0 && session.groups.length > 0 ? /* @__PURE__ */ jsxs(View, {
670
+ style: [styles.groupsRow, session.profile && styles.underAvatar],
671
+ accessibilityLabel: "groups",
672
+ children: [/* @__PURE__ */ jsx(UsersIcon, {
673
+ size: 13,
674
+ color: "dim"
675
+ }), /* @__PURE__ */ jsx(View, {
676
+ style: styles.groups,
677
+ children: session.groups.map((group) => /* @__PURE__ */ jsx(Badge, {
678
+ tone: "magenta",
679
+ size: "xs",
680
+ children: group
681
+ }, group))
682
+ })]
683
+ }) : null,
427
684
  session.error ? /* @__PURE__ */ jsx(Text, {
428
685
  style: styles.error,
429
686
  numberOfLines: 3,
430
687
  children: session.error
431
688
  }) : null
432
689
  ]
433
- });
690
+ }), session.pendingSetups.map((setup) => /* @__PURE__ */ jsxs(View, {
691
+ style: styles.setup,
692
+ children: [
693
+ /* @__PURE__ */ jsx(Text, {
694
+ style: styles.name,
695
+ numberOfLines: 1,
696
+ children: setup.name
697
+ }),
698
+ /* @__PURE__ */ jsx(Text, {
699
+ style: styles.setupStatus(setup.failed),
700
+ children: setup.status
701
+ }),
702
+ setup.recovery ? /* @__PURE__ */ jsx(Text, {
703
+ style: styles.recovery,
704
+ accessibilityRole: setup.failed ? "alert" : void 0,
705
+ children: setup.recovery
706
+ }) : null
707
+ ]
708
+ }, setup.id))] });
434
709
  }
435
710
  function WorkspaceGroup({ workspace, onOpen, actions, onSessionMenu, onWorkspaceMenu }) {
436
711
  return /* @__PURE__ */ jsxs(View, {
@@ -489,14 +764,49 @@ function WorkspaceGroup({ workspace, onOpen, actions, onSessionMenu, onWorkspace
489
764
  ]
490
765
  });
491
766
  }
767
+ /** The cockpit rail's empty state: one way in, adding a folder. */
768
+ function NoWorkspaces({ actions }) {
769
+ const [adding, setAdding] = useState(false);
770
+ return /* @__PURE__ */ jsxs(View, {
771
+ style: styles.screen,
772
+ children: [/* @__PURE__ */ jsx(View, {
773
+ style: styles.content,
774
+ children: /* @__PURE__ */ jsxs(View, {
775
+ style: styles.empty,
776
+ children: [/* @__PURE__ */ jsx(Text, {
777
+ style: styles.emptyText,
778
+ children: "Add a folder to start working with Po."
779
+ }), /* @__PURE__ */ jsxs(Button, {
780
+ style: styles.emptyButton,
781
+ onPress: () => setAdding(true),
782
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: 14 }), "Add workspace"]
783
+ })]
784
+ })
785
+ }), /* @__PURE__ */ jsx(AddWorkspaceSheet, {
786
+ open: adding,
787
+ actions,
788
+ onClose: () => setAdding(false)
789
+ })]
790
+ });
791
+ }
492
792
  /** The Advanced template's session list: the cockpit rail's workspace groups and cards, sized for a phone. */
493
793
  function AdvancedSessions({ workspaces, openSession, actions }) {
494
794
  const [sessionMenu, setSessionMenu] = useState(null);
495
795
  const [workspaceMenu, setWorkspaceMenu] = useState(null);
496
- if (workspaces.length === 0) return /* @__PURE__ */ jsx(EmptyState, {
497
- title: "No sessions yet.",
498
- description: "Start one in Po on your computer."
499
- });
796
+ if (workspaces.length === 0) {
797
+ const { addWorkspace, searchDirectories, listDirectory } = actions;
798
+ return addWorkspace && searchDirectories && listDirectory ? /* @__PURE__ */ jsx(NoWorkspaces, { actions: {
799
+ addWorkspace,
800
+ searchDirectories,
801
+ listDirectory
802
+ } }) : /* @__PURE__ */ jsx(View, {
803
+ style: styles.screen,
804
+ children: /* @__PURE__ */ jsx(EmptyState, {
805
+ title: "No sessions yet.",
806
+ description: "Start one in Po on your computer."
807
+ })
808
+ });
809
+ }
500
810
  const sessions = workspaces.flatMap((workspace) => workspace.sessions);
501
811
  return /* @__PURE__ */ jsxs(Fragment, { children: [
502
812
  /* @__PURE__ */ jsx(ScrollView, {
@@ -579,6 +889,22 @@ const styles = StyleSheet.create((theme) => {
579
889
  paddingHorizontal: theme.spacing(1),
580
890
  uni__dependencies: [0]
581
891
  },
892
+ empty: {
893
+ gap: theme.spacing(3),
894
+ paddingHorizontal: theme.spacing(4),
895
+ paddingVertical: theme.spacing(5),
896
+ borderRadius: theme.borderRadius.lg,
897
+ borderWidth: 1,
898
+ borderStyle: "dashed",
899
+ borderColor: theme.colors.border,
900
+ uni__dependencies: [0]
901
+ },
902
+ emptyText: text("sm", theme.colors.dim),
903
+ emptyButton: {
904
+ justifyContent: "flex-start",
905
+ backgroundColor: theme.colors.panel,
906
+ uni__dependencies: [0]
907
+ },
582
908
  card: {
583
909
  gap: theme.spacing(2),
584
910
  padding: theme.spacing(3),
@@ -637,9 +963,16 @@ const styles = StyleSheet.create((theme) => {
637
963
  gap: theme.spacing(1),
638
964
  uni__dependencies: [0]
639
965
  },
966
+ nameRow: {
967
+ flexDirection: "row",
968
+ alignItems: "center",
969
+ gap: theme.spacing(1.5),
970
+ uni__dependencies: [0]
971
+ },
640
972
  name: {
641
973
  ...text("base", theme.colors.hi),
642
974
  fontWeight: theme.fontWeight.semibold,
975
+ flexShrink: 1,
643
976
  uni__dependencies: [0]
644
977
  },
645
978
  statusRow: {
@@ -670,8 +1003,27 @@ const styles = StyleSheet.create((theme) => {
670
1003
  uni__dependencies: [0]
671
1004
  },
672
1005
  modified: text("sm", theme.colors.yellow),
1006
+ groupsRow: {
1007
+ flexDirection: "row",
1008
+ alignItems: "flex-start",
1009
+ gap: theme.spacing(1.5),
1010
+ uni__dependencies: [0]
1011
+ },
1012
+ groups: {
1013
+ flex: 1,
1014
+ flexDirection: "row",
1015
+ flexWrap: "wrap",
1016
+ gap: theme.spacing(1),
1017
+ uni__dependencies: [0]
1018
+ },
673
1019
  setup: {
674
- gap: theme.spacing(.5),
1020
+ gap: theme.spacing(1),
1021
+ marginLeft: theme.spacing(4),
1022
+ padding: theme.spacing(3),
1023
+ borderRadius: theme.borderRadius.md,
1024
+ borderWidth: 1,
1025
+ borderColor: theme.colors["border-soft"],
1026
+ backgroundColor: theme.colors.panel,
675
1027
  uni__dependencies: [0]
676
1028
  },
677
1029
  setupStatus: (failed) => text("sm", failed ? theme.colors.red : theme.colors.dim),