@mercury-fw/plugin-bitbucket 0.1.0
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/README.md +21 -0
- package/bitbucket.json +12 -0
- package/dist/index.d.ts +18 -0
- package/index.ts +62 -0
- package/package.json +53 -0
- package/scripts/install-bitbucket-cli.ts +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @mercury-fw/plugin-bitbucket
|
|
2
|
+
|
|
3
|
+
Gives a [Mercury](https://github.com/lucabro81/mercury-fw) agent read-only access to Bitbucket pull requests (listing them, reading one), through the `bitbucket` CLI. The pinned binary downloads when the package installs.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun add @mercury-fw/plugin-bitbucket
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
In the app: list it in `trustedDependencies` (or Bun skips the install script that downloads the binary), add `bitbucket` to `MERCURY_CLIS`, and declare it in `mercury.config.ts`:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { bitbucketPlugin } from "@mercury-fw/plugin-bitbucket";
|
|
13
|
+
|
|
14
|
+
plugins: [bitbucketPlugin],
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Credentials
|
|
18
|
+
|
|
19
|
+
The CLI keeps its login under `~/.config/bitbucket-cli`, which in a container lives on the `cli-credentials` volume. Log in with the CLI's own setup (see [CLI-monorepo](https://github.com/lucabro81/CLI-monorepo)), then bring that folder into the volume; doing it from the env file is planned ([#57](https://github.com/lucabro81/mercury-fw/issues/57)).
|
|
20
|
+
|
|
21
|
+
MIT
|
package/bitbucket.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"binary": "bitbucket",
|
|
3
|
+
"commands": [
|
|
4
|
+
{ "prefix": ["pr", "list"], "confirm": false, "mutating": false },
|
|
5
|
+
{ "prefix": ["pr", "get"], "confirm": false, "mutating": false },
|
|
6
|
+
{ "prefix": ["doctor"], "confirm": false, "mutating": false },
|
|
7
|
+
{ "prefix": ["auth", "whoami"], "confirm": false, "mutating": false }
|
|
8
|
+
],
|
|
9
|
+
"globalFlags": [
|
|
10
|
+
{ "flag": "--select", "takesValue": true }
|
|
11
|
+
]
|
|
12
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Bitbucket plugin — the minimal CLI-based plugin. Read-only (pr list/get,
|
|
3
|
+
* doctor, auth whoami — no mutating or confirm-gated commands), no result
|
|
4
|
+
* post-processing, no post-turn guard, no prompt block of its own (the
|
|
5
|
+
* `--help`-driven discovery in the system prompt covers it).
|
|
6
|
+
*
|
|
7
|
+
* Like Jira, it works only through a CLI, so it owns its tool: it depends on
|
|
8
|
+
* `@mercury-fw/cli-engine` and, in `build()`, validates its own allowlist and
|
|
9
|
+
* builds its `bitbucketCommand` tool from it. Its allowlist (`bitbucket.json`)
|
|
10
|
+
* and its pinned CLI binary (via the package's postinstall, using
|
|
11
|
+
* `@mercury-fw/utils`) travel with the package.
|
|
12
|
+
*/
|
|
13
|
+
import { type Plugin } from "@mercury-fw/plugin-types";
|
|
14
|
+
/** The raw, unvalidated allowlist object. The plugin validates it itself through
|
|
15
|
+
* `@mercury-fw/cli-engine`'s loader, so nothing reaches the model's executable
|
|
16
|
+
* surface unvalidated. */
|
|
17
|
+
export declare const bitbucketCliConfig: unknown;
|
|
18
|
+
export declare const bitbucketPlugin: Plugin;
|
package/index.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Bitbucket plugin — the minimal CLI-based plugin. Read-only (pr list/get,
|
|
3
|
+
* doctor, auth whoami — no mutating or confirm-gated commands), no result
|
|
4
|
+
* post-processing, no post-turn guard, no prompt block of its own (the
|
|
5
|
+
* `--help`-driven discovery in the system prompt covers it).
|
|
6
|
+
*
|
|
7
|
+
* Like Jira, it works only through a CLI, so it owns its tool: it depends on
|
|
8
|
+
* `@mercury-fw/cli-engine` and, in `build()`, validates its own allowlist and
|
|
9
|
+
* builds its `bitbucketCommand` tool from it. Its allowlist (`bitbucket.json`)
|
|
10
|
+
* and its pinned CLI binary (via the package's postinstall, using
|
|
11
|
+
* `@mercury-fw/utils`) travel with the package.
|
|
12
|
+
*/
|
|
13
|
+
import { PLUGIN_API_VERSION, type Plugin } from "@mercury-fw/plugin-types";
|
|
14
|
+
import { runCli, createCliTool, parseCliConfig, createCliStatusDescriber } from "@mercury-fw/cli-engine";
|
|
15
|
+
import rawConfig from "./bitbucket.json";
|
|
16
|
+
|
|
17
|
+
/** The raw, unvalidated allowlist object. The plugin validates it itself through
|
|
18
|
+
* `@mercury-fw/cli-engine`'s loader, so nothing reaches the model's executable
|
|
19
|
+
* surface unvalidated. */
|
|
20
|
+
export const bitbucketCliConfig: unknown = rawConfig;
|
|
21
|
+
|
|
22
|
+
/** Reads the command string off a `bitbucketCommand` call's input for the status
|
|
23
|
+
* label; a missing/non-string command falls back to the generic label. */
|
|
24
|
+
function commandOf(input: unknown): string | undefined {
|
|
25
|
+
if (typeof input === "object" && input !== null && "command" in input) {
|
|
26
|
+
const command = (input as { command: unknown }).command;
|
|
27
|
+
if (typeof command === "string") return command;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const bitbucketPlugin: Plugin = {
|
|
33
|
+
apiVersion: PLUGIN_API_VERSION,
|
|
34
|
+
name: "bitbucket",
|
|
35
|
+
build: (ctx) => {
|
|
36
|
+
// Schema-only validation — the pinned binary is co-shipped, so no
|
|
37
|
+
// `--version` check (see the Jira plugin / `parseCliConfig`).
|
|
38
|
+
const loaded = parseCliConfig(bitbucketCliConfig);
|
|
39
|
+
if (!loaded.ok) {
|
|
40
|
+
ctx.log(`bitbucket allowlist failed to load, bitbucket tool not contributed: ${loaded.reason}`);
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
const configs = { [loaded.binary]: loaded.config };
|
|
44
|
+
const describeCli = createCliStatusDescriber(configs, {});
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
sessionTools: (sctx) => {
|
|
48
|
+
const { runCommand } = createCliTool(runCli, configs, {
|
|
49
|
+
stageConfirmation: sctx.stageConfirmation,
|
|
50
|
+
stashDisplay: sctx.stashDisplay,
|
|
51
|
+
});
|
|
52
|
+
return { bitbucketCommand: runCommand };
|
|
53
|
+
},
|
|
54
|
+
toolStatusDescribers: {
|
|
55
|
+
bitbucketCommand: (input) => {
|
|
56
|
+
const command = commandOf(input);
|
|
57
|
+
return command !== undefined ? describeCli(command) : "esecuzione di un comando";
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mercury-fw/plugin-bitbucket",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/lucabro81/mercury-fw.git",
|
|
8
|
+
"directory": "packages/tools/plugin-bitbucket"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"*.ts",
|
|
12
|
+
"dist",
|
|
13
|
+
"bitbucket.json",
|
|
14
|
+
"scripts",
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"!**/*.test.ts"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@mercury-fw/cli-engine": ">=0.24.0 <1.0.0",
|
|
23
|
+
"@mercury-fw/plugin-types": ">=0.24.0 <1.0.0",
|
|
24
|
+
"@mercury-fw/utils": ">=0.24.0 <1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@mercury-fw/cli-engine": "0.25.0",
|
|
28
|
+
"@mercury-fw/plugin-types": "0.25.0",
|
|
29
|
+
"@mercury-fw/typescript-config": "*",
|
|
30
|
+
"@mercury-fw/utils": "0.25.0",
|
|
31
|
+
"@types/bun": "^1.4.0",
|
|
32
|
+
"typescript": "^6.0.3"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"mercury-fw-source": "./index.ts",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"default": "./index.ts"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"postinstall": "bun run scripts/install-bitbucket-cli.ts",
|
|
43
|
+
"test": "bun test",
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
45
|
+
},
|
|
46
|
+
"mercury": {
|
|
47
|
+
"cliBinary": {
|
|
48
|
+
"repo": "lucabro81/CLI-monorepo",
|
|
49
|
+
"crate": "bitbucket",
|
|
50
|
+
"version": "0.6.0"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* postinstall hook for @mercury-fw/plugin-bitbucket: downloads the pinned bitbucket
|
|
3
|
+
* CLI binary for the current platform into this package's `bin/`. Identical in
|
|
4
|
+
* shape to the Jira plugin's — the mechanism lives in `@mercury-fw/utils`; this
|
|
5
|
+
* script only names the pin (its own package.json's `mercury.cliBinary`) and
|
|
6
|
+
* where to write it (`import.meta.url`). The Dockerfile symlinks the downloaded
|
|
7
|
+
* binary onto PATH so `runCommand` can spawn `bitbucket` by name.
|
|
8
|
+
*/
|
|
9
|
+
import { downloadPinnedBinary } from "@mercury-fw/utils";
|
|
10
|
+
import pkg from "../package.json";
|
|
11
|
+
|
|
12
|
+
await downloadPinnedBinary(pkg, import.meta.url);
|