@inneranimalmedia/agentsam-sdk 2.5.0 → 2.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/AGENTSAM.md +55 -0
- package/README.md +12 -8
- package/bin/agentsam +2 -0
- package/docs/AGENTSAM_ASTRA_OPENAI_INTEGRATION.md +1363 -0
- package/docs/CLI_SHELL.md +163 -53
- package/docs/PLATFORM_RUNTIME_EVENTS.md +48 -0
- package/docs/RELEASES.md +16 -7
- package/docs/SOURCE_ARCHITECTURE.md +58 -0
- package/docs/TEST_TIERS.md +26 -0
- package/migrations/runtime/0001_cli_runtime.sql +298 -0
- package/package.json +45 -12
- package/packages/agentsam-repository/README.md +15 -0
- package/packages/agentsam-repository/package.json +25 -0
- package/packages/agentsam-repository/src/contracts.js +113 -0
- package/packages/agentsam-repository/src/index.js +3 -0
- package/{src/lib → packages/agentsam-repository/src}/merkle/cloudflare-persistence.js +14 -24
- package/{src/lib → packages/agentsam-repository/src}/merkle/index.js +1 -0
- package/{src/lib → packages/agentsam-repository/src}/merkle/persistence.js +6 -4
- package/{src/lib → packages/agentsam-repository/src}/merkle/policy.js +1 -0
- package/packages/agentsam-repository/test/contracts.test.mjs +40 -0
- package/packages/agentsam-repository/test/git-context.test.mjs +24 -0
- package/{test/merkle.test.mjs → packages/agentsam-repository/test/merkle-core.test.mjs} +2 -32
- package/{test → packages/agentsam-repository/test}/merkle-persistence.test.mjs +11 -6
- package/packages/connectors/cloudflare/package.json +10 -0
- package/packages/connectors/cloudflare/src/index.js +127 -0
- package/packages/connectors/cloudflare/src/owner.js +76 -0
- package/packages/connectors/cloudflare/src/routes.js +223 -0
- package/packages/connectors/cloudflare/src/vault.js +80 -0
- package/packages/connectors/cloudflare/tests/connector.test.mjs +44 -0
- package/packages/identity/package.json +2 -2
- package/packages/identity/src/contracts/auth-config.js +18 -7
- package/packages/identity/tests/auth-config.test.mjs +9 -5
- package/packages/identity/tests/oauth-credentials.test.mjs +4 -4
- package/protocol/COMPANY_REPOSITORY_GRAPH_V1.md +91 -0
- package/protocol/MERKLE_PERSISTENCE_V1.md +2 -0
- package/protocol/MERKLE_PERSISTENCE_V2.md +40 -0
- package/protocol/README.md +1 -0
- package/protocol/capabilities/cloudflare-cpu-audit-input.schema.json +19 -0
- package/protocol/capabilities/cloudflare-cpu-profile-input.schema.json +13 -0
- package/protocol/capabilities/cloudflare-wrangler-native-input.schema.json +19 -0
- package/protocol/capabilities/manifest.json +47 -0
- package/protocol/context/context-budget.schema.json +10 -15
- package/protocol/context/context-item.schema.json +4 -5
- package/protocol/context/resolved-context-pack.schema.json +19 -14
- package/protocol/models/README.md +373 -0
- package/protocol/models/model-inventory-v2.schema.json +212 -0
- package/protocol/repository/repository-contract.schema.json +24 -0
- package/protocol/repository/repository-dependency.schema.json +24 -0
- package/protocol/repository/repository-identity.schema.json +17 -0
- package/protocol/rpc/v1/common.proto +16 -0
- package/protocol/rpc/v1/errors.proto +35 -0
- package/protocol/rpc/v1/knowledge.proto +77 -0
- package/services/knowledge/package-lock.json +333 -0
- package/services/knowledge/package.json +5 -1
- package/skills/agentsam-cloudflare-workers/SKILL.md +53 -0
- package/skills/agentsam-cloudflare-workers/references/cpu-profiling.md +16 -0
- package/skills/agentsam-cloudflare-workers/references/errors-and-observability.md +29 -0
- package/skills/agentsam-cloudflare-workers/references/wrangler-native-map.md +28 -0
- package/skills/catalog.json +18 -0
- package/src/agent/capability-adapter.js +25 -13
- package/src/agent/index.js +1 -0
- package/src/agent/responses-runner.js +353 -0
- package/src/capabilities/repository-snapshot.js +3 -3
- package/src/cli.js +118 -31
- package/src/cloudflare/cpu-profile.js +115 -0
- package/src/cloudflare/index.js +14 -0
- package/src/cloudflare/wrangler.js +132 -0
- package/src/commands/account-auth.js +47 -0
- package/src/commands/cloudflare.js +58 -0
- package/src/commands/connections.js +93 -0
- package/src/commands/context-economics.js +129 -0
- package/src/commands/context.js +1 -1
- package/src/commands/db.js +20 -3
- package/src/commands/deploy.js +39 -3
- package/src/commands/env.js +90 -0
- package/src/commands/eval.js +63 -0
- package/src/commands/interactive.js +2 -5
- package/src/commands/knowledge.js +12 -4
- package/src/commands/merkle-persist.js +30 -11
- package/src/commands/merkle.js +1 -1
- package/src/commands/models.js +149 -46
- package/src/commands/ollama.js +26 -0
- package/src/commands/preferences.js +130 -61
- package/src/commands/resume.js +67 -0
- package/src/commands/security.js +5 -3
- package/src/commands/shell.js +568 -119
- package/src/commands/tunnel.js +2 -2
- package/src/commands/whoami.js +86 -0
- package/src/context/budget.js +68 -6
- package/src/context/index.js +3 -1
- package/src/context/rehydrate.js +35 -0
- package/src/context/resolve.js +44 -12
- package/src/errors/contract.js +236 -0
- package/src/errors/diagnostic.js +160 -0
- package/src/errors/index.js +23 -0
- package/src/eval/context.js +191 -0
- package/src/eval/index.js +1 -0
- package/src/index.js +68 -2
- package/src/knowledge/service/auth.js +13 -0
- package/src/knowledge/service/grpc-client.js +115 -0
- package/src/knowledge/service/grpc-codec.js +237 -0
- package/src/knowledge/service/grpc-server.js +83 -0
- package/src/knowledge/service/job-engine.js +248 -0
- package/src/knowledge/service/server.js +87 -135
- package/src/knowledge/source.js +1 -1
- package/src/lib/account-session.js +98 -0
- package/src/lib/agent-instructions.js +73 -0
- package/src/lib/auth.js +4 -0
- package/src/lib/cli-preferences.js +55 -24
- package/src/lib/deploy/git-guard.js +69 -0
- package/src/lib/deploy/health.js +57 -0
- package/src/lib/deploy/local-studio.js +283 -0
- package/src/lib/deploy/secret-scan.js +65 -0
- package/src/lib/deploy-receipt/index.js +2 -2
- package/src/lib/detect-context.js +2 -2
- package/src/lib/execution-approvals.js +59 -0
- package/src/lib/knowledge-docker.js +6 -3
- package/src/lib/local-sessions.js +148 -0
- package/src/lib/local-status.js +1 -1
- package/src/lib/project-config.js +1 -1
- package/src/lib/provider-credentials.js +183 -0
- package/src/lib/scaffold/templates/worker-api/index.js +101 -20
- package/src/lib/scaffold/wizards/worker-api.js +27 -11
- package/src/lib/slash-commands.js +23 -16
- package/src/local/migrations.js +93 -0
- package/src/local/runtime-store.js +141 -0
- package/src/local/sqlite.js +2 -0
- package/src/local-pty/server.js +113 -51
- package/src/models/catalog.js +135 -0
- package/src/models/discovery.js +292 -0
- package/src/models/index.js +7 -0
- package/src/providers/anthropic-messages.js +192 -0
- package/src/providers/cloudflare-chat.js +183 -0
- package/src/providers/factory.js +69 -0
- package/src/providers/gemini-generate-content.js +208 -0
- package/src/providers/index.js +10 -0
- package/src/providers/ollama-chat.js +148 -0
- package/src/providers/openai-responses.js +426 -0
- package/src/repository/index.js +14 -2
- package/src/rpc/generated/common_grpc_pb.js +1 -0
- package/src/rpc/generated/common_pb.js +536 -0
- package/src/rpc/generated/errors_grpc_pb.js +1 -0
- package/src/rpc/generated/errors_pb.js +482 -0
- package/src/rpc/generated/knowledge_grpc_pb.js +135 -0
- package/src/rpc/generated/knowledge_pb.js +2168 -0
- package/src/rpc/generated/package.json +3 -0
- package/src/security/process.js +35 -9
- package/src/security/trust-boundary.js +2 -2
- package/src/telemetry/contracts.js +203 -0
- package/src/telemetry/events.js +51 -0
- package/src/telemetry/index.js +8 -0
- package/src/tools/hydrate.js +35 -0
- package/src/tools/index.js +1 -0
- package/src/ui/boot.js +15 -17
- package/src/ui/cli/activity.js +76 -0
- package/src/ui/cli/compaction.js +15 -0
- package/src/ui/cli/footer.js +39 -0
- package/src/ui/cli/help.js +192 -0
- package/src/ui/cli/plan.js +20 -0
- package/src/ui/cli/runtime-events.js +110 -0
- package/src/ui/cli/waiting.js +16 -0
- package/src/ui/merkle/render.js +1 -1
- package/test/account-session.test.mjs +36 -0
- package/test/cli/preferences-runtime.test.mjs +11 -0
- package/test/cli/runtime-ui.test.mjs +74 -0
- package/test/cli-preferences.test.mjs +26 -5
- package/test/cloudflare-connector.test.mjs +96 -0
- package/test/cloudflare-runtime.test.mjs +75 -0
- package/test/context.test.mjs +61 -12
- package/test/deploy-health-scan.test.mjs +67 -0
- package/test/error-diagnostics.test.mjs +115 -0
- package/test/eval-context.test.mjs +37 -0
- package/test/execution-approvals.test.mjs +27 -0
- package/test/fixtures/knowledge-rpc-worker.mjs +16 -0
- package/test/integration/cli-help.test.mjs +37 -0
- package/test/integration/knowledge-rpc.test.mjs +112 -0
- package/test/integration/merkle-cli.test.mjs +61 -0
- package/test/integration/merkle-persistence-identity.test.mjs +48 -0
- package/test/integration/provider-env-cli.test.mjs +49 -0
- package/test/integration/provider-factory.test.mjs +197 -0
- package/test/integration/repository-company-graph.test.mjs +90 -0
- package/test/integration/runtime-migrations.test.mjs +82 -0
- package/test/knowledge-service.test.mjs +5 -0
- package/test/knowledge.test.mjs +16 -0
- package/test/live/terminal-transport.live.test.mjs +24 -0
- package/test/local-sessions.test.mjs +48 -0
- package/test/local-studio-deploy.test.mjs +83 -0
- package/test/model-catalog.test.mjs +43 -0
- package/test/models.test.mjs +127 -16
- package/test/npm10-lock.test.mjs +29 -0
- package/test/ollama.test.mjs +21 -0
- package/test/openai-responses.test.mjs +95 -0
- package/test/portable-context.test.mjs +1 -1
- package/test/provider-credentials.test.mjs +96 -0
- package/test/rehydrate.test.mjs +25 -0
- package/test/release-hygiene.test.mjs +13 -5
- package/test/responses-runner.test.mjs +150 -0
- package/test/shell.test.mjs +92 -23
- package/test/smoke.mjs +4 -1
- package/test/telemetry.test.mjs +79 -0
- package/test/terminal/local-pty.mock.test.mjs +151 -0
- package/test/tools-search.test.mjs +14 -1
- package/test/whoami-resume.test.mjs +56 -0
- /package/{src/lib → packages/agentsam-repository/src}/git-context.js +0 -0
- /package/{src/lib → packages/agentsam-repository/src}/merkle/diff.js +0 -0
- /package/{src/lib → packages/agentsam-repository/src}/merkle/filemeta.js +0 -0
- /package/{src/lib → packages/agentsam-repository/src}/merkle/git-ignore.js +0 -0
- /package/{src/lib → packages/agentsam-repository/src}/merkle/hash.js +0 -0
- /package/{src/lib → packages/agentsam-repository/src}/merkle/semantic.js +0 -0
- /package/{src/lib → packages/agentsam-repository/src}/merkle/snapshot.js +0 -0
- /package/{src/lib → packages/agentsam-repository/src}/merkle/tree.js +0 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
-- AgentSam portable CLI/runtime state.
|
|
2
|
+
-- Compatible with Node SQLite and Cloudflare D1.
|
|
3
|
+
-- Identity is account_id when available; standalone installs may leave account_id NULL.
|
|
4
|
+
-- Derived from live IAM runtime tables on 2026-09-17, with tenant/workspace fields intentionally removed.
|
|
5
|
+
|
|
6
|
+
PRAGMA foreign_keys = ON;
|
|
7
|
+
|
|
8
|
+
CREATE TABLE IF NOT EXISTS agentsam_agent_run (
|
|
9
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
10
|
+
account_id TEXT,
|
|
11
|
+
conversation_id TEXT,
|
|
12
|
+
external_agent_id TEXT,
|
|
13
|
+
external_run_id TEXT,
|
|
14
|
+
parent_run_id TEXT REFERENCES agentsam_agent_run(id) ON DELETE SET NULL,
|
|
15
|
+
source_client TEXT,
|
|
16
|
+
surface TEXT,
|
|
17
|
+
mode TEXT NOT NULL DEFAULT 'agent'
|
|
18
|
+
CHECK (mode IN ('ask','plan','agent','debug','multitask')),
|
|
19
|
+
model_key TEXT,
|
|
20
|
+
reasoning_effort TEXT,
|
|
21
|
+
requested_service_tier TEXT,
|
|
22
|
+
actual_service_tier TEXT,
|
|
23
|
+
selected_by TEXT CHECK (selected_by IS NULL OR selected_by IN ('manual','automatic','fallback')),
|
|
24
|
+
status TEXT NOT NULL DEFAULT 'queued'
|
|
25
|
+
CHECK (status IN ('queued','running','paused','completed','failed','partial','cancelled')),
|
|
26
|
+
cancel_requested INTEGER NOT NULL DEFAULT 0 CHECK (cancel_requested IN (0,1)),
|
|
27
|
+
error_code TEXT,
|
|
28
|
+
error_message TEXT,
|
|
29
|
+
model_call_count INTEGER NOT NULL DEFAULT 0 CHECK (model_call_count >= 0),
|
|
30
|
+
tool_call_count INTEGER NOT NULL DEFAULT 0 CHECK (tool_call_count >= 0),
|
|
31
|
+
input_tokens INTEGER NOT NULL DEFAULT 0 CHECK (input_tokens >= 0),
|
|
32
|
+
cached_input_tokens INTEGER NOT NULL DEFAULT 0 CHECK (cached_input_tokens >= 0),
|
|
33
|
+
output_tokens INTEGER NOT NULL DEFAULT 0 CHECK (output_tokens >= 0),
|
|
34
|
+
reasoning_tokens INTEGER NOT NULL DEFAULT 0 CHECK (reasoning_tokens >= 0),
|
|
35
|
+
cost_usd REAL NOT NULL DEFAULT 0 CHECK (cost_usd >= 0),
|
|
36
|
+
created_at_unix INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
37
|
+
started_at_unix INTEGER,
|
|
38
|
+
completed_at_unix INTEGER,
|
|
39
|
+
updated_at_unix INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
40
|
+
latency_ms INTEGER
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_agent_run_account_updated
|
|
44
|
+
ON agentsam_agent_run(account_id, updated_at_unix DESC);
|
|
45
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_agent_run_parent
|
|
46
|
+
ON agentsam_agent_run(parent_run_id, created_at_unix);
|
|
47
|
+
|
|
48
|
+
CREATE TABLE IF NOT EXISTS agentsam_compaction_events (
|
|
49
|
+
id TEXT PRIMARY KEY DEFAULT ('cmp_' || lower(hex(randomblob(8)))),
|
|
50
|
+
account_id TEXT,
|
|
51
|
+
agent_run_id TEXT REFERENCES agentsam_agent_run(id) ON DELETE SET NULL,
|
|
52
|
+
conversation_id TEXT,
|
|
53
|
+
compaction_type TEXT NOT NULL DEFAULT 'context_summary'
|
|
54
|
+
CHECK (compaction_type IN (
|
|
55
|
+
'context_summary','data_summary','run_summary','usage_summary',
|
|
56
|
+
'memory_summary','rule_summary','audit_summary','performance_summary','routing_summary'
|
|
57
|
+
)),
|
|
58
|
+
compaction_scope TEXT NOT NULL DEFAULT 'agent_run'
|
|
59
|
+
CHECK (compaction_scope IN ('rowset','table','agent_run','workflow','system')),
|
|
60
|
+
compaction_strategy TEXT NOT NULL DEFAULT 'summarize'
|
|
61
|
+
CHECK (compaction_strategy IN ('summarize','truncate','selective','full','rollup','audit')),
|
|
62
|
+
source_kind TEXT NOT NULL DEFAULT 'api'
|
|
63
|
+
CHECK (source_kind IN (
|
|
64
|
+
'd1','sqlite','r2','supabase','vectorize','hyperdrive','github',
|
|
65
|
+
'filesystem','worker_logs','api','browser','screenshot','mixed'
|
|
66
|
+
)),
|
|
67
|
+
source_table TEXT NOT NULL DEFAULT '',
|
|
68
|
+
source_row_count INTEGER NOT NULL DEFAULT 0,
|
|
69
|
+
source_min_epoch INTEGER,
|
|
70
|
+
source_max_epoch INTEGER,
|
|
71
|
+
source_filter_json TEXT NOT NULL DEFAULT '{}',
|
|
72
|
+
source_snapshot_json TEXT NOT NULL DEFAULT '{}',
|
|
73
|
+
source_query_hash TEXT NOT NULL DEFAULT '',
|
|
74
|
+
content_hash TEXT NOT NULL DEFAULT '',
|
|
75
|
+
provider TEXT NOT NULL DEFAULT '',
|
|
76
|
+
model_key TEXT NOT NULL DEFAULT '',
|
|
77
|
+
tokens_before INTEGER NOT NULL DEFAULT 0,
|
|
78
|
+
tokens_after INTEGER NOT NULL DEFAULT 0,
|
|
79
|
+
tokens_saved INTEGER GENERATED ALWAYS AS (tokens_before - tokens_after) STORED,
|
|
80
|
+
cost_before_usd REAL NOT NULL DEFAULT 0,
|
|
81
|
+
cost_after_usd REAL NOT NULL DEFAULT 0,
|
|
82
|
+
cost_saved_usd REAL GENERATED ALWAYS AS (cost_before_usd - cost_after_usd) STORED,
|
|
83
|
+
status TEXT NOT NULL DEFAULT 'completed'
|
|
84
|
+
CHECK(status IN ('queued','running','completed','failed','cancelled','needs_review')),
|
|
85
|
+
summary_text TEXT NOT NULL DEFAULT '',
|
|
86
|
+
summary_json TEXT NOT NULL DEFAULT '{}',
|
|
87
|
+
metrics_json TEXT NOT NULL DEFAULT '{}',
|
|
88
|
+
findings_json TEXT NOT NULL DEFAULT '{}',
|
|
89
|
+
recommended_actions_json TEXT NOT NULL DEFAULT '[]',
|
|
90
|
+
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
91
|
+
source_stored TEXT NOT NULL DEFAULT 'local:agentsam_compaction_events',
|
|
92
|
+
source_url TEXT NOT NULL DEFAULT '',
|
|
93
|
+
report_artifact_url TEXT NOT NULL DEFAULT '',
|
|
94
|
+
expires_at_epoch INTEGER,
|
|
95
|
+
compacted_at_epoch INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
96
|
+
created_at_epoch INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
97
|
+
updated_at_epoch INTEGER NOT NULL DEFAULT (unixepoch())
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_compaction_run
|
|
101
|
+
ON agentsam_compaction_events(agent_run_id, compacted_at_epoch DESC);
|
|
102
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_compaction_expiry
|
|
103
|
+
ON agentsam_compaction_events(expires_at_epoch)
|
|
104
|
+
WHERE expires_at_epoch IS NOT NULL;
|
|
105
|
+
|
|
106
|
+
CREATE TABLE IF NOT EXISTS agentsam_context_digest (
|
|
107
|
+
id TEXT PRIMARY KEY,
|
|
108
|
+
account_id TEXT,
|
|
109
|
+
digest_type TEXT NOT NULL CHECK (
|
|
110
|
+
digest_type IN (
|
|
111
|
+
'schema','repo','docs','memory','tool_registry','route_map',
|
|
112
|
+
'session','deployment','rag','conversation','handoff','project'
|
|
113
|
+
)
|
|
114
|
+
),
|
|
115
|
+
project_id TEXT,
|
|
116
|
+
agent_run_id TEXT REFERENCES agentsam_agent_run(id) ON DELETE SET NULL,
|
|
117
|
+
session_id TEXT,
|
|
118
|
+
source_hash TEXT NOT NULL,
|
|
119
|
+
digest_hash TEXT NOT NULL UNIQUE,
|
|
120
|
+
raw_size_bytes INTEGER,
|
|
121
|
+
reduced_size_bytes INTEGER,
|
|
122
|
+
token_count INTEGER,
|
|
123
|
+
digest_text TEXT NOT NULL,
|
|
124
|
+
generation_model TEXT,
|
|
125
|
+
namespace TEXT,
|
|
126
|
+
hit_count INTEGER NOT NULL DEFAULT 0,
|
|
127
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
128
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
129
|
+
created_at_unix INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
130
|
+
source_updated_at_unix INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
131
|
+
updated_at_unix INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
132
|
+
expires_at_unix INTEGER,
|
|
133
|
+
embedding_model TEXT,
|
|
134
|
+
embedding_dimensions INTEGER,
|
|
135
|
+
compaction_event_id TEXT
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_context_digest_session
|
|
139
|
+
ON agentsam_context_digest(session_id, source_updated_at_unix DESC)
|
|
140
|
+
WHERE session_id IS NOT NULL;
|
|
141
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_context_digest_run
|
|
142
|
+
ON agentsam_context_digest(agent_run_id, source_updated_at_unix DESC)
|
|
143
|
+
WHERE agent_run_id IS NOT NULL;
|
|
144
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_context_digest_compaction
|
|
145
|
+
ON agentsam_context_digest(compaction_event_id)
|
|
146
|
+
WHERE compaction_event_id IS NOT NULL;
|
|
147
|
+
|
|
148
|
+
CREATE TRIGGER IF NOT EXISTS context_digest_set_initial_expiry
|
|
149
|
+
AFTER INSERT ON agentsam_context_digest
|
|
150
|
+
WHEN NEW.expires_at_unix IS NULL
|
|
151
|
+
BEGIN
|
|
152
|
+
UPDATE agentsam_context_digest
|
|
153
|
+
SET expires_at_unix = CASE
|
|
154
|
+
WHEN NEW.digest_type IN ('session','conversation','handoff')
|
|
155
|
+
THEN unixepoch() + 2592000
|
|
156
|
+
ELSE NULL
|
|
157
|
+
END
|
|
158
|
+
WHERE id = NEW.id;
|
|
159
|
+
END;
|
|
160
|
+
|
|
161
|
+
CREATE TRIGGER IF NOT EXISTS context_digest_extend_on_hit
|
|
162
|
+
AFTER UPDATE OF hit_count ON agentsam_context_digest
|
|
163
|
+
WHEN NEW.hit_count > OLD.hit_count AND OLD.expires_at_unix IS NOT NULL
|
|
164
|
+
BEGIN
|
|
165
|
+
UPDATE agentsam_context_digest
|
|
166
|
+
SET expires_at_unix = unixepoch() + 2592000,
|
|
167
|
+
updated_at_unix = unixepoch(),
|
|
168
|
+
updated_at = datetime('now')
|
|
169
|
+
WHERE id = NEW.id;
|
|
170
|
+
END;
|
|
171
|
+
|
|
172
|
+
CREATE TABLE IF NOT EXISTS agentsam_plans (
|
|
173
|
+
id TEXT PRIMARY KEY,
|
|
174
|
+
account_id TEXT,
|
|
175
|
+
session_id TEXT,
|
|
176
|
+
agent_run_id TEXT REFERENCES agentsam_agent_run(id) ON DELETE SET NULL,
|
|
177
|
+
plan_type TEXT NOT NULL DEFAULT 'feature'
|
|
178
|
+
CHECK(plan_type IN ('daily','sprint','incident','feature','refactor','run')),
|
|
179
|
+
title TEXT NOT NULL,
|
|
180
|
+
status TEXT NOT NULL DEFAULT 'active'
|
|
181
|
+
CHECK(status IN ('draft','active','complete','abandoned')),
|
|
182
|
+
summary_text TEXT NOT NULL DEFAULT '',
|
|
183
|
+
token_budget INTEGER,
|
|
184
|
+
tokens_used INTEGER NOT NULL DEFAULT 0 CHECK(tokens_used >= 0),
|
|
185
|
+
cost_usd REAL NOT NULL DEFAULT 0 CHECK(cost_usd >= 0),
|
|
186
|
+
tasks_total INTEGER NOT NULL DEFAULT 0 CHECK(tasks_total >= 0),
|
|
187
|
+
tasks_done INTEGER NOT NULL DEFAULT 0 CHECK(tasks_done >= 0),
|
|
188
|
+
tasks_blocked INTEGER NOT NULL DEFAULT 0 CHECK(tasks_blocked >= 0),
|
|
189
|
+
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
190
|
+
created_at_unix INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
191
|
+
updated_at_unix INTEGER NOT NULL DEFAULT (unixepoch())
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
CREATE TABLE IF NOT EXISTS agentsam_todo (
|
|
195
|
+
id TEXT PRIMARY KEY,
|
|
196
|
+
account_id TEXT,
|
|
197
|
+
plan_id TEXT REFERENCES agentsam_plans(id) ON DELETE CASCADE,
|
|
198
|
+
agent_run_id TEXT REFERENCES agentsam_agent_run(id) ON DELETE SET NULL,
|
|
199
|
+
title TEXT NOT NULL,
|
|
200
|
+
description TEXT,
|
|
201
|
+
status TEXT NOT NULL DEFAULT 'open'
|
|
202
|
+
CHECK(status IN ('open','running','blocked','complete','cancelled')),
|
|
203
|
+
priority TEXT NOT NULL DEFAULT 'medium'
|
|
204
|
+
CHECK(priority IN ('low','medium','high','critical')),
|
|
205
|
+
sort_order INTEGER NOT NULL DEFAULT 50,
|
|
206
|
+
token_budget INTEGER,
|
|
207
|
+
tokens_used INTEGER NOT NULL DEFAULT 0 CHECK(tokens_used >= 0),
|
|
208
|
+
cost_usd REAL NOT NULL DEFAULT 0 CHECK(cost_usd >= 0),
|
|
209
|
+
requires_approval INTEGER NOT NULL DEFAULT 0 CHECK(requires_approval IN (0,1)),
|
|
210
|
+
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
211
|
+
started_at_unix INTEGER,
|
|
212
|
+
completed_at_unix INTEGER,
|
|
213
|
+
created_at_unix INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
214
|
+
updated_at_unix INTEGER NOT NULL DEFAULT (unixepoch())
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_todo_plan
|
|
218
|
+
ON agentsam_todo(plan_id, sort_order, created_at_unix);
|
|
219
|
+
|
|
220
|
+
CREATE TABLE IF NOT EXISTS agentsam_approval_queue (
|
|
221
|
+
id TEXT PRIMARY KEY DEFAULT ('appr_' || lower(hex(randomblob(8)))),
|
|
222
|
+
account_id TEXT,
|
|
223
|
+
session_id TEXT,
|
|
224
|
+
conversation_id TEXT,
|
|
225
|
+
agent_run_id TEXT REFERENCES agentsam_agent_run(id) ON DELETE SET NULL,
|
|
226
|
+
plan_id TEXT REFERENCES agentsam_plans(id) ON DELETE SET NULL,
|
|
227
|
+
todo_id TEXT REFERENCES agentsam_todo(id) ON DELETE SET NULL,
|
|
228
|
+
capability_key TEXT,
|
|
229
|
+
tool_name TEXT,
|
|
230
|
+
action_summary TEXT NOT NULL,
|
|
231
|
+
sanitized_input_json TEXT NOT NULL DEFAULT '{}',
|
|
232
|
+
response_json TEXT NOT NULL DEFAULT '{}',
|
|
233
|
+
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
234
|
+
risk_level TEXT NOT NULL DEFAULT 'medium'
|
|
235
|
+
CHECK (risk_level IN ('low','medium','high','critical')),
|
|
236
|
+
approval_type TEXT NOT NULL DEFAULT 'tool'
|
|
237
|
+
CHECK (approval_type IN (
|
|
238
|
+
'tool','workflow','command','script','deploy','db_write','r2_write',
|
|
239
|
+
'github_write','terminal','spawn','escalation','route_upgrade'
|
|
240
|
+
)),
|
|
241
|
+
status TEXT NOT NULL DEFAULT 'pending'
|
|
242
|
+
CHECK (status IN ('pending','approved','denied','expired')),
|
|
243
|
+
approved_by TEXT,
|
|
244
|
+
decided_at INTEGER,
|
|
245
|
+
expires_at INTEGER DEFAULT (unixepoch() + 300),
|
|
246
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_approval_pending
|
|
250
|
+
ON agentsam_approval_queue(status, expires_at)
|
|
251
|
+
WHERE status = 'pending';
|
|
252
|
+
|
|
253
|
+
CREATE TABLE IF NOT EXISTS active_timers (
|
|
254
|
+
id TEXT PRIMARY KEY,
|
|
255
|
+
account_id TEXT,
|
|
256
|
+
label TEXT NOT NULL DEFAULT '',
|
|
257
|
+
timer_kind TEXT NOT NULL CHECK (timer_kind IN ('stopwatch','countdown')),
|
|
258
|
+
status TEXT NOT NULL DEFAULT 'running'
|
|
259
|
+
CHECK (status IN ('running','paused','completed','cancelled','expired')),
|
|
260
|
+
started_at_unix INTEGER NOT NULL,
|
|
261
|
+
ends_at_unix INTEGER,
|
|
262
|
+
paused_at_unix INTEGER,
|
|
263
|
+
elapsed_seconds INTEGER NOT NULL DEFAULT 0,
|
|
264
|
+
completed_at_unix INTEGER,
|
|
265
|
+
agent_run_id TEXT REFERENCES agentsam_agent_run(id) ON DELETE CASCADE,
|
|
266
|
+
approval_queue_id TEXT REFERENCES agentsam_approval_queue(id) ON DELETE CASCADE,
|
|
267
|
+
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
268
|
+
updated_at_unix INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
269
|
+
CHECK (
|
|
270
|
+
timer_kind != 'countdown'
|
|
271
|
+
OR (ends_at_unix IS NOT NULL AND ends_at_unix > started_at_unix)
|
|
272
|
+
),
|
|
273
|
+
CHECK (agent_run_id IS NOT NULL OR approval_queue_id IS NOT NULL)
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
CREATE INDEX IF NOT EXISTS idx_active_timers_running
|
|
277
|
+
ON active_timers(status, ends_at_unix)
|
|
278
|
+
WHERE status = 'running';
|
|
279
|
+
|
|
280
|
+
CREATE TABLE IF NOT EXISTS agentsam_cron_runs (
|
|
281
|
+
id TEXT PRIMARY KEY DEFAULT ('acr_' || lower(hex(randomblob(8)))),
|
|
282
|
+
account_id TEXT,
|
|
283
|
+
job_name TEXT NOT NULL,
|
|
284
|
+
cron_expression TEXT,
|
|
285
|
+
status TEXT NOT NULL DEFAULT 'running'
|
|
286
|
+
CHECK(status IN ('running','completed','failed','skipped')),
|
|
287
|
+
started_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
288
|
+
completed_at INTEGER,
|
|
289
|
+
duration_ms INTEGER,
|
|
290
|
+
rows_read INTEGER NOT NULL DEFAULT 0,
|
|
291
|
+
rows_written INTEGER NOT NULL DEFAULT 0,
|
|
292
|
+
error_message TEXT,
|
|
293
|
+
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
294
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
CREATE INDEX IF NOT EXISTS idx_agentsam_cron_runs_job_started
|
|
298
|
+
ON agentsam_cron_runs(job_name, started_at DESC);
|
package/package.json
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inneranimalmedia/agentsam-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Portable AgentSam SDK and CLI kits for local scaffolding, repository intelligence, incremental indexing, identity adapters, and verified dependency maintenance.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
9
|
-
"./git-context": "./src/
|
|
9
|
+
"./git-context": "./packages/agentsam-repository/src/git-context.js",
|
|
10
10
|
"./bridge-client": "./src/lib/bridge-client.js",
|
|
11
11
|
"./local/sqlite": "./src/local/sqlite.js",
|
|
12
12
|
"./dockerize": "./src/lib/dockerize.js",
|
|
13
13
|
"./mini": "./src/lib/mini/index.js",
|
|
14
|
-
"./merkle": "./src/
|
|
14
|
+
"./merkle": "./packages/agentsam-repository/src/merkle/index.js",
|
|
15
15
|
"./deploy-receipt": "./src/lib/deploy-receipt/index.js",
|
|
16
16
|
"./knowledge": "./src/knowledge/index.js",
|
|
17
17
|
"./knowledge-service-client": "./src/knowledge/service/client.js",
|
|
18
|
+
"./knowledge-service-grpc-client": "./src/knowledge/service/grpc-client.js",
|
|
18
19
|
"./capabilities": "./src/capabilities/index.js",
|
|
19
20
|
"./capability-manifest": "./protocol/capabilities/manifest.json",
|
|
20
21
|
"./repository": "./src/repository/index.js",
|
|
22
|
+
"./repository/contracts": "./packages/agentsam-repository/src/contracts.js",
|
|
23
|
+
"./repository/identity-schema": "./protocol/repository/repository-identity.schema.json",
|
|
24
|
+
"./repository/contract-schema": "./protocol/repository/repository-contract.schema.json",
|
|
25
|
+
"./repository/dependency-schema": "./protocol/repository/repository-dependency.schema.json",
|
|
21
26
|
"./agent": "./src/agent/index.js",
|
|
22
27
|
"./presets": "./src/presets/index.js",
|
|
23
28
|
"./preset-catalog": "./protocol/presets/catalog.json",
|
|
@@ -50,6 +55,12 @@
|
|
|
50
55
|
"./context": "./src/context/index.js",
|
|
51
56
|
"./indexing": "./src/indexing/index.js",
|
|
52
57
|
"./tools": "./src/tools/index.js",
|
|
58
|
+
"./models": "./src/models/index.js",
|
|
59
|
+
"./telemetry": "./src/telemetry/index.js",
|
|
60
|
+
"./providers": "./src/providers/index.js",
|
|
61
|
+
"./errors": "./src/errors/index.js",
|
|
62
|
+
"./cloudflare": "./src/cloudflare/index.js",
|
|
63
|
+
"./eval": "./src/eval/index.js",
|
|
53
64
|
"./context/result-policy-schema": "./protocol/context/result-policy.schema.json",
|
|
54
65
|
"./context/budget-schema": "./protocol/context/context-budget.schema.json",
|
|
55
66
|
"./context/pack-schema": "./protocol/context/resolved-context-pack.schema.json",
|
|
@@ -57,20 +68,23 @@
|
|
|
57
68
|
"./skills/catalog": "./skills/catalog.json"
|
|
58
69
|
},
|
|
59
70
|
"bin": {
|
|
60
|
-
"agentsam": "
|
|
61
|
-
"agentsam-sdk": "
|
|
71
|
+
"agentsam": "bin/agentsam",
|
|
72
|
+
"agentsam-sdk": "bin/agentsam",
|
|
62
73
|
"agentsam-scaffold": "bin/scaffold.mjs",
|
|
63
74
|
"agentsam-auth-portal": "packages/identity/scripts/preview-auth-portal.mjs"
|
|
64
75
|
},
|
|
65
76
|
"files": [
|
|
66
77
|
"src",
|
|
67
78
|
"packages/identity",
|
|
79
|
+
"packages/agentsam-repository",
|
|
80
|
+
"packages/connectors/cloudflare",
|
|
68
81
|
"templates",
|
|
69
82
|
"docs",
|
|
70
83
|
"examples",
|
|
71
84
|
"test",
|
|
72
85
|
"python",
|
|
73
86
|
"protocol",
|
|
87
|
+
"migrations",
|
|
74
88
|
"skills",
|
|
75
89
|
"services/knowledge/package.json",
|
|
76
90
|
"services/knowledge/package-lock.json",
|
|
@@ -79,25 +93,35 @@
|
|
|
79
93
|
"bin",
|
|
80
94
|
"README.md",
|
|
81
95
|
"LICENSE",
|
|
82
|
-
"DEVELOPMENT.md"
|
|
96
|
+
"DEVELOPMENT.md",
|
|
97
|
+
"AGENTSAM.md"
|
|
83
98
|
],
|
|
84
99
|
"workspaces": [
|
|
85
100
|
"packages/agentsam-shell-kit",
|
|
86
101
|
"packages/identity",
|
|
87
102
|
"packages/agentsam-contracts",
|
|
103
|
+
"packages/agentsam-repository",
|
|
88
104
|
"packages/agentsam-workbench"
|
|
89
105
|
],
|
|
90
106
|
"scripts": {
|
|
91
|
-
"test": "
|
|
107
|
+
"test": "npm run test:standard && npm --prefix packages/identity test && npm run test:connectors",
|
|
108
|
+
"test:standard": "node test/smoke.mjs && npm run test:unit && npm run test:cli && npm run test:integration:mock && npm run test:terminal:mock",
|
|
109
|
+
"test:unit": "node --test test/*.test.mjs",
|
|
110
|
+
"test:cli": "node --test test/cli/*.test.mjs",
|
|
111
|
+
"test:integration:mock": "node --test test/integration/*.test.mjs",
|
|
112
|
+
"test:terminal:mock": "node --test test/terminal/*.test.mjs",
|
|
113
|
+
"test:live:terminal": "node --test test/live/*.live.test.mjs",
|
|
92
114
|
"test:identity": "npm --prefix packages/identity test",
|
|
115
|
+
"test:workspaces": "npm --prefix packages/agentsam-contracts test && npm --prefix packages/agentsam-contracts run typecheck && npm --prefix packages/agentsam-repository test && npm --prefix packages/agentsam-workbench test && npm --prefix packages/agentsam-workbench run typecheck && npm --prefix packages/agentsam-shell-kit run typecheck",
|
|
93
116
|
"smoke": "node test/smoke.mjs",
|
|
94
117
|
"verify:package": "node scripts/verify-package.mjs",
|
|
118
|
+
"verify:boundaries": "node scripts/verify-source-boundaries.mjs",
|
|
95
119
|
"verify:bootstrap": "node scripts/verify-bootstrap.mjs",
|
|
96
120
|
"verify:knowledge-package": "node scripts/verify-knowledge-package.mjs",
|
|
97
121
|
"test:python": "node scripts/verify-python.mjs",
|
|
98
122
|
"verify:release": "npm run verify && npm run verify:knowledge-package && npm run test:python && npm run security:check",
|
|
99
123
|
"pack:check": "npm pack --dry-run --json",
|
|
100
|
-
"verify": "npm test && npm run verify:package && npm run verify:bootstrap && npm run pack:check",
|
|
124
|
+
"verify": "npm run proto:check && npm test && npm run test:workspaces && npm run verify:boundaries && npm run verify:package && npm run verify:bootstrap && npm run pack:check",
|
|
101
125
|
"publish:identity-alpha": "bash scripts/publish-identity-alpha.sh",
|
|
102
126
|
"publish:identity-alpha:dry-run": "bash scripts/publish-identity-alpha.sh --dry-run",
|
|
103
127
|
"publish:identity-alpha:publish-only": "bash scripts/publish-identity-alpha.sh --publish-only",
|
|
@@ -105,13 +129,20 @@
|
|
|
105
129
|
"prepublishOnly": "npm run verify:release",
|
|
106
130
|
"security:check": "node src/security/cli.mjs scan",
|
|
107
131
|
"security:repair": "node src/security/cli.mjs repair",
|
|
108
|
-
"ui:preview": "node scripts/ui-preview.mjs"
|
|
132
|
+
"ui:preview": "node scripts/ui-preview.mjs",
|
|
133
|
+
"test:connectors": "node --test packages/connectors/cloudflare/tests/**/*.test.mjs",
|
|
134
|
+
"verify:npm10-lock": "node apps/local-studio/scripts/verify-npm10-lock.mjs",
|
|
135
|
+
"proto:generate": "node scripts/generate-proto.mjs",
|
|
136
|
+
"proto:check": "node scripts/verify-proto.mjs"
|
|
109
137
|
},
|
|
110
138
|
"engines": {
|
|
111
|
-
"node": ">=22
|
|
139
|
+
"node": ">=22 <25",
|
|
140
|
+
"npm": ">=10 <12"
|
|
112
141
|
},
|
|
113
142
|
"dependencies": {
|
|
114
143
|
"@clack/prompts": "^1.7.0",
|
|
144
|
+
"@grpc/grpc-js": "^1.14.4",
|
|
145
|
+
"google-protobuf": "^3.21.4",
|
|
115
146
|
"node-pty": "^1.0.0",
|
|
116
147
|
"pg": "8.16.3",
|
|
117
148
|
"picocolors": "^1.1.1",
|
|
@@ -145,6 +176,8 @@
|
|
|
145
176
|
},
|
|
146
177
|
"devDependencies": {
|
|
147
178
|
"@electric-sql/pglite": "0.5.8",
|
|
148
|
-
"@electric-sql/pglite-pgvector": "0.0.9"
|
|
149
|
-
|
|
179
|
+
"@electric-sql/pglite-pgvector": "0.0.9",
|
|
180
|
+
"grpc-tools": "^1.13.1"
|
|
181
|
+
},
|
|
182
|
+
"packageManager": "npm@10.9.2"
|
|
150
183
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @inneranimalmedia/agentsam-repository
|
|
2
|
+
|
|
3
|
+
Owned repository/runtime package for AgentSam.
|
|
4
|
+
|
|
5
|
+
It owns deterministic repository identity and Merkle behavior that must be reusable independently of the CLI surface:
|
|
6
|
+
|
|
7
|
+
- Git remote/context normalization
|
|
8
|
+
- Merkle content trees and snapshots
|
|
9
|
+
- semantic/file metadata classification
|
|
10
|
+
- Merkle persistence contracts and Cloudflare binding adapters
|
|
11
|
+
- repository graph runtime normalization
|
|
12
|
+
|
|
13
|
+
It does **not** own authenticated account sessions, CLI commands, UI rendering, knowledge retrieval, deployment orchestration, or product application state. Those layers consume this package through explicit imports.
|
|
14
|
+
|
|
15
|
+
The workspace is private while the extraction stabilizes. Cross-repository consumers should continue using the published `@inneranimalmedia/agentsam-sdk` facade until this package receives its own release policy.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inneranimalmedia/agentsam-repository",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Portable AgentSam repository identity, Merkle, semantic file metadata, persistence, and repository graph runtime contracts.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./src/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.js",
|
|
10
|
+
"./git-context": "./src/git-context.js",
|
|
11
|
+
"./contracts": "./src/contracts.js",
|
|
12
|
+
"./merkle": "./src/merkle/index.js",
|
|
13
|
+
"./merkle/persistence": "./src/merkle/persistence.js",
|
|
14
|
+
"./merkle/cloudflare-persistence": "./src/merkle/cloudflare-persistence.js"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node --test test/*.test.mjs"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"typescript": "5.9.3"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22 <25"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export const COMPANY_REPOSITORY_GRAPH_SCHEMA_VERSION = 1;
|
|
2
|
+
|
|
3
|
+
export const REPOSITORY_STATUSES = Object.freeze(['active', 'archived', 'disabled']);
|
|
4
|
+
export const REPOSITORY_CONTRACT_TYPES = Object.freeze(['api', 'schema', 'runtime', 'cli', 'event', 'receipt', 'package']);
|
|
5
|
+
export const REPOSITORY_CONTRACT_STATUSES = Object.freeze(['active', 'deprecated', 'retired']);
|
|
6
|
+
export const REPOSITORY_DEPENDENCY_TYPES = Object.freeze(['runtime', 'build', 'contract', 'package', 'deploy', 'tool', 'data']);
|
|
7
|
+
export const REPOSITORY_DEPENDENCY_CRITICALITIES = Object.freeze(['informational', 'compatible', 'strict', 'critical']);
|
|
8
|
+
export const REPOSITORY_FAILURE_POLICIES = Object.freeze(['warn', 'block_certification', 'block_deploy', 'degrade']);
|
|
9
|
+
|
|
10
|
+
const LEGACY_OWNERSHIP_KEYS = Object.freeze([
|
|
11
|
+
'tenant_id', 'tenantId',
|
|
12
|
+
'workspace_id', 'workspaceId',
|
|
13
|
+
'user_id', 'userId',
|
|
14
|
+
'owner_user_id', 'ownerUserId',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
function clean(value) {
|
|
18
|
+
return value == null ? '' : String(value).trim();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function required(value, label) {
|
|
22
|
+
const text = clean(value);
|
|
23
|
+
if (!text) throw new TypeError(`${label} is required`);
|
|
24
|
+
return text;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function optional(value) {
|
|
28
|
+
const text = clean(value);
|
|
29
|
+
return text || null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function enumValue(value, allowed, label) {
|
|
33
|
+
const text = required(value, label).toLowerCase();
|
|
34
|
+
if (!allowed.includes(text)) throw new RangeError(`unsupported ${label}: ${text}`);
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function optionalUnix(value, label) {
|
|
39
|
+
if (value == null || value === '') return null;
|
|
40
|
+
const number = Number(value);
|
|
41
|
+
if (!Number.isInteger(number) || number < 0) throw new RangeError(`${label} must be a non-negative integer`);
|
|
42
|
+
return number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function rejectLegacyOwnership(value) {
|
|
46
|
+
for (const key of LEGACY_OWNERSHIP_KEYS) {
|
|
47
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
48
|
+
throw new TypeError(`legacy ownership field is not supported: ${key}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Portable repository identity. Ownership is intentionally not embedded here;
|
|
55
|
+
* the authenticated host binds repository_id to account_id in its registry.
|
|
56
|
+
*/
|
|
57
|
+
export function createRepositoryIdentity(value = {}) {
|
|
58
|
+
rejectLegacyOwnership(value);
|
|
59
|
+
if (Object.prototype.hasOwnProperty.call(value, 'account_id') || Object.prototype.hasOwnProperty.call(value, 'accountId')) {
|
|
60
|
+
throw new TypeError('repository identity must not embed account_id');
|
|
61
|
+
}
|
|
62
|
+
return Object.freeze({
|
|
63
|
+
schema_version: COMPANY_REPOSITORY_GRAPH_SCHEMA_VERSION,
|
|
64
|
+
repository_id: required(value.repository_id ?? value.repositoryId, 'repository_id'),
|
|
65
|
+
full_name: required(value.full_name ?? value.fullName, 'full_name'),
|
|
66
|
+
role: required(value.role, 'role'),
|
|
67
|
+
default_branch: optional(value.default_branch ?? value.defaultBranch) || 'main',
|
|
68
|
+
canonical_url: optional(value.canonical_url ?? value.canonicalUrl),
|
|
69
|
+
status: enumValue(value.status || 'active', REPOSITORY_STATUSES, 'repository status'),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Account-bound declaration of one public repository contract. */
|
|
74
|
+
export function createRepositoryContract(value = {}) {
|
|
75
|
+
rejectLegacyOwnership(value);
|
|
76
|
+
return Object.freeze({
|
|
77
|
+
schema_version: COMPANY_REPOSITORY_GRAPH_SCHEMA_VERSION,
|
|
78
|
+
id: required(value.id, 'id'),
|
|
79
|
+
account_id: required(value.account_id ?? value.accountId, 'account_id'),
|
|
80
|
+
repository_id: required(value.repository_id ?? value.repositoryId, 'repository_id'),
|
|
81
|
+
contract_key: required(value.contract_key ?? value.contractKey, 'contract_key'),
|
|
82
|
+
contract_version: required(value.contract_version ?? value.contractVersion, 'contract_version'),
|
|
83
|
+
contract_type: enumValue(value.contract_type ?? value.contractType, REPOSITORY_CONTRACT_TYPES, 'contract_type'),
|
|
84
|
+
name: optional(value.name) || required(value.contract_key ?? value.contractKey, 'contract_key'),
|
|
85
|
+
description: optional(value.description),
|
|
86
|
+
manifest_path: optional(value.manifest_path ?? value.manifestPath),
|
|
87
|
+
contract_hash: required(value.contract_hash ?? value.contractHash, 'contract_hash'),
|
|
88
|
+
status: enumValue(value.status || 'active', REPOSITORY_CONTRACT_STATUSES, 'contract status'),
|
|
89
|
+
created_at: optionalUnix(value.created_at ?? value.createdAt, 'created_at'),
|
|
90
|
+
updated_at: optionalUnix(value.updated_at ?? value.updatedAt, 'updated_at'),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Account-bound cross-repository dependency edge. */
|
|
95
|
+
export function createRepositoryDependency(value = {}) {
|
|
96
|
+
rejectLegacyOwnership(value);
|
|
97
|
+
return Object.freeze({
|
|
98
|
+
schema_version: COMPANY_REPOSITORY_GRAPH_SCHEMA_VERSION,
|
|
99
|
+
id: required(value.id, 'id'),
|
|
100
|
+
account_id: required(value.account_id ?? value.accountId, 'account_id'),
|
|
101
|
+
source_repository_id: required(value.source_repository_id ?? value.sourceRepositoryId, 'source_repository_id'),
|
|
102
|
+
target_repository_id: required(value.target_repository_id ?? value.targetRepositoryId, 'target_repository_id'),
|
|
103
|
+
dependency_type: enumValue(value.dependency_type ?? value.dependencyType, REPOSITORY_DEPENDENCY_TYPES, 'dependency_type'),
|
|
104
|
+
contract_id: optional(value.contract_id ?? value.contractId),
|
|
105
|
+
criticality: enumValue(value.criticality, REPOSITORY_DEPENDENCY_CRITICALITIES, 'criticality'),
|
|
106
|
+
required_version: optional(value.required_version ?? value.requiredVersion),
|
|
107
|
+
required_contract_hash: optional(value.required_contract_hash ?? value.requiredContractHash),
|
|
108
|
+
failure_policy: enumValue(value.failure_policy ?? value.failurePolicy, REPOSITORY_FAILURE_POLICIES, 'failure_policy'),
|
|
109
|
+
description: optional(value.description),
|
|
110
|
+
created_at: optionalUnix(value.created_at ?? value.createdAt, 'created_at'),
|
|
111
|
+
updated_at: optionalUnix(value.updated_at ?? value.updatedAt, 'updated_at'),
|
|
112
|
+
});
|
|
113
|
+
}
|