@gatebolt/cli 0.5.0 → 0.6.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.
- package/dist/commands/init.js +2 -1
- package/dist/commands/link.js +3 -5
- package/dist/profiles.js +30 -12
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -7,7 +7,7 @@ import { claudeCodeAdapter } from "../agents/claude-code.js";
|
|
|
7
7
|
import { repoIdentityFromName, resolveConnection } from "../config.js";
|
|
8
8
|
import { hooksPath, repoContext } from "../git.js";
|
|
9
9
|
import { isRecord } from "../json.js";
|
|
10
|
-
import { profileLoader, readRepoLink } from "../profiles.js";
|
|
10
|
+
import { pinRepoProfile, profileLoader, readRepoLink } from "../profiles.js";
|
|
11
11
|
import { deriveIdentity, linkRepository } from "./link.js";
|
|
12
12
|
const ADAPTERS = [claudeCodeAdapter];
|
|
13
13
|
const ENFORCE_VALUES = ["lenient", "strict"];
|
|
@@ -78,6 +78,7 @@ async function connect(loadProfile) {
|
|
|
78
78
|
async function ensureLink(connection, root, name) {
|
|
79
79
|
const existing = await readRepoLink(root);
|
|
80
80
|
if (existing) {
|
|
81
|
+
await pinRepoProfile(existing.repositoryId, connection.profileName);
|
|
81
82
|
return { repositoryId: existing.repositoryId, existed: true };
|
|
82
83
|
}
|
|
83
84
|
const identity = name ? repoIdentityFromName(name) : await deriveIdentity();
|
package/dist/commands/link.js
CHANGED
|
@@ -2,7 +2,7 @@ import { parseArgs } from "node:util";
|
|
|
2
2
|
import { parseRemoteUrl, repoIdentityFromName, resolveConnection, } from "../config.js";
|
|
3
3
|
import { remoteOriginUrl, repoContext } from "../git.js";
|
|
4
4
|
import { isRecord } from "../json.js";
|
|
5
|
-
import { profileLoader, writeRepoLink } from "../profiles.js";
|
|
5
|
+
import { pinRepoProfile, profileLoader, writeRepoLink } from "../profiles.js";
|
|
6
6
|
import { postChange } from "../transport.js";
|
|
7
7
|
export async function runLink(argv) {
|
|
8
8
|
const { values } = parseArgs({
|
|
@@ -42,10 +42,8 @@ export async function linkRepository(connection, root, identity) {
|
|
|
42
42
|
if (!isLinkResult(result)) {
|
|
43
43
|
throw new Error("Unexpected response from server.");
|
|
44
44
|
}
|
|
45
|
-
await writeRepoLink(root, {
|
|
46
|
-
|
|
47
|
-
...(connection.profileName ? { profile: connection.profileName } : {}),
|
|
48
|
-
});
|
|
45
|
+
await writeRepoLink(root, { repositoryId: result.repositoryId });
|
|
46
|
+
await pinRepoProfile(result.repositoryId, connection.profileName);
|
|
49
47
|
return result;
|
|
50
48
|
}
|
|
51
49
|
function raiseNoRemote() {
|
package/dist/profiles.js
CHANGED
|
@@ -24,8 +24,23 @@ export function parseConfig(raw) {
|
|
|
24
24
|
if (typeof raw.default === "string") {
|
|
25
25
|
config.default = raw.default;
|
|
26
26
|
}
|
|
27
|
+
if (raw.repos !== undefined) {
|
|
28
|
+
const repos = parseRepos(raw.repos);
|
|
29
|
+
if (Object.keys(repos).length > 0)
|
|
30
|
+
config.repos = repos;
|
|
31
|
+
}
|
|
27
32
|
return config;
|
|
28
33
|
}
|
|
34
|
+
function parseRepos(value) {
|
|
35
|
+
if (!isRecord(value))
|
|
36
|
+
return {};
|
|
37
|
+
const repos = {};
|
|
38
|
+
for (const [id, name] of Object.entries(value)) {
|
|
39
|
+
if (typeof name === "string")
|
|
40
|
+
repos[id] = name;
|
|
41
|
+
}
|
|
42
|
+
return repos;
|
|
43
|
+
}
|
|
29
44
|
function parseProfile(value) {
|
|
30
45
|
if (!isRecord(value))
|
|
31
46
|
return null;
|
|
@@ -52,9 +67,8 @@ export async function resolveProfile(opts) {
|
|
|
52
67
|
const config = await loadConfig();
|
|
53
68
|
if (!config)
|
|
54
69
|
return null;
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const preference = configured(config, nonEmpty(opts.preferred)) ?? pointer;
|
|
70
|
+
const pin = await repoPin(config, opts.root);
|
|
71
|
+
const preference = configured(config, nonEmpty(opts.preferred)) ?? configured(config, pin);
|
|
58
72
|
const name = selectProfileName(config, {
|
|
59
73
|
name: opts.name,
|
|
60
74
|
env: process.env.GATEBOLT_PROFILE,
|
|
@@ -65,8 +79,6 @@ export async function resolveProfile(opts) {
|
|
|
65
79
|
const profile = config.profiles[name];
|
|
66
80
|
if (profile)
|
|
67
81
|
return { name, ...profile };
|
|
68
|
-
if (!explicit && name === preference)
|
|
69
|
-
return null;
|
|
70
82
|
throw new Error(`Profile "${name}" is not in ${configPath()}. Run \`gatebolt configure --profile ${name}\`.`);
|
|
71
83
|
}
|
|
72
84
|
function configured(config, name) {
|
|
@@ -108,15 +120,25 @@ async function loadConfig() {
|
|
|
108
120
|
}
|
|
109
121
|
return config;
|
|
110
122
|
}
|
|
111
|
-
async function
|
|
123
|
+
async function repoPin(config, root) {
|
|
112
124
|
try {
|
|
113
125
|
const link = await readRepoLink(root);
|
|
114
|
-
return link?.
|
|
126
|
+
return link ? config.repos?.[link.repositoryId] : undefined;
|
|
115
127
|
}
|
|
116
128
|
catch {
|
|
129
|
+
// A malformed .gatebolt still resolves a key so `link` can repair it.
|
|
117
130
|
return undefined;
|
|
118
131
|
}
|
|
119
132
|
}
|
|
133
|
+
export async function pinRepoProfile(repositoryId, profileName) {
|
|
134
|
+
if (!profileName)
|
|
135
|
+
return;
|
|
136
|
+
const config = await readConfigForWrite();
|
|
137
|
+
if (config.repos?.[repositoryId] === profileName)
|
|
138
|
+
return;
|
|
139
|
+
config.repos = { ...config.repos, [repositoryId]: profileName };
|
|
140
|
+
await writeConfig(config);
|
|
141
|
+
}
|
|
120
142
|
export async function readRepoLink(root) {
|
|
121
143
|
let raw;
|
|
122
144
|
try {
|
|
@@ -134,11 +156,7 @@ export async function readRepoLink(root) {
|
|
|
134
156
|
throw new Error(`${join(root, REPO_LINK_FILE)} is malformed — it should hold {"repositoryId": "<uuid>"}. ` +
|
|
135
157
|
"Run `gatebolt link` from the repo root to rewrite it, then commit it.");
|
|
136
158
|
}
|
|
137
|
-
|
|
138
|
-
if (typeof data.profile === "string") {
|
|
139
|
-
link.profile = data.profile;
|
|
140
|
-
}
|
|
141
|
-
return link;
|
|
159
|
+
return { repositoryId: data.repositoryId };
|
|
142
160
|
}
|
|
143
161
|
export async function writeRepoLink(root, link) {
|
|
144
162
|
const path = join(root, REPO_LINK_FILE);
|
package/package.json
CHANGED