hyperforge 3.3.0

Multi-forge repository management
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# LFORGE2 Design Clarifications

This document captures critical design decisions and clarifications.

---

## 1. No SSH Host Aliases

**Old approach** (deprecated):
```bash
# ~/.ssh/config
Host github-alice
    HostName github.com
    IdentityFile ~/.ssh/alice_key

# Git remote
git@github-alice:alice/repo.git
```

**New approach**:
Use git's native `core.sshCommand` config per repo:

```bash
# Set per-repo SSH key
git config core.sshCommand "ssh -i ~/.ssh/alice_github"

# Git remote (standard format)
git@github.com:alice/repo.git
```

**Why**:
- Standard git remote URLs (portable, works everywhere)
- Per-repo SSH key configuration via git config
- No global SSH config pollution
- Works in CI/CD without SSH config setup

**Implementation**: LFORGE2-3, LFORGE2-4

---

## 2. Secret Path Structure (Granular Scopes)

Secrets use fully-qualified paths:

```
git/{forge}/{org}/{repo}/{repo_name}/token

Examples:
  git/github/alice/repo/my-tool/token
  git/codeberg/acme-corp/repo/web-app/token
  git/gitlab/bob/repo/lib-core/token

cargo/{user}/{package}/token
npm/@{org}/{package}/token
pypi/{user}/{package}/token
```

**Why granular**:
- Can't predict which repos need which tokens at startup
- Request scopes lazily as operations require them
- Each scope maps to single repo/package operation
- Future: can grant per-repo permissions
- Even though tokens may be same underlying value in vault, scope names are precise

**Org/Repo Extraction**:
From `git@github.com:alice/repo/my-tool.git`:
- Extract everything after `:``alice/repo/my-tool`
- Parse: `alice` (org), `repo/my-tool` (repo path)
- Or from URL: `https://github.com/alice/my-tool.git``alice`, `my-tool`

**Implementation**: PKG-9, LFORGE2-17

---

## 3. Hyperforge Config is Ground Truth

`.hyperforge/config.toml` is authoritative. Git config follows.

**Reconciliation**:
```bash
# Config says:
forges = ["github", "codeberg"]

# Git has:
git remote -v
# origin   git@github.com:...
# gitlab   git@gitlab.com:...

# hyperforge sync --path . will:
# 1. Warn: gitlab remote not in config, will be removed
# 2. Add codeberg remote (missing from git)
# 3. Remove gitlab remote (not in config)
# 4. Require --force to proceed if removing remotes
```

**Import from Git**:
```bash
# Import existing git config into hyperforge
hyperforge init --path . --import-from-git

# Detects existing remotes, builds config from them
```

**Implementation**: LFORGE2-5 (sync command)

---

## 4. Remote URL Construction

Build git remote URLs from `.hyperforge/config.toml`:

```toml
forges = ["github", "codeberg"]
org = "alice"
repo_name = "my-tool"

[ssh]
github = "~/.ssh/alice_github"
codeberg = "~/.ssh/alice_codeberg"
```

**Constructed remotes**:
```bash
# GitHub
git remote add github git@github.com:alice/my-tool.git
git config core.sshCommand "ssh -i ~/.ssh/alice_github"

# Codeberg
git remote add codeberg git@codeberg.org:alice/my-tool.git
git config core.sshCommand "ssh -i ~/.ssh/alice_codeberg"
```

**Forge URL patterns**:
- GitHub: `git@github.com:{org}/{repo}.git`
- Codeberg: `git@codeberg.org:{org}/{repo}.git`
- GitLab: `git@gitlab.com:{org}/{repo}.git`

**Implementation**: LFORGE2-4 (init command)

---

## 5. Lazy Scope Requests

Scopes requested on-demand, not upfront:

```rust
// When hyperforge needs a token:
async fn push_to_github(&self, repo: &str) -> Result<()> {
    // Build scope path
    let scope = format!("git/github/alice/repo/{}/token", repo);

    // This triggers auth request if scope not granted
    let token = self.auth.get_secret(&scope).await?;

    // Use token
    git::push_with_token(repo, &token).await
}
```

**Flow**:
1. Hyperforge requests `git/github/alice/repo/my-tool/token`
2. Auth provider checks if scope granted
3. If not: request approval (queue, timeout)
4. User approves in WorkOS UI or CLI
5. Token returned to hyperforge
6. Cached for session

**User can approve async**:
- Request goes into approval queue
- Hyperforge times out after 30s
- User approves in separate UI
- Next time hyperforge runs, scope is granted

**Implementation**: LFORGE2-17, PKG-9

---

## 6. Publishing: Build First, Then Publish

Validate packages build locally before publishing:

```rust
async fn publish(&self, path: &Path, bump: VersionBump) -> Result<()> {
    // 1. Bump version
    let new_version = self.bump_version(path, bump).await?;

    // 2. Build locally (cargo build, npm run build, etc.)
    self.build_locally(path).await?;

    // 3. Run tests
    self.run_tests(path).await?;

    // 4. If build/test fails, rollback version bump
    if build_failed || test_failed {
        self.rollback_version(path).await?;
        return Err(anyhow!("Build/test failed, rolled back"));
    }

    // 5. Publish to registry
    self.publish_to_registry(path).await?;

    // 6. Commit version bump
    self.commit_version(path, new_version).await?;

    // 7. Tag release
    self.tag_release(path, new_version).await?;

    Ok(())
}
```

**Why**:
- Catch build errors before publishing
- Don't publish broken packages
- Can't unpublish from most registries
- Local validation is fast

**Implementation**: PKG-10, PKG-11

---

## 7. Push: Stop on First Failure

When pushing to multiple forges, stop on first failure:

```rust
async fn push_to_all_forges(&self, path: &Path) -> Result<()> {
    let forges = self.config.forges()?;

    for forge in forges {
        // If this fails, don't try remaining forges
        self.push_to_forge(path, forge).await?;
    }

    Ok(())
}
```

**Why**:
- Can't easily resolve push failures automatically
- User needs to fix issue (auth, conflicts, etc.)
- Better to fail fast than continue with partial state
- User sees first error, fixes it, reruns

**Workspace push**:
Still stop on first repo failure (can't continue safely).

**Implementation**: LFORGE2-7 (push command)

---

## 8. Dry-Run for All Operations

Every command should support `--dry-run`:

```bash
# Preview without changes
hyperforge init --path . --forges github,codeberg --dry-run
hyperforge sync --path . --dry-run
hyperforge push --path . --dry-run
hyperforge publish --path . --bump patch --dry-run
hyperforge workspace push --path . --dry-run
```

**Dry-run behavior**:
- Show what would be done
- Don't modify files
- Don't call APIs
- Don't commit/push

**Implementation**: All command tickets

---

## 9. Workspace Defaults (Directory-Level Config)

`.hyperforge/defaults.toml` at any level provides defaults for child repos:

```
~/projects/
  ├── .hyperforge/
  │   └── defaults.toml       # Applies to all repos in ~/projects/
  ├── alice/
  │   ├── .hyperforge/
  │   │   └── defaults.toml   # Overrides parent, applies to alice repos
  │   ├── tool1/.hyperforge/config.toml  # Inherits from ../defaults.toml
  │   └── tool2/.hyperforge/config.toml
  └── bob/
      └── app/.hyperforge/config.toml    # Inherits from ~/projects/defaults.toml
```

**Inheritance chain**:
1. Load all `defaults.toml` from repo up to root
2. Apply in order: root → ... → parent
3. Repo `config.toml` overrides all defaults

**Example**:
```toml
# ~/projects/.hyperforge/defaults.toml
forges = ["github"]
visibility = "public"

# ~/projects/alice/.hyperforge/defaults.toml
org = "alice"
forges = ["github", "codeberg"]  # Overrides parent

# ~/projects/alice/tool1/.hyperforge/config.toml
repo_name = "tool1"
visibility = "private"  # Overrides defaults

# Effective config for tool1:
# org = "alice"
# repo_name = "tool1"
# forges = ["github", "codeberg"]
# visibility = "private"
```

**When importing**:
```bash
hyperforge remote github pull --org alice

# If no defaults.toml found, prompt:
# "No workspace defaults found. Create .hyperforge/defaults.toml? [Y/n]"
```

**Implementation**: LFORGE2-20 (remote import), LFORGE2-2 (config loading)

---

## 10. Migration Path from Old Hyperforge

**No automatic migration**. Fresh start approach:

**Step 1: Import from forges**
```bash
cd ~/projects/alice
hyperforge remote github pull --org alice --all
```

**Step 2: Workspace operations now work**
```bash
hyperforge workspace push --path .
hyperforge workspace publish --path . --bump patch
```

**Old hyperforge**:
- Keep as-is
- Users migrate repos one-by-one
- Or use `remote pull` to bulk import

**Implementation**: LFORGE2-20

---

## 11. WorkOS Vault Integration

**WorkOS provides**:
- Identity/authentication
- Scope management (permissions)
- Master token issuance
- Vault for secret storage

**Flow**:
```
1. User logs in → WorkOS returns master token
2. Hyperforge starts with master token
3. Needs git/github/alice/repo/tool/token
4. Requests scope from WorkOS (master token + scope)
5. WorkOS checks permissions
6. If granted: returns access token
7. Hyperforge uses access token to get secret from Vault
8. Vault returns actual GitHub token
9. Hyperforge pushes with token
```

**Multi-provider support**:
```toml
# Can route different scopes to different providers
[auth]
default = "workos"

[auth.providers.workos]
type = "workos"
vault_url = "https://vault.workos.com"

[auth.providers.local]
type = "keychain"

[auth.routing]
"git/github/acme-corp/*" = "workos"  # Company secrets
"git/github/alice/*" = "local"       # Personal secrets
```

**Implementation**: LFORGE2-17, PKG-9

---

## Summary of Key Changes to Plans

1. **LFORGE2-0**: New ticket for worktree setup
2.**LFORGE2-20**: New ticket for remote import
3. 🔄 **LFORGE2-2**: Update config schema with inheritance
4. 🔄 **LFORGE2-3**: Update git integration with core.sshCommand
5. 🔄 **LFORGE2-4**: Update remote construction logic
6. 🔄 **LFORGE2-5**: Update sync semantics (config is ground truth)
7. 🔄 **PKG-9**: Update auth with granular scopes
8. 🔄 **All**: Add --dry-run support

Next: Update existing tickets with these clarifications.