From 5feddffa6fd9e0768e107109ac09257443a28f86 Mon Sep 17 00:00:00 2001 From: pasta Date: Fri, 25 Sep 2026 11:50:00 -0500 Subject: [PATCH 1/8] feat(web): read forge-v2 repos through a RepoSource with v1 read-compat A RepoRef is now a v1 repo contract or a forge-v2 repo document, and every reader (refs, config, packs and chunks, issues and PRs with events and authorEvents, comments, reviews, stars, members) builds its queries through one RepoSource. forge-v2 queries are scoped by repoId, folds run FORGE_RULES_V2 (event + authorEvent, well-formedness, approvals), pack copies are read in orderPackCopies order, and chunk reads name the uploader. Resolution tries the forge-v2 repo by (owner, name) before the v1 registry; routes accept ?repo= and ?contract= pins and a DPNS owner name. Landing and profile read forge-core directly (recent repos with provable star and issue counts in one composite read; owned and member repos). Permission-gated UI uses membership documents on v2. On a network without forge-v2 the v1 surfaces keep working and say so. Adds seed-v2-fixture.mjs (the moutai fixture), unit tests over a filtering mock SDK, a live devnet smoke, and v2-reads.spec.ts for devnet builds (E2E_DEVNET=moutai). Co-Authored-By: Claude Opus 5.5 (1M context) --- forge-contracts/scripts/seed-v2-fixture.mjs | 403 ++++++++++++++++++ forge-web/app/new/page.tsx | 15 +- forge-web/app/page.tsx | 42 +- forge-web/components/app-header.tsx | 5 +- forge-web/components/profile-content.tsx | 72 +++- forge-web/components/repo-card.tsx | 44 +- forge-web/components/repo/approvals.tsx | 88 ++++ forge-web/components/repo/clone-box.tsx | 12 +- forge-web/components/repo/issue-content.tsx | 31 +- forge-web/components/repo/issues-content.tsx | 14 +- forge-web/components/repo/pull-content.tsx | 59 ++- forge-web/components/repo/pull-diff.tsx | 51 ++- forge-web/components/repo/pulls-content.tsx | 6 +- forge-web/components/repo/repo-header.tsx | 34 +- forge-web/components/repo/repo-rail.tsx | 12 +- forge-web/components/repo/repo-scaffold.tsx | 8 +- .../components/repo/settings-content.tsx | 126 +++++- .../components/repo/stargazers-content.tsx | 21 +- forge-web/components/repo/v2-writes-note.tsx | 18 + forge-web/components/ui/cost-preview.tsx | 2 +- forge-web/components/ui/network-badge.tsx | 46 +- forge-web/components/ui/trust-panel.tsx | 8 +- forge-web/e2e/a11y.spec.ts | 45 +- forge-web/e2e/fallback-browse.spec.ts | 5 +- forge-web/e2e/helpers.ts | 50 +++ forge-web/e2e/read-paths.spec.ts | 4 + forge-web/e2e/v2-reads.spec.ts | 157 +++++++ forge-web/e2e/zero-backend.spec.ts | 5 +- forge-web/hooks/use-browse.ts | 8 +- forge-web/hooks/use-fallback-browse.ts | 10 +- forge-web/hooks/use-query-param.ts | 30 +- forge-web/hooks/use-repo.ts | 59 ++- forge-web/hooks/use-sdk.ts | 17 +- forge-web/lib/repo/collab.ts | 8 +- forge-web/lib/repo/config.ts | 26 +- forge-web/lib/repo/contract.ts | 93 +++- forge-web/lib/repo/index.ts | 48 ++- forge-web/lib/repo/issues.ts | 269 +++++++++--- forge-web/lib/repo/members.ts | 149 +++++++ forge-web/lib/repo/packs.test.ts | 8 +- forge-web/lib/repo/packs.ts | 115 ++++- forge-web/lib/repo/pagination.test.ts | 4 +- forge-web/lib/repo/refs.test.ts | 4 +- forge-web/lib/repo/refs.ts | 60 +-- forge-web/lib/repo/resolveRepo.ts | 229 +++++++++- forge-web/lib/repo/social.ts | 122 ++++++ forge-web/lib/repo/source.ts | 129 ++++++ forge-web/lib/repo/tokens.test.ts | 12 +- forge-web/lib/repo/tokens.ts | 10 +- forge-web/lib/repo/v2.live.test.ts | 98 +++++ forge-web/lib/repo/v2.test.ts | 396 +++++++++++++++++ forge-web/lib/repo/write.live.test.ts | 5 +- forge-web/lib/repo/writes.ts | 28 +- forge-web/lib/view/browse-fallback.test.ts | 36 +- forge-web/lib/view/browse-fallback.ts | 32 +- forge-web/lib/view/browse-source.test.ts | 5 +- forge-web/lib/view/browse-source.ts | 128 ++++-- forge-web/lib/view/discovery.ts | 262 +++++++++--- forge-web/lib/view/index.ts | 1 + forge-web/lib/view/issues-view.ts | 186 +++++--- forge-web/lib/view/pull-actions.test.ts | 18 + forge-web/lib/view/pull-actions.ts | 19 +- forge-web/lib/view/repo-view.ts | 56 ++- forge-web/lib/view/trust.test.ts | 5 + forge-web/lib/view/trust.ts | 8 +- forge-web/playwright.config.ts | 10 +- 66 files changed, 3466 insertions(+), 620 deletions(-) create mode 100644 forge-contracts/scripts/seed-v2-fixture.mjs create mode 100644 forge-web/components/repo/approvals.tsx create mode 100644 forge-web/components/repo/v2-writes-note.tsx create mode 100644 forge-web/e2e/v2-reads.spec.ts create mode 100644 forge-web/lib/repo/members.ts create mode 100644 forge-web/lib/repo/social.ts create mode 100644 forge-web/lib/repo/source.ts create mode 100644 forge-web/lib/repo/v2.live.test.ts create mode 100644 forge-web/lib/repo/v2.test.ts diff --git a/forge-contracts/scripts/seed-v2-fixture.mjs b/forge-contracts/scripts/seed-v2-fixture.mjs new file mode 100644 index 000000000..c1656f9cf --- /dev/null +++ b/forge-contracts/scripts/seed-v2-fixture.mjs @@ -0,0 +1,403 @@ +#!/usr/bin/env node +// seed-v2-fixture.mjs — seed the forge-v2 read fixture that forge-web's devnet Playwright +// specs and live tests read. +// +// node forge-contracts/scripts/seed-v2-fixture.mjs [--network devnet --devnet-name moutai] +// +// Needs `npm ci` in forge-contracts/sdk-v2 (evo-sdk 4.2, protocol 14) and the devnet test +// identities in ~/.config/dash-forge/test-identities// (OWNER, MAINTAINER, COLLAB, +// CONTRIB). +// +// It writes, as the forge-v2 contracts define them (docs/contracts/forge-v2.md): +// * repo `forge-v2-demo` owned by OWNER; OWNER and MAINTAINER as maintainers, COLLAB as a +// writer; a config protecting refs/heads/main; +// * one deterministic git history (three commits, a feature branch, a tag) packed with git, +// stored on Platform as `chunk` documents behind a kind-0 `packManifest`, plus a kind-1 +// objectLocator over it, so the web app browses it through the published index; +// * refs: main by protectedRefUpdate (two updates), the feature branch by COLLAB's +// refUpdate, the tag by OWNER; +// * issues, a PR still open with an approval, a merged PR, comments, `event`s and an +// `authorEvent`, a star; +// * repo `forge-v2-empty` owned by MAINTAINER, with no refs (the empty-repo state). +// +// The git-remote-dash v2 push path is not there yet (forge-core PR C), which is why the +// pack and the locator are written here directly. The chunk layout is forge-core +// `pack::split` (4900-byte fields, three per chunk); the locator is `pack/locator.rs` +// (fanout || 36-byte rows, deltaChainSpan = the sentinel so readers walk each base). +// +// Idempotent: the result of every step is recorded in +// ~/.cache/dash-forge/seed-v2-.json and a rerun skips what is recorded. Delete that +// file (and pick new repo names) to seed from scratch. + +import { execFileSync } from 'node:child_process'; +import { createHash } from 'node:crypto'; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; +import { homedir, tmpdir } from 'node:os'; +import { dirname, join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import { loadEvoSdk } from './deploy-v2.mjs'; + +const HERE = dirname(fileURLToPath(import.meta.url)); +const ROOT = resolve(HERE, '..'); + +const DEMO = 'forge-v2-demo'; +const EMPTY = 'forge-v2-empty'; +const FIELD_MAX = 4900; +const FIELDS_PER_DOC = 3; +const FANOUT_LEN = 1024; +const ROW_LEN = 36; +const SPAN_SENTINEL = 0xffffffff; +const EVENT = { close: 1, reopen: 2, merge: 3, labelAdd: 4 }; + +const log = (m) => console.error(`${new Date().toISOString().slice(11, 19)} ${m}`); + +function args() { + const out = { network: 'devnet', 'devnet-name': 'moutai' }; + const a = process.argv.slice(2); + for (let i = 0; i < a.length; i += 2) out[a[i].replace(/^--/, '')] = a[i + 1]; + return out; +} + +const sha256 = (bytes) => createHash('sha256').update(bytes).digest(); + +// --------------------------------------------------------------------------- +// The deterministic git history +// --------------------------------------------------------------------------- + +function git(cwd, argv, env = {}) { + return execFileSync('git', argv, { + cwd, + env: { ...process.env, GIT_CONFIG_NOSYSTEM: '1', HOME: cwd, ...env }, + maxBuffer: 64 << 20, + }); +} + +function buildHistory() { + const dir = mkdtempSync(join(tmpdir(), 'forge-v2-fixture-')); + git(dir, ['init', '-q', '-b', 'main']); + const commit = (message, when, files) => { + for (const [path, body] of Object.entries(files)) { + mkdirSync(dirname(join(dir, path)), { recursive: true }); + writeFileSync(join(dir, path), body); + } + git(dir, ['add', '-A']); + const date = `${when} +0000`; + git(dir, ['commit', '-q', '-m', message], { + GIT_AUTHOR_NAME: 'Forge Fixture', + GIT_AUTHOR_EMAIL: 'fixture@dash-forge.invalid', + GIT_COMMITTER_NAME: 'Forge Fixture', + GIT_COMMITTER_EMAIL: 'fixture@dash-forge.invalid', + GIT_AUTHOR_DATE: date, + GIT_COMMITTER_DATE: date, + }); + return git(dir, ['rev-parse', 'HEAD']).toString().trim(); + }; + + const c1 = commit('Initial import', '2026-09-01T12:00:00', { + 'README.md': '# forge-v2-demo\n\nThe forge-v2 read fixture: a repository that lives in the shared\n**forge-core** and **forge-collab** contracts (protocol 14).\n\n- `src/` holds the code\n- `lib/` holds helpers\n', + 'src/main.rs': 'fn main() {\n println!("hello from forge-v2");\n}\n', + 'lib/util.ts': 'export function add(a: number, b: number): number {\n return a + b\n}\n', + }); + const c2 = commit('Document the fold rules', '2026-09-02T12:00:00', { + 'docs/rules.md': '# Rules\n\nIssue and PR state is folded from `event` and `authorEvent` documents.\n', + 'src/main.rs': 'fn main() {\n println!("hello from forge-v2");\n println!("reads are proof-checked");\n}\n', + }); + git(dir, ['tag', 'v0.1.0', c1]); + git(dir, ['checkout', '-q', '-b', 'feature/greeting']); + const c3 = commit('Greet by name', '2026-09-03T12:00:00', { + 'src/main.rs': 'fn main() {\n let name = std::env::args().nth(1).unwrap_or("forge".into());\n println!("hello, {name}");\n println!("reads are proof-checked");\n}\n', + }); + git(dir, ['checkout', '-q', 'main']); + return { dir, commits: { c1, c2, c3 } }; +} + +/** `git pack-objects --stdout --all` needs rev-list input; feed it explicitly. */ +function packAll(dir) { + const revs = git(dir, ['rev-list', '--objects', '--all']).toString(); + return execFileSync('git', ['pack-objects', '--stdout', '-q'], { + cwd: dir, + input: revs, + maxBuffer: 64 << 20, + }); +} + +/** Locator rows for one pack (packRef 0), from `git verify-pack -v`. */ +function buildLocator(dir, pack) { + const packPath = join(dir, 'fixture.pack'); + writeFileSync(packPath, pack); + git(dir, ['index-pack', '-o', join(dir, 'fixture.idx'), packPath]); + const out = git(dir, ['verify-pack', '-v', join(dir, 'fixture.idx')]).toString(); + const rows = []; + for (const line of out.split('\n')) { + const m = /^([0-9a-f]{40}) (\w+)\s+(\d+) (\d+) (\d+)(?: (\d+) ([0-9a-f]{40}))?/.exec(line); + if (!m) continue; + rows.push({ oid: m[1], length: Number(m[4]), offset: Number(m[5]), depth: m[6] ? Number(m[6]) : 0 }); + } + rows.sort((a, b) => (a.oid < b.oid ? -1 : a.oid > b.oid ? 1 : 0)); + const bytes = Buffer.alloc(FANOUT_LEN + rows.length * ROW_LEN); + const counts = new Array(256).fill(0); + for (const r of rows) counts[parseInt(r.oid.slice(0, 2), 16)]++; + let cum = 0; + for (let i = 0; i < 256; i++) { + cum += counts[i]; + bytes.writeUInt32BE(cum, i * 4); + } + let at = FANOUT_LEN; + for (const r of rows) { + Buffer.from(r.oid, 'hex').copy(bytes, at); + bytes.writeUInt16BE(0, at + 20); + bytes.writeUIntBE(r.offset, at + 22, 5); + bytes.writeUInt32BE(r.length, at + 27); + bytes.writeUInt32BE(SPAN_SENTINEL, at + 31); + bytes[at + 35] = Math.min(r.depth, 255); + at += ROW_LEN; + } + return { bytes, objectCount: rows.length }; +} + +/** forge-core `pack::split`: fill 4900-byte fields, three per chunk. */ +function split(data) { + const chunks = []; + for (let at = 0; at < data.length; at += FIELD_MAX * FIELDS_PER_DOC) { + const doc = data.subarray(at, at + FIELD_MAX * FIELDS_PER_DOC); + const fields = []; + for (let f = 0; f < doc.length; f += FIELD_MAX) fields.push(doc.subarray(f, f + FIELD_MAX)); + chunks.push(fields); + } + return chunks; +} + +// --------------------------------------------------------------------------- +// Platform writes +// --------------------------------------------------------------------------- + +async function main() { + const a = args(); + const network = a.network; + const devnetName = network === 'devnet' ? a['devnet-name'] : null; + const key = devnetName ? `devnet-${devnetName}` : network; + const dep = JSON.parse(readFileSync(join(ROOT, 'deployments', `${key}.json`), 'utf8')); + const core = dep.v2?.forgeCore?.contractId; + const collab = dep.v2?.forgeCollab?.contractId; + if (!core || !collab) throw new Error(`no forge-v2 deployment recorded for ${key}`); + + const evo = await loadEvoSdk(); + const { EvoSDK, Document, IdentityPublicKey, IdentitySigner, PrivateKey } = evo; + const sdk = new EvoSDK({ + network, + trusted: true, + ...(devnetName ? { devnetName } : {}), + ...(dep.dapiAddresses ? { addresses: dep.dapiAddresses } : {}), + settings: { timeoutMs: 30000 }, + }); + await sdk.connect(); + + const idDir = join(homedir(), '.config/dash-forge/test-identities', key); + const load = (name) => { + const rec = JSON.parse(readFileSync(join(idDir, `${name}.identity.json`), 'utf8')); + const k = rec.identityKeys.find((x) => x.purpose === 'AUTHENTICATION' && x.securityLevel === 'HIGH'); + const identityKey = new IdentityPublicKey({ + keyId: k.id, + purpose: k.purpose, + securityLevel: k.securityLevel, + keyType: k.keyType, + isReadOnly: false, + data: Buffer.from(k.publicKeyHex, 'hex'), + }); + const signer = new IdentitySigner(); + signer.addKey(PrivateKey.fromWIF(k.privateKeyWif)); + return { name, id: rec.identityId, identityKey, signer }; + }; + const OWNER = load('OWNER'); + const MAINTAINER = load('MAINTAINER'); + const COLLAB = load('COLLAB'); + const CONTRIB = load('CONTRIB'); + + const statePath = join(homedir(), '.cache/dash-forge', `seed-v2-${key}.json`); + mkdirSync(dirname(statePath), { recursive: true }); + const state = existsSync(statePath) ? JSON.parse(readFileSync(statePath, 'utf8')) : {}; + const save = () => writeFileSync(statePath, `${JSON.stringify(state, null, 2)}\n`); + + const b58 = (s) => Buffer.from(evo.Identifier.fromBase58(s).toBytes()); + const version = sdk.version(); + + /** Create one document (once: the step name is recorded with its id). */ + async function create(step, who, contractId, documentTypeName, data) { + if (state[step]) return state[step]; + const base = new Document({ properties: {}, documentTypeName, dataContractId: contractId, ownerId: who.id }); + const document = Document.fromObject({ ...base.toObject(), ...data }, version); + const created = await sdk.documents.create({ document, identityKey: who.identityKey, signer: who.signer }); + const id = created.id.toBase58(); + state[step] = id; + save(); + log(`${step}: ${documentTypeName} ${id} (${who.name})`); + return id; + } + + // --- repos, membership, config ----------------------------------------------------- + const repoId = await create('repo', OWNER, core, 'repo', { + name: DEMO, + visibility: 'public', + displayName: 'forge-v2 demo', + description: 'The forge-v2 read fixture: code, issues and pull requests in the shared contracts.', + defaultBranch: 'main', + topics: ['fixture', 'forge-v2'], + }); + const R = b58(repoId); + await create('maintainer:owner', OWNER, core, 'maintainer', { repoId: R, memberId: b58(OWNER.id) }); + await create('config', OWNER, core, 'config', { + repoId: R, + defaultBranch: 'main', + protectedPatterns: ['refs/heads/main'], + backend: { mode: 0 }, + }); + await create('maintainer:maintainer', OWNER, core, 'maintainer', { repoId: R, memberId: b58(MAINTAINER.id) }); + await create('writer:collab', OWNER, core, 'writer', { repoId: R, memberId: b58(COLLAB.id) }); + + const emptyId = await create('repo:empty', MAINTAINER, core, 'repo', { + name: EMPTY, + visibility: 'public', + description: 'A forge-v2 repository with nothing pushed yet.', + }); + const E = b58(emptyId); + await create('empty:maintainer', MAINTAINER, core, 'maintainer', { repoId: E, memberId: b58(MAINTAINER.id) }); + await create('empty:config', MAINTAINER, core, 'config', { repoId: E, defaultBranch: 'main' }); + + // --- content: pack + locator on Platform -------------------------------------------- + const { dir, commits } = buildHistory(); + if (state.commits && JSON.stringify(state.commits) !== JSON.stringify(commits)) { + throw new Error(`the fixture history changed (${JSON.stringify(commits)} vs recorded ${JSON.stringify(state.commits)})`); + } + state.commits = commits; + save(); + const pack = packAll(dir); + const packHash = sha256(pack); + const locator = buildLocator(dir, pack); + const locatorHash = sha256(locator.bytes); + + async function storeArtifact(label, bytes, hash, kind, objectCount) { + const chunks = split(bytes); + for (let seq = 0; seq < chunks.length; seq++) { + const data = { repoId: R, packHash: hash, seq }; + chunks[seq].forEach((field, i) => { + data[`d${i}`] = Uint8Array.from(field); + }); + await create(`${label}:chunk:${seq}`, OWNER, core, 'chunk', data); + } + return create(`${label}:manifest`, OWNER, core, 'packManifest', { + repoId: R, + packHash: hash, + kind, + sizeBytes: bytes.length, + objectCount, + chunkCount: chunks.length, + storage: 0, + offsetIndexParts: 0, + }); + } + await storeArtifact('pack', pack, packHash, 0, locator.objectCount); + await storeArtifact('locator', locator.bytes, locatorHash, 1, locator.objectCount); + + // --- refs --------------------------------------------------------------------------- + const oid = (hex) => Buffer.from(hex, 'hex'); + const refHash = (name) => sha256(Buffer.from(name)); + await create('ref:main:1', OWNER, core, 'protectedRefUpdate', { + repoId: R, refNameHash: refHash('refs/heads/main'), refName: 'refs/heads/main', newOid: oid(commits.c1), + }); + await create('ref:main:2', MAINTAINER, core, 'protectedRefUpdate', { + repoId: R, refNameHash: refHash('refs/heads/main'), refName: 'refs/heads/main', prevOid: oid(commits.c1), newOid: oid(commits.c2), + }); + await create('ref:feature', COLLAB, core, 'refUpdate', { + repoId: R, refNameHash: refHash('refs/heads/feature/greeting'), refName: 'refs/heads/feature/greeting', newOid: oid(commits.c3), + }); + await create('ref:tag', OWNER, core, 'refUpdate', { + repoId: R, refNameHash: refHash('refs/tags/v0.1.0'), refName: 'refs/tags/v0.1.0', newOid: oid(commits.c1), + }); + + // --- issues ------------------------------------------------------------------------- + const issue = (n, who, title, body) => + create(`issue:${n}`, who, collab, 'issue', { repoId: R, number: n, title, body }); + const i1 = await issue(1, CONTRIB, 'README should explain the event split', 'The README does not say why `authorEvent` is its own type.'); + const i2 = await issue(2, CONTRIB, 'Duplicate of #1', 'Opened twice by mistake.'); + const i3 = await issue(3, CONTRIB, 'Add a rules page', 'A page documenting the fold would help.'); + const ev = (step, who, type, targetId, targetNumber, kind, extra = {}) => + create(step, who, collab, type, { repoId: R, targetId: b58(targetId), targetNumber, kind, ...extra }); + await ev('issue:2:author-close', CONTRIB, 'authorEvent', i2, 2, EVENT.close); + await ev('issue:3:label', MAINTAINER, 'event', i3, 3, EVENT.labelAdd, { value: 'docs' }); + await ev('issue:3:close', MAINTAINER, 'event', i3, 3, EVENT.close); + await ev('issue:1:label', COLLAB, 'event', i1, 1, EVENT.labelAdd, { value: 'question' }); + const comment = (step, who, targetId, body) => + create(step, who, collab, 'comment', { repoId: R, targetId: b58(targetId), body }); + await comment('issue:1:comment:1', MAINTAINER, i1, 'Good point: the split is in docs/contracts/forge-v2.md §3.'); + await comment('issue:3:comment:1', MAINTAINER, i3, 'Done in docs/rules.md; closing.'); + + // --- pull requests ------------------------------------------------------------------ + const patch = (n, who, title, body, headOid, sourceRef) => + create(`patch:${n}`, who, collab, 'patch', { + repoId: R, + number: n, + title, + body, + baseRefNameHash: refHash('refs/heads/main'), + baseRefName: 'refs/heads/main', + sourceRepoId: R, + sourceRefNameHash: refHash(sourceRef), + sourceRefName: sourceRef, + headOid: oid(headOid), + }); + const p1 = await patch(1, COLLAB, 'Greet by name', 'Reads the name from argv.', commits.c3, 'refs/heads/feature/greeting'); + const p2 = await patch(2, MAINTAINER, 'Document the fold rules', 'Adds docs/rules.md.', commits.c2, 'refs/heads/main'); + await create('patch:1:review', MAINTAINER, collab, 'review', { + repoId: R, patchId: b58(p1), verdict: 1, commitOid: oid(commits.c3), body: 'Looks good.', + }); + await comment('patch:1:comment:1', OWNER, p1, 'Nice. Waiting on one more review.'); + await ev('patch:2:merge', OWNER, 'event', p2, 2, EVENT.merge, { oid: oid(commits.c2) }); + + // --- social --------------------------------------------------------------------------- + // `star` is indexOnly: evo-sdk 4.2's strict wait refuses that transition family after it + // lands, so the star is confirmed by a count read instead. + if (!state['star:contrib']) { + const starCount = async () => { + const counts = await sdk.documents.count({ + dataContractId: collab, + documentTypeName: 'star', + where: [['repoId', '==', repoId]], + }); + let n = 0n; + for (const v of counts.values()) n += v; + return n; + }; + if ((await starCount()) === 0n) { + const base = new Document({ properties: {}, documentTypeName: 'star', dataContractId: collab, ownerId: CONTRIB.id }); + const document = Document.fromObject({ ...base.toObject(), repoId: R }, version); + try { + await sdk.documents.create({ document, identityKey: CONTRIB.identityKey, signer: CONTRIB.signer }); + } catch (e) { + if (!/VerifiedDocuments snapshot/.test(String(e?.message ?? e))) throw e; + } + for (let i = 0; i < 10 && (await starCount()) === 0n; i++) await new Promise((r) => setTimeout(r, 2000)); + if ((await starCount()) === 0n) throw new Error('the star did not land'); + } + state['star:contrib'] = 'indexOnly'; + save(); + log('star:contrib'); + } + + const summary = { + network: key, + forgeCore: core, + forgeCollab: collab, + demo: { owner: OWNER.id, name: DEMO, repoId }, + empty: { owner: MAINTAINER.id, name: EMPTY, repoId: emptyId }, + commits, + packHash: packHash.toString('hex'), + locatorHash: locatorHash.toString('hex'), + }; + console.log(JSON.stringify(summary, null, 2)); +} + +main().catch((e) => { + console.error(e?.stack ?? e?.message ?? String(e)); + process.exit(1); +}); diff --git a/forge-web/app/new/page.tsx b/forge-web/app/new/page.tsx index 6a1c2e0b7..e0946bd8b 100644 --- a/forge-web/app/new/page.tsx +++ b/forge-web/app/new/page.tsx @@ -8,14 +8,15 @@ import { useMemo, useState } from 'react' import { useRouter } from 'next/navigation' -import { GitBranch, Hammer, Lock } from 'lucide-react' +import { GitBranch, Hammer, Lock, Terminal } from 'lucide-react' import { AppShell } from '@/components/app-shell' import { Button } from '@/components/ui/button' import { Field, Input, Textarea } from '@/components/ui/input' import { CostPreview } from '@/components/ui/cost-preview' import { ConfirmDialog } from '@/components/confirm-dialog' import { EmptyState } from '@/components/ui/states' -import { NotDeployedState, isRegistryDeployed } from '@/components/ui/network-badge' +import { NotDeployedState, isRegistryDeployed, isV2Deployed } from '@/components/ui/network-badge' +import { ACTIVE_NETWORK } from '@/lib/constants' import { useAuth } from '@/contexts/auth-context' import { useUiStore } from '@/hooks/use-ui-store' import { useSdk } from '@/hooks/use-sdk' @@ -70,7 +71,15 @@ export default function NewRepoPage(): JSX.Element { if (!isRegistryDeployed()) { return ( - + {isV2Deployed() ? ( + .`} + /> + ) : ( + + )} ) } diff --git a/forge-web/app/page.tsx b/forge-web/app/page.tsx index 88e29d3b2..0570dfa39 100644 --- a/forge-web/app/page.tsx +++ b/forge-web/app/page.tsx @@ -15,20 +15,28 @@ import { RepoCard } from '@/components/repo-card' import { Button } from '@/components/ui/button' import { VerificationChip } from '@/components/ui/verification-chip' import { EmptyState, ErrorState, Spinner } from '@/components/ui/states' -import { NotDeployedState, isRegistryDeployed } from '@/components/ui/network-badge' +import { + NotDeployedState, + V2NotDeployedNote, + isForgeDeployed, + isRegistryDeployed, + isV2Deployed, +} from '@/components/ui/network-badge' import { useSdk } from '@/hooks/use-sdk' import { useAsync } from '@/hooks/use-async' -import { connectionTrust, deriveConnectionTrust, listRecentRepos } from '@/lib/view' +import { connectionTrust, deriveConnectionTrust, listRecentRepos, type DiscoveredRepo } from '@/lib/view' export default function LandingPage(): JSX.Element { const { sdk, ready, trusted, error: sdkError, network } = useSdk() const proofs = deriveConnectionTrust(network, connectionTrust(ready, trusted)) - const deployed = isRegistryDeployed() + const deployed = isForgeDeployed() + const v2 = isV2Deployed() const feed = useAsync( () => listRecentRepos(sdk!, { network, limit: 24 }), [ready, network], { enabled: deployed && ready && sdk !== null }, ) + const total = feed.data ? feed.data.v2.length + feed.data.v1.length : 0 return ( @@ -71,7 +79,7 @@ export default function LandingPage(): JSX.Element {

Recent repos

- {feed.loading ? : null} + {feed.loading ? : null}
{!deployed ? ( @@ -80,11 +88,11 @@ export default function LandingPage(): JSX.Element { ) : feed.error ? ( - ) : feed.data && feed.data.length === 0 ? ( + ) : feed.data && total === 0 ? (

- Push and pull with the git-remote-dash helper. Contract{' '} - + Push and pull with the git-remote-dash helper.{' '} + {home.repo.kind === 'v1' ? ( + <> + Contract + + ) : ( + <> + Repo + + )}

diff --git a/forge-web/components/repo/issue-content.tsx b/forge-web/components/repo/issue-content.tsx index e6109f8a1..159c55412 100644 --- a/forge-web/components/repo/issue-content.tsx +++ b/forge-web/components/repo/issue-content.tsx @@ -12,7 +12,7 @@ import { useState } from 'react' import { CheckCircle2, CircleDot } from 'lucide-react' import type { RepoHome, IssueThread } from '@/lib/view' import { loadIssueThread, timeAgo } from '@/lib/view' -import { closeTarget, createComment, readViewerHoldings, reopenTarget } from '@/lib/repo' +import { closeTarget, createComment, readViewerPermissions, reopenTarget, repoContractIds, repoKey } from '@/lib/repo' import type { Holdings } from '@/lib/rules' import { previewDocumentCreate } from '@/lib/sdk' import { useSdk } from '@/hooks/use-sdk' @@ -27,6 +27,7 @@ import { Button } from '@/components/ui/button' import { Textarea } from '@/components/ui/input' import { CostPreview } from '@/components/ui/cost-preview' import { EmptyState, ErrorState, LoadingBlock } from '@/components/ui/states' +import { V2WritesNote } from '@/components/repo/v2-writes-note' import { errorMessage } from '@/lib/utils' export function IssueContent({ @@ -36,19 +37,22 @@ export function IssueContent({ home: RepoHome number: number }): JSX.Element { - const { sdk, ready, network } = useSdk([home.repo.contractId]) + const { sdk, ready, network } = useSdk(repoContractIds(home.repo)) + // The web app writes to v1 repos only; forge-v2 writes are the next step (`V2WritesNote`). + const v1 = home.repo.kind === 'v1' ? home.repo : null const { identity, signer } = useAuth() const openLogin = useUiStore((s) => s.openLogin) const { data, loading, error, reload } = useAsync( () => loadIssueThread(sdk!, home.repo, number), - [ready, home.repo.contractId, number], + [ready, repoKey(home.repo), number], { enabled: ready && sdk !== null && Number.isFinite(number) }, ) + // v1: WRITE/MAINTAIN token holdings; forge-v2: a current maintainer/writer document. const holdings = useAsync( - () => readViewerHoldings(sdk!, home.repo, identity!, network), - [ready, home.repo.contractId, identity ?? '', network], + () => readViewerPermissions(sdk!, home.repo, identity!, network), + [ready, repoKey(home.repo), identity ?? '', network], { enabled: ready && sdk !== null && identity !== null }, ) @@ -70,7 +74,7 @@ export function IssueContent({ // rather than silently withholding the control (the PR page does the same for merge). const toggleHint = !canToggle && identity !== null && holdings.settled && holdings.data === null - ? "Couldn't read this repo's token history, so close/reopen permission is unknown." + ? `Couldn't read this repo's ${v1 ? 'token history' : 'members'}, so close/reopen permission is unknown.` : null const postComment = async (): Promise => { @@ -78,11 +82,11 @@ export function IssueContent({ openLogin() return } - if (!sdk || comment.trim() === '') return + if (!sdk || !v1 || comment.trim() === '') return setPosting(true) setCommentError(null) try { - await createComment(sdk, signer, home.repo, { targetId: issue.id, body: comment.trim() }) + await createComment(sdk, signer, v1, { targetId: issue.id, body: comment.trim() }) setComment('') reload() } catch (e) { @@ -93,9 +97,9 @@ export function IssueContent({ } const toggleState = async (): Promise => { - if (!sdk || !signer) return - if (open) await closeTarget(sdk, signer, home.repo, issue.id) - else await reopenTarget(sdk, signer, home.repo, issue.id) + if (!sdk || !signer || !v1) return + if (open) await closeTarget(sdk, signer, v1, issue.id) + else await reopenTarget(sdk, signer, v1, issue.id) reload() } @@ -142,15 +146,16 @@ export function IssueContent({
{canToggle ? ( - ) : null} -
+ {!v1 ? : null} {toggleHint !== null ? (

{toggleHint}

) : null} diff --git a/forge-web/components/repo/issues-content.tsx b/forge-web/components/repo/issues-content.tsx index 58076c752..270f1822f 100644 --- a/forge-web/components/repo/issues-content.tsx +++ b/forge-web/components/repo/issues-content.tsx @@ -11,7 +11,7 @@ import Link from 'next/link' import { CircleDot, CheckCircle2, MessageSquarePlus } from 'lucide-react' import type { RepoHome } from '@/lib/view' import type { IssueView } from '@/lib/repo' -import { createIssue, listIssues } from '@/lib/repo' +import { createIssue, listIssues, repoContractIds, repoKey } from '@/lib/repo' import { previewDocumentCreate } from '@/lib/sdk' import { timeAgo } from '@/lib/view' import { useSdk } from '@/hooks/use-sdk' @@ -24,6 +24,7 @@ import { Dialog } from '@/components/ui/dialog' import { Field, Input, Textarea } from '@/components/ui/input' import { CostPreview } from '@/components/ui/cost-preview' import { EmptyState, ErrorState, LoadingBlock } from '@/components/ui/states' +import { V2WritesNote } from '@/components/repo/v2-writes-note' import type { RepoAddress } from '@/hooks/use-query-param' import { repoHref } from '@/hooks/use-query-param' import { cn, errorMessage } from '@/lib/utils' @@ -31,13 +32,13 @@ import { cn, errorMessage } from '@/lib/utils' type Filter = 'open' | 'closed' | 'all' export function IssuesContent({ home, addr }: { home: RepoHome; addr: RepoAddress }): JSX.Element { - const { sdk, ready } = useSdk([home.repo.contractId]) + const { sdk, ready } = useSdk(repoContractIds(home.repo)) const [filter, setFilter] = useState('open') const [composing, setComposing] = useState(false) const { data, loading, error, reload } = useAsync( () => listIssues(sdk!, home.repo, undefined, 100), - [ready, home.repo.contractId], + [ready, repoKey(home.repo)], { enabled: ready && sdk !== null }, ) @@ -161,7 +162,7 @@ function ComposeIssueDialog({ onCreated: () => void addr: RepoAddress }): JSX.Element { - const { sdk } = useSdk([repo.contractId]) + const { sdk } = useSdk(repoContractIds(repo)) const { identity, signer } = useAuth() const openLogin = useUiStore((s) => s.openLogin) const [title, setTitle] = useState('') @@ -176,7 +177,7 @@ function ComposeIssueDialog({ openLogin() return } - if (!sdk || title.trim() === '') return + if (!sdk || repo.kind !== 'v1' || title.trim() === '') return setPending(true) setError(null) try { @@ -201,7 +202,7 @@ function ComposeIssueDialog({ footer={ <> - @@ -215,6 +216,7 @@ function ComposeIssueDialog({