@ottocode/sdk 0.1.210 → 0.1.211

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ottocode/sdk",
3
- "version": "0.1.210",
3
+ "version": "0.1.211",
4
4
  "description": "AI agent SDK for building intelligent assistants - tree-shakable and comprehensive",
5
5
  "author": "nitishxyz",
6
6
  "license": "MIT",
@@ -4,6 +4,7 @@ import { spawn } from 'node:child_process';
4
4
  import DESCRIPTION from './bash.txt' with { type: 'text' };
5
5
  import { createToolError, type ToolResponse } from '../error.ts';
6
6
  import { getAugmentedPath } from '../bin-manager.ts';
7
+ import { injectCoAuthorIntoGitCommit } from './git-identity.ts';
7
8
 
8
9
  function normalizePath(p: string) {
9
10
  const normalized = p.replace(/\\/g, '/');
@@ -95,8 +96,10 @@ export function buildBashTool(projectRoot: string): {
95
96
 
96
97
  const absCwd = resolveSafePath(projectRoot, cwd || '.');
97
98
 
99
+ const finalCmd = injectCoAuthorIntoGitCommit(cmd);
100
+
98
101
  return new Promise((resolve) => {
99
- const proc = spawn(cmd, {
102
+ const proc = spawn(finalCmd, {
100
103
  cwd: absCwd,
101
104
  shell: true,
102
105
  stdio: ['ignore', 'pipe', 'pipe'],
@@ -0,0 +1,23 @@
1
+ const OTTOCODE_BOT_USER_ID = '261994719';
2
+
3
+ export const OTTOCODE_BOT_NAME = 'ottocode-io[bot]';
4
+ export const OTTOCODE_BOT_EMAIL = `${OTTOCODE_BOT_USER_ID}+${OTTOCODE_BOT_NAME}@users.noreply.github.com`;
5
+ export const OTTOCODE_CO_AUTHOR = `Co-authored-by: ${OTTOCODE_BOT_NAME} <${OTTOCODE_BOT_EMAIL}>`;
6
+
7
+ export function appendCoAuthorTrailer(message: string): string {
8
+ if (message.includes(OTTOCODE_CO_AUTHOR)) return message;
9
+ return `${message}\n\n${OTTOCODE_CO_AUTHOR}`;
10
+ }
11
+
12
+ const GIT_COMMIT_MSG_RE =
13
+ /git\s+commit\s+(?:[^"']*?)(?:-[a-z]*m|-m)\s+(["'])([\s\S]*?)\1/g;
14
+
15
+ export function injectCoAuthorIntoGitCommit(cmd: string): string {
16
+ return cmd.replace(GIT_COMMIT_MSG_RE, (match, quote, msg) => {
17
+ const patched = appendCoAuthorTrailer(msg);
18
+ return match.replace(
19
+ `${quote}${msg}${quote}`,
20
+ `${quote}${patched}${quote}`,
21
+ );
22
+ });
23
+ }
@@ -6,6 +6,7 @@ import GIT_STATUS_DESCRIPTION from './git.status.txt' with { type: 'text' };
6
6
  import GIT_DIFF_DESCRIPTION from './git.diff.txt' with { type: 'text' };
7
7
  import GIT_COMMIT_DESCRIPTION from './git.commit.txt' with { type: 'text' };
8
8
  import { createToolError, type ToolResponse } from '../error.ts';
9
+ import { appendCoAuthorTrailer } from './git-identity.ts';
9
10
 
10
11
  const execAsync = promisify(exec);
11
12
 
@@ -119,13 +120,14 @@ export function buildGitTools(
119
120
  });
120
121
  }
121
122
  const gitRoot = await findGitRoot();
123
+ const fullMessage = appendCoAuthorTrailer(message);
122
124
  const args = [
123
125
  'git',
124
126
  '-C',
125
127
  `"${gitRoot}"`,
126
128
  'commit',
127
129
  '-m',
128
- `"${message.replace(/"/g, '\\"')}"`,
130
+ `"${fullMessage.replace(/"/g, '\\"')}"`,
129
131
  ];
130
132
  if (amend) args.push('--amend');
131
133
  if (signoff) args.push('--signoff');
@@ -5,6 +5,7 @@ import { createToolError } from '../error.ts';
5
5
  import type { TerminalManager } from '../../terminals/index.ts';
6
6
  import type { TerminalStatus } from '../../terminals/terminal.ts';
7
7
  import { normalizeTerminalLine } from '../../utils/ansi.ts';
8
+ import { injectCoAuthorIntoGitCommit } from './git-identity.ts';
8
9
 
9
10
  function shellQuote(segment: string): string {
10
11
  if (/^[a-zA-Z0-9._-]+$/.test(segment)) {
@@ -163,7 +164,7 @@ export function buildTerminalTool(
163
164
 
164
165
  if (initialCommand) {
165
166
  queueMicrotask(() => {
166
- term.write(`${initialCommand}\n`);
167
+ term.write(`${injectCoAuthorIntoGitCommit(initialCommand)}\n`);
167
168
  });
168
169
  }
169
170
 
@@ -238,7 +239,7 @@ export function buildTerminalTool(
238
239
  return createToolError(`Terminal ${params.terminalId} not found`);
239
240
  }
240
241
 
241
- term.write(params.input);
242
+ term.write(injectCoAuthorIntoGitCommit(params.input));
242
243
 
243
244
  return {
244
245
  ok: true,
package/src/index.ts CHANGED
@@ -222,6 +222,13 @@ export type { DiscoveredTool, DiscoverResult } from './core/src/index.ts';
222
222
  export { setTerminalManager, getTerminalManager } from './core/src/index.ts';
223
223
  export { buildFsTools } from './core/src/index.ts';
224
224
  export { buildGitTools } from './core/src/index.ts';
225
+ export {
226
+ appendCoAuthorTrailer,
227
+ injectCoAuthorIntoGitCommit,
228
+ OTTOCODE_BOT_NAME,
229
+ OTTOCODE_BOT_EMAIL,
230
+ OTTOCODE_CO_AUTHOR,
231
+ } from './core/src/tools/builtin/git-identity.ts';
225
232
  export { buildEditTool } from './core/src/index.ts';
226
233
  export { buildMultiEditTool } from './core/src/index.ts';
227
234