finch-git-branch 0.2.9 → 0.2.11

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/dist/index.js CHANGED
@@ -4,12 +4,17 @@ import { execFile } from 'node:child_process';
4
4
  import { promisify } from 'node:util';
5
5
  const execFileAsync = promisify(execFile);
6
6
  const CURRENT_BRANCH_KEY = 'currentBranch';
7
- const FINCH_CODE_CO_AUTHOR = 'Co-authored-by: finch-code <noreply@finchwork.app>';
7
+ const CO_AUTHOR_ENABLED_KEY = 'coAuthorEnabled';
8
+ const FINCH_CODE_EMAIL = 'noreply@finchwork.app';
8
9
  // Tracks the most-recently-seen cwd so the background poller can use it.
9
10
  let activeCwd;
10
11
  function readIconSvg(name) {
11
12
  return readFileSync(new URL(`../icons/${name}.svg`, import.meta.url), 'utf-8');
12
13
  }
14
+ async function getCoAuthorTrailer(ctx) {
15
+ const { assistantName } = await ctx.app.getInfo();
16
+ return `Co-authored-by: ${assistantName} <${FINCH_CODE_EMAIL}>`;
17
+ }
13
18
  // ── Git helpers ──────────────────────────────────────────────────────────────
14
19
  async function git(cwd, args, timeout = 5000) {
15
20
  const { stdout } = await execFileAsync('git', ['-C', cwd, ...args], {
@@ -123,6 +128,7 @@ export function activate(ctx) {
123
128
  ctx.subscriptions.push(ctx.icons.register('git-branch', {
124
129
  plus: { svg: readIconSvg('plus'), description: 'Create branch' },
125
130
  'plus-circle': { svg: readIconSvg('plus-circle'), description: 'Create branch' },
131
+ handshake: { svg: readIconSvg('handshake'), description: 'Include Finch Code co-author' },
126
132
  }));
127
133
  const composerAction = ctx.composerActions.register('git-branch', {
128
134
  async getBadge({ cwd }) {
@@ -139,6 +145,12 @@ export function activate(ctx) {
139
145
  }
140
146
  return await ctx.storage.get(CURRENT_BRANCH_KEY);
141
147
  },
148
+ async getReminder({ cwd, surface }) {
149
+ if (surface === 'home' || !cwd || !isGitRepo(cwd) || (await ctx.storage.get(CO_AUTHOR_ENABLED_KEY)) !== true) {
150
+ return undefined;
151
+ }
152
+ return `When creating any Git commit, append a blank line followed by the exact trailer: ${await getCoAuthorTrailer(ctx)}`;
153
+ },
142
154
  async getMenu({ cwd }) {
143
155
  if (!cwd)
144
156
  return [];
@@ -165,7 +177,19 @@ export function activate(ctx) {
165
177
  if (desc)
166
178
  pinnedDiffs.set(b, desc);
167
179
  }));
168
- const items = [];
180
+ const coAuthorEnabled = await ctx.storage.get(CO_AUTHOR_ENABLED_KEY) === true;
181
+ const { assistantName } = await ctx.app.getInfo();
182
+ const items = [{
183
+ id: '__toggle_co_author__',
184
+ label: ctx.i18n.t('git.branch.coauthor.label', { finchName: assistantName }),
185
+ description: ctx.i18n.t(coAuthorEnabled ? 'git.branch.coauthor.on' : 'git.branch.coauthor.off'),
186
+ current: coAuthorEnabled,
187
+ iconName: 'ext:git-branch/handshake',
188
+ }, {
189
+ id: '__coauthor_sep__',
190
+ label: '',
191
+ separator: true,
192
+ }];
169
193
  items.push({
170
194
  id: currentBranch,
171
195
  label: currentBranch,
@@ -223,6 +247,18 @@ export function activate(ctx) {
223
247
  async execute({ cwd }, itemId, actions) {
224
248
  if (!cwd || !itemId)
225
249
  return;
250
+ if (itemId === '__toggle_co_author__') {
251
+ const enabled = await ctx.storage.get(CO_AUTHOR_ENABLED_KEY) === true;
252
+ const next = !enabled;
253
+ await ctx.storage.set(CO_AUTHOR_ENABLED_KEY, next);
254
+ await ctx.ui.showToast({
255
+ title: ctx.i18n.t(next ? 'git.branch.coauthor.tip.on' : 'git.branch.coauthor.tip.off'),
256
+ variant: next ? 'success' : 'info',
257
+ position: 'TC',
258
+ });
259
+ composerAction.notifyUpdate();
260
+ return;
261
+ }
226
262
  // ── Create branch: 直接填入 Prompt ────────────────────────────
227
263
  if (itemId === '__create_branch__') {
228
264
  await actions.fillComposer(ctx.i18n.t('git.branch.create.prompt'));
@@ -253,8 +289,9 @@ export function activate(ctx) {
253
289
  await git(cwd, [
254
290
  'commit', '-m',
255
291
  ctx.i18n.t('git.branch.switch.commit.msg', { branch: itemId }),
256
- '-m',
257
- FINCH_CODE_CO_AUTHOR,
292
+ ...(await ctx.storage.get(CO_AUTHOR_ENABLED_KEY) === true
293
+ ? ['-m', await getCoAuthorTrailer(ctx)]
294
+ : []),
258
295
  ]);
259
296
  checkpointCommit = await git(cwd, ['rev-parse', '--short', 'HEAD']).catch(() => undefined);
260
297
  }
@@ -341,8 +378,9 @@ export function activate(ctx) {
341
378
  await git(cwd, [
342
379
  'commit', '-m',
343
380
  `checkpoint: before creating branch ${branchName}`,
344
- '-m',
345
- FINCH_CODE_CO_AUTHOR,
381
+ ...(await ctx.storage.get(CO_AUTHOR_ENABLED_KEY) === true
382
+ ? ['-m', await getCoAuthorTrailer(ctx)]
383
+ : []),
346
384
  ]);
347
385
  }
348
386
  await git(cwd, ['checkout', '-b', branchName], 10_000);
package/i18n/en-US.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "Git Branch",
3
3
  "description": "Manage Git branches from the dialog box.",
4
- "systemPrompt": "When creating a Git branch, use create_git_branch. Pass branchName to create and check out a known branch without a form; otherwise omit it to collect the name in a form. When you create any Git commit, always append a blank line followed by the exact trailer: Co-authored-by: finch-code <noreply@finchwork.app>.",
4
+ "systemPrompt": "When creating a Git branch, use create_git_branch. Pass branchName to create and check out a known branch without a form; otherwise omit it to collect the name in a form.",
5
5
  "toolMeta": {
6
6
  "name": "Git Branch"
7
7
  },
@@ -11,6 +11,11 @@
11
11
  }
12
12
  },
13
13
 
14
+ "git.branch.coauthor.label": "Include {finchName} as code co-author",
15
+ "git.branch.coauthor.on": "On",
16
+ "git.branch.coauthor.off": "Off",
17
+ "git.branch.coauthor.tip.on": "Code Co-authored enabled, takes effect in a new session",
18
+ "git.branch.coauthor.tip.off": "Code Co-authored disabled, takes effect in a new session",
14
19
  "git.branch.changes": "{count} changes",
15
20
  "git.branch.more": "More branches",
16
21
  "git.branch.more.group": "Branches",
package/i18n/zh-CN.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "Git 分支",
3
3
  "description": "在对话框里管理 Git 分支的小工具",
4
- "systemPrompt": "当需要创建 Git 分支时,使用 create_git_branch 工具。已确定分支名时传入 branchName 参数以静默创建并检出;否则省略该参数以弹出表单收集分支名。创建任何 Git 提交时,必须在提交信息末尾空一行,并追加完全一致的 trailer:Co-authored-by: finch-code <noreply@finchwork.app>。",
4
+ "systemPrompt": "当需要创建 Git 分支时,使用 create_git_branch 工具。已确定分支名时传入 branchName 参数以静默创建并检出;否则省略该参数以弹出表单收集分支名。",
5
5
  "toolMeta": {
6
6
  "name": "Git 分支"
7
7
  },
@@ -11,6 +11,11 @@
11
11
  }
12
12
  },
13
13
 
14
+ "git.branch.coauthor.label": "包含 {finchName} 作为代码协作者",
15
+ "git.branch.coauthor.on": "已开启",
16
+ "git.branch.coauthor.off": "已关闭",
17
+ "git.branch.coauthor.tip.on": "Code Co-authored 已开启,开启新会话生效",
18
+ "git.branch.coauthor.tip.off": "Code Co-authored 已关闭,开启新会话生效",
14
19
  "git.branch.changes": "{count} 个改动",
15
20
  "git.branch.more": "更多分支",
16
21
  "git.branch.more.group": "分支",
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-handshake-icon lucide-handshake"><path d="m11 17 2 2a1 1 0 1 0 3-3"/><path d="m14 14 2.5 2.5a1 1 0 1 0 3-3l-3.88-3.88a3 3 0 0 0-4.24 0l-.88.88a1 1 0 1 1-3-3l2.81-2.81a5.79 5.79 0 0 1 7.06-.87l.47.28a2 2 0 0 0 1.42.25L21 4"/><path d="m21 3 1 11h-2"/><path d="M3 3 2 14l6.5 6.5a1 1 0 1 0 3-3"/><path d="M3 4h8"/></svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "finch-git-branch",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "Git Branch Manager for Finch Composer toolbar.",
5
5
  "author": {
6
6
  "name": "Finch Team",
@@ -23,7 +23,7 @@
23
23
  "id": "git-branch",
24
24
  "name": "Git Branch",
25
25
  "description": "Switch Git branches from the Composer toolbar with change previews.",
26
- "systemPrompt": "When creating a Git branch, use create_git_branch. Pass branchName to create and check out a known branch without a form; otherwise omit it to collect the name in a form. When you create any Git commit, always append a blank line followed by the exact trailer: Co-authored-by: finch-code <noreply@finchwork.app>.",
26
+ "systemPrompt": "When creating a Git branch, use create_git_branch. Pass branchName to create and check out a known branch without a form; otherwise omit it to collect the name in a form.",
27
27
  "main": "dist/index.js",
28
28
  "activationEvents": [
29
29
  "onStartup"