@microsoft/agent-governance-antigravity-cli 4.0.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 +99 -0
- package/assets/extensions/agt-global-policy/ANTIGRAVITY.md +9 -0
- package/assets/extensions/agt-global-policy/antigravity-extension.json +30 -0
- package/assets/extensions/agt-global-policy/commands/agt/check.toml +15 -0
- package/assets/extensions/agt-global-policy/commands/agt/status.toml +13 -0
- package/assets/extensions/agt-global-policy/config/default-policy.json +245 -0
- package/assets/extensions/agt-global-policy/config/profiles/advisory.json +246 -0
- package/assets/extensions/agt-global-policy/config/profiles/balanced.json +246 -0
- package/assets/extensions/agt-global-policy/config/profiles/strict.json +246 -0
- package/assets/extensions/agt-global-policy/hooks/after-tool.mjs +43 -0
- package/assets/extensions/agt-global-policy/hooks/before-agent.mjs +39 -0
- package/assets/extensions/agt-global-policy/hooks/before-tool.mjs +41 -0
- package/assets/extensions/agt-global-policy/hooks/hooks.json +60 -0
- package/assets/extensions/agt-global-policy/hooks/session-start.mjs +18 -0
- package/assets/extensions/agt-global-policy/lib/hook-runtime.mjs +62 -0
- package/assets/extensions/agt-global-policy/lib/poisoning.mjs +61 -0
- package/assets/extensions/agt-global-policy/lib/policy.mjs +1388 -0
- package/assets/extensions/agt-global-policy/lib/sdk-loader.mjs +46 -0
- package/assets/extensions/agt-global-policy/mcp/server.mjs +224 -0
- package/assets/extensions/agt-global-policy/package.json +4 -0
- package/bin/agt-antigravity.mjs +8 -0
- package/lib/cli.mjs +941 -0
- package/package.json +42 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { loadHookPolicyState, runHookMain, writeHookOutput } from "../lib/hook-runtime.mjs";
|
|
5
|
+
|
|
6
|
+
await runHookMain(async () => {
|
|
7
|
+
const state = await loadHookPolicyState(import.meta.url);
|
|
8
|
+
await writeHookOutput({
|
|
9
|
+
hookSpecificOutput: {
|
|
10
|
+
additionalContext: state.policy.additionalContext.join("\n"),
|
|
11
|
+
},
|
|
12
|
+
systemMessage: "AGT Antigravity governance policy is active.",
|
|
13
|
+
});
|
|
14
|
+
}, async (error) => {
|
|
15
|
+
await writeHookOutput({
|
|
16
|
+
systemMessage: `AGT Antigravity governance could not load startup context: ${error.message}`,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { loadPolicy } from "./policy.mjs";
|
|
6
|
+
|
|
7
|
+
export async function loadHookInput() {
|
|
8
|
+
const chunks = [];
|
|
9
|
+
for await (const chunk of process.stdin) {
|
|
10
|
+
chunks.push(chunk);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const payload = Buffer.concat(chunks).toString("utf8").trim();
|
|
14
|
+
return payload ? JSON.parse(payload) : {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function loadHookPolicyState(importMetaUrl) {
|
|
18
|
+
return loadPolicy({
|
|
19
|
+
extensionRoot: fileURLToPath(new URL("..", importMetaUrl)),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function extractAntigravityToolResponse(toolResponse) {
|
|
24
|
+
return {
|
|
25
|
+
error: toolResponse?.error,
|
|
26
|
+
llmContent: toolResponse?.llmContent,
|
|
27
|
+
returnDisplay: toolResponse?.returnDisplay,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function writeHookOutput(output) {
|
|
32
|
+
await new Promise((resolve, reject) => {
|
|
33
|
+
const onError = (error) => {
|
|
34
|
+
process.stdout.off("error", onError);
|
|
35
|
+
reject(error);
|
|
36
|
+
};
|
|
37
|
+
process.stdout.once("error", onError);
|
|
38
|
+
process.stdout.write(`${JSON.stringify(output ?? {})}\n`, "utf8", () => {
|
|
39
|
+
process.stdout.off("error", onError);
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function writeHookStderr(message) {
|
|
46
|
+
await new Promise((resolve) => {
|
|
47
|
+
process.stderr.write(`${String(message ?? "").trim()}\n`, "utf8", resolve);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function runHookMain(handler, onError) {
|
|
52
|
+
try {
|
|
53
|
+
await handler();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
await onError(error instanceof Error ? error : new Error(String(error)));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function emitSystemBlock(message) {
|
|
60
|
+
await writeHookStderr(message);
|
|
61
|
+
process.exitCode = 2;
|
|
62
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
export function flattenText(value) {
|
|
5
|
+
if (value === undefined || value === null) {
|
|
6
|
+
return "";
|
|
7
|
+
}
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
12
|
+
return String(value);
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return value.map(flattenText).join("\n");
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === "object") {
|
|
18
|
+
return Object.values(value).map(flattenText).join("\n");
|
|
19
|
+
}
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function summarizeText(text, maxLength = 4000) {
|
|
24
|
+
const normalized = flattenText(text).replace(/\s+/g, " ").trim();
|
|
25
|
+
if (normalized.length <= maxLength) {
|
|
26
|
+
return normalized;
|
|
27
|
+
}
|
|
28
|
+
return `${normalized.slice(0, maxLength)}...`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function summarizeTextWindows(text, maxLength = 12000) {
|
|
32
|
+
const normalized = flattenText(text).replace(/\s+/g, " ").trim();
|
|
33
|
+
if (!normalized) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
if (normalized.length <= maxLength) {
|
|
37
|
+
return [normalized];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const windowSize = Math.max(Math.floor(maxLength / 4), 1000);
|
|
41
|
+
const midStart = Math.max(Math.floor(normalized.length / 2) - Math.floor(windowSize / 2), 0);
|
|
42
|
+
const tailStart = Math.max(normalized.length - windowSize, 0);
|
|
43
|
+
|
|
44
|
+
return dedupeStrings([
|
|
45
|
+
`${normalized.slice(0, windowSize)}...`,
|
|
46
|
+
`...${normalized.slice(midStart, midStart + windowSize)}...`,
|
|
47
|
+
`...${normalized.slice(tailStart)}`,
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function safeJsonStringify(value, space = 0) {
|
|
52
|
+
try {
|
|
53
|
+
return JSON.stringify(value, null, space);
|
|
54
|
+
} catch {
|
|
55
|
+
return "[unserializable]";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function dedupeStrings(values) {
|
|
60
|
+
return [...new Set(values.filter(Boolean))];
|
|
61
|
+
}
|