@gaia-ai/addon-workspace-git 0.6.1
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/src/index.d.ts +38 -0
- package/dist/src/index.js +95 -0
- package/dist/src/instructions.d.ts +6 -0
- package/dist/src/instructions.js +16 -0
- package/dist/src/preset.d.ts +2 -0
- package/dist/src/preset.js +5 -0
- package/package.json +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 keytec GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# @gaia-ai/addon-workspace-git
|
|
2
|
+
|
|
3
|
+
GAIA conductor workspace addon: plain git-worktree workspace + the WORKFLOW.md instruction loader.
|
|
4
|
+
|
|
5
|
+
Part of the GAIA CLI. Install the meta package `@gaia-ai/gaia` to get the `gaia` CLI with all addons. Source: https://git.key-tec.de/keytec/gaia (gaia-cli/).
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { EnsuredWorkspace, GaiaWorkspace, WorkspacePlugin } from '@gaia-ai/conductor/contract';
|
|
2
|
+
export { loadInstructions } from './instructions.js';
|
|
3
|
+
/** Default branch template: `<prefix><key>-<title-slug>` (readable). */
|
|
4
|
+
export declare const DEFAULT_BRANCH_TEMPLATE = "{branchPrefix}{key}-{titleSlug}";
|
|
5
|
+
export type GitRunner = (args: string[], cwd: string) => Promise<void>;
|
|
6
|
+
export interface GitWorkspaceOptions {
|
|
7
|
+
/** Main clone (a git repo): config source + worktree base. */
|
|
8
|
+
root: string;
|
|
9
|
+
/** Where per-ticket worktrees live. Default: `${root}-worktrees`. */
|
|
10
|
+
worktreesRoot?: string;
|
|
11
|
+
/** Branch name prefix per ticket. Default: 'gaia/'. */
|
|
12
|
+
branchPrefix?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Branch name template. Vars: {branchPrefix}, {key} (sanitized identifier),
|
|
15
|
+
* {identifier}, {titleSlug}. Default: `{branchPrefix}{key}-{titleSlug}`.
|
|
16
|
+
*/
|
|
17
|
+
branchTemplate?: string;
|
|
18
|
+
runGit?: GitRunner;
|
|
19
|
+
}
|
|
20
|
+
export declare class GitWorkspace implements GaiaWorkspace {
|
|
21
|
+
private readonly runGit;
|
|
22
|
+
private readonly root;
|
|
23
|
+
private readonly worktreesRoot;
|
|
24
|
+
private readonly branchPrefix;
|
|
25
|
+
private readonly branchTemplate;
|
|
26
|
+
constructor(options: GitWorkspaceOptions);
|
|
27
|
+
/** Render the branch name for a ticket from the configured template. */
|
|
28
|
+
branchFor(identifier: string, title?: string): string;
|
|
29
|
+
keyFor(identifier: string): string;
|
|
30
|
+
private pathFor;
|
|
31
|
+
ensure(identifier: string, title?: string, _baseRef?: string): Promise<EnsuredWorkspace>;
|
|
32
|
+
remove(identifier: string): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export declare function gitWorkspace(opts?: {
|
|
35
|
+
branchPrefix?: string;
|
|
36
|
+
branchTemplate?: string;
|
|
37
|
+
}): WorkspacePlugin;
|
|
38
|
+
export default gitWorkspace;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// GAIA-224 (Finding 6, decisions 8 + 10): the plain git-worktree workspace —
|
|
2
|
+
// formerly `@gaia-ai/core`'s `plugins/workspace/git.ts` — now its own
|
|
3
|
+
// conductor-surface addon, which ALSO owns `loadInstructions` (the WORKFLOW.md
|
|
4
|
+
// loader that used to be a core util). `@gaia-ai/addon-herdr` depends on this
|
|
5
|
+
// package for it: the one addon→addon edge the layered acyclic rule permits.
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { dirname, join, resolve } from 'node:path';
|
|
8
|
+
import { exec, slugify } from '@gaia-ai/core';
|
|
9
|
+
import { loadInstructions } from './instructions.js';
|
|
10
|
+
export { loadInstructions } from './instructions.js';
|
|
11
|
+
/** Default branch template: `<prefix><key>-<title-slug>` (readable). */
|
|
12
|
+
export const DEFAULT_BRANCH_TEMPLATE = '{branchPrefix}{key}-{titleSlug}';
|
|
13
|
+
function renderBranchTemplate(template, vars) {
|
|
14
|
+
const rendered = template.replace(/\{(\w+)\}/g, (whole, key) => {
|
|
15
|
+
const value = vars[key];
|
|
16
|
+
return value === undefined ? whole : value;
|
|
17
|
+
});
|
|
18
|
+
// An empty title slug leaves a dangling separator (e.g. `gaia/GL-9-`) —
|
|
19
|
+
// trim trailing branch separators so the branch stays a valid, tidy ref.
|
|
20
|
+
return rendered.replace(/[-_./]+$/g, '');
|
|
21
|
+
}
|
|
22
|
+
const defaultGitRunner = async (args, cwd) => {
|
|
23
|
+
await exec('git', args, { cwd });
|
|
24
|
+
};
|
|
25
|
+
export class GitWorkspace {
|
|
26
|
+
runGit;
|
|
27
|
+
root;
|
|
28
|
+
worktreesRoot;
|
|
29
|
+
branchPrefix;
|
|
30
|
+
branchTemplate;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.runGit = options.runGit ?? defaultGitRunner;
|
|
33
|
+
this.root = resolve(options.root);
|
|
34
|
+
this.worktreesRoot = options.worktreesRoot
|
|
35
|
+
? resolve(options.worktreesRoot)
|
|
36
|
+
: `${this.root}-worktrees`;
|
|
37
|
+
this.branchPrefix = options.branchPrefix ?? 'gaia/';
|
|
38
|
+
this.branchTemplate = options.branchTemplate ?? DEFAULT_BRANCH_TEMPLATE;
|
|
39
|
+
}
|
|
40
|
+
/** Render the branch name for a ticket from the configured template. */
|
|
41
|
+
branchFor(identifier, title) {
|
|
42
|
+
return renderBranchTemplate(this.branchTemplate, {
|
|
43
|
+
branchPrefix: this.branchPrefix,
|
|
44
|
+
key: this.keyFor(identifier),
|
|
45
|
+
identifier,
|
|
46
|
+
titleSlug: slugify(title ?? ''),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
keyFor(identifier) {
|
|
50
|
+
return identifier.replace(/[^A-Za-z0-9._-]/g, '_');
|
|
51
|
+
}
|
|
52
|
+
pathFor(key) {
|
|
53
|
+
return resolve(join(this.worktreesRoot, key));
|
|
54
|
+
}
|
|
55
|
+
async ensure(identifier, title, _baseRef) {
|
|
56
|
+
const key = this.keyFor(identifier);
|
|
57
|
+
// Reject empty and dot-leading keys: a dot-leading key would produce an
|
|
58
|
+
// invalid git ref (e.g. `gaia/.hidden`) and covers '.'/'..' too.
|
|
59
|
+
if (key === '' || key.startsWith('.')) {
|
|
60
|
+
throw new Error(`invalid workspace identifier: ${identifier}`);
|
|
61
|
+
}
|
|
62
|
+
const path = this.pathFor(key);
|
|
63
|
+
if (existsSync(path)) {
|
|
64
|
+
return { path, instructions: loadInstructions(path), created: false };
|
|
65
|
+
}
|
|
66
|
+
const branch = this.branchFor(identifier, title);
|
|
67
|
+
await this.runGit(['-C', this.root, 'worktree', 'add', '--force', '-B', branch, path], this.root);
|
|
68
|
+
// The `after_create` hook is run by the executor (GAIA-84), not here — the
|
|
69
|
+
// workspace only reports that it created a fresh worktree.
|
|
70
|
+
return { path, instructions: loadInstructions(path), created: true };
|
|
71
|
+
}
|
|
72
|
+
async remove(identifier) {
|
|
73
|
+
const key = this.keyFor(identifier);
|
|
74
|
+
const path = this.pathFor(key);
|
|
75
|
+
await this.runGit(['-C', this.root, 'worktree', 'remove', '--force', path], this.root);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function gitWorkspace(opts = {}) {
|
|
79
|
+
return {
|
|
80
|
+
kind: 'workspace',
|
|
81
|
+
id: 'git',
|
|
82
|
+
requiredModules: [],
|
|
83
|
+
async createWorkspace(config) {
|
|
84
|
+
const root = config.config_path
|
|
85
|
+
? dirname(config.config_path)
|
|
86
|
+
: process.cwd();
|
|
87
|
+
return new GitWorkspace({
|
|
88
|
+
root,
|
|
89
|
+
...(opts.branchPrefix ? { branchPrefix: opts.branchPrefix } : {}),
|
|
90
|
+
...(opts.branchTemplate ? { branchTemplate: opts.branchTemplate } : {}),
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export default gitWorkspace;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
/** Loads ./WORKFLOW.md from the workspace, hashing its content. */
|
|
5
|
+
export function loadInstructions(workspacePath) {
|
|
6
|
+
const path = resolve(workspacePath, 'WORKFLOW.md');
|
|
7
|
+
if (!existsSync(path)) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const text = readFileSync(path, 'utf8');
|
|
11
|
+
return {
|
|
12
|
+
path,
|
|
13
|
+
sha256: createHash('sha256').update(text).digest('hex'),
|
|
14
|
+
text,
|
|
15
|
+
};
|
|
16
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gaia-ai/addon-workspace-git",
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"description": "GAIA conductor workspace addon: plain git-worktree workspace + the WORKFLOW.md instruction loader.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/src/index.js",
|
|
9
|
+
"./preset": "./dist/src/preset.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/src"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://git.key-tec.de/keytec/gaia.git",
|
|
20
|
+
"directory": "gaia-cli/addons/workspace-git"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@gaia-ai/conductor": "^0.6.1",
|
|
24
|
+
"@gaia-ai/core": "^0.6.1"
|
|
25
|
+
}
|
|
26
|
+
}
|