+3
-2
@@ -62,7 +62,7 @@ export function supportsBrowserPageFlag(commandPath: string[]): boolean {
|
||||
if (['open', 'status'].includes(commandPath[0])) {
|
||||
return false
|
||||
}
|
||||
if (['repo', 'worktree', 'terminal', 'computer'].includes(commandPath[0])) {
|
||||
if (['repo', 'worktree', 'terminal', 'computer', 'note'].includes(commandPath[0])) {
|
||||
return false
|
||||
}
|
||||
return ![
|
||||
@@ -92,7 +92,8 @@ export function isCommandGroup(commandPath: string[]): boolean {
|
||||
'dialog',
|
||||
'storage',
|
||||
'orchestration',
|
||||
'computer'
|
||||
'computer',
|
||||
'note'
|
||||
].includes(commandPath[0])) ||
|
||||
(commandPath.length === 2 &&
|
||||
commandPath[0] === 'storage' &&
|
||||
|
||||
+3
-1
@@ -14,6 +14,7 @@ import { BROWSER_ENV_HANDLERS } from './handlers/browser-env'
|
||||
import { BROWSER_STORAGE_HANDLERS } from './handlers/browser-storage'
|
||||
import { ORCHESTRATION_HANDLERS } from './handlers/orchestration'
|
||||
import { COMPUTER_HANDLERS } from './handlers/computer'
|
||||
import { NOTE_HANDLERS } from './handlers/note'
|
||||
|
||||
export type HandlerContext = {
|
||||
flags: Map<string, string | boolean>
|
||||
@@ -40,7 +41,8 @@ function buildHandlers(): Map<string, CommandHandler> {
|
||||
BROWSER_ENV_HANDLERS,
|
||||
BROWSER_STORAGE_HANDLERS,
|
||||
ORCHESTRATION_HANDLERS,
|
||||
COMPUTER_HANDLERS
|
||||
COMPUTER_HANDLERS,
|
||||
NOTE_HANDLERS
|
||||
]
|
||||
for (const group of groups) {
|
||||
for (const [key, handler] of Object.entries(group)) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import type {
|
||||
RuntimeWorktreePsResult,
|
||||
RuntimeWorktreeRecord
|
||||
} from '../shared/runtime-types'
|
||||
import type { NoteListResult, NoteMutationResult, NoteShowResult } from '../shared/notes-types'
|
||||
import type { RuntimeRpcFailure, RuntimeRpcSuccess } from './runtime-client'
|
||||
import { RuntimeClientError, RuntimeRpcFailureError } from './runtime-client'
|
||||
|
||||
@@ -179,6 +180,39 @@ export function formatTerminalWait(result: { wait: RuntimeTerminalWait }): strin
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
export function formatNoteList(result: NoteListResult): string {
|
||||
if (result.notes.length === 0) {
|
||||
return 'No notes.'
|
||||
}
|
||||
const body = result.notes
|
||||
.map((note) => {
|
||||
const link = note.linkKind ? ` ${note.linkKind}` : ''
|
||||
const preview = note.preview ? `\n${note.preview}` : ''
|
||||
return `${note.id} ${note.title}${link}\npath: ${note.relativePath}\nupdated: ${note.updatedAt}${preview}`
|
||||
})
|
||||
.join('\n\n')
|
||||
return result.truncated
|
||||
? `${body}\n\ntruncated: showing ${result.notes.length} of ${result.totalCount}`
|
||||
: body
|
||||
}
|
||||
|
||||
export function formatNoteShow(result: NoteShowResult): string {
|
||||
const link = result.linkKind ? `link: ${result.linkKind}` : 'link: none'
|
||||
return [
|
||||
`id: ${result.note.id}`,
|
||||
`path: ${result.note.relativePath}`,
|
||||
`title: ${result.note.title}`,
|
||||
`revision: ${result.note.revision}`,
|
||||
link,
|
||||
'',
|
||||
result.note.bodyMarkdown
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
export function formatNoteMutation(result: NoteMutationResult): string {
|
||||
return `Saved note ${result.note.id} (${result.note.title}) revision ${result.note.revision}.`
|
||||
}
|
||||
|
||||
export function formatWorktreePs(result: RuntimeWorktreePsResult): string {
|
||||
if (result.worktrees.length === 0) {
|
||||
return 'No worktrees found.'
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { readFileSync } from 'fs'
|
||||
import type { NoteListResult, NoteMutationResult, NoteShowResult } from '../../shared/notes-types'
|
||||
import type { CommandHandler } from '../dispatch'
|
||||
import { formatNoteList, formatNoteMutation, formatNoteShow, printResult } from '../format'
|
||||
import {
|
||||
getOptionalPositiveIntegerFlag,
|
||||
getOptionalStringFlag,
|
||||
getRequiredStringFlag
|
||||
} from '../flags'
|
||||
import { RuntimeClientError } from '../runtime-client'
|
||||
import { getBrowserWorktreeSelector } from '../selectors'
|
||||
|
||||
async function getNoteWorktreeSelector(
|
||||
flags: Map<string, string | boolean>,
|
||||
cwd: string,
|
||||
client: Parameters<CommandHandler>[0]['client']
|
||||
): Promise<string> {
|
||||
const worktree = await getBrowserWorktreeSelector(flags, cwd, client)
|
||||
if (!worktree) {
|
||||
throw new RuntimeClientError(
|
||||
'selector_not_found',
|
||||
'No Orca-managed worktree contains the current directory. Pass --worktree.'
|
||||
)
|
||||
}
|
||||
return worktree
|
||||
}
|
||||
|
||||
function readBody(flags: Map<string, string | boolean>, required: boolean): string | undefined {
|
||||
const body = getOptionalStringFlag(flags, 'body')
|
||||
const bodyFile = getOptionalStringFlag(flags, 'body-file')
|
||||
const bodyStdin = flags.get('body-stdin') === true
|
||||
const specified = [body !== undefined, bodyFile !== undefined, bodyStdin].filter(Boolean).length
|
||||
if (specified > 1) {
|
||||
throw new RuntimeClientError(
|
||||
'invalid_argument',
|
||||
'Pass only one of --body, --body-file, or --body-stdin'
|
||||
)
|
||||
}
|
||||
if (body !== undefined) {
|
||||
return body
|
||||
}
|
||||
if (bodyFile) {
|
||||
return readFileSync(bodyFile, 'utf8')
|
||||
}
|
||||
if (bodyStdin) {
|
||||
return readFileSync(0, 'utf8')
|
||||
}
|
||||
if (required) {
|
||||
throw new RuntimeClientError('invalid_argument', 'Missing note body')
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
export const NOTE_HANDLERS: Record<string, CommandHandler> = {
|
||||
'note list': async ({ flags, client, cwd, json }) => {
|
||||
const result = await client.call<NoteListResult>('note.list', {
|
||||
worktree: await getNoteWorktreeSelector(flags, cwd, client),
|
||||
limit: getOptionalPositiveIntegerFlag(flags, 'limit')
|
||||
})
|
||||
printResult(result, json, formatNoteList)
|
||||
},
|
||||
'note show': async ({ flags, client, cwd, json }) => {
|
||||
const result = await client.call<NoteShowResult>('note.show', {
|
||||
worktree: await getNoteWorktreeSelector(flags, cwd, client),
|
||||
note: getRequiredStringFlag(flags, 'note')
|
||||
})
|
||||
printResult(result, json, formatNoteShow)
|
||||
},
|
||||
'note create': async ({ flags, client, cwd, json }) => {
|
||||
const result = await client.call<NoteMutationResult>('note.create', {
|
||||
worktree: await getNoteWorktreeSelector(flags, cwd, client),
|
||||
title: getRequiredStringFlag(flags, 'title'),
|
||||
bodyMarkdown: readBody(flags, false),
|
||||
makeActive: true
|
||||
})
|
||||
printResult(result, json, formatNoteMutation)
|
||||
},
|
||||
'note append': async ({ flags, client, cwd, json }) => {
|
||||
const result = await client.call<NoteMutationResult>('note.append', {
|
||||
worktree: await getNoteWorktreeSelector(flags, cwd, client),
|
||||
note: getRequiredStringFlag(flags, 'note'),
|
||||
bodyMarkdown: readBody(flags, true),
|
||||
makeActive: true
|
||||
})
|
||||
printResult(result, json, formatNoteMutation)
|
||||
},
|
||||
'note search': async ({ flags, client, cwd, json }) => {
|
||||
const result = await client.call<NoteListResult>('note.search', {
|
||||
worktree: await getNoteWorktreeSelector(flags, cwd, client),
|
||||
query: getRequiredStringFlag(flags, 'query'),
|
||||
limit: getOptionalPositiveIntegerFlag(flags, 'limit')
|
||||
})
|
||||
printResult(result, json, formatNoteList)
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,13 @@ import { BROWSER_BASIC_COMMAND_SPECS } from './browser-basic'
|
||||
import { CORE_COMMAND_SPECS } from './core'
|
||||
import { ORCHESTRATION_COMMAND_SPECS } from './orchestration'
|
||||
import { COMPUTER_COMMAND_SPECS } from './computer'
|
||||
import { NOTE_COMMAND_SPECS } from './note'
|
||||
|
||||
export const COMMAND_SPECS: CommandSpec[] = [
|
||||
...CORE_COMMAND_SPECS,
|
||||
...BROWSER_BASIC_COMMAND_SPECS,
|
||||
...BROWSER_ADVANCED_COMMAND_SPECS,
|
||||
...ORCHESTRATION_COMMAND_SPECS,
|
||||
...COMPUTER_COMMAND_SPECS
|
||||
...COMPUTER_COMMAND_SPECS,
|
||||
...NOTE_COMMAND_SPECS
|
||||
]
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import type { CommandSpec } from '../args'
|
||||
import { GLOBAL_FLAGS } from '../args'
|
||||
|
||||
export const NOTE_COMMAND_SPECS: CommandSpec[] = [
|
||||
{
|
||||
path: ['note', 'list'],
|
||||
summary: 'List project notes for the current Orca worktree',
|
||||
usage: 'orca note list [--worktree <selector>] [--limit <n>] [--json]',
|
||||
allowedFlags: [...GLOBAL_FLAGS, 'worktree', 'limit']
|
||||
},
|
||||
{
|
||||
path: ['note', 'show'],
|
||||
summary: 'Show a project note',
|
||||
usage: 'orca note show --note <selector> [--worktree <selector>] [--json]',
|
||||
allowedFlags: [...GLOBAL_FLAGS, 'note', 'worktree']
|
||||
},
|
||||
{
|
||||
path: ['note', 'create'],
|
||||
summary: 'Create a project note',
|
||||
usage:
|
||||
'orca note create --title <title> [--body <text>|--body-file <path>|--body-stdin] [--worktree <selector>] [--json]',
|
||||
allowedFlags: [...GLOBAL_FLAGS, 'title', 'body', 'body-file', 'body-stdin', 'worktree']
|
||||
},
|
||||
{
|
||||
path: ['note', 'append'],
|
||||
summary: 'Append Markdown to a project note',
|
||||
usage:
|
||||
'orca note append --note <selector> [--body <text>|--body-file <path>|--body-stdin] [--worktree <selector>] [--json]',
|
||||
allowedFlags: [...GLOBAL_FLAGS, 'note', 'body', 'body-file', 'body-stdin', 'worktree']
|
||||
},
|
||||
{
|
||||
path: ['note', 'search'],
|
||||
summary: 'Search project notes',
|
||||
usage: 'orca note search --query <text> [--worktree <selector>] [--limit <n>] [--json]',
|
||||
allowedFlags: [...GLOBAL_FLAGS, 'query', 'worktree', 'limit']
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user