@meistrari/tela-cli 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.
@@ -0,0 +1,208 @@
1
+ export interface CommandExample {
2
+ command: string
3
+ description: string
4
+ }
5
+
6
+ export interface CommandMetadata {
7
+ name: string
8
+ summary: string
9
+ argumentHint?: string
10
+ aliases?: string[]
11
+ whenToUse: string
12
+ examples: CommandExample[]
13
+ supportsJson: boolean
14
+ relatedCommands: string[]
15
+ }
16
+
17
+ const COMMANDS: CommandMetadata[] = [
18
+ {
19
+ name: 'setup',
20
+ summary: 'Configure Tela CLI, choose an Agent API target, and verify the local environment',
21
+ whenToUse: 'Run this first on a new machine, or any time your Agent API target/origin, clone root, or key changes.',
22
+ examples: [
23
+ {
24
+ command: 'tela setup',
25
+ description: 'Choose production, staging, or a custom API origin and run post-setup checks',
26
+ },
27
+ ],
28
+ supportsJson: false,
29
+ relatedCommands: ['status', 'doctor', 'sync'],
30
+ },
31
+ {
32
+ name: 'sync',
33
+ summary: 'Clone or update a Tela repository, or refresh the current checkout',
34
+ argumentHint: '[repo]',
35
+ whenToUse: 'Use this before coding to get a clean local checkout, or to refresh every repository under the configured clone root.',
36
+ examples: [
37
+ {
38
+ command: 'tela sync agent-api',
39
+ description: 'Clone or update a specific repository under the clone root',
40
+ },
41
+ {
42
+ command: 'tela sync --current',
43
+ description: 'Sync the repository for the current working directory',
44
+ },
45
+ {
46
+ command: 'tela sync --all',
47
+ description: 'Refresh every repository directly under the clone root',
48
+ },
49
+ ],
50
+ supportsJson: true,
51
+ relatedCommands: ['setup', 'status', 'doctor', 'run', 'push'],
52
+ },
53
+ {
54
+ name: 'run',
55
+ summary: 'Run the local agent repository with Claude',
56
+ whenToUse: 'Use this from inside an agent repository when you want Claude to follow the local contract files, show its progress live, and produce the expected result artifact.',
57
+ examples: [
58
+ {
59
+ command: 'tela run',
60
+ description: 'Run the current agent repository with the live viewer',
61
+ },
62
+ {
63
+ command: 'tela run --plain',
64
+ description: 'Force scrollback-first text output',
65
+ },
66
+ {
67
+ command: 'tela run --json',
68
+ description: 'Emit the final execution and artifact envelope as JSON',
69
+ },
70
+ ],
71
+ supportsJson: true,
72
+ relatedCommands: ['sync', 'status', 'doctor'],
73
+ },
74
+ {
75
+ name: 'push',
76
+ summary: 'Preview, commit, and push the current repository',
77
+ whenToUse: 'Use this after reviewing local changes when you want Tela to stage everything, produce a commit message, and push the branch.',
78
+ examples: [
79
+ {
80
+ command: 'tela push',
81
+ description: 'Choose the commit-message flow interactively',
82
+ },
83
+ {
84
+ command: 'tela push --claude',
85
+ description: 'Generate a commit message from the current worktree',
86
+ },
87
+ {
88
+ command: 'tela push --message "Update feedback flow"',
89
+ description: 'Skip prompts and use an explicit commit message',
90
+ },
91
+ ],
92
+ supportsJson: true,
93
+ relatedCommands: ['run', 'status', 'feedback', 'doctor'],
94
+ },
95
+ {
96
+ name: 'feedback',
97
+ summary: 'Guided review of commit feedback with optional Claude handoff',
98
+ whenToUse: 'Use this after pushing or after a feedback-producing commit when you want a guided review of the feedback, a prompt preview before launch, and an outcome summary after Claude exits.',
99
+ examples: [
100
+ {
101
+ command: 'tela feedback --list',
102
+ description: 'Open the guided review flow without launching Claude',
103
+ },
104
+ {
105
+ command: 'tela feedback --apply all',
106
+ description: 'Preview and launch Claude against every actionable suggestion',
107
+ },
108
+ {
109
+ command: 'tela feedback --apply select',
110
+ description: 'Choose specific actionable suggestions before launching Claude',
111
+ },
112
+ ],
113
+ supportsJson: true,
114
+ relatedCommands: ['push', 'status', 'doctor'],
115
+ },
116
+ {
117
+ name: 'status',
118
+ summary: 'Show Tela config, tool availability, repo state, and Agent API origin reachability',
119
+ whenToUse: 'Use this for a quick snapshot of whether the local environment is ready before running mutating commands.',
120
+ examples: [
121
+ {
122
+ command: 'tela status',
123
+ description: 'Render a human-readable environment summary',
124
+ },
125
+ {
126
+ command: 'tela status --json',
127
+ description: 'Emit a machine-readable status report',
128
+ },
129
+ ],
130
+ supportsJson: true,
131
+ relatedCommands: ['setup', 'doctor', 'sync', 'run', 'push', 'feedback'],
132
+ },
133
+ {
134
+ name: 'doctor',
135
+ summary: 'Diagnose config, tools, filesystem state, repo health, and Agent API origin reachability',
136
+ aliases: ['diag'],
137
+ whenToUse: 'Use this when Tela fails or behaves unexpectedly and you need exact remediation steps.',
138
+ examples: [
139
+ {
140
+ command: 'tela doctor',
141
+ description: 'Run the full diagnostic suite with remediation guidance',
142
+ },
143
+ {
144
+ command: 'tela doctor --json',
145
+ description: 'Emit structured diagnostic output for scripts',
146
+ },
147
+ ],
148
+ supportsJson: true,
149
+ relatedCommands: ['status', 'setup', 'sync', 'run'],
150
+ },
151
+ ]
152
+
153
+ export function getCommandMetadata(name: string): CommandMetadata | undefined {
154
+ return COMMANDS.find(command => command.name === name)
155
+ }
156
+
157
+ export function listCommandMetadata(): CommandMetadata[] {
158
+ return [...COMMANDS]
159
+ }
160
+
161
+ export function renderReadmeMarkdown(): string {
162
+ const lines = [
163
+ '# Tela CLI',
164
+ '',
165
+ 'Tela CLI is a one-shot terminal tool for syncing Tela repositories, running local agents, preparing pushes, and applying commit feedback with Claude.',
166
+ '',
167
+ '## Commands',
168
+ '',
169
+ ]
170
+
171
+ for (const command of COMMANDS) {
172
+ lines.push(`### \`${command.name}${command.argumentHint ? ` ${command.argumentHint}` : ''}\``)
173
+ lines.push('')
174
+ lines.push(command.summary)
175
+ lines.push('')
176
+ lines.push(`When to use: ${command.whenToUse}`)
177
+ lines.push('')
178
+
179
+ if (command.aliases?.length) {
180
+ lines.push(`Aliases: ${command.aliases.map(alias => `\`${alias}\``).join(', ')}`)
181
+ lines.push('')
182
+ }
183
+
184
+ lines.push('Examples:')
185
+ for (const example of command.examples) {
186
+ lines.push(`- \`${example.command}\` — ${example.description}`)
187
+ }
188
+ lines.push('')
189
+ }
190
+
191
+ lines.push('## Output modes')
192
+ lines.push('')
193
+ lines.push('- Human output is structured for terminal use with grouped summaries and next actions.')
194
+ lines.push('- `--json` is available on read-heavy flows and on `tela run` for the final execution envelope.')
195
+ lines.push('- `--silent-bark` disables bark audio during interactive Ink startup while keeping the visual intro.')
196
+ lines.push('')
197
+ lines.push('## First run')
198
+ lines.push('')
199
+ lines.push('1. `tela setup`')
200
+ lines.push('2. `tela status`')
201
+ lines.push('3. `tela sync <repo>` or `tela sync --current`')
202
+ lines.push('4. `tela run`')
203
+ lines.push('5. `tela push`')
204
+ lines.push('6. `tela feedback --list`')
205
+ lines.push('')
206
+
207
+ return `${lines.join('\n').trimEnd()}\n`
208
+ }
@@ -0,0 +1,208 @@
1
+ import type { ClaudeCommitContext } from '../commit-message.ts'
2
+ import {
3
+ fallbackCommitMessageFromFiles,
4
+ generateCommitMessageWithClaude,
5
+ } from '../commit-message.ts'
6
+ import {
7
+ buildFallbackCommitMessage,
8
+ commitWithMessage,
9
+ getChangedFilesAgainstHead,
10
+ getCurrentBranch,
11
+ getDiffAgainstHead,
12
+ getRecentLog,
13
+ getRepositoryRoot,
14
+ getHeadShortSha,
15
+ getShortStatus,
16
+ getStatusCounts,
17
+ getStagedDiff,
18
+ getStagedFiles,
19
+ getUpstreamBranch,
20
+ pushBranch,
21
+ stageAll,
22
+ } from '../git.ts'
23
+ import { CommandError } from '../process.ts'
24
+ import type { PushResult } from '../types.ts'
25
+
26
+ export interface PushRepositoryOptions {
27
+ cwd?: string
28
+ mode: 'manual' | 'claude'
29
+ manualMessage?: string
30
+ generateCommitMessage?: (context: ClaudeCommitContext) => Promise<string>
31
+ resolvedMessage?: ResolvedCommitMessage
32
+ }
33
+
34
+ export interface ResolvedCommitMessage {
35
+ message: string
36
+ source: 'manual' | 'claude' | 'fallback'
37
+ fallbackReason?: string
38
+ }
39
+
40
+ export interface PushPreview {
41
+ repoRoot: string
42
+ branch?: string
43
+ upstream?: string | null
44
+ detached: boolean
45
+ hasChanges: boolean
46
+ worktreeStatus: string
47
+ statusCounts: {
48
+ staged: number
49
+ unstaged: number
50
+ untracked: number
51
+ total: number
52
+ }
53
+ suggestedMessage?: string
54
+ messageSource?: ResolvedCommitMessage['source']
55
+ fallbackReason?: string
56
+ }
57
+
58
+ function shouldRetryCommit(error: unknown): boolean {
59
+ if (!(error instanceof CommandError)) {
60
+ return false
61
+ }
62
+
63
+ const details = `${error.result.stdout}\n${error.result.stderr}`.toLowerCase()
64
+ return details.includes('hook')
65
+ || details.includes('pre-commit')
66
+ || details.includes('modified')
67
+ || details.includes('stashed changes conflicted')
68
+ }
69
+
70
+ async function resolveCommitMessage(
71
+ repoRoot: string,
72
+ options: PushRepositoryOptions,
73
+ mode: 'staged' | 'worktree' = 'staged',
74
+ ): Promise<ResolvedCommitMessage> {
75
+ if (options.mode === 'manual' && options.manualMessage?.trim()) {
76
+ return {
77
+ message: options.manualMessage.trim(),
78
+ source: 'manual',
79
+ }
80
+ }
81
+
82
+ const [status, diff, log, files] = await Promise.all([
83
+ getShortStatus(repoRoot),
84
+ mode === 'staged' ? getStagedDiff(repoRoot) : getDiffAgainstHead(repoRoot),
85
+ getRecentLog(repoRoot),
86
+ mode === 'staged' ? getStagedFiles(repoRoot) : getChangedFilesAgainstHead(repoRoot),
87
+ ])
88
+
89
+ const generateCommitMessage = options.generateCommitMessage ?? generateCommitMessageWithClaude
90
+
91
+ try {
92
+ const generatedMessage = await generateCommitMessage({ status, diff, log })
93
+ if (generatedMessage.trim()) {
94
+ return {
95
+ message: generatedMessage.trim(),
96
+ source: 'claude',
97
+ }
98
+ }
99
+ }
100
+ catch (error) {
101
+ const fallbackMessage = fallbackCommitMessageFromFiles(files) || buildFallbackCommitMessage(files)
102
+ return {
103
+ message: fallbackMessage,
104
+ source: 'fallback',
105
+ fallbackReason: error instanceof Error ? error.message : String(error),
106
+ }
107
+ }
108
+
109
+ return {
110
+ message: fallbackCommitMessageFromFiles(files) || buildFallbackCommitMessage(files),
111
+ source: 'fallback',
112
+ fallbackReason: 'Claude returned an empty commit message.',
113
+ }
114
+ }
115
+
116
+ function isDetachedHeadError(error: unknown): boolean {
117
+ return error instanceof Error && error.message.includes('Detached HEAD')
118
+ }
119
+
120
+ export async function previewPush(options: PushRepositoryOptions): Promise<PushPreview> {
121
+ const repoRoot = await getRepositoryRoot(options.cwd ?? process.cwd())
122
+ const [worktreeStatus, statusCounts] = await Promise.all([
123
+ getShortStatus(repoRoot),
124
+ getStatusCounts(repoRoot),
125
+ ])
126
+
127
+ let branch: string | undefined
128
+ let detached = false
129
+ try {
130
+ branch = await getCurrentBranch(repoRoot)
131
+ }
132
+ catch (error) {
133
+ if (!isDetachedHeadError(error)) {
134
+ throw error
135
+ }
136
+
137
+ detached = true
138
+ }
139
+
140
+ const upstream = detached ? null : await getUpstreamBranch(repoRoot)
141
+ const hasChanges = Boolean(worktreeStatus.trim())
142
+
143
+ let suggestedMessage: string | undefined
144
+ let messageSource: ResolvedCommitMessage['source'] | undefined
145
+ let fallbackReason: string | undefined
146
+ if (hasChanges) {
147
+ const resolved = await resolveCommitMessage(repoRoot, options, 'worktree')
148
+ suggestedMessage = resolved.message
149
+ messageSource = resolved.source
150
+ fallbackReason = resolved.fallbackReason
151
+ }
152
+
153
+ return {
154
+ repoRoot,
155
+ branch,
156
+ upstream,
157
+ detached,
158
+ hasChanges,
159
+ worktreeStatus: worktreeStatus.trim(),
160
+ statusCounts,
161
+ suggestedMessage,
162
+ messageSource,
163
+ fallbackReason,
164
+ }
165
+ }
166
+
167
+ export async function pushRepository(options: PushRepositoryOptions): Promise<PushResult> {
168
+ const repoRoot = await getRepositoryRoot(options.cwd ?? process.cwd())
169
+ const worktreeStatus = await getShortStatus(repoRoot)
170
+ if (!worktreeStatus.trim()) {
171
+ throw new Error('No changes to push.')
172
+ }
173
+
174
+ await stageAll(repoRoot)
175
+
176
+ const resolvedMessage = options.resolvedMessage ?? await resolveCommitMessage(repoRoot, options)
177
+ const message = resolvedMessage.message
178
+
179
+ let retriedCommit = false
180
+ try {
181
+ await commitWithMessage(repoRoot, message)
182
+ }
183
+ catch (error) {
184
+ if (!shouldRetryCommit(error)) {
185
+ throw error
186
+ }
187
+
188
+ retriedCommit = true
189
+ await stageAll(repoRoot)
190
+ await commitWithMessage(repoRoot, message)
191
+ }
192
+
193
+ const branch = await getCurrentBranch(repoRoot)
194
+ const upstream = await getUpstreamBranch(repoRoot)
195
+
196
+ await pushBranch(repoRoot, branch, !upstream)
197
+
198
+ return {
199
+ repoRoot,
200
+ branch,
201
+ message,
202
+ retriedCommit,
203
+ commitSha: await getHeadShortSha(repoRoot),
204
+ upstream: await getUpstreamBranch(repoRoot),
205
+ messageSource: resolvedMessage.source,
206
+ fallbackReason: resolvedMessage.fallbackReason,
207
+ }
208
+ }