@adroit-app/session-start 0.0.0 → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alisue <lambdalisue@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,152 @@
1
- # @adroit-app/session-start
1
+ # adroit-chat
2
2
 
3
- Reserved for [adroit-chat](https://github.com/adroit-app/adroit-chat). The first release is on its way.
3
+ [![crates.io](https://img.shields.io/crates/v/adroit-chat.svg?label=adroit-chat)](https://crates.io/crates/adroit-chat)
4
+ [![npm](https://img.shields.io/npm/v/@adroit-app/chat-core.svg?label=chat-core)](https://www.npmjs.com/package/@adroit-app/chat-core)
5
+ [![npm](https://img.shields.io/npm/v/@adroit-app/chat-ui.svg?label=chat-ui)](https://www.npmjs.com/package/@adroit-app/chat-ui)
6
+ [![npm](https://img.shields.io/npm/v/@adroit-app/chat-tauri.svg?label=chat-tauri)](https://www.npmjs.com/package/@adroit-app/chat-tauri)
7
+ [![npm](https://img.shields.io/npm/v/@adroit-app/session-start.svg?label=session-start)](https://www.npmjs.com/package/@adroit-app/session-start)
8
+
9
+ A chat window for any coding agent that speaks the
10
+ [Agent Client Protocol](https://agentclientprotocol.com).
11
+
12
+ ```ts
13
+ import "@adroit-app/chat-ui";
14
+ import { fromV1 } from "@adroit-app/chat-core";
15
+
16
+ const chat = document.createElement("adroit-chat");
17
+ chat.theme = "dark";
18
+ chat.cwd = "/path/to/project";
19
+ chat.connection = fromV1(session); // or an ACP v2 ChatConnection as it is
20
+ document.body.append(chat);
21
+ ```
22
+
23
+ `<adroit-chat>` shows one ACP session: the transcript of what the agent said
24
+ and did, the asks it waits on, the plan, the prompts it holds, and a composer
25
+ to prompt it. Its only input is a connection to the session. What it takes
26
+ and promises is in [docs/spec/adroit-chat.md](docs/spec/adroit-chat.md).
27
+
28
+ The repository is <https://github.com/adroit-app/adroit-chat>.
29
+
30
+ ## The window
31
+
32
+ ```sh
33
+ adroit-chat claude [--model <model>] [--resume <session>]
34
+ adroit-chat codex [--model <model>] [--resume <thread>]
35
+ adroit-chat --acp -- <agent that speaks ACP>…
36
+ ```
37
+
38
+ Adroit Chat, started as `adroit-chat`, opens a window with the Chat on one agent's session, in the
39
+ current folder (or `--cwd <dir>`). `claude` runs your own Claude Code and
40
+ `codex` your own Codex, installed and signed in, through
41
+ [acp-adapter](https://github.com/adroit-app/acp-adapter) inside the program;
42
+ `--acp` runs any agent that speaks ACP. Started with no agent, as from Finder,
43
+ it opens a start form to choose the agent and the folder; File › New Window
44
+ opens another window, each with its own session. The composer's keys can be set in a
45
+ settings file; where it lives and what it holds is in
46
+ [docs/spec/app.md](docs/spec/app.md). Settings… opens a Preferences window over that
47
+ file.
48
+
49
+ ## Install
50
+
51
+ The window, on macOS (Apple silicon), with its `adroit-chat` command:
52
+
53
+ ```sh
54
+ brew install --cask adroit-app/tap/adroit-chat
55
+ ```
56
+
57
+ Each [release](https://github.com/adroit-app/adroit-chat/releases) carries
58
+ the window's bundles, with a `.sha256` for each: the disk image for macOS
59
+ (Apple silicon), the `.deb` and `.AppImage` for Linux (x86_64, aarch64), and
60
+ the installer for Windows (x86_64). The app is signed by a self-signed
61
+ certificate and not notarized; the cask lifts the quarantine Gatekeeper
62
+ would refuse it under. It can also be built from this repository (see
63
+ Development), with `just build` for the bundled app or
64
+ `just run -- claude` to run it from source.
65
+
66
+ What a host embeds the Chat with is published at each release:
67
+
68
+ | Package | What it is | Published to |
69
+ | --- | --- | --- |
70
+ | `@adroit-app/chat-core` | the view model of a session, its controller, and the ACP v1 adapter | [![npm](https://img.shields.io/npm/v/@adroit-app/chat-core.svg?label=chat-core)](https://www.npmjs.com/package/@adroit-app/chat-core) |
71
+ | `@adroit-app/chat-ui` | the `<adroit-chat>` element | [![npm](https://img.shields.io/npm/v/@adroit-app/chat-ui.svg?label=chat-ui)](https://www.npmjs.com/package/@adroit-app/chat-ui) |
72
+ | `@adroit-app/chat-tauri` | the Chat's connection to the `adroit-chat` Tauri plugin | [![npm](https://img.shields.io/npm/v/@adroit-app/chat-tauri.svg?label=chat-tauri)](https://www.npmjs.com/package/@adroit-app/chat-tauri) |
73
+ | `@adroit-app/session-start` | the `<adroit-session-start>` form a session starts from | [![npm](https://img.shields.io/npm/v/@adroit-app/session-start.svg?label=session-start)](https://www.npmjs.com/package/@adroit-app/session-start) |
74
+ | `adroit-chat` | the library and Tauri plugin another Tauri app embeds the Chat with, its page built in | [![crates.io](https://img.shields.io/crates/v/adroit-chat.svg?label=adroit-chat)](https://crates.io/crates/adroit-chat) |
75
+ | `@adroit-app/fake-agent` | a scripted agent for the design and the tests | no |
76
+ | `@adroit-app/preferences` | the window's Preferences page | no |
77
+ | `adroit-chat-app` | the window | the release's assets, and the Homebrew cask |
78
+
79
+ The npm packages are JavaScript with declarations, and keep the Vite asset
80
+ imports of their sources (`?raw`, `?url`, `?inline`), as
81
+ [arto-markdown](https://github.com/arto-app/arto-markdown)
82
+ (`@arto-app/markdown`), which renders the Chat's Markdown, does: a host
83
+ builds them with Vite.
84
+
85
+ Inside this repository the packages are Bun workspaces whose exports name
86
+ their TypeScript sources, and the crates are a Cargo workspace.
87
+
88
+ ## Usage
89
+
90
+ The Storybook of main is published at
91
+ <https://adroit-app.github.io/adroit-chat/>.
92
+
93
+ `just storybook` opens Storybook with every scenario the fake agent plays,
94
+ at its end or live, in light and dark; its toolbar switches the theme and
95
+ its controls set the rendering policy. It serves on a local port.
96
+
97
+ `just shots` builds Storybook and takes a screenshot of every story in both
98
+ themes into `dist/shots/`, from the build opened from disk, without a port.
99
+
100
+ ## Development
101
+
102
+ Enter the development shell with `nix develop` (or
103
+ copy `.envrc.sample` to `.envrc` and `direnv allow`), which carries Bun,
104
+ Node, Rust and, on Linux, the libraries Tauri builds against, and:
105
+
106
+ ```sh
107
+ just install # the dependencies bun.lock pins
108
+ just fmt # format every source
109
+ just check # format check, lint, types, unit tests (TS and Rust), Storybook build,
110
+ # the packages as a release publishes them, the version stamp, the workflows
111
+ just ci # all of the above, and every story played in Chromium
112
+ just ci-vm # the web half of `just ci` and the screenshot comparison, in a vitro VM
113
+ just ui # build the Chat's page the adroit-chat crate embeds
114
+ just package # the npm packages staged into dist/npm, and the crate's package, checked
115
+ just build # the bundled app, into target/release/bundle
116
+ just bundle # what a release attaches for this platform, into dist/ (after `just ui`)
117
+ just run -- claude # the app from source
118
+ just run -- codex # the same with Codex
119
+ ```
120
+
121
+ The stories run in Chromium through a local port, so on a workstation they
122
+ run in a throwaway vitro VM (`just ci-vm`). The screenshots they are
123
+ compared with are taken there, in vitro's `linux` image, and only compare in
124
+ that image.
125
+
126
+ ### Releasing
127
+
128
+ Write the notes and publish a GitHub release with a new tag `vX.Y.Z` on
129
+ main. The release workflow stamps that version over the manifests' `0.0.0`,
130
+ then publishes the `adroit-chat` crate, with the Chat's page built in, to
131
+ crates.io, and the npm packages to npm, their `workspace:` dependencies
132
+ pinned to the same version. Both go through trusted publishing; no token is
133
+ stored. It also bundles the window for each platform, outside Nix, signs the
134
+ macOS app by the identity "lambdalisue Release" (from the organization's
135
+ secrets `MACOS_SIGNING_P12` and `MACOS_SIGNING_PASSWORD`), attaches the
136
+ bundles and their checksums to the release, and dispatches to
137
+ [adroit-app/homebrew-tap](https://github.com/adroit-app/homebrew-tap), which
138
+ moves `Casks/adroit-chat.rb` to the disk image. CI bundles the same way on
139
+ every pull request, signed ad hoc. Nothing is committed for a release: the
140
+ tag is the only record of the version.
141
+
142
+ Dependabot keeps the crates, the Bun packages and the actions current,
143
+ except `agent-client-protocol` and `playwright`, which move by hand; a weekly
144
+ workflow does the same for `flake.lock`.
145
+
146
+ The design lives in [docs/concept.md](docs/concept.md), the decisions behind it
147
+ in [docs/adr/](docs/adr/), and the behaviour it promises in
148
+ [docs/spec/](docs/spec/).
149
+
150
+ ## License
151
+
152
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,2 @@
1
+ export * from "./model.ts";
2
+ export * from "./session-start.ts";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./model.js";
2
+ export * from "./session-start.js";
@@ -0,0 +1,56 @@
1
+ /** An agent the host can start, as the start form offers it. */
2
+ export interface StartAgent {
3
+ id: string;
4
+ label: string;
5
+ description?: string;
6
+ /** What the agent calls a session to continue, when it can continue one. */
7
+ resume?: string;
8
+ /** The agent is a command the user writes. */
9
+ command?: boolean;
10
+ }
11
+ /** What the form holds, as the user left it. */
12
+ export interface StartFields {
13
+ agent: string | null;
14
+ cwd: string;
15
+ resume: string;
16
+ command: string;
17
+ }
18
+ /** What the user chose: the `start` event's detail. */
19
+ export interface StartChoice {
20
+ agent: string;
21
+ cwd: string;
22
+ /** A session to continue; none starts a new one. */
23
+ resume: string | null;
24
+ /** The command of an agent that is one. */
25
+ command: string | null;
26
+ }
27
+ /** The choice `fields` make among `agents`, or what is missing for one. */
28
+ export declare function startChoice(agents: readonly StartAgent[], fields: StartFields): {
29
+ choice: StartChoice;
30
+ problem: null;
31
+ } | {
32
+ choice: null;
33
+ problem: string;
34
+ };
35
+ /** A session the chosen agent has in the chosen folder, offered to continue. */
36
+ export interface SessionChoice {
37
+ id: string;
38
+ title?: string | null;
39
+ /** When it last changed, in RFC 3339. */
40
+ updatedAt?: string | null;
41
+ }
42
+ /**
43
+ * The sessions to offer for what is typed in the session field: those whose
44
+ * title or id holds it, most recent first. Once the field holds the id of
45
+ * the one session it matches, there is nothing left to offer.
46
+ */
47
+ export declare function sessionSuggestions(sessions: readonly SessionChoice[], typed: string): SessionChoice[];
48
+ /** How long before `now` (milliseconds since the epoch) `time` was, in words; nothing for no time. */
49
+ export declare function ago(time: string | null | undefined, now: number): string;
50
+ /** An id short enough to tell sessions apart at a glance. */
51
+ export declare function shortId(id: string): string;
52
+ /**
53
+ * The suggestion `step` (1 down, -1 up) moves to from `current` among
54
+ * `length`, round at either end; -1 for none.
55
+ */
56
+ export declare function nextSuggestion(current: number, step: 1 | -1, length: number): number;
package/dist/model.js ADDED
@@ -0,0 +1,79 @@
1
+ /** The choice `fields` make among `agents`, or what is missing for one. */
2
+ export function startChoice(agents, fields) {
3
+ const agent = agents.find((a) => a.id === fields.agent);
4
+ if (!agent)
5
+ return { choice: null, problem: "Choose an agent" };
6
+ const cwd = fields.cwd.trim();
7
+ if (!cwd)
8
+ return { choice: null, problem: "Choose the folder the agent works in" };
9
+ const command = agent.command ? fields.command.trim() : "";
10
+ if (agent.command && !command) {
11
+ return { choice: null, problem: "Write the command that starts the agent" };
12
+ }
13
+ const resume = agent.resume ? fields.resume.trim() : "";
14
+ return {
15
+ choice: { agent: agent.id, cwd, resume: resume || null, command: command || null },
16
+ problem: null,
17
+ };
18
+ }
19
+ /**
20
+ * The sessions to offer for what is typed in the session field: those whose
21
+ * title or id holds it, most recent first. Once the field holds the id of
22
+ * the one session it matches, there is nothing left to offer.
23
+ */
24
+ export function sessionSuggestions(sessions, typed) {
25
+ const wanted = typed.trim().toLowerCase();
26
+ const matching = sessions.filter((s) => s.id.toLowerCase().includes(wanted) || (s.title ?? "").toLowerCase().includes(wanted));
27
+ if (matching.length === 1 && matching[0]?.id === typed.trim())
28
+ return [];
29
+ return matching
30
+ .map((session) => {
31
+ const at = Date.parse(session.updatedAt ?? "");
32
+ return { session, at: Number.isNaN(at) ? -Infinity : at };
33
+ })
34
+ .sort((a, b) => (a.at === b.at ? 0 : b.at > a.at ? 1 : -1))
35
+ .map(({ session }) => session);
36
+ }
37
+ const MINUTE = 60_000;
38
+ const HOUR = 60 * MINUTE;
39
+ const DAY = 24 * HOUR;
40
+ function count(n, unit) {
41
+ return `${n} ${unit}${n === 1 ? "" : "s"} ago`;
42
+ }
43
+ /** How long before `now` (milliseconds since the epoch) `time` was, in words; nothing for no time. */
44
+ export function ago(time, now) {
45
+ const at = Date.parse(time ?? "");
46
+ if (Number.isNaN(at))
47
+ return "";
48
+ const past = now - at;
49
+ if (past < MINUTE)
50
+ return "just now";
51
+ if (past < HOUR)
52
+ return count(Math.floor(past / MINUTE), "minute");
53
+ if (past < DAY)
54
+ return count(Math.floor(past / HOUR), "hour");
55
+ if (past < 2 * DAY)
56
+ return "yesterday";
57
+ if (past < 14 * DAY)
58
+ return count(Math.floor(past / DAY), "day");
59
+ if (past < 60 * DAY)
60
+ return count(Math.floor(past / (7 * DAY)), "week");
61
+ if (past < 365 * DAY)
62
+ return count(Math.floor(past / (30 * DAY)), "month");
63
+ return count(Math.floor(past / (365 * DAY)), "year");
64
+ }
65
+ /** An id short enough to tell sessions apart at a glance. */
66
+ export function shortId(id) {
67
+ return id.slice(0, 8);
68
+ }
69
+ /**
70
+ * The suggestion `step` (1 down, -1 up) moves to from `current` among
71
+ * `length`, round at either end; -1 for none.
72
+ */
73
+ export function nextSuggestion(current, step, length) {
74
+ if (length === 0)
75
+ return -1;
76
+ if (current < 0)
77
+ return step === 1 ? 0 : length - 1;
78
+ return (current + step + length) % length;
79
+ }
@@ -0,0 +1,84 @@
1
+ import { LitElement, type TemplateResult } from "lit";
2
+ import { type SessionChoice, type StartAgent, type StartFields } from "./model.ts";
3
+ /**
4
+ * The form a session starts from: which agent, in which folder, continuing
5
+ * which session. It starts nothing itself: Start is a `start` event carrying
6
+ * the choice, for the host to start the session and say why when it cannot.
7
+ */
8
+ export declare class AdroitSessionStart extends LitElement {
9
+ #private;
10
+ static properties: {
11
+ agents: {
12
+ attribute: boolean;
13
+ };
14
+ defaults: {
15
+ attribute: boolean;
16
+ };
17
+ pickFolder: {
18
+ attribute: boolean;
19
+ };
20
+ listSessions: {
21
+ attribute: boolean;
22
+ };
23
+ problem: {};
24
+ starting: {
25
+ type: BooleanConstructor;
26
+ };
27
+ theme: {
28
+ reflect: boolean;
29
+ };
30
+ _fields: {
31
+ state: boolean;
32
+ };
33
+ _shown: {
34
+ state: boolean;
35
+ };
36
+ _sessions: {
37
+ state: boolean;
38
+ };
39
+ _open: {
40
+ state: boolean;
41
+ };
42
+ _active: {
43
+ state: boolean;
44
+ };
45
+ };
46
+ /** The agents the host can start, in the order offered. */
47
+ agents: StartAgent[];
48
+ /** What the form starts with. */
49
+ defaults: Partial<StartFields> | null;
50
+ /** The system's folder chooser, from the folder written; without one the folder is written. */
51
+ pickFolder: ((from: string) => Promise<string | null>) | null;
52
+ /**
53
+ * The sessions `agent` has in `cwd`, offered as the session to continue;
54
+ * without one the session is written.
55
+ */
56
+ listSessions: ((agent: string, cwd: string, command: string | null) => Promise<SessionChoice[]>) | null;
57
+ /** Why the session the host was asked for did not start. */
58
+ problem: string | null;
59
+ /** The host is starting the session. */
60
+ starting: boolean;
61
+ theme: "light" | "dark" | undefined;
62
+ _fields: StartFields;
63
+ /** What is missing, once Start was pressed without it. */
64
+ _shown: string | null;
65
+ /** The sessions the agent has in the folder, as last listed. */
66
+ _sessions: SessionChoice[];
67
+ /** The suggestions under the session field are shown. */
68
+ _open: boolean;
69
+ /** The suggestion the keyboard is on; -1 for none. */
70
+ _active: number;
71
+ constructor();
72
+ protected willUpdate(changed: Map<string, unknown>): void;
73
+ protected updated(changed: Map<string, unknown>): void;
74
+ disconnectedCallback(): void;
75
+ /** Starts the session the form is filled in for, or says what is missing. */
76
+ submit(): void;
77
+ protected render(): TemplateResult;
78
+ static styles: import("lit").CSSResult[];
79
+ }
80
+ declare global {
81
+ interface HTMLElementTagNameMap {
82
+ "adroit-session-start": AdroitSessionStart;
83
+ }
84
+ }
@@ -0,0 +1,441 @@
1
+ import { chatTokens } from "@adroit-app/chat-ui";
2
+ import { css, html, LitElement, nothing } from "lit";
3
+ import { ago, nextSuggestion, sessionSuggestions, shortId, startChoice, } from "./model.js";
4
+ /** How long the folder or command rests before the sessions there are asked for. */
5
+ const SETTLE_MS = 250;
6
+ /**
7
+ * The form a session starts from: which agent, in which folder, continuing
8
+ * which session. It starts nothing itself: Start is a `start` event carrying
9
+ * the choice, for the host to start the session and say why when it cannot.
10
+ */
11
+ export class AdroitSessionStart extends LitElement {
12
+ static properties = {
13
+ agents: { attribute: false },
14
+ defaults: { attribute: false },
15
+ pickFolder: { attribute: false },
16
+ listSessions: { attribute: false },
17
+ problem: {},
18
+ starting: { type: Boolean },
19
+ theme: { reflect: true },
20
+ _fields: { state: true },
21
+ _shown: { state: true },
22
+ _sessions: { state: true },
23
+ _open: { state: true },
24
+ _active: { state: true },
25
+ };
26
+ /** What the sessions were last asked for, so a change asks again. */
27
+ #asked = null;
28
+ /** Counts the askings, so an answer to an earlier one is dropped. */
29
+ #asking = 0;
30
+ #settle;
31
+ constructor() {
32
+ super();
33
+ this.agents = [];
34
+ this.defaults = null;
35
+ this.pickFolder = null;
36
+ this.listSessions = null;
37
+ this._sessions = [];
38
+ this._open = false;
39
+ this._active = -1;
40
+ this.problem = null;
41
+ this.starting = false;
42
+ this.theme = undefined;
43
+ this._fields = { agent: null, cwd: "", resume: "", command: "" };
44
+ this._shown = null;
45
+ }
46
+ willUpdate(changed) {
47
+ if (changed.has("defaults") || changed.has("agents")) {
48
+ const d = this.defaults ?? {};
49
+ this._fields = {
50
+ agent: d.agent ?? this._fields.agent ?? this.agents[0]?.id ?? null,
51
+ cwd: d.cwd ?? this._fields.cwd,
52
+ resume: d.resume ?? this._fields.resume,
53
+ command: d.command ?? this._fields.command,
54
+ };
55
+ }
56
+ if (changed.has("listSessions"))
57
+ this.#asked = null;
58
+ this.#askForSessions();
59
+ }
60
+ updated(changed) {
61
+ if (changed.has("_active") && this._active >= 0) {
62
+ this.renderRoot
63
+ .querySelector(`#session-${this._active}`)
64
+ ?.scrollIntoView({ block: "nearest" });
65
+ }
66
+ }
67
+ disconnectedCallback() {
68
+ super.disconnectedCallback();
69
+ clearTimeout(this.#settle);
70
+ }
71
+ /**
72
+ * Asks for the sessions of the agent and folder chosen, once they rest,
73
+ * when the session field is shown and they changed since last asked. The
74
+ * sessions of what was chosen before are dropped at once.
75
+ */
76
+ #askForSessions() {
77
+ const agent = this.agents.find((a) => a.id === this._fields.agent);
78
+ const cwd = this._fields.cwd.trim();
79
+ const command = agent?.command ? this._fields.command.trim() || null : null;
80
+ const list = this.listSessions;
81
+ const wanted = list && agent?.resume && cwd ? JSON.stringify([agent.id, cwd, command]) : null;
82
+ if (wanted === this.#asked)
83
+ return;
84
+ this.#asked = wanted;
85
+ this.#asking += 1;
86
+ clearTimeout(this.#settle);
87
+ this._sessions = [];
88
+ this._active = -1;
89
+ if (!list || !agent || wanted === null)
90
+ return;
91
+ const asking = this.#asking;
92
+ this.#settle = setTimeout(() => {
93
+ list(agent.id, cwd, command).then((sessions) => {
94
+ if (asking === this.#asking)
95
+ this._sessions = sessions;
96
+ }, () => {
97
+ if (asking === this.#asking)
98
+ this._sessions = [];
99
+ });
100
+ }, SETTLE_MS);
101
+ }
102
+ #pick(session) {
103
+ this.#set({ resume: session.id });
104
+ this._open = false;
105
+ this._active = -1;
106
+ }
107
+ #keydown(e, shown) {
108
+ const active = this._open ? shown[this._active] : undefined;
109
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
110
+ if (shown.length === 0)
111
+ return;
112
+ e.preventDefault();
113
+ const step = e.key === "ArrowDown" ? 1 : -1;
114
+ this._active = nextSuggestion(this._open ? this._active : -1, step, shown.length);
115
+ this._open = true;
116
+ }
117
+ else if (e.key === "Enter" && active) {
118
+ // Enter picks the suggestion rather than sending the form.
119
+ e.preventDefault();
120
+ this.#pick(active);
121
+ }
122
+ else if (e.key === "Escape" && this._open && shown.length > 0) {
123
+ e.preventDefault();
124
+ e.stopPropagation();
125
+ this._open = false;
126
+ this._active = -1;
127
+ }
128
+ }
129
+ #resumeField(label) {
130
+ const shown = this.listSessions ? sessionSuggestions(this._sessions, this._fields.resume) : [];
131
+ const open = this._open && shown.length > 0;
132
+ const now = Date.now();
133
+ return html `<div class="field">
134
+ <label for="resume">${label}</label>
135
+ <div class="combo">
136
+ <input
137
+ id="resume"
138
+ name="resume"
139
+ placeholder="Leave empty to start a new one"
140
+ spellcheck="false"
141
+ autocomplete="off"
142
+ role=${this.listSessions ? "combobox" : nothing}
143
+ aria-autocomplete=${this.listSessions ? "list" : nothing}
144
+ aria-expanded=${this.listSessions ? (open ? "true" : "false") : nothing}
145
+ aria-controls=${open ? "sessions" : nothing}
146
+ aria-activedescendant=${open && this._active >= 0 ? `session-${this._active}` : nothing}
147
+ .value=${this._fields.resume}
148
+ @input=${(e) => {
149
+ this.#set({ resume: e.target.value });
150
+ this._open = true;
151
+ this._active = -1;
152
+ }}
153
+ @focus=${() => {
154
+ this._open = true;
155
+ }}
156
+ @blur=${() => {
157
+ this._open = false;
158
+ this._active = -1;
159
+ }}
160
+ @keydown=${(e) => this.#keydown(e, shown)}
161
+ />
162
+ ${open
163
+ ? html `<ul id="sessions" class="sessions" role="listbox" aria-label=${label}>
164
+ ${shown.map((s, i) => html `<li
165
+ id="session-${i}"
166
+ role="option"
167
+ class="session ${i === this._active ? "active" : ""}"
168
+ aria-selected=${i === this._active ? "true" : "false"}
169
+ @mousedown=${(e) => e.preventDefault()}
170
+ @click=${() => this.#pick(s)}
171
+ >
172
+ <span class="title ${s.title ? "" : "untitled"}">${s.title || "Untitled"}</span>
173
+ <span class="when">${ago(s.updatedAt, now)}</span>
174
+ <span class="id">${shortId(s.id)}</span>
175
+ </li>`)}
176
+ </ul>`
177
+ : nothing}
178
+ </div>
179
+ </div>`;
180
+ }
181
+ #set(fields) {
182
+ this._fields = { ...this._fields, ...fields };
183
+ this._shown = null;
184
+ }
185
+ /** Starts the session the form is filled in for, or says what is missing. */
186
+ submit() {
187
+ if (this.starting)
188
+ return;
189
+ const { choice, problem } = startChoice(this.agents, this._fields);
190
+ this._shown = problem;
191
+ if (!choice)
192
+ return;
193
+ this.dispatchEvent(new CustomEvent("start", { detail: choice, bubbles: true, composed: true }));
194
+ }
195
+ async #choose() {
196
+ const folder = await this.pickFolder?.(this._fields.cwd);
197
+ if (folder)
198
+ this.#set({ cwd: folder });
199
+ }
200
+ render() {
201
+ const agent = this.agents.find((a) => a.id === this._fields.agent);
202
+ const said = this._shown ?? this.problem;
203
+ return html `<form
204
+ @submit=${(e) => {
205
+ e.preventDefault();
206
+ this.submit();
207
+ }}
208
+ >
209
+ <h1>New session</h1>
210
+ <fieldset class="agents" role="radiogroup" aria-label="Agent">
211
+ ${this.agents.map((a) => html `<button
212
+ type="button"
213
+ role="radio"
214
+ class="agent ${a.id === agent?.id ? "chosen" : ""}"
215
+ aria-checked=${a.id === agent?.id ? "true" : "false"}
216
+ @click=${() => this.#set({ agent: a.id })}
217
+ >
218
+ <span class="name">${a.label}</span>
219
+ ${a.description ? html `<span class="description">${a.description}</span>` : nothing}
220
+ </button>`)}
221
+ </fieldset>
222
+ ${agent?.command
223
+ ? html `<label class="field">
224
+ <span>Command</span>
225
+ <input
226
+ name="command"
227
+ placeholder="gemini --experimental-acp"
228
+ spellcheck="false"
229
+ .value=${this._fields.command}
230
+ @input=${(e) => this.#set({ command: e.target.value })}
231
+ />
232
+ </label>`
233
+ : nothing}
234
+ <label class="field">
235
+ <span>Folder</span>
236
+ <div class="row">
237
+ <input
238
+ name="cwd"
239
+ spellcheck="false"
240
+ .value=${this._fields.cwd}
241
+ @input=${(e) => this.#set({ cwd: e.target.value })}
242
+ />
243
+ ${this.pickFolder
244
+ ? html `<button type="button" class="choose" @click=${() => void this.#choose()}>Choose…</button>`
245
+ : nothing}
246
+ </div>
247
+ </label>
248
+ ${agent?.resume ? this.#resumeField(agent.resume) : nothing}
249
+ <div class="foot">
250
+ ${said ? html `<p class="problem" role="alert">${said}</p>` : html `<span></span>`}
251
+ <button type="submit" class="start" ?disabled=${this.starting}>
252
+ ${this.starting ? "Starting…" : "Start"}
253
+ </button>
254
+ </div>
255
+ </form>`;
256
+ }
257
+ static styles = [
258
+ chatTokens,
259
+ css `
260
+ :host {
261
+ display: grid;
262
+ place-items: center;
263
+ min-height: 100%;
264
+ background: var(--ground);
265
+ color: var(--text);
266
+ font: calc(13 * var(--px)) / 1.5 var(--sans);
267
+ }
268
+ form {
269
+ display: flex;
270
+ flex-direction: column;
271
+ gap: calc(14 * var(--px));
272
+ width: min(calc(520 * var(--px)), calc(100% - 48 * var(--px)));
273
+ padding: calc(24 * var(--px)) 0;
274
+ }
275
+ h1 {
276
+ margin: 0;
277
+ font-size: calc(20 * var(--px));
278
+ font-weight: 600;
279
+ }
280
+ .agents {
281
+ display: grid;
282
+ grid-template-columns: repeat(auto-fit, minmax(calc(150 * var(--px)), 1fr));
283
+ gap: calc(8 * var(--px));
284
+ margin: 0;
285
+ padding: 0;
286
+ border: none;
287
+ }
288
+ .agent {
289
+ display: flex;
290
+ flex-direction: column;
291
+ gap: calc(2 * var(--px));
292
+ padding: calc(10 * var(--px)) calc(12 * var(--px));
293
+ border: 1px solid var(--line-strong);
294
+ border-radius: calc(8 * var(--px));
295
+ background: var(--panel);
296
+ color: var(--text);
297
+ font: inherit;
298
+ text-align: left;
299
+ cursor: pointer;
300
+ }
301
+ .agent:hover {
302
+ background: var(--raised);
303
+ }
304
+ .agent.chosen {
305
+ border-color: var(--run);
306
+ background: var(--run-tint);
307
+ }
308
+ .agent .name {
309
+ font-weight: 600;
310
+ }
311
+ .agent .description {
312
+ color: var(--text-3);
313
+ font-size: calc(12 * var(--px));
314
+ }
315
+ .field {
316
+ display: flex;
317
+ flex-direction: column;
318
+ gap: calc(4 * var(--px));
319
+ }
320
+ .field > span,
321
+ .field > label {
322
+ color: var(--text-2);
323
+ font-size: calc(12 * var(--px));
324
+ }
325
+ .combo {
326
+ position: relative;
327
+ display: flex;
328
+ flex-direction: column;
329
+ }
330
+ .sessions {
331
+ position: absolute;
332
+ top: calc(100% + 4 * var(--px));
333
+ left: 0;
334
+ right: 0;
335
+ z-index: 1;
336
+ max-height: calc(240 * var(--px));
337
+ overflow-y: auto;
338
+ margin: 0;
339
+ padding: calc(4 * var(--px));
340
+ list-style: none;
341
+ border: 1px solid var(--line-strong);
342
+ border-radius: calc(6 * var(--px));
343
+ background: var(--panel);
344
+ box-shadow: 0 calc(6 * var(--px)) calc(18 * var(--px)) rgb(0 0 0 / 0.25);
345
+ }
346
+ .session {
347
+ display: grid;
348
+ grid-template-columns: minmax(0, 1fr) auto auto;
349
+ align-items: baseline;
350
+ gap: calc(10 * var(--px));
351
+ padding: calc(5 * var(--px)) calc(8 * var(--px));
352
+ border-radius: calc(4 * var(--px));
353
+ cursor: pointer;
354
+ }
355
+ .session:hover,
356
+ .session.active {
357
+ background: var(--run-tint);
358
+ }
359
+ .session .title {
360
+ overflow: hidden;
361
+ text-overflow: ellipsis;
362
+ white-space: nowrap;
363
+ }
364
+ .session .title.untitled {
365
+ color: var(--text-3);
366
+ font-style: italic;
367
+ }
368
+ .session .when {
369
+ color: var(--text-3);
370
+ font-size: calc(12 * var(--px));
371
+ }
372
+ .session .id {
373
+ color: var(--text-4);
374
+ font: calc(11.5 * var(--px)) var(--mono);
375
+ }
376
+ .row {
377
+ display: flex;
378
+ gap: calc(6 * var(--px));
379
+ }
380
+ .row input {
381
+ flex: 1;
382
+ }
383
+ input {
384
+ min-width: 0;
385
+ height: calc(30 * var(--px));
386
+ padding: 0 calc(8 * var(--px));
387
+ border: 1px solid var(--line-strong);
388
+ border-radius: calc(6 * var(--px));
389
+ background: var(--panel);
390
+ color: var(--text);
391
+ font: calc(12.5 * var(--px)) var(--mono);
392
+ }
393
+ input::placeholder {
394
+ color: var(--text-4);
395
+ font-family: var(--sans);
396
+ }
397
+ button:focus-visible,
398
+ input:focus-visible {
399
+ outline: 2px solid var(--run);
400
+ outline-offset: 1px;
401
+ }
402
+ .choose {
403
+ padding: 0 calc(12 * var(--px));
404
+ border: 1px solid var(--line-strong);
405
+ border-radius: calc(6 * var(--px));
406
+ background: var(--raised);
407
+ color: var(--text);
408
+ font: inherit;
409
+ cursor: pointer;
410
+ }
411
+ .foot {
412
+ display: flex;
413
+ align-items: center;
414
+ justify-content: space-between;
415
+ gap: calc(12 * var(--px));
416
+ margin-top: calc(4 * var(--px));
417
+ }
418
+ .problem {
419
+ margin: 0;
420
+ color: var(--fail);
421
+ }
422
+ .start {
423
+ padding: calc(6 * var(--px)) calc(20 * var(--px));
424
+ border: none;
425
+ border-radius: calc(6 * var(--px));
426
+ background: var(--run);
427
+ color: white;
428
+ font: inherit;
429
+ font-weight: 600;
430
+ cursor: pointer;
431
+ }
432
+ .start:disabled {
433
+ opacity: 0.6;
434
+ cursor: default;
435
+ }
436
+ `,
437
+ ];
438
+ }
439
+ if (!customElements.get("adroit-session-start")) {
440
+ customElements.define("adroit-session-start", AdroitSessionStart);
441
+ }
package/package.json CHANGED
@@ -1,12 +1,28 @@
1
1
  {
2
2
  "name": "@adroit-app/session-start",
3
- "version": "0.0.0",
4
- "description": "Reserved for adroit-chat's @adroit-app/session-start; the first release is on its way.",
3
+ "version": "0.1.0",
4
+ "description": "<adroit-session-start>, the form a session starts from: the agent, the folder and a session to continue",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/adroit-app/adroit-chat.git",
9
9
  "directory": "packages/session-start"
10
10
  },
11
- "files": ["README.md"]
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "dependencies": {
25
+ "@adroit-app/chat-ui": "0.1.0",
26
+ "lit": "^3.3.3"
27
+ }
12
28
  }