@shardworks/nexus-core 0.1.16 → 0.1.18

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.
Files changed (44) hide show
  1. package/dist/clockworks.d.ts +54 -0
  2. package/dist/clockworks.d.ts.map +1 -0
  3. package/dist/clockworks.js +264 -0
  4. package/dist/clockworks.js.map +1 -0
  5. package/dist/commission.d.ts +35 -0
  6. package/dist/commission.d.ts.map +1 -0
  7. package/dist/commission.js +80 -0
  8. package/dist/commission.js.map +1 -0
  9. package/dist/engine.d.ts +60 -0
  10. package/dist/engine.d.ts.map +1 -0
  11. package/dist/engine.js +45 -0
  12. package/dist/engine.js.map +1 -0
  13. package/dist/events.d.ts +49 -0
  14. package/dist/events.d.ts.map +1 -0
  15. package/dist/events.js +134 -0
  16. package/dist/events.js.map +1 -0
  17. package/dist/guild-config.d.ts +37 -3
  18. package/dist/guild-config.d.ts.map +1 -1
  19. package/dist/guild-config.js +1 -1
  20. package/dist/guild-config.js.map +1 -1
  21. package/dist/index.d.ts +6 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +5 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/init-guild.d.ts.map +1 -1
  26. package/dist/init-guild.js +71 -2
  27. package/dist/init-guild.js.map +1 -1
  28. package/dist/ledger.d.ts +1 -1
  29. package/dist/ledger.d.ts.map +1 -1
  30. package/dist/ledger.js +7 -6
  31. package/dist/ledger.js.map +1 -1
  32. package/dist/rehydrate.d.ts +7 -0
  33. package/dist/rehydrate.d.ts.map +1 -1
  34. package/dist/rehydrate.js +33 -8
  35. package/dist/rehydrate.js.map +1 -1
  36. package/dist/workshop.d.ts +85 -0
  37. package/dist/workshop.d.ts.map +1 -0
  38. package/dist/workshop.js +189 -0
  39. package/dist/workshop.js.map +1 -0
  40. package/package.json +1 -1
  41. package/dist/dispatch.d.ts +0 -26
  42. package/dist/dispatch.d.ts.map +0 -1
  43. package/dist/dispatch.js +0 -55
  44. package/dist/dispatch.js.map +0 -1
@@ -0,0 +1,85 @@
1
+ export interface AddWorkshopOptions {
2
+ /** Absolute path to the guild root. */
3
+ home: string;
4
+ /** Workshop name (used as the key in guild.json and the bare clone directory name). */
5
+ name: string;
6
+ /** Git remote URL to clone from. */
7
+ remoteUrl: string;
8
+ }
9
+ export interface AddWorkshopResult {
10
+ /** Workshop name. */
11
+ name: string;
12
+ /** Remote URL that was cloned. */
13
+ remoteUrl: string;
14
+ /** Path to the bare clone on disk. */
15
+ barePath: string;
16
+ }
17
+ export interface RemoveWorkshopOptions {
18
+ /** Absolute path to the guild root. */
19
+ home: string;
20
+ /** Workshop name to remove. */
21
+ name: string;
22
+ }
23
+ export interface WorkshopInfo {
24
+ /** Workshop name. */
25
+ name: string;
26
+ /** Remote URL from guild.json. */
27
+ remoteUrl: string;
28
+ /** When the workshop was added. */
29
+ addedAt: string;
30
+ /** Whether the bare clone exists on disk. */
31
+ cloned: boolean;
32
+ /** Number of active commission worktrees. */
33
+ activeWorktrees: number;
34
+ }
35
+ export interface CreateWorkshopOptions {
36
+ /** Absolute path to the guild root. */
37
+ home: string;
38
+ /** Repository name in org/name format. */
39
+ repoName: string;
40
+ /** Whether to create a private repo (default: true). */
41
+ private?: boolean;
42
+ }
43
+ /**
44
+ * Derive a workshop name from a remote URL or repo name.
45
+ * "https://github.com/org/my-repo.git" → "my-repo"
46
+ * "org/my-repo" → "my-repo"
47
+ * "git@github.com:org/my-repo.git" → "my-repo"
48
+ */
49
+ export declare function deriveWorkshopName(input: string): string;
50
+ /**
51
+ * Add a workshop by cloning a remote repo as a bare clone and registering
52
+ * it in guild.json.
53
+ *
54
+ * @throws If the workshop name already exists in guild.json.
55
+ * @throws If the bare clone directory already exists on disk.
56
+ * @throws If the git clone fails.
57
+ */
58
+ export declare function addWorkshop(opts: AddWorkshopOptions): AddWorkshopResult;
59
+ /**
60
+ * Remove a workshop — deletes the bare clone, any commission worktrees,
61
+ * and the guild.json entry.
62
+ *
63
+ * @throws If the workshop doesn't exist in guild.json.
64
+ */
65
+ export declare function removeWorkshop(opts: RemoveWorkshopOptions): void;
66
+ /**
67
+ * List all workshops with status info.
68
+ */
69
+ export declare function listWorkshops(home: string): WorkshopInfo[];
70
+ /**
71
+ * Check whether `gh` is installed and authenticated.
72
+ * Returns null if OK, or an error message if not.
73
+ */
74
+ export declare function checkGhAuth(): string | null;
75
+ /**
76
+ * Create a new GitHub repo and add it as a workshop.
77
+ *
78
+ * Precondition: `gh` must be installed and authenticated. Call checkGhAuth()
79
+ * first to verify.
80
+ *
81
+ * @param opts.repoName - Repository name in "org/name" format.
82
+ * @throws If gh auth check fails, repo creation fails, or add fails.
83
+ */
84
+ export declare function createWorkshop(opts: CreateWorkshopOptions): AddWorkshopResult;
85
+ //# sourceMappingURL=workshop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workshop.d.ts","sourceRoot":"","sources":["../src/workshop.ts"],"names":[],"mappings":"AAsBA,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,MAAM,EAAE,OAAO,CAAC;IAChB,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,qBAAqB;IACpC,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAmBD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQxD;AAID;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,iBAAiB,CA4BvE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI,CAyBhE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CA2B1D;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,MAAM,GAAG,IAAI,CAsB3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,iBAAiB,CAqB7E"}
@@ -0,0 +1,189 @@
1
+ /**
2
+ * workshop — core logic for managing guild workshops.
3
+ *
4
+ * Workshops are repositories where the guild does its work. Each workshop
5
+ * is stored as a bare git clone in .nexus/workshops/{name}.git, with
6
+ * commission worktrees created from it by the worktree-setup engine.
7
+ *
8
+ * This module provides:
9
+ * - addWorkshop: clone a remote repo and register it in guild.json
10
+ * - removeWorkshop: remove the bare clone, worktrees, and guild.json entry
11
+ * - listWorkshops: return workshop entries with status info
12
+ * - createWorkshop: create a new GitHub repo via `gh`, then add it
13
+ */
14
+ import { execFileSync } from 'node:child_process';
15
+ import fs from 'node:fs';
16
+ import path from 'node:path';
17
+ import { readGuildConfig, writeGuildConfig } from "./guild-config.js";
18
+ import { workshopBarePath, workshopsPath, worktreesPath } from "./nexus-home.js";
19
+ // ── Helpers ────────────────────────────────────────────────────────────
20
+ function git(args, cwd) {
21
+ return execFileSync('git', args, {
22
+ cwd,
23
+ encoding: 'utf-8',
24
+ stdio: ['pipe', 'pipe', 'pipe'],
25
+ }).trim();
26
+ }
27
+ function gh(args) {
28
+ return execFileSync('gh', args, {
29
+ encoding: 'utf-8',
30
+ stdio: ['pipe', 'pipe', 'pipe'],
31
+ }).trim();
32
+ }
33
+ /**
34
+ * Derive a workshop name from a remote URL or repo name.
35
+ * "https://github.com/org/my-repo.git" → "my-repo"
36
+ * "org/my-repo" → "my-repo"
37
+ * "git@github.com:org/my-repo.git" → "my-repo"
38
+ */
39
+ export function deriveWorkshopName(input) {
40
+ // Handle org/name format
41
+ if (input.includes('/') && !input.includes(':') && !input.includes('.')) {
42
+ return input.split('/').pop();
43
+ }
44
+ // Handle URLs — take the last path segment, strip .git
45
+ const basename = input.split('/').pop() ?? input;
46
+ return basename.replace(/\.git$/, '');
47
+ }
48
+ // ── Core operations ───────────────────────────────────────────────────
49
+ /**
50
+ * Add a workshop by cloning a remote repo as a bare clone and registering
51
+ * it in guild.json.
52
+ *
53
+ * @throws If the workshop name already exists in guild.json.
54
+ * @throws If the bare clone directory already exists on disk.
55
+ * @throws If the git clone fails.
56
+ */
57
+ export function addWorkshop(opts) {
58
+ const { home, name, remoteUrl } = opts;
59
+ const config = readGuildConfig(home);
60
+ if (name in config.workshops) {
61
+ throw new Error(`Workshop "${name}" already exists in guild.json.`);
62
+ }
63
+ const barePath = workshopBarePath(home, name);
64
+ if (fs.existsSync(barePath)) {
65
+ throw new Error(`Bare clone already exists at ${barePath}. Remove it first or choose a different name.`);
66
+ }
67
+ // Ensure workshops directory exists
68
+ fs.mkdirSync(workshopsPath(home), { recursive: true });
69
+ // Clone as bare repo
70
+ git(['clone', '--bare', remoteUrl, barePath]);
71
+ // Register in guild.json
72
+ const entry = {
73
+ remoteUrl,
74
+ addedAt: new Date().toISOString(),
75
+ };
76
+ config.workshops[name] = entry;
77
+ writeGuildConfig(home, config);
78
+ return { name, remoteUrl, barePath };
79
+ }
80
+ /**
81
+ * Remove a workshop — deletes the bare clone, any commission worktrees,
82
+ * and the guild.json entry.
83
+ *
84
+ * @throws If the workshop doesn't exist in guild.json.
85
+ */
86
+ export function removeWorkshop(opts) {
87
+ const { home, name } = opts;
88
+ const config = readGuildConfig(home);
89
+ if (!(name in config.workshops)) {
90
+ throw new Error(`Workshop "${name}" not found in guild.json. Available workshops: ${Object.keys(config.workshops).join(', ') || '(none)'}`);
91
+ }
92
+ // Remove commission worktrees for this workshop
93
+ const wtDir = path.join(worktreesPath(home), name);
94
+ if (fs.existsSync(wtDir)) {
95
+ fs.rmSync(wtDir, { recursive: true, force: true });
96
+ }
97
+ // Remove the bare clone
98
+ const barePath = workshopBarePath(home, name);
99
+ if (fs.existsSync(barePath)) {
100
+ fs.rmSync(barePath, { recursive: true, force: true });
101
+ }
102
+ // Remove from guild.json
103
+ delete config.workshops[name];
104
+ writeGuildConfig(home, config);
105
+ }
106
+ /**
107
+ * List all workshops with status info.
108
+ */
109
+ export function listWorkshops(home) {
110
+ const config = readGuildConfig(home);
111
+ const results = [];
112
+ for (const [name, entry] of Object.entries(config.workshops)) {
113
+ const barePath = workshopBarePath(home, name);
114
+ const cloned = fs.existsSync(barePath);
115
+ // Count active worktrees
116
+ let activeWorktrees = 0;
117
+ const wtDir = path.join(worktreesPath(home), name);
118
+ if (fs.existsSync(wtDir)) {
119
+ activeWorktrees = fs.readdirSync(wtDir, { withFileTypes: true })
120
+ .filter(e => e.isDirectory())
121
+ .length;
122
+ }
123
+ results.push({
124
+ name,
125
+ remoteUrl: entry.remoteUrl,
126
+ addedAt: entry.addedAt,
127
+ cloned,
128
+ activeWorktrees,
129
+ });
130
+ }
131
+ return results;
132
+ }
133
+ /**
134
+ * Check whether `gh` is installed and authenticated.
135
+ * Returns null if OK, or an error message if not.
136
+ */
137
+ export function checkGhAuth() {
138
+ try {
139
+ execFileSync('which', ['gh'], { stdio: 'pipe' });
140
+ }
141
+ catch {
142
+ return 'GitHub CLI (gh) is not installed. Install from https://cli.github.com/';
143
+ }
144
+ try {
145
+ const output = execFileSync('gh', ['auth', 'status'], {
146
+ encoding: 'utf-8',
147
+ stdio: ['pipe', 'pipe', 'pipe'],
148
+ });
149
+ // gh auth status exits 0 when authenticated
150
+ return null;
151
+ }
152
+ catch (err) {
153
+ // gh auth status may write to stderr even on success in some versions
154
+ if (err && typeof err === 'object' && 'stderr' in err) {
155
+ const stderr = err.stderr ?? '';
156
+ if (stderr.includes('Logged in'))
157
+ return null;
158
+ }
159
+ return 'GitHub CLI is not authenticated. Run: gh auth login';
160
+ }
161
+ }
162
+ /**
163
+ * Create a new GitHub repo and add it as a workshop.
164
+ *
165
+ * Precondition: `gh` must be installed and authenticated. Call checkGhAuth()
166
+ * first to verify.
167
+ *
168
+ * @param opts.repoName - Repository name in "org/name" format.
169
+ * @throws If gh auth check fails, repo creation fails, or add fails.
170
+ */
171
+ export function createWorkshop(opts) {
172
+ const { home, repoName, private: isPrivate = true } = opts;
173
+ // Verify gh is available and authenticated
174
+ const authError = checkGhAuth();
175
+ if (authError) {
176
+ throw new Error(authError);
177
+ }
178
+ // Create the repo on GitHub
179
+ const visibility = isPrivate ? '--private' : '--public';
180
+ gh(['repo', 'create', repoName, visibility, '--confirm']);
181
+ // Get the clone URL
182
+ const remoteUrl = `https://github.com/${repoName}.git`;
183
+ const name = deriveWorkshopName(repoName);
184
+ // Need to initialize the repo so bare clone works.
185
+ // gh repo create with --confirm creates it but it may be empty.
186
+ // We'll clone it (possibly empty) — git clone --bare handles empty repos.
187
+ return addWorkshop({ home, name, remoteUrl });
188
+ }
189
+ //# sourceMappingURL=workshop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workshop.js","sourceRoot":"","sources":["../src/workshop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,O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GAA2B,CAAC,MAAM,IAAI,EAAE,CAAC;YACzD,IAAI,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;gBAAE,OAAO,IAAI,CAAC;QAChD,CAAC;QACD,OAAO,qDAAqD,CAAC;IAC/D,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,IAA2B;IACxD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAE3D,2CAA2C;IAC3C,MAAM,SAAS,GAAG,WAAW,EAAE,CAAC;IAChC,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,4BAA4B;IAC5B,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC;IACxD,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAE1D,oBAAoB;IACpB,MAAM,SAAS,GAAG,sBAAsB,QAAQ,MAAM,CAAC;IACvD,MAAM,IAAI,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAE1C,mDAAmD;IACnD,gEAAgE;IAChE,0EAA0E;IAC1E,OAAO,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;AAChD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shardworks/nexus-core",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "license": "ISC",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,26 +0,0 @@
1
- export interface DispatchOptions {
2
- /** Absolute path to the guild root. */
3
- home: string;
4
- /** Commission specification — what needs to be done. */
5
- spec: string;
6
- /** Target workshop for the commission. */
7
- workshop: string;
8
- /** Target anima name. If provided, the commission is assigned immediately. */
9
- anima?: string;
10
- }
11
- export interface DispatchResult {
12
- /** The ID of the created commission. */
13
- commissionId: number;
14
- /** Whether the commission was assigned to an anima. */
15
- assigned: boolean;
16
- /** The anima name if assigned. */
17
- assignedTo?: string;
18
- }
19
- /**
20
- * Post a commission to the guild.
21
- *
22
- * Creates a commission in the Ledger. If an anima is specified, validates that
23
- * the anima exists and is active, then creates an assignment record.
24
- */
25
- export declare function dispatch(opts: DispatchOptions): DispatchResult;
26
- //# sourceMappingURL=dispatch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,eAAe;IAC9B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,uDAAuD;IACvD,QAAQ,EAAE,OAAO,CAAC;IAClB,kCAAkC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,cAAc,CAgE9D"}
package/dist/dispatch.js DELETED
@@ -1,55 +0,0 @@
1
- /**
2
- * dispatch — core logic for posting commissions to the guild.
3
- *
4
- * Creates a commission record in the Ledger and optionally assigns it to an anima.
5
- * The dispatch implement and CLI both call this function.
6
- */
7
- import Database from 'better-sqlite3';
8
- import { ledgerPath } from "./nexus-home.js";
9
- import { readGuildConfig } from "./guild-config.js";
10
- /**
11
- * Post a commission to the guild.
12
- *
13
- * Creates a commission in the Ledger. If an anima is specified, validates that
14
- * the anima exists and is active, then creates an assignment record.
15
- */
16
- export function dispatch(opts) {
17
- const { home, spec, workshop, anima } = opts;
18
- // Validate workshop exists in guild.json
19
- const config = readGuildConfig(home);
20
- if (!config.workshops.includes(workshop)) {
21
- throw new Error(`Workshop "${workshop}" not found in guild.json. Available workshops: ${config.workshops.join(', ') || '(none)'}`);
22
- }
23
- const db = new Database(ledgerPath(home));
24
- db.pragma('foreign_keys = ON');
25
- try {
26
- const initialStatus = anima ? 'assigned' : 'posted';
27
- // Create commission
28
- const insertCommission = db.prepare(`INSERT INTO commissions (content, status, workshop) VALUES (?, ?, ?)`);
29
- const commissionResult = insertCommission.run(spec, initialStatus, workshop);
30
- const commissionId = Number(commissionResult.lastInsertRowid);
31
- let assigned = false;
32
- let assignedTo;
33
- if (anima) {
34
- // Validate anima exists and is active
35
- const animaRow = db.prepare(`SELECT id, status FROM animas WHERE name = ?`).get(anima);
36
- if (!animaRow) {
37
- throw new Error(`Anima "${anima}" not found in the Ledger.`);
38
- }
39
- if (animaRow.status !== 'active') {
40
- throw new Error(`Anima "${anima}" is not active (status: ${animaRow.status}).`);
41
- }
42
- // Create assignment
43
- db.prepare(`INSERT INTO commission_assignments (commission_id, anima_id) VALUES (?, ?)`).run(commissionId, animaRow.id);
44
- assigned = true;
45
- assignedTo = anima;
46
- }
47
- // Audit log
48
- db.prepare(`INSERT INTO audit_log (actor, action, target_type, target_id, detail) VALUES (?, ?, ?, ?, ?)`).run('dispatch', assigned ? 'commission_dispatched_and_assigned' : 'commission_dispatched', 'commission', commissionId, JSON.stringify({ workshop, anima: assignedTo }));
49
- return { commissionId, assigned, assignedTo };
50
- }
51
- finally {
52
- db.close();
53
- }
54
- }
55
- //# sourceMappingURL=dispatch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C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