auggy 0.3.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.
Files changed (121) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/LICENSE +201 -0
  3. package/README.md +161 -0
  4. package/package.json +76 -0
  5. package/src/agent-card.ts +39 -0
  6. package/src/agent.ts +283 -0
  7. package/src/agentmail-client.ts +138 -0
  8. package/src/augments/bash/index.ts +463 -0
  9. package/src/augments/bash/skill/SKILL.md +156 -0
  10. package/src/augments/budgets/budget-store.ts +513 -0
  11. package/src/augments/budgets/index.ts +134 -0
  12. package/src/augments/budgets/preamble.ts +93 -0
  13. package/src/augments/budgets/types.ts +89 -0
  14. package/src/augments/file-memory/index.ts +71 -0
  15. package/src/augments/filesystem/index.ts +533 -0
  16. package/src/augments/filesystem/skill/SKILL.md +142 -0
  17. package/src/augments/filesystem/skill/references/mount-permissions.md +81 -0
  18. package/src/augments/layered-memory/extractor/buffer.ts +56 -0
  19. package/src/augments/layered-memory/extractor/frequency.ts +79 -0
  20. package/src/augments/layered-memory/extractor/inject-handler.ts +103 -0
  21. package/src/augments/layered-memory/extractor/parse.ts +75 -0
  22. package/src/augments/layered-memory/extractor/prompt.md +26 -0
  23. package/src/augments/layered-memory/index.ts +757 -0
  24. package/src/augments/layered-memory/skill/SKILL.md +153 -0
  25. package/src/augments/layered-memory/storage/migrations/README.md +16 -0
  26. package/src/augments/layered-memory/storage/migrations/supabase-add-fact-fields.sql +9 -0
  27. package/src/augments/layered-memory/storage/sqlite-store.ts +352 -0
  28. package/src/augments/layered-memory/storage/supabase-store.ts +263 -0
  29. package/src/augments/layered-memory/storage/types.ts +98 -0
  30. package/src/augments/link/index.ts +489 -0
  31. package/src/augments/link/translate.ts +261 -0
  32. package/src/augments/notify/adapters/agentmail.ts +70 -0
  33. package/src/augments/notify/adapters/telegram.ts +60 -0
  34. package/src/augments/notify/adapters/webhook.ts +55 -0
  35. package/src/augments/notify/index.ts +284 -0
  36. package/src/augments/notify/skill/SKILL.md +150 -0
  37. package/src/augments/org-context/index.ts +721 -0
  38. package/src/augments/org-context/skill/SKILL.md +96 -0
  39. package/src/augments/skills/index.ts +103 -0
  40. package/src/augments/supabase-memory/index.ts +151 -0
  41. package/src/augments/telegram-transport/index.ts +312 -0
  42. package/src/augments/telegram-transport/polling.ts +55 -0
  43. package/src/augments/telegram-transport/webhook.ts +56 -0
  44. package/src/augments/turn-control/index.ts +61 -0
  45. package/src/augments/turn-control/skill/SKILL.md +155 -0
  46. package/src/augments/visitor-auth/email-validation.ts +66 -0
  47. package/src/augments/visitor-auth/index.ts +779 -0
  48. package/src/augments/visitor-auth/rate-limiter.ts +90 -0
  49. package/src/augments/visitor-auth/skill/SKILL.md +55 -0
  50. package/src/augments/visitor-auth/storage/sqlite-store.ts +398 -0
  51. package/src/augments/visitor-auth/storage/types.ts +164 -0
  52. package/src/augments/visitor-auth/types.ts +123 -0
  53. package/src/augments/visitor-auth/verify-page.ts +179 -0
  54. package/src/augments/web-fetch/index.ts +331 -0
  55. package/src/augments/web-fetch/skill/SKILL.md +100 -0
  56. package/src/cli/agent-index.ts +289 -0
  57. package/src/cli/augment-catalog.ts +320 -0
  58. package/src/cli/augment-resolver.ts +597 -0
  59. package/src/cli/commands/add-skill.ts +194 -0
  60. package/src/cli/commands/add.ts +87 -0
  61. package/src/cli/commands/chat.ts +207 -0
  62. package/src/cli/commands/create.ts +462 -0
  63. package/src/cli/commands/dev.ts +139 -0
  64. package/src/cli/commands/eval.ts +180 -0
  65. package/src/cli/commands/ls.ts +66 -0
  66. package/src/cli/commands/remove.ts +95 -0
  67. package/src/cli/commands/restart.ts +40 -0
  68. package/src/cli/commands/start.ts +123 -0
  69. package/src/cli/commands/status.ts +104 -0
  70. package/src/cli/commands/stop.ts +84 -0
  71. package/src/cli/commands/visitors-revoke.ts +155 -0
  72. package/src/cli/commands/visitors.ts +101 -0
  73. package/src/cli/config-parser.ts +1034 -0
  74. package/src/cli/engine-resolver.ts +68 -0
  75. package/src/cli/index.ts +178 -0
  76. package/src/cli/model-picker.ts +89 -0
  77. package/src/cli/pid-registry.ts +146 -0
  78. package/src/cli/plist-generator.ts +117 -0
  79. package/src/cli/resolve-config.ts +56 -0
  80. package/src/cli/scaffold-skills.ts +158 -0
  81. package/src/cli/scaffold.ts +291 -0
  82. package/src/cli/skill-frontmatter.ts +51 -0
  83. package/src/cli/skill-validator.ts +151 -0
  84. package/src/cli/types.ts +228 -0
  85. package/src/cli/yaml-helpers.ts +66 -0
  86. package/src/engines/_shared/cost.ts +55 -0
  87. package/src/engines/_shared/schema-normalize.ts +75 -0
  88. package/src/engines/anthropic/pricing.ts +117 -0
  89. package/src/engines/anthropic.ts +483 -0
  90. package/src/engines/openai/pricing.ts +67 -0
  91. package/src/engines/openai.ts +446 -0
  92. package/src/engines/openrouter/pricing.ts +83 -0
  93. package/src/engines/openrouter.ts +185 -0
  94. package/src/helpers.ts +24 -0
  95. package/src/http.ts +387 -0
  96. package/src/index.ts +165 -0
  97. package/src/kernel/capability-table.ts +172 -0
  98. package/src/kernel/context-allocator.ts +161 -0
  99. package/src/kernel/history-manager.ts +198 -0
  100. package/src/kernel/lifecycle-manager.ts +106 -0
  101. package/src/kernel/output-validator.ts +35 -0
  102. package/src/kernel/preamble.ts +23 -0
  103. package/src/kernel/route-collector.ts +97 -0
  104. package/src/kernel/timeout.ts +21 -0
  105. package/src/kernel/tool-selector.ts +47 -0
  106. package/src/kernel/trace-emitter.ts +66 -0
  107. package/src/kernel/transport-queue.ts +147 -0
  108. package/src/kernel/turn-loop.ts +1148 -0
  109. package/src/memory/context-synthesis.ts +83 -0
  110. package/src/memory/memory-bus.ts +61 -0
  111. package/src/memory/registry.ts +80 -0
  112. package/src/memory/tools.ts +320 -0
  113. package/src/memory/types.ts +8 -0
  114. package/src/parts.ts +30 -0
  115. package/src/scaffold-templates/identity.md +31 -0
  116. package/src/telegram-client.ts +145 -0
  117. package/src/tokenizer.ts +14 -0
  118. package/src/transports/ag-ui-events.ts +253 -0
  119. package/src/transports/visitor-token.ts +82 -0
  120. package/src/transports/web-transport.ts +948 -0
  121. package/src/types.ts +1009 -0
@@ -0,0 +1,93 @@
1
+ import type { ContextBlock } from "../../types";
2
+ import type { BudgetCaps } from "./types";
3
+
4
+ export interface BuildBudgetPreambleInput {
5
+ caps: BudgetCaps | null;
6
+ used: { thread: number; day: number; costUsd: number; unpricedTurns: number };
7
+ }
8
+
9
+ /**
10
+ * Build a BATS-style budget context block. Returns null when caps
11
+ * is null (bypass tier — creator/internal trigger) or when no caps
12
+ * fields are configured (nothing to render).
13
+ *
14
+ * The block content includes:
15
+ * - Per-cap remaining values (turns/thread, turns/day, $/day)
16
+ * - A behavioral guidance line based on the minimum budgetRatio
17
+ *
18
+ * Bucketed (not continuous) is deliberate — four distinct behavioral
19
+ * modes are more interpretable to a prose model than a smooth gradient.
20
+ *
21
+ * ratio > 0.6 → "Explore thoroughly. No urgency."
22
+ * ratio 0.2 ≤ 0.6 → "Focus on the core question. Begin wrapping up."
23
+ * ratio < 0.2 → "Final response. Deliver a complete answer."
24
+ * ratio === 0 → "Grace turn — summarize and close."
25
+ *
26
+ * Note on timing: when context() is called the current turn's reservation
27
+ * is already committed (Phase 3 of the 2PC gate runs before the context
28
+ * pipeline). So `used.thread` counts the current turn as consumed —
29
+ * "remaining" values correctly reflect how many turns are left *after*
30
+ * this one.
31
+ */
32
+ export function buildBudgetPreamble(input: BuildBudgetPreambleInput): ContextBlock | null {
33
+ if (input.caps === null) return null;
34
+
35
+ const ratios: number[] = [];
36
+ if (input.caps.maxTurnsPerThread !== undefined) {
37
+ const remaining = Math.max(0, input.caps.maxTurnsPerThread - input.used.thread);
38
+ ratios.push(remaining / input.caps.maxTurnsPerThread);
39
+ }
40
+ if (input.caps.maxTurnsPerDay !== undefined) {
41
+ const remaining = Math.max(0, input.caps.maxTurnsPerDay - input.used.day);
42
+ ratios.push(remaining / input.caps.maxTurnsPerDay);
43
+ }
44
+ if (input.caps.maxUsdPerDay !== undefined) {
45
+ const remaining = Math.max(0, input.caps.maxUsdPerDay - input.used.costUsd);
46
+ ratios.push(remaining / input.caps.maxUsdPerDay);
47
+ }
48
+
49
+ if (ratios.length === 0) return null;
50
+ const ratio = Math.min(...ratios);
51
+
52
+ const lines: string[] = [];
53
+ if (input.caps.maxTurnsPerThread !== undefined) {
54
+ const remaining = Math.max(0, input.caps.maxTurnsPerThread - input.used.thread);
55
+ lines.push(`Turns remaining in this thread: ${remaining} of ${input.caps.maxTurnsPerThread}`);
56
+ }
57
+ if (input.caps.maxTurnsPerDay !== undefined) {
58
+ const remaining = Math.max(0, input.caps.maxTurnsPerDay - input.used.day);
59
+ lines.push(`Turns remaining today: ${remaining} of ${input.caps.maxTurnsPerDay}`);
60
+ }
61
+ if (input.caps.maxUsdPerDay !== undefined) {
62
+ lines.push(
63
+ `Estimated spend today: $${input.used.costUsd.toFixed(2)} of $${input.caps.maxUsdPerDay.toFixed(2)}`,
64
+ );
65
+ }
66
+ // Note: `input.used.unpricedTurns` is intentionally NOT rendered into the
67
+ // BATS preamble. Codex adversarial review (2026-05-04) flagged that
68
+ // exposing "Unpriced turns today: N" to the model lets a misaligned agent
69
+ // infer when budget enforcement is degraded — exactly the moment more
70
+ // spend can fly under the cap. The counter remains accessible via
71
+ // store.getPeerUsage() for operator-side tooling (deferred — see ROADMAP
72
+ // "Cost: operator cost-read API").
73
+ lines.push("");
74
+ lines.push(`Behavioral guidance (budgetRatio = ${ratio.toFixed(2)}): ${bucketGuidance(ratio)}`);
75
+
76
+ return {
77
+ source: "budgets",
78
+ content: lines.join("\n"),
79
+ placement: "preamble",
80
+ provenance: "augment",
81
+ priority: "high",
82
+ eviction: "drop",
83
+ origin: "system",
84
+ ttl: "turn",
85
+ };
86
+ }
87
+
88
+ function bucketGuidance(ratio: number): string {
89
+ if (ratio <= 0.0) return "Grace turn — summarize and close.";
90
+ if (ratio < 0.2) return "Final response. Deliver a complete answer.";
91
+ if (ratio < 0.6) return "Focus on the core question. Begin wrapping up.";
92
+ return "Explore thoroughly. No urgency.";
93
+ }
@@ -0,0 +1,89 @@
1
+ import type { TrustLevel } from "../../types";
2
+
3
+ /**
4
+ * Per-trust-level spend and turn caps. All fields optional — omit a cap
5
+ * to leave it unconstrained.
6
+ */
7
+ export interface BudgetCaps {
8
+ /** Maximum USD spend per calendar day for this peer. */
9
+ maxUsdPerDay?: number;
10
+ /** Maximum turns per thread per calendar day. */
11
+ maxTurnsPerThread?: number;
12
+ /** Maximum turns across all threads per calendar day for this peer. */
13
+ maxTurnsPerDay?: number;
14
+ }
15
+
16
+ /**
17
+ * Differentiated caps for the public trust level, split by publicSubstate.
18
+ * anonymous (no identity): tighter defaults (5 turns/thread, no daily).
19
+ * recognized (cookie/token-identified): looser defaults (20 turns/thread, 50/day, $1/day).
20
+ */
21
+ export interface PublicBudgets {
22
+ anonymous?: BudgetCaps;
23
+ recognized?: BudgetCaps;
24
+ }
25
+
26
+ /**
27
+ * Full budgets augment config (passed by the T7 factory).
28
+ * creator omitted from caps = bypass entirely (no caps, no store write).
29
+ */
30
+ export interface BudgetsConfig {
31
+ dbPath: string;
32
+ caps?: {
33
+ /** Caps for agent-trust peers. Omit = no caps for agents. */
34
+ agent?: BudgetCaps;
35
+ /**
36
+ * Caps for public-trust peers, differentiated by publicSubstate.
37
+ * Omit = no caps for public peers.
38
+ */
39
+ public?: PublicBudgets;
40
+ // creator omitted = bypass entirely
41
+ };
42
+ /**
43
+ * Facility-wide limit on anonymous prepares per rolling minute.
44
+ * Applies to publicSubstate === "anonymous" peers only.
45
+ */
46
+ anonymousGlobalLimit?: number;
47
+ /**
48
+ * Facility-wide daily USD ceiling (sum of all priced turns across all
49
+ * peers). Blocks admission once the day's total crosses this threshold.
50
+ */
51
+ dailyBudgetUsd?: number;
52
+ /** Milliseconds before a pending reservation is swept to 'allow:incomplete'. Default: 3_600_000. */
53
+ cleanupWindowMs?: number;
54
+ }
55
+
56
+ /**
57
+ * A staged reservation row — created inside the prepare transaction,
58
+ * committed when the kernel confirms the ticket.
59
+ */
60
+ export interface TurnReservation {
61
+ turnId: string;
62
+ peerId: string;
63
+ threadId: string;
64
+ day: string; // YYYY-MM-DD UTC
65
+ trustLevel: TrustLevel;
66
+ publicSubstate: "anonymous" | "recognized" | null;
67
+ reservedAt: number;
68
+ committedAt: number | null;
69
+ costUsd: number | null;
70
+ priced: boolean;
71
+ decision: "allow" | "allow:incomplete" | "allow:orphaned";
72
+ reason: string | null;
73
+ }
74
+
75
+ /**
76
+ * Internal result produced by cap evaluation. null = allowed;
77
+ * string = denial reason.
78
+ */
79
+ export type ReservationDecision = { allow: true } | { allow: false; reason: string };
80
+
81
+ /**
82
+ * BudgetStore construction config (identical to the augment-level
83
+ * BudgetsConfig but slimmed to what the store actually needs).
84
+ */
85
+ export interface BudgetStoreConfig {
86
+ dbPath: string;
87
+ /** Milliseconds before a pending reservation is swept. Default: 3_600_000. */
88
+ cleanupWindowMs?: number;
89
+ }
@@ -0,0 +1,71 @@
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import type {
3
+ Augment,
4
+ MemoryEntry,
5
+ ContextOrigin,
6
+ ContextPriority,
7
+ ContextPlacement,
8
+ EvictionPolicy,
9
+ } from "../../types";
10
+
11
+ export interface FileMemoryOptions {
12
+ label: string;
13
+ source: string;
14
+ mutable: boolean;
15
+ origin: ContextOrigin;
16
+ priority: ContextPriority;
17
+ placement: ContextPlacement;
18
+ eviction: EvictionPolicy;
19
+ ttl?: "turn" | "session" | "persistent";
20
+ }
21
+
22
+ /**
23
+ * File-backed memory provider. Loads a file at boot into memory,
24
+ * serves read requests from the cache, and (if mutable) persists
25
+ * writes both in-memory and to disk.
26
+ *
27
+ * Used for identity (mutable: false, origin: "operator") and for
28
+ * agent self-notes (mutable: true, origin: "system").
29
+ */
30
+ export function fileMemory(opts: FileMemoryOptions): Augment {
31
+ let cache: string | null = null;
32
+
33
+ const read = async (label: string): Promise<MemoryEntry | null> => {
34
+ if (label !== opts.label) return null;
35
+ if (cache === null) return null;
36
+ return { label: opts.label, content: cache };
37
+ };
38
+
39
+ const write = opts.mutable
40
+ ? async (label: string, content: string): Promise<void> => {
41
+ if (label !== opts.label) {
42
+ throw new Error(
43
+ `fileMemory: label "${label}" does not match declared label "${opts.label}"`,
44
+ );
45
+ }
46
+ cache = content;
47
+ await writeFile(opts.source, content, "utf-8");
48
+ }
49
+ : undefined;
50
+
51
+ return {
52
+ name: `file-memory-${opts.label}`,
53
+ capabilities: ["context", "tools"],
54
+ memory: {
55
+ owns: { kind: "static", labels: [opts.label] },
56
+ defaults: {
57
+ mutable: opts.mutable,
58
+ origin: opts.origin,
59
+ priority: opts.priority,
60
+ placement: opts.placement,
61
+ eviction: opts.eviction,
62
+ ttl: opts.ttl ?? "persistent",
63
+ },
64
+ read,
65
+ write,
66
+ },
67
+ onBoot: async () => {
68
+ cache = await readFile(opts.source, "utf-8");
69
+ },
70
+ };
71
+ }