@interchained/portal-agent 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.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Sentinel — reviews Runner output before it touches the codebase.
3
+ *
4
+ * The sentinel is a stronger/slower model that:
5
+ * 1. Checks that the patch actually fixes what it claims to fix
6
+ * 2. Verifies no forbidden claims or brand violations were introduced
7
+ * 3. Confirms the change is faithful to the app contract
8
+ * 4. Produces a human-readable review summary for the approval UI
9
+ */
10
+ import { AiAssistClient } from "./aiassist.js";
11
+ export class Sentinel {
12
+ client;
13
+ constructor(config = {}) {
14
+ this.client = new AiAssistClient({
15
+ apiKey: config.apiKey ?? process.env["AIASSIST_API_KEY"] ?? process.env["VITE_AIAS_API_KEY"] ?? "",
16
+ baseUrl: config.baseUrl,
17
+ model: config.model ?? "gpt-4o",
18
+ timeoutMs: config.timeoutMs ?? 90_000,
19
+ });
20
+ }
21
+ /** Review a generated patch against the app contract */
22
+ async review(opts) {
23
+ const contractStr = JSON.stringify(opts.contract, null, 2);
24
+ const prompt = `You are a code sentinel reviewing an AI-generated patch.
25
+ Your job: verify the patch is safe, faithful to the app contract, and actually fixes what it claims.
26
+
27
+ App Contract:
28
+ \`\`\`json
29
+ ${contractStr}
30
+ \`\`\`
31
+
32
+ Agent task: ${opts.agentTask}
33
+ File: ${opts.filePath}
34
+
35
+ ORIGINAL:
36
+ \`\`\`tsx
37
+ ${opts.original}
38
+ \`\`\`
39
+
40
+ PROPOSED PATCH:
41
+ \`\`\`tsx
42
+ ${opts.proposed}
43
+ \`\`\`
44
+
45
+ Check for:
46
+ 1. Forbidden claims from policies.forbiddenClaims
47
+ 2. Forbidden phrases from brand.forbiddenPhrases
48
+ 3. Changed brand colors without explicit permission
49
+ 4. Hallucinated data (phone numbers, prices, names not in data sources)
50
+ 5. Whether the patch faithfully serves the stated goals
51
+ 6. Whether it actually fixes the agent task
52
+
53
+ Respond as JSON:
54
+ {
55
+ "approved": true/false,
56
+ "summary": "one sentence summary of what the patch does",
57
+ "violations": ["list of issues if any"],
58
+ "annotations": [{"line": null, "type": "ok|warning|violation", "note": "..."}]
59
+ }`;
60
+ const raw = await this.client.complete(prompt, undefined, { temperature: 0.1, maxTokens: 2_000 });
61
+ try {
62
+ const jsonStr = raw.replace(/^```json\s*/i, "").replace(/\s*```$/, "").trim();
63
+ return JSON.parse(jsonStr);
64
+ }
65
+ catch {
66
+ return {
67
+ approved: false,
68
+ summary: "Sentinel could not parse its own review — manual review required.",
69
+ violations: ["Unparseable sentinel response"],
70
+ annotations: [],
71
+ };
72
+ }
73
+ }
74
+ }
75
+ //# sourceMappingURL=sentinel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentinel.js","sourceRoot":"","sources":["../src/sentinel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAuB,MAAM,eAAe,CAAC;AAepE,MAAM,OAAO,QAAQ;IACX,MAAM,CAAiB;IAE/B,YAAY,SAAkC,EAAE;QAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC;YAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,EAAE;YAClG,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,QAAQ;YAC/B,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM;SACtC,CAAC,CAAC;IACL,CAAC;IAED,wDAAwD;IACxD,KAAK,CAAC,MAAM,CAAC,IAMZ;QACC,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAE3D,MAAM,MAAM,GAAG;;;;;EAKjB,WAAW;;;cAGC,IAAI,CAAC,SAAS;QACpB,IAAI,CAAC,QAAQ;;;;EAInB,IAAI,CAAC,QAAQ;;;;;EAKb,IAAI,CAAC,QAAQ;;;;;;;;;;;;;;;;;EAiBb,CAAC;QAEC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QAElG,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YAC9E,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAmB,CAAC;QAC/C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,mEAAmE;gBAC5E,UAAU,EAAE,CAAC,+BAA+B,CAAC;gBAC7C,WAAW,EAAE,EAAE;aAChB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@interchained/portal-agent",
3
+ "version": "0.1.0",
4
+ "description": "Agent runtime for Portal — AiAssist.net runner/sentinel, audit, generate, improve, guard",
5
+ "license": "GPL-3.0-or-later",
6
+ "author": "Interchained <dev@interchained.org>",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": { "import": "./dist/index.js", "types": "./dist/index.d.ts" }
10
+ },
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "files": ["dist", "README.md", "LICENSE"],
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "dev": "tsc --watch",
17
+ "typecheck": "tsc --noEmit",
18
+ "clean": "rm -rf dist",
19
+ "prepublishOnly": "npm run typecheck && npm run build"
20
+ },
21
+ "dependencies": {
22
+ "@interchained/portal-contract": "workspace:*",
23
+ "picocolors": "^1.0.1",
24
+ "ora": "^8.0.1"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^20.12.7",
28
+ "typescript": "^5.4.5"
29
+ },
30
+ "engines": { "node": ">=18" },
31
+ "publishConfig": { "access": "public" }
32
+ }