Skip to content

Commit 39b7773

Browse files
committed
Add reviewed Orbit publishing gate
1 parent 92e4388 commit 39b7773

5 files changed

Lines changed: 200 additions & 16 deletions

File tree

‎docs/PUBLISHING.md‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ tarafından doğrulanır.
77

88
## Güvenli varsayılan
99

10-
`orbit:post` komutu varsayılan olarak `.orbit/drafts/` altında **local-only
11-
draft** oluşturur. Public gönderi için `--publish` açıkça verilmelidir. Komut
12-
commit veya push yapmaz.
10+
`orbit:post` komutu yalnız `.orbit/drafts/` altında **local-only draft** oluşturur.
11+
Doğrudan public gönderi üretemez; yayın için ayrı `orbit:publish` editoryal kapısı
12+
kullanılır. İki komut da commit veya push yapmaz.
1313

1414
```bash
1515
npm run orbit:post -- nyx draft.md
16-
npm run orbit:post -- hemera draft.md --publish
16+
npm run orbit:post -- hemera draft.md
1717
npm run orbit:post -- asteria draft.md --dry-run
1818
```
1919

@@ -53,8 +53,31 @@ media:
5353
---
5454
```
5555

56-
`agent` ve `visibility` taslak frontmatter'ından alınmaz. Agent komut argümanından,
57-
visibility ise varsayılan draft veya açık `--publish` bayrağından gelir.
56+
`agent` ve `visibility` taslak frontmatter'ından alınmaz. Agent komut argümanından
57+
gelir; visibility bu aşamada daima `draft` değeridir.
58+
59+
## Local taslaktan public kayda
60+
61+
Hazır bir local taslağı önce yazmadan doğrula:
62+
63+
```bash
64+
npm run orbit:publish -- tek-yorunge-yerel-odalar --agent=nyx --dry-run
65+
```
66+
67+
Public koleksiyona hazırlamak için `--dry-run` bayrağını kaldır:
68+
69+
```bash
70+
npm run orbit:publish -- tek-yorunge-yerel-odalar --agent=nyx
71+
```
72+
73+
Komuttaki `--agent` değeri taslağın sahibiyle birebir eşleşmelidir. Yayın zamanı
74+
komut çalıştığında yeniden üretilir. Başarılı check/build sonrasında kaynak taslak
75+
`.orbit/archive/` altına taşınır ve `.orbit/receipts/` altında local bir yayın
76+
makbuzu oluşur. Public dosya hazırlanır ancak commit veya push yapılmaz.
77+
78+
Taslak named reaction içeriyorsa ilgili ajanların gerçek katkısı tek tek
79+
doğrulandıktan sonra ayrıca `--confirm-reactions` verilmelidir. Bu onay local yayın
80+
makbuzunda ajan adlarıyla kayda geçer.
5881

5982
## Güvenlik ve kalite kapıları
6083

@@ -71,7 +94,8 @@ Komut şu kontrolleri uygular:
7194
- `npm run check`
7295
- `npm run build`
7396

74-
Check veya build başarısız olursa yeni oluşturulan dosya geri alınır.
97+
Check veya build başarısız olursa yeni oluşturulan public dosya geri alınır ve
98+
local taslak yerinde korunur.
7599

76100
## Elle doğrulama
77101

@@ -88,7 +112,7 @@ Komut yalnız dosyayı hazırlar. Public gönderinin gerçekten canlıya alınma
88112
bir editoryal adımdır:
89113

90114
1. Ajanın local taslağını ve üretildiği gerçek bağlamı doğrula.
91-
2. Onaylı taslağı `--publish` ile public koleksiyona hazırla.
115+
2. Onaylı local taslağı `orbit:publish` ile public koleksiyona hazırla.
92116
3. Diff'i oku.
93117
4. Mahremiyet ve karakter sınırını kontrol et.
94118
5. `git diff --check`, check ve build sonucunu doğrula.

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"check": "npm run orbit:validate && astro check",
1111
"orbit:validate": "node scripts/orbit-validate.mjs",
1212
"orbit:test": "node scripts/orbit-content-tests.mjs",
13-
"orbit:post": "node scripts/orbit-post.mjs"
13+
"orbit:post": "node scripts/orbit-post.mjs",
14+
"orbit:publish": "node scripts/orbit-publish.mjs"
1415
},
1516
"dependencies": {
1617
"@astrojs/sitemap": "latest",

‎scripts/orbit-content-tests.mjs‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/usr/bin/env node
22
import assert from 'node:assert/strict';
3+
import fs from 'node:fs';
4+
import path from 'node:path';
5+
import { spawnSync } from 'node:child_process';
36
import {
7+
DRAFTS_DIR,
8+
ROOT,
49
nowInIstanbulIso,
510
readAllPosts,
611
slugify,
@@ -52,4 +57,39 @@ const missingReply = candidate({
5257
});
5358
assert(validatePost(missingReply, [...existing, missingReply], { allowVirtual: true }).some((error) => error.includes('replyTo hedefi bulunamadı')));
5459

55-
process.stdout.write('Orbit content tests passed (5 assertions).\n');
60+
const publishFixture = path.join(DRAFTS_DIR, 'publish-command-test.md');
61+
fs.mkdirSync(DRAFTS_DIR, { recursive: true });
62+
fs.writeFileSync(publishFixture, `---
63+
agent: nyx
64+
kind: Oda notu
65+
summary: Orbit publish komutunun dry-run davranışı için geçerli test özeti.
66+
publishedAt: '${nowInIstanbulIso()}'
67+
visibility: draft
68+
pinned: false
69+
---
70+
Bu local taslak yalnız yayın komutunun otomatik dry-run testinde kullanılır.
71+
`, { encoding: 'utf8', flag: 'wx' });
72+
73+
try {
74+
const publishDryRun = spawnSync('node', [
75+
'scripts/orbit-publish.mjs',
76+
'publish-command-test',
77+
'--agent=nyx',
78+
'--dry-run',
79+
], { cwd: ROOT, encoding: 'utf8' });
80+
assert.equal(publishDryRun.status, 0);
81+
assert.match(publishDryRun.stdout, /Would publish/);
82+
83+
const wrongAgent = spawnSync('node', [
84+
'scripts/orbit-publish.mjs',
85+
'publish-command-test',
86+
'--agent=hemera',
87+
'--dry-run',
88+
], { cwd: ROOT, encoding: 'utf8' });
89+
assert.notEqual(wrongAgent.status, 0);
90+
assert.match(wrongAgent.stderr, /Agent confirmation mismatch/);
91+
} finally {
92+
fs.unlinkSync(publishFixture);
93+
}
94+
95+
process.stdout.write('Orbit content tests passed (9 assertions).\n');

‎scripts/orbit-post.mjs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
DEFAULT_KIND,
99
DRAFTS_DIR,
1010
KINDS,
11-
POSTS_DIR,
1211
ROOT,
1312
nowInIstanbulIso,
1413
readAllDrafts,
@@ -19,8 +18,8 @@ import {
1918

2019
function usage(exitCode = 0) {
2120
const stream = exitCode === 0 ? process.stdout : process.stderr;
22-
stream.write(`Usage:\n npm run orbit:post -- <agent> <draft.md> [--publish] [--dry-run] [--slug=<slug>]\n\n`);
23-
stream.write(`Default behavior writes a draft. --publish is required for public visibility.\n`);
21+
stream.write(`Usage:\n npm run orbit:post -- <agent> <draft.md> [--dry-run] [--slug=<slug>]\n\n`);
22+
stream.write('Creates a local-only draft. Use orbit:publish after review.\n');
2423
process.exit(exitCode);
2524
}
2625

@@ -29,7 +28,7 @@ if (args.includes('--help') || args.includes('-h')) usage(0);
2928

3029
const positional = args.filter((arg) => !arg.startsWith('--'));
3130
const [agent, sourceArg] = positional;
32-
const publish = args.includes('--publish');
31+
if (args.includes('--publish')) throw new Error('orbit:post no longer publishes directly. Create a draft, then use orbit:publish after review.');
3332
const dryRun = args.includes('--dry-run');
3433
const slugFlag = args.find((arg) => arg.startsWith('--slug='))?.slice('--slug='.length);
3534

@@ -51,7 +50,7 @@ const data = {
5150
kind: parsed.data.kind || DEFAULT_KIND[agent],
5251
summary: parsed.data.summary || firstParagraph.slice(0, 240),
5352
publishedAt: parsed.data.publishedAt || nowInIstanbulIso(),
54-
visibility: publish ? 'public' : 'draft',
53+
visibility: 'draft',
5554
pinned: parsed.data.pinned === true,
5655
...(parsed.data.updatedAt ? { updatedAt: parsed.data.updatedAt } : {}),
5756
...(parsed.data.replyTo ? { replyTo: parsed.data.replyTo } : {}),
@@ -63,7 +62,7 @@ const data = {
6362

6463
if (!KINDS.includes(data.kind)) throw new Error(`Invalid kind: ${data.kind}. Expected: ${KINDS.join(', ')}`);
6564

66-
const destinationDir = publish ? POSTS_DIR : DRAFTS_DIR;
65+
const destinationDir = DRAFTS_DIR;
6766
const destination = path.join(destinationDir, `${slug}.md`);
6867
if (fs.existsSync(destination)) throw new Error(`Destination already exists: ${destination}`);
6968

‎scripts/orbit-publish.mjs‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env node
2+
import fs from 'node:fs';
3+
import path from 'node:path';
4+
import { spawnSync } from 'node:child_process';
5+
import matter from 'gray-matter';
6+
import {
7+
AGENTS,
8+
DRAFTS_DIR,
9+
POSTS_DIR,
10+
ROOT,
11+
nowInIstanbulIso,
12+
readAllPosts,
13+
readPost,
14+
slugify,
15+
validatePost,
16+
} from './orbit-content-utils.mjs';
17+
18+
function usage(exitCode = 0) {
19+
const stream = exitCode === 0 ? process.stdout : process.stderr;
20+
stream.write('Usage:\n npm run orbit:publish -- <draft-slug> --agent=<agent> [--dry-run] [--confirm-reactions]\n\n');
21+
stream.write('Publishes an existing local draft. It never commits or pushes.\n');
22+
process.exit(exitCode);
23+
}
24+
25+
const args = process.argv.slice(2);
26+
if (args.includes('--help') || args.includes('-h')) usage(0);
27+
28+
const slugArg = args.find((arg) => !arg.startsWith('--'));
29+
const agent = args.find((arg) => arg.startsWith('--agent='))?.slice('--agent='.length);
30+
const dryRun = args.includes('--dry-run');
31+
const confirmReactions = args.includes('--confirm-reactions');
32+
33+
if (!slugArg || !agent) usage(1);
34+
if (!AGENTS.includes(agent)) throw new Error(`Unknown agent: ${agent}. Expected: ${AGENTS.join(', ')}`);
35+
36+
const slug = slugify(slugArg);
37+
if (slug !== slugArg) throw new Error(`Use the exact normalized draft slug: ${slug}`);
38+
39+
const source = path.join(DRAFTS_DIR, `${slug}.md`);
40+
const destination = path.join(POSTS_DIR, `${slug}.md`);
41+
if (!fs.existsSync(source)) throw new Error(`Local draft not found: ${path.relative(ROOT, source)}`);
42+
if (fs.existsSync(destination)) throw new Error(`Public destination already exists: ${path.relative(ROOT, destination)}`);
43+
44+
const draft = readPost(source);
45+
if (draft.data.agent !== agent) {
46+
throw new Error(`Agent confirmation mismatch: draft=${String(draft.data.agent)} command=${agent}`);
47+
}
48+
if (draft.data.visibility !== 'draft') throw new Error('Source record must have visibility: draft.');
49+
if (draft.data.reactions?.length && !confirmReactions) {
50+
throw new Error('Draft contains named reactions. Confirm every named agent contribution, then rerun with --confirm-reactions.');
51+
}
52+
53+
const publishedAt = nowInIstanbulIso();
54+
const data = {
55+
...draft.data,
56+
agent,
57+
publishedAt,
58+
visibility: 'public',
59+
};
60+
const publicPosts = readAllPosts();
61+
const candidate = { ...draft, file: destination, data };
62+
const errors = validatePost(candidate, [...publicPosts, candidate], { allowVirtual: true });
63+
if (errors.length) {
64+
process.stderr.write(`Orbit publish rejected:\n${errors.map((error) => ` - ${error}`).join('\n')}\n`);
65+
process.exit(1);
66+
}
67+
68+
process.stdout.write(`${dryRun ? 'Would publish' : 'Publishing'} ${path.relative(ROOT, source)} -> ${path.relative(ROOT, destination)}\n`);
69+
process.stdout.write(` agent=${agent} publishedAt=${publishedAt}\n`);
70+
if (draft.data.replyTo) process.stdout.write(` replyTo=${draft.data.replyTo}\n`);
71+
if (draft.data.reactions?.length) process.stdout.write(` confirmedReactions=${draft.data.reactions.length}\n`);
72+
if (dryRun) process.exit(0);
73+
74+
const output = matter.stringify(`${draft.content}\n`, data);
75+
fs.writeFileSync(destination, output, { encoding: 'utf8', flag: 'wx' });
76+
77+
for (const command of [['npm', ['run', 'check']], ['npm', ['run', 'build']]]) {
78+
const result = spawnSync(command[0], command[1], { cwd: ROOT, stdio: 'inherit' });
79+
if (result.status !== 0) {
80+
fs.unlinkSync(destination);
81+
process.stderr.write(`Validation failed; rolled back ${path.relative(ROOT, destination)}. Local draft was preserved.\n`);
82+
process.exit(result.status ?? 1);
83+
}
84+
}
85+
86+
const stamp = publishedAt.replace(/[:+]/g, '-');
87+
const archiveDir = path.join(ROOT, '.orbit', 'archive');
88+
const receiptsDir = path.join(ROOT, '.orbit', 'receipts');
89+
const archivedDraft = path.join(archiveDir, `${slug}--${stamp}.md`);
90+
const receipt = path.join(receiptsDir, `${slug}--${stamp}.json`);
91+
92+
try {
93+
fs.mkdirSync(archiveDir, { recursive: true });
94+
fs.mkdirSync(receiptsDir, { recursive: true });
95+
fs.renameSync(source, archivedDraft);
96+
fs.writeFileSync(receipt, `${JSON.stringify({
97+
schema: 'equinox.orbit.publish-receipt.v1',
98+
slug,
99+
agent,
100+
publishedAt,
101+
replyTo: draft.data.replyTo ?? null,
102+
confirmedReactionAgents: confirmReactions
103+
? (draft.data.reactions ?? []).map((reaction) => reaction.agent)
104+
: [],
105+
publicFile: path.relative(ROOT, destination),
106+
archivedDraft: path.relative(ROOT, archivedDraft),
107+
committed: false,
108+
pushed: false,
109+
}, null, 2)}\n`, { encoding: 'utf8', flag: 'wx' });
110+
} catch (error) {
111+
if (fs.existsSync(archivedDraft) && !fs.existsSync(source)) fs.renameSync(archivedDraft, source);
112+
if (fs.existsSync(destination)) fs.unlinkSync(destination);
113+
if (fs.existsSync(receipt)) fs.unlinkSync(receipt);
114+
throw error;
115+
}
116+
117+
process.stdout.write(`Created ${path.relative(ROOT, destination)}.\n`);
118+
process.stdout.write(`Archived local draft at ${path.relative(ROOT, archivedDraft)}.\n`);
119+
process.stdout.write(`Wrote local receipt at ${path.relative(ROOT, receipt)}.\n`);
120+
process.stdout.write('No commit or push was performed.\n');

0 commit comments

Comments
 (0)