@ywldan/kiro 0.3.0 → 0.3.2

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.
@@ -0,0 +1,112 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Box, Text, useInput } from 'ink';
4
+ import { pickerPopupRows, pickerRangeLabel, pickerWindow } from './model-picker.js';
5
+ import { buildSessionRows, sessionCounts, sessionEmptyText, sessionRange, sessionRowItems, sessionRowLines, sessionRowText, sessionTabLabel, } from './session-picker.js';
6
+ /** Keys are highlighted so the hint reads at a glance; the rest stays dim. */
7
+ const KEY_COLOR = '#ff9e64';
8
+ function Key({ children }) {
9
+ return _jsx(Text, { color: KEY_COLOR, children: children });
10
+ }
11
+ function Said({ children }) {
12
+ return _jsx(Text, { dimColor: true, children: children });
13
+ }
14
+ /**
15
+ * Session picker with two tabs: the current directory and every other
16
+ * directory that has saved sessions. Left/right switch tabs.
17
+ */
18
+ export function SessionPicker({ cwd, data, activeSessionId = null, width, maxRows = 8, height, onSelect, onCancel, }) {
19
+ const [scope, setScope] = useState('current');
20
+ const [index, setIndex] = useState(0);
21
+ const [query, setQuery] = useState('');
22
+ const counts = sessionCounts(data);
23
+ const rows = buildSessionRows(data, scope, cwd, query);
24
+ const lines = sessionRowLines(rows);
25
+ const sessions = sessionRowItems(rows);
26
+ const count = sessions.length;
27
+ const selected = Math.min(index, Math.max(0, count - 1));
28
+ const selectedLine = lines[selected] ?? 0;
29
+ const popup = height !== undefined;
30
+ const hintRows = scope === 'others' ? 1 : 0;
31
+ // The tab bar takes one row the model picker does not have.
32
+ const listRows = popup ? pickerPopupRows(height, hintRows + 1) : maxRows;
33
+ const { start, end } = pickerWindow(selectedLine, rows.length, listRows);
34
+ const range = popup ? sessionRange(rows, start, end) : null;
35
+ const empty = sessionEmptyText(scope, query, count > 0);
36
+ // The opaque frame needs an explicit foreground even on light terminal themes.
37
+ const base = popup ? 'white' : undefined;
38
+ const switchScope = (next) => {
39
+ if (next === scope)
40
+ return;
41
+ setScope(next);
42
+ setIndex(0);
43
+ setQuery('');
44
+ };
45
+ useInput((input, key) => {
46
+ if (key.leftArrow) {
47
+ switchScope('current');
48
+ return;
49
+ }
50
+ if (key.rightArrow) {
51
+ switchScope('others');
52
+ return;
53
+ }
54
+ if (key.tab) {
55
+ switchScope(scope === 'current' ? 'others' : 'current');
56
+ return;
57
+ }
58
+ if (key.escape) {
59
+ if (query) {
60
+ setQuery('');
61
+ setIndex(0);
62
+ return;
63
+ }
64
+ onCancel();
65
+ return;
66
+ }
67
+ if (key.upArrow || key.downArrow) {
68
+ if (count === 0)
69
+ return;
70
+ const delta = key.upArrow ? -1 : 1;
71
+ setIndex(Math.min(count - 1, Math.max(0, selected + delta)));
72
+ return;
73
+ }
74
+ if (key.home) {
75
+ setIndex(0);
76
+ return;
77
+ }
78
+ if (key.end) {
79
+ setIndex(Math.max(0, count - 1));
80
+ return;
81
+ }
82
+ if (!key.return) {
83
+ if (key.backspace || key.delete) {
84
+ if (query) {
85
+ setQuery(query.slice(0, -1));
86
+ setIndex(0);
87
+ }
88
+ return;
89
+ }
90
+ if (key.ctrl || key.meta || key.pageUp || key.pageDown)
91
+ return;
92
+ const typed = input.replace(/[\u0000-\u001f\u007f]/g, '');
93
+ if (typed) {
94
+ setQuery(query + typed);
95
+ setIndex(0);
96
+ }
97
+ return;
98
+ }
99
+ const session = sessions[selected];
100
+ if (session)
101
+ onSelect(session);
102
+ });
103
+ return (_jsxs(Box, { flexDirection: "column", width: width, height: height, borderStyle: "round", borderColor: "cyan", paddingX: 1, flexShrink: 0, backgroundColor: popup ? 'black' : undefined, overflow: height === undefined ? undefined : 'hidden', children: [_jsx(Text, { bold: true, color: "cyan", wrap: "truncate-end", children: "Sessions" }), _jsxs(Text, { color: base, wrap: "truncate-end", children: [_jsx(Text, { inverse: scope === 'current', color: scope === 'current' ? 'cyan' : base, children: ` ${sessionTabLabel('current', counts)} ` }), _jsx(Said, { children: " " }), _jsx(Text, { inverse: scope === 'others', color: scope === 'others' ? 'cyan' : base, children: ` ${sessionTabLabel('others', counts)} ` })] }), _jsxs(Text, { color: base, wrap: "truncate-end", children: [_jsx(Said, { children: "Search: " }), query || _jsx(Said, { children: "type to filter" })] }), rows.slice(start, end).map((row, offset) => {
104
+ const line = start + offset;
105
+ if (row.kind === 'header') {
106
+ return (_jsx(Text, { dimColor: true, color: base, wrap: "truncate-end", children: row.text }, `h${line}`));
107
+ }
108
+ const focused = line === selectedLine;
109
+ return (_jsx(Text, { color: focused ? 'cyan' : base, bold: focused, wrap: "truncate-end", children: sessionRowText(row.session, row.session.id === activeSessionId) }, `s${line}`));
110
+ }), empty ? (_jsx(Text, { dimColor: true, color: base, wrap: "truncate-end", children: empty })) : null, scope === 'others' ? (_jsx(Text, { dimColor: true, color: base, wrap: "truncate-end", children: "Enter resumes and switches to that directory." })) : null, range ? (_jsx(Text, { dimColor: true, color: base, wrap: "truncate-end", children: pickerRangeLabel(range) })) : null, height === undefined ? null : _jsx(Box, { flexGrow: 1 }), _jsxs(Text, { color: base, wrap: "truncate-end", children: [_jsx(Key, { children: "\u2190/\u2192" }), _jsx(Said, { children: " tab \u00B7 " }), _jsx(Key, { children: "\u2191/\u2193" }), _jsx(Said, { children: " move \u00B7 " }), _jsx(Key, { children: "Enter" }), _jsx(Said, { children: " resume \u00B7 " }), _jsx(Key, { children: "Esc" }), _jsx(Said, { children: ` ${query ? 'clear search' : 'close'}` })] })] }));
111
+ }
112
+ //# sourceMappingURL=SessionPicker.js.map
@@ -6,8 +6,8 @@ export const SLASH_COMMANDS = [
6
6
  { name: '/context', description: 'show approximate context usage' },
7
7
  { name: '/usage', description: 'show or hide the usage card' },
8
8
  { name: '/compact', description: 'summarize older turns to free context' },
9
- { name: '/sessions', description: 'list saved sessions for this directory' },
10
- { name: '/resume', usage: '<n | id>', description: 'resume a saved session' },
9
+ { name: '/sessions', description: 'list saved sessions, this directory and others' },
10
+ { name: '/resume', usage: '[n | id]', description: 'open the session picker, or resume by number or id' },
11
11
  { name: '/undo', description: 'revert the last file change Kiro made (write/edit/patch)' },
12
12
  { name: '/clear', description: 'start a new session' },
13
13
  { name: '/export', usage: '[file]', description: 'write the transcript to a Markdown file' },
@@ -0,0 +1,96 @@
1
+ import { homedir } from 'node:os';
2
+ import path from 'node:path';
3
+ import { formatSessionTime } from '../sessions.js';
4
+ /** Rows the inline session picker reserves below the transcript. */
5
+ export const SESSION_INLINE_ROWS = 13;
6
+ export function sessionCounts(data) {
7
+ return {
8
+ current: data.current.length,
9
+ others: data.others.reduce((total, group) => total + group.sessions.length, 0),
10
+ };
11
+ }
12
+ export function sessionTabLabel(scope, counts) {
13
+ return scope === 'current'
14
+ ? `This directory (${counts.current})`
15
+ : `Other directories (${counts.others})`;
16
+ }
17
+ /** Home-relative path so other directories read short in the picker. */
18
+ export function shortCwd(cwd, currentCwd) {
19
+ const resolved = path.resolve(cwd);
20
+ if (resolved === path.resolve(currentCwd))
21
+ return '.';
22
+ const home = homedir();
23
+ if (resolved === home)
24
+ return '~';
25
+ if (resolved.startsWith(`${home}${path.sep}`))
26
+ return `~${resolved.slice(home.length)}`;
27
+ return resolved;
28
+ }
29
+ /** Case-insensitive multi-term search across title, id, and directory. */
30
+ export function filterSessions(sessions, query) {
31
+ const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
32
+ if (terms.length === 0)
33
+ return sessions;
34
+ return sessions.filter((session) => {
35
+ const haystack = `${session.title} ${session.id} ${session.cwd} ${session.profile} ${session.model}`.toLowerCase();
36
+ return terms.every((term) => haystack.includes(term));
37
+ });
38
+ }
39
+ export function sessionRowText(session, active) {
40
+ const marker = active ? '*' : ' ';
41
+ const count = `${session.messageCount} msg${session.messageCount === 1 ? '' : 's'}`;
42
+ return `${marker} ${session.id.slice(0, 8)} ${formatSessionTime(session.updatedAt)} ${count} ${session.title}`;
43
+ }
44
+ /** Display rows for one tab; other directories get a header per cwd. */
45
+ export function buildSessionRows(data, scope, currentCwd, query = '') {
46
+ if (scope === 'current') {
47
+ return filterSessions(data.current, query).map((session) => ({
48
+ kind: 'session',
49
+ scope,
50
+ session,
51
+ }));
52
+ }
53
+ const rows = [];
54
+ for (const group of data.others) {
55
+ const sessions = filterSessions(group.sessions, query);
56
+ if (sessions.length === 0)
57
+ continue;
58
+ rows.push({
59
+ kind: 'header',
60
+ scope,
61
+ text: `${shortCwd(group.cwd, currentCwd)} (${sessions.length})`,
62
+ });
63
+ for (const session of sessions)
64
+ rows.push({ kind: 'session', scope, session });
65
+ }
66
+ return rows;
67
+ }
68
+ export function sessionRowLines(rows) {
69
+ return rows.flatMap((row, index) => (row.kind === 'session' ? [index] : []));
70
+ }
71
+ export function sessionRowItems(rows) {
72
+ return rows.flatMap((row) => (row.kind === 'session' ? [row.session] : []));
73
+ }
74
+ /** Same as profileRange, counting sessions while skipping directory headers. */
75
+ export function sessionRange(rows, start, end) {
76
+ const lines = sessionRowLines(rows);
77
+ const above = lines.filter((line) => line < start).length;
78
+ const visible = lines.filter((line) => line >= start && line < end).length;
79
+ return {
80
+ above,
81
+ below: lines.length - above - visible,
82
+ first: visible === 0 ? 0 : above + 1,
83
+ last: above + visible,
84
+ total: lines.length,
85
+ };
86
+ }
87
+ export function sessionEmptyText(scope, query, hasSessions) {
88
+ if (query.trim())
89
+ return `No sessions match "${query}". Backspace to edit, Esc to clear.`;
90
+ if (hasSessions)
91
+ return '';
92
+ return scope === 'current'
93
+ ? 'No saved sessions for this directory.'
94
+ : 'No sessions from other directories.';
95
+ }
96
+ //# sourceMappingURL=session-picker.js.map
package/dist/version.js CHANGED
@@ -1,2 +1,5 @@
1
- export const VERSION = '0.3.0';
1
+ import { createRequire } from 'node:module';
2
+ /** Single source of truth: the version npm publishes, read at runtime from package.json. */
3
+ const { version } = createRequire(import.meta.url)('../package.json');
4
+ export const VERSION = version;
2
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,61 +1,61 @@
1
- {
2
- "name": "@ywldan/kiro",
3
- "version": "0.3.0",
4
- "description": "A small terminal coding agent with your own OpenAI-compatible endpoint",
5
- "keywords": [
6
- "ai",
7
- "agent",
8
- "cli",
9
- "coding-agent",
10
- "openai",
11
- "terminal",
12
- "tui"
13
- ],
14
- "license": "MIT",
15
- "author": "ywildan",
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/ywildan/kiro.git"
19
- },
20
- "homepage": "https://github.com/ywildan/kiro#readme",
21
- "bugs": {
22
- "url": "https://github.com/ywildan/kiro/issues"
23
- },
24
- "type": "module",
25
- "bin": {
26
- "kiro": "dist/index.js"
27
- },
28
- "main": "dist/index.js",
29
- "files": [
30
- "dist",
31
- "!dist/**/*.map",
32
- "README.md"
33
- ],
34
- "engines": {
35
- "node": ">=20"
36
- },
37
- "publishConfig": {
38
- "access": "public"
39
- },
40
- "scripts": {
41
- "build": "tsc -p tsconfig.json",
42
- "dev": "tsx src/index.tsx",
43
- "test": "tsx test/e2e.ts",
44
- "mock": "tsx test/mock-server.ts",
45
- "prepublishOnly": "npm run build"
46
- },
47
- "dependencies": {
48
- "diff": "^9.0.0",
49
- "ink": "^6.8.0",
50
- "react": "^19.3.1",
51
- "string-width": "^8.3.0",
52
- "wrap-ansi": "^10.0.2"
53
- },
54
- "devDependencies": {
55
- "@types/diff": "^8.0.0",
56
- "@types/node": "^24.10.0",
57
- "@types/react": "^19.3.0",
58
- "tsx": "^4.23.15",
59
- "typescript": "^5.9.3"
60
- }
61
- }
1
+ {
2
+ "name": "@ywldan/kiro",
3
+ "version": "0.3.2",
4
+ "description": "A small terminal coding agent with your own OpenAI-compatible endpoint",
5
+ "keywords": [
6
+ "ai",
7
+ "agent",
8
+ "cli",
9
+ "coding-agent",
10
+ "openai",
11
+ "terminal",
12
+ "tui"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "ywildan",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/ywildan/kiro.git"
19
+ },
20
+ "homepage": "https://github.com/ywildan/kiro#readme",
21
+ "bugs": {
22
+ "url": "https://github.com/ywildan/kiro/issues"
23
+ },
24
+ "type": "module",
25
+ "bin": {
26
+ "kiro": "dist/index.js"
27
+ },
28
+ "main": "dist/index.js",
29
+ "files": [
30
+ "dist",
31
+ "!dist/**/*.map",
32
+ "README.md"
33
+ ],
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc -p tsconfig.json",
42
+ "dev": "tsx src/index.tsx",
43
+ "test": "tsx test/e2e.ts",
44
+ "mock": "tsx test/mock-server.ts",
45
+ "prepublishOnly": "npm run build"
46
+ },
47
+ "dependencies": {
48
+ "diff": "^9.0.0",
49
+ "ink": "^6.8.0",
50
+ "react": "^19.3.1",
51
+ "string-width": "^8.3.0",
52
+ "wrap-ansi": "^10.0.2"
53
+ },
54
+ "devDependencies": {
55
+ "@types/diff": "^8.0.0",
56
+ "@types/node": "^24.10.0",
57
+ "@types/react": "^19.3.0",
58
+ "tsx": "^4.23.15",
59
+ "typescript": "^5.9.3"
60
+ }
61
+ }