@newtype-ai/nit 0.1.0 → 0.1.1

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.
@@ -276,10 +276,22 @@ async function readConfig(nitDir) {
276
276
  }
277
277
  return parseConfig(raw);
278
278
  }
279
+ async function writeConfig(nitDir, config) {
280
+ const configPath = join4(nitDir, CONFIG_FILE);
281
+ await fs4.writeFile(configPath, serializeConfig(config), "utf-8");
282
+ }
279
283
  async function getRemoteCredential(nitDir, remoteName) {
280
284
  const config = await readConfig(nitDir);
281
285
  return config.remotes[remoteName]?.credential ?? null;
282
286
  }
287
+ async function setRemoteCredential(nitDir, remoteName, credential) {
288
+ const config = await readConfig(nitDir);
289
+ if (!config.remotes[remoteName]) {
290
+ config.remotes[remoteName] = {};
291
+ }
292
+ config.remotes[remoteName].credential = credential;
293
+ await writeConfig(nitDir, config);
294
+ }
283
295
  function parseConfig(raw) {
284
296
  const remotes = {};
285
297
  let currentRemote = null;
@@ -306,6 +318,17 @@ function parseConfig(raw) {
306
318
  }
307
319
  return { remotes };
308
320
  }
321
+ function serializeConfig(config) {
322
+ const lines = [];
323
+ for (const [name, remote2] of Object.entries(config.remotes)) {
324
+ lines.push(`[remote "${name}"]`);
325
+ if (remote2.credential) {
326
+ lines.push(` credential = ${remote2.credential}`);
327
+ }
328
+ lines.push("");
329
+ }
330
+ return lines.join("\n");
331
+ }
309
332
 
310
333
  // src/skills.ts
311
334
  import { promises as fs5 } from "fs";
@@ -517,7 +540,7 @@ async function pushBranch(nitDir, remoteName, branch2, cardJson, commitHash) {
517
540
  commitHash,
518
541
  remoteUrl: API_BASE,
519
542
  success: false,
520
- error: `No credential configured for remote "${remoteName}". Run: nit remote`
543
+ error: `No credential configured for remote "${remoteName}". Run: nit remote set-credential <agent-key>`
521
544
  };
522
545
  }
523
546
  const url = `${API_BASE}/agent-card/branches/${encodeURIComponent(branch2)}`;
@@ -905,6 +928,11 @@ async function remote(options) {
905
928
  hasCredential: credential !== null
906
929
  };
907
930
  }
931
+ async function setCredential(credential, options) {
932
+ const nitDir = findNitDir(options?.projectDir);
933
+ const remoteName = options?.remoteName || "origin";
934
+ await setRemoteCredential(nitDir, remoteName, credential);
935
+ }
908
936
 
909
937
  export {
910
938
  formatPublicKeyField,
@@ -923,5 +951,6 @@ export {
923
951
  branch,
924
952
  checkout,
925
953
  push,
926
- remote
954
+ remote,
955
+ setCredential
927
956
  };
package/dist/cli.js CHANGED
@@ -10,8 +10,9 @@ import {
10
10
  log,
11
11
  push,
12
12
  remote,
13
+ setCredential,
13
14
  status
14
- } from "./chunk-5EGCFUZ7.js";
15
+ } from "./chunk-5AVY6P7B.js";
15
16
 
16
17
  // src/cli.ts
17
18
  var bold = (s) => `\x1B[1m${s}\x1B[0m`;
@@ -48,7 +49,7 @@ async function main() {
48
49
  await cmdPush(args);
49
50
  break;
50
51
  case "remote":
51
- await cmdRemote();
52
+ await cmdRemote(args);
52
53
  break;
53
54
  case "help":
54
55
  case "--help":
@@ -175,7 +176,18 @@ async function cmdPush(args) {
175
176
  }
176
177
  }
177
178
  }
178
- async function cmdRemote() {
179
+ async function cmdRemote(args) {
180
+ const subcommand = args[0];
181
+ if (subcommand === "set-credential") {
182
+ const token = args[1];
183
+ if (!token) {
184
+ console.error("Usage: nit remote set-credential <agent-key>");
185
+ process.exit(1);
186
+ }
187
+ await setCredential(token);
188
+ console.log(`Credential ${green("configured")} for origin.`);
189
+ return;
190
+ }
179
191
  const info = await remote();
180
192
  console.log(`${bold(info.name)}`);
181
193
  console.log(` URL: ${info.url}`);
@@ -199,6 +211,7 @@ ${bold("Commands:")}
199
211
  checkout <branch> Switch branch (overwrites agent-card.json)
200
212
  push [--all] Push branch(es) to remote
201
213
  remote Show remote info
214
+ remote set-credential <key> Set push credential (agent key)
202
215
 
203
216
  ${bold("Examples:")}
204
217
  nit init
package/dist/index.d.ts CHANGED
@@ -239,5 +239,12 @@ interface RemoteInfo {
239
239
  declare function remote(options?: {
240
240
  projectDir?: string;
241
241
  }): Promise<RemoteInfo>;
242
+ /**
243
+ * Set the push credential for a remote.
244
+ */
245
+ declare function setCredential(credential: string, options?: {
246
+ projectDir?: string;
247
+ remoteName?: string;
248
+ }): Promise<void>;
242
249
 
243
- export { type AgentCard, type AgentCardSkill, type DiffResult, type FieldDiff, type InitResult, type NitBranch, type NitCommit, type NitConfig, type NitHead, type NitRemoteConfig, type PushResult, type RemoteInfo, type SkillMetadata, type StatusResult, branch, checkout, commit, diff, diffCards, fetchBranchCard, findNitDir, formatDiff, formatPublicKeyField, init, log, parsePublicKeyField, push, remote, signChallenge, status, verifySignature };
250
+ export { type AgentCard, type AgentCardSkill, type DiffResult, type FieldDiff, type InitResult, type NitBranch, type NitCommit, type NitConfig, type NitHead, type NitRemoteConfig, type PushResult, type RemoteInfo, type SkillMetadata, type StatusResult, branch, checkout, commit, diff, diffCards, fetchBranchCard, findNitDir, formatDiff, formatPublicKeyField, init, log, parsePublicKeyField, push, remote, setCredential, signChallenge, status, verifySignature };
package/dist/index.js CHANGED
@@ -14,10 +14,11 @@ import {
14
14
  parsePublicKeyField,
15
15
  push,
16
16
  remote,
17
+ setCredential,
17
18
  signChallenge,
18
19
  status,
19
20
  verifySignature
20
- } from "./chunk-5EGCFUZ7.js";
21
+ } from "./chunk-5AVY6P7B.js";
21
22
  export {
22
23
  branch,
23
24
  checkout,
@@ -33,6 +34,7 @@ export {
33
34
  parsePublicKeyField,
34
35
  push,
35
36
  remote,
37
+ setCredential,
36
38
  signChallenge,
37
39
  status,
38
40
  verifySignature
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newtype-ai/nit",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Version control for agent cards",
5
5
  "type": "module",
6
6
  "bin": {