@subcortex-ai/sdk 0.1.3 → 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.
package/dist/index.d.ts CHANGED
@@ -517,6 +517,8 @@ interface RegisterPersonInput {
517
517
  details?: string;
518
518
  /** Confidence level */
519
519
  confidence?: ConfidenceLevel | number;
520
+ /** Session ID for experience binding */
521
+ sessionId?: string;
520
522
  }
521
523
  /** Result of person registration */
522
524
  interface RegisterPersonResult {
@@ -685,6 +687,214 @@ declare class SignalsNamespace {
685
687
  }>;
686
688
  }
687
689
 
690
+ /**
691
+ * Rule types — typed code guardrails stored as assertions.
692
+ *
693
+ * Rules are assertions with structured predicates (`rule:banned_pattern`,
694
+ * `rule:required_pattern`, etc.) and typed values. The engine stores them
695
+ * identically to any other assertion — same WAL, same content-addressable IDs,
696
+ * same temporal model, same supersession chain.
697
+ *
698
+ * The RulesNamespace provides typed CRUD and file-scope matching on top of
699
+ * the raw assertion layer, so consumers don't parse JSON blobs in hooks.
700
+ */
701
+ /** The kind of enforcement a rule performs. */
702
+ type RuleType = 'banned_pattern' | 'required_pattern' | 'file_constraint' | 'requires_propagation';
703
+ /** How the system responds to a violation. */
704
+ type RuleSeverity = 'block' | 'warn' | 'info';
705
+ /** Well-known rule predicates. Scoped under `rule:` to avoid collision with general assertions. */
706
+ declare const RulePredicates: {
707
+ readonly BANNED_PATTERN: "rule:banned_pattern";
708
+ readonly REQUIRED_PATTERN: "rule:required_pattern";
709
+ readonly FILE_CONSTRAINT: "rule:file_constraint";
710
+ readonly REQUIRES_PROPAGATION: "rule:requires_propagation";
711
+ };
712
+ type RulePredicate = typeof RulePredicates[keyof typeof RulePredicates];
713
+ /** The typed structure stored in the assertion value field. */
714
+ interface RuleValue {
715
+ /** Regex pattern to match against file content (banned/required pattern rules). */
716
+ pattern?: string;
717
+ /** Glob or regex for which files this rule applies to. If omitted, applies to all files. */
718
+ fileScope?: string;
719
+ /** Human-readable description of what this rule enforces and why. */
720
+ description: string;
721
+ /** What surfaces must be updated when this rule's scope is changed (propagation rules). */
722
+ propagatesTo?: string[];
723
+ }
724
+ /** A rule — a typed, parsed view of an enforcement assertion. */
725
+ interface Rule {
726
+ /** Assertion ID (content-addressable BLAKE3 hash) */
727
+ id: string;
728
+ /** Tenant this rule belongs to */
729
+ tenantId: string;
730
+ /** Subject scope — e.g. `project:{id}`, `intent:api`, `file:prisma/schema.prisma` */
731
+ subject: string;
732
+ /** Rule type — which enforcement behavior this rule triggers */
733
+ type: RuleType;
734
+ /** The full typed predicate, e.g. `rule:banned_pattern` */
735
+ predicate: RulePredicate;
736
+ /** Structured rule configuration */
737
+ value: RuleValue;
738
+ /** Severity — block (enforcement), warn (guidance), info (context) */
739
+ severity: RuleSeverity;
740
+ /** Confidence score from the underlying assertion */
741
+ confidence: number;
742
+ /** When this rule became active */
743
+ validFrom: string;
744
+ /** Whether this rule has been superseded by a newer version */
745
+ isSuperseded: boolean;
746
+ }
747
+ /** Input for creating a rule. */
748
+ interface CreateRuleInput {
749
+ /** Subject scope — e.g. `project:{id}`, `intent:api`, `file:src/db/schema.ts` */
750
+ subject: string;
751
+ /** Rule type */
752
+ type: RuleType;
753
+ /** Regex pattern (for banned_pattern and required_pattern) */
754
+ pattern?: string;
755
+ /** File scope glob/regex — which files this rule applies to */
756
+ fileScope?: string;
757
+ /** Human-readable description of the rule and its rationale */
758
+ description: string;
759
+ /** Surfaces that must be updated (for requires_propagation rules) */
760
+ propagatesTo?: string[];
761
+ /** Severity — defaults to 'block' for confidence 1.0, 'warn' for >= 0.7, 'info' otherwise */
762
+ severity?: RuleSeverity;
763
+ /** Confidence — defaults to 1.0 (enforcement). Set lower for guidance/context. */
764
+ confidence?: number;
765
+ /** Override tenant ID */
766
+ tenantId?: string;
767
+ }
768
+ /** Input for updating (superseding) a rule. */
769
+ interface UpdateRuleInput {
770
+ /** ID of the rule to supersede */
771
+ ruleId: string;
772
+ /** Updated fields (only provided fields change; others carry forward) */
773
+ pattern?: string;
774
+ fileScope?: string;
775
+ description?: string;
776
+ propagatesTo?: string[];
777
+ severity?: RuleSeverity;
778
+ confidence?: number;
779
+ /** Override tenant ID */
780
+ tenantId?: string;
781
+ }
782
+ /** Options for querying rules. */
783
+ interface RuleQueryOptions {
784
+ /** Filter by rule type */
785
+ type?: RuleType;
786
+ /** Filter by severity */
787
+ severity?: RuleSeverity;
788
+ /** Include superseded rules in results (default: false) */
789
+ includeSuperseded?: boolean;
790
+ /** Override tenant ID */
791
+ tenantId?: string;
792
+ }
793
+
794
+ /**
795
+ * RulesNamespace — typed code guardrails stored as assertions.
796
+ *
797
+ * Rules are assertions with `rule:*` predicates and structured values.
798
+ * This namespace provides typed CRUD, file-scope matching, and intent-based
799
+ * queries so consumers work with `Rule` objects instead of raw assertions
800
+ * with JSON blobs stuffed into the value field.
801
+ *
802
+ * @example
803
+ * ```typescript
804
+ * // Create a rule
805
+ * const rule = await subcortex.rules.create({
806
+ * subject: 'intent:api',
807
+ * type: 'banned_pattern',
808
+ * pattern: 'NextResponse\\.json\\(',
809
+ * fileScope: 'app/api/.*\\.ts$',
810
+ * description: 'Use apiSuccess() instead of NextResponse.json()',
811
+ * })
812
+ *
813
+ * // Get all rules that apply to a file
814
+ * const rules = await subcortex.rules.forFile('app/api/users/route.ts')
815
+ *
816
+ * // Get enforcement rules only
817
+ * const enforcement = await subcortex.rules.list({ severity: 'block' })
818
+ * ```
819
+ */
820
+
821
+ declare class RulesNamespace {
822
+ private http;
823
+ private tenantId;
824
+ constructor(http: HttpTransport, tenantId: string);
825
+ /**
826
+ * Create a new rule.
827
+ *
828
+ * Stores an assertion with a `rule:*` predicate and a typed value.
829
+ * Defaults to confidence 1.0 (enforcement) if not specified.
830
+ *
831
+ * @example
832
+ * ```typescript
833
+ * await subcortex.rules.create({
834
+ * subject: 'project:my-project',
835
+ * type: 'banned_pattern',
836
+ * pattern: 'as any',
837
+ * description: 'No any casts — use proper types',
838
+ * })
839
+ * ```
840
+ */
841
+ create(input: CreateRuleInput): Promise<Rule>;
842
+ /**
843
+ * Get a rule by its assertion ID.
844
+ */
845
+ get(ruleId: string, options?: {
846
+ tenantId?: string;
847
+ }): Promise<Rule>;
848
+ /**
849
+ * List all rules for this project, optionally filtered by type or severity.
850
+ */
851
+ list(options?: RuleQueryOptions): Promise<Rule[]>;
852
+ /**
853
+ * Get all rules whose fileScope matches the given file path.
854
+ *
855
+ * This is the primary query for the PreToolUse hook — "what rules apply
856
+ * to the file I'm about to modify?"
857
+ *
858
+ * @example
859
+ * ```typescript
860
+ * const rules = await subcortex.rules.forFile('app/api/users/route.ts')
861
+ * // Returns banned_pattern and required_pattern rules whose fileScope
862
+ * // matches the path, plus any project-wide rules without a fileScope.
863
+ * ```
864
+ */
865
+ forFile(filePath: string, options?: RuleQueryOptions): Promise<Rule[]>;
866
+ /**
867
+ * Get all rules scoped to a specific intent subject.
868
+ *
869
+ * @example
870
+ * ```typescript
871
+ * const apiRules = await subcortex.rules.forIntent('api')
872
+ * // Queries subject "intent:api" for all rule assertions
873
+ * ```
874
+ */
875
+ forIntent(intent: string, options?: RuleQueryOptions): Promise<Rule[]>;
876
+ /**
877
+ * Get all rules scoped to a specific subject (project, file, intent, etc.).
878
+ */
879
+ forSubject(subject: string, options?: RuleQueryOptions): Promise<Rule[]>;
880
+ /**
881
+ * Update a rule by superseding it.
882
+ *
883
+ * The old rule is marked as superseded, a new one is created.
884
+ * Full assertion history is preserved.
885
+ */
886
+ update(input: UpdateRuleInput): Promise<Rule>;
887
+ /**
888
+ * Retract (deactivate) a rule.
889
+ *
890
+ * The assertion's temporal bounds are closed. The rule stops matching
891
+ * in future queries but its history is preserved.
892
+ */
893
+ retract(ruleId: string, options?: {
894
+ tenantId?: string;
895
+ }): Promise<void>;
896
+ }
897
+
688
898
  /**
689
899
  * SubCortexClient — the main entry point for the SubCortex SDK.
690
900
  *
@@ -1053,6 +1263,7 @@ interface ComposedInstructions {
1053
1263
  modelProvider: string;
1054
1264
  modelId: string;
1055
1265
  temperature: number;
1266
+ maxTokens: number;
1056
1267
  voiceId: string;
1057
1268
  }
1058
1269
  /**
@@ -1287,6 +1498,197 @@ declare class IntakeNamespace {
1287
1498
  /** Get intake processing stats for an agent. */
1288
1499
  stats(agentId: string): Promise<IntakeStats>;
1289
1500
  }
1501
+ interface Experience {
1502
+ id: string;
1503
+ tenant_id: string;
1504
+ agent_id: string | null;
1505
+ session_id: string;
1506
+ start_time: string;
1507
+ end_time: string | null;
1508
+ assertion_ids: string[];
1509
+ relationship_ids: string[];
1510
+ summary: string | null;
1511
+ topic: string | null;
1512
+ emotional_arc: string | null;
1513
+ }
1514
+ declare class ExperiencesNamespace {
1515
+ private http;
1516
+ private tenantId;
1517
+ constructor(http: HttpTransport, tenantId: string);
1518
+ /** List experiences, optionally filtered by subject. */
1519
+ list(input?: {
1520
+ subject?: string;
1521
+ limit?: number;
1522
+ tenantId?: string;
1523
+ }): Promise<Experience[]>;
1524
+ /** Get a single experience by ID. */
1525
+ get(experienceId: string, options?: {
1526
+ tenantId?: string;
1527
+ }): Promise<Experience>;
1528
+ }
1529
+ interface RecallResult {
1530
+ assertion_id: string;
1531
+ score: number;
1532
+ subject: string;
1533
+ predicate: string;
1534
+ snippet: string;
1535
+ }
1536
+ interface RecallSearchInput {
1537
+ query: string;
1538
+ limit?: number;
1539
+ tenantId?: string;
1540
+ }
1541
+ interface RecallSearchResponse {
1542
+ results: RecallResult[];
1543
+ total_hits: number;
1544
+ }
1545
+ declare class RecallNamespace {
1546
+ private http;
1547
+ private tenantId;
1548
+ constructor(http: HttpTransport, tenantId: string);
1549
+ /** BM25 full-text search across assertions. */
1550
+ search(input: RecallSearchInput): Promise<RecallSearchResponse>;
1551
+ }
1552
+ interface GraphPath {
1553
+ subjects: string[];
1554
+ total_confidence: number;
1555
+ length: number;
1556
+ }
1557
+ interface FindPathsInput {
1558
+ from: string;
1559
+ to: string;
1560
+ maxDepth?: number;
1561
+ minConfidence?: number;
1562
+ /** "shortest" | "highest_confidence" | "all" */
1563
+ strategy?: string;
1564
+ tenantId?: string;
1565
+ }
1566
+ interface TraversalNode {
1567
+ subject: string;
1568
+ depth: number;
1569
+ path_confidence: number;
1570
+ }
1571
+ interface TraversalResult {
1572
+ nodes: TraversalNode[];
1573
+ edge_count: number;
1574
+ depth_reached: number;
1575
+ truncated: boolean;
1576
+ }
1577
+ interface TraverseInput {
1578
+ startSubject: string;
1579
+ maxDepth?: number;
1580
+ relationshipTypes?: string[];
1581
+ minConfidence?: number;
1582
+ maxNodes?: number;
1583
+ tenantId?: string;
1584
+ }
1585
+ declare class GraphNamespace {
1586
+ private http;
1587
+ private tenantId;
1588
+ constructor(http: HttpTransport, tenantId: string);
1589
+ /** Find paths between two subjects. */
1590
+ findPaths(input: FindPathsInput): Promise<GraphPath[]>;
1591
+ /** BFS traversal from a starting subject. */
1592
+ traverse(input: TraverseInput): Promise<TraversalResult>;
1593
+ }
1594
+ interface TemporalSnapshot {
1595
+ subject: string;
1596
+ point: string;
1597
+ assertions: Assertion[];
1598
+ }
1599
+ interface TemporalRange {
1600
+ subject: string;
1601
+ start: string;
1602
+ end: string;
1603
+ assertions: Assertion[];
1604
+ }
1605
+ declare class TemporalNamespace {
1606
+ private http;
1607
+ private tenantId;
1608
+ constructor(http: HttpTransport, tenantId: string);
1609
+ /** Get assertions valid at a specific point in time. */
1610
+ at(subject: string, point: Date | string, options?: {
1611
+ tenantId?: string;
1612
+ }): Promise<TemporalSnapshot>;
1613
+ /** Get assertions within a date range. */
1614
+ range(subject: string, start: Date | string, end: Date | string, options?: {
1615
+ tenantId?: string;
1616
+ }): Promise<TemporalRange>;
1617
+ }
1618
+ interface SearchResult {
1619
+ assertion_id: string;
1620
+ similarity: number;
1621
+ }
1622
+ interface SemanticSearchInput {
1623
+ embedding: number[];
1624
+ topK?: number;
1625
+ tenantId?: string;
1626
+ }
1627
+ declare class SearchNamespace {
1628
+ private http;
1629
+ private tenantId;
1630
+ constructor(http: HttpTransport, tenantId: string);
1631
+ /** Semantic nearest-neighbor search over assertion embeddings. */
1632
+ semantic(input: SemanticSearchInput): Promise<SearchResult[]>;
1633
+ }
1634
+ interface CreateEntityInput {
1635
+ /** Entity name (used as the subject identifier, e.g. "Project") */
1636
+ name: string;
1637
+ /** Human-readable description */
1638
+ description?: string;
1639
+ /** Entity type classification (e.g. "model", "workflow", "reference") */
1640
+ type?: string;
1641
+ /** Override default tenant */
1642
+ tenantId?: string;
1643
+ }
1644
+ interface AddPropertyInput {
1645
+ /** Entity name this property belongs to */
1646
+ entityName: string;
1647
+ /** Property name */
1648
+ name: string;
1649
+ /** Property field type (e.g. "string", "number", "date", "boolean", "reference") */
1650
+ fieldType: string;
1651
+ /** Whether this property is required */
1652
+ required?: boolean;
1653
+ /** Override default tenant */
1654
+ tenantId?: string;
1655
+ }
1656
+ interface EntityDescription {
1657
+ subject: string;
1658
+ name: string;
1659
+ type: string | null;
1660
+ description: string | null;
1661
+ properties: Array<{
1662
+ name: string;
1663
+ fieldType: string | null;
1664
+ required: boolean;
1665
+ }>;
1666
+ relationships: Array<{
1667
+ type: string;
1668
+ target: string;
1669
+ confidence: number;
1670
+ }>;
1671
+ }
1672
+ declare class EntitiesNamespace {
1673
+ private http;
1674
+ private tenantId;
1675
+ constructor(http: HttpTransport, tenantId: string);
1676
+ /** Create an entity with optional description and type. */
1677
+ create(input: CreateEntityInput): Promise<Assertion>;
1678
+ /** Add a property to an entity. */
1679
+ addProperty(input: AddPropertyInput): Promise<{
1680
+ assertion: Assertion;
1681
+ relationship: Relationship;
1682
+ }>;
1683
+ /** Describe an entity by reconstructing its properties and relationships from assertions. */
1684
+ describe(entityName: string, options?: {
1685
+ tenantId?: string;
1686
+ }): Promise<EntityDescription>;
1687
+ /** List all entities for a tenant (subjects with entity: prefix that have a type predicate). */
1688
+ list(options?: {
1689
+ tenantId?: string;
1690
+ }): Promise<Assertion[]>;
1691
+ }
1290
1692
  declare class SubCortexClient {
1291
1693
  /** Assertion operations (low-level knowledge primitives) */
1292
1694
  readonly assertions: AssertionsNamespace;
@@ -1302,6 +1704,20 @@ declare class SubCortexClient {
1302
1704
  readonly users: UsersNamespace;
1303
1705
  /** Emotional signals — record, query, and resolve */
1304
1706
  readonly signals: SignalsNamespace;
1707
+ /** Graph queries — pathfinding and traversal */
1708
+ readonly graph: GraphNamespace;
1709
+ /** Temporal queries — point-in-time snapshots and range queries */
1710
+ readonly temporal: TemporalNamespace;
1711
+ /** Semantic search over assertion embeddings */
1712
+ readonly search: SearchNamespace;
1713
+ /** BM25 full-text recall search */
1714
+ readonly recall: RecallNamespace;
1715
+ /** Episodic memory — experiences grouped by session */
1716
+ readonly experiences: ExperiencesNamespace;
1717
+ /** Entity schema management — create, describe, and manage data models */
1718
+ readonly entities: EntitiesNamespace;
1719
+ /** Code guardrails — typed rules stored as assertions with file-scope matching */
1720
+ readonly rules: RulesNamespace;
1305
1721
  private readonly http;
1306
1722
  constructor(options: SubCortexClientOptions);
1307
1723
  /** Check SubCortex server health. */
@@ -1450,4 +1866,4 @@ declare class SubCortexTimeoutError extends SubCortexNetworkError {
1450
1866
  constructor(timeoutMs: number);
1451
1867
  }
1452
1868
 
1453
- export { type AgentCapability, type AgentConfig, type AgentInstructions, type AgentMemoryPolicy, type AgentModelConfig, type AgentPersonality, AgentsNamespace, type Assertion, AssertionsNamespace, type BatchResult, CONTEXT_SCHEMA_VERSION, type CandidateAssertion, type ComposedInstructions, ConfidenceLevel, type ConfidenceScore, ConfidenceScores, type ConflictItem, type ConnectedPerson, type ContextFormat, type ContextFormatOptions, type CreateAgentInput, type CreateAssertionInput, type CreateRelationshipInput, EntityPredicate, EntityRelationship, EventPredicate, type HealthResponse, type IdentifyUserInput, IdentityPredicate, IntakeNamespace, type IntakeResponseItem, type IntakeResult, type IntakeStats, type IntakeSubmission, MULTI_VALUE_PREDICATES, MemoryNamespace, MemoryPredicate, NEGATIVE_SIGNALS, OrgRelationship, POSITIVE_SIGNALS, type PaginatedResponse, Predicates, type Provenance, RELATIONSHIP_LABELS, REVERSE_RELATIONSHIPS, RapportPredicate, type RecordRapportInput, type RecordSignalInput, type RegisterPersonInput, type RegisterPersonResult, type Relationship, RelationshipTypes, RelationshipsNamespace, type ResolveSignalInput, type RetryConfig, SIGNAL_DECAY_CONFIG, SYSTEM_SIGNAL_TYPES, type SignalEntry, type SignalQueryOptions, type SignalSnapshot, type SignalType, SignalsNamespace, type StoreMemoryInput, SubCortexAuthenticationError, SubCortexAuthorizationError, SubCortexClient, type SubCortexClientOptions, SubCortexConflictError, SubCortexError, SubCortexNetworkError, SubCortexNotFoundError, SubCortexRateLimitError, SubCortexServerError, SubCortexTimeoutError, SubCortexValidationError, SubjectPrefix, type SupersedeAssertionInput, type SystemSignalType, type TemporalBounds, type Trajectory, type UpdateAgentInput, type UserIdentification, type UserMemory, UsersNamespace, WorkPredicate, confidenceToScore, formatContext, getDecayHalfLife, isValidSignalType, scoreToConfidence, subject, toContextXml };
1869
+ export { type AddPropertyInput, type AgentCapability, type AgentConfig, type AgentInstructions, type AgentMemoryPolicy, type AgentModelConfig, type AgentPersonality, AgentsNamespace, type Assertion, AssertionsNamespace, type BatchResult, CONTEXT_SCHEMA_VERSION, type CandidateAssertion, type ComposedInstructions, ConfidenceLevel, type ConfidenceScore, ConfidenceScores, type ConflictItem, type ConnectedPerson, type ContextFormat, type ContextFormatOptions, type CreateAgentInput, type CreateAssertionInput, type CreateEntityInput, type CreateRelationshipInput, type CreateRuleInput, EntitiesNamespace, type EntityDescription, EntityPredicate, EntityRelationship, EventPredicate, type Experience, ExperiencesNamespace, type FindPathsInput, GraphNamespace, type GraphPath, type HealthResponse, type IdentifyUserInput, IdentityPredicate, IntakeNamespace, type IntakeResponseItem, type IntakeResult, type IntakeStats, type IntakeSubmission, MULTI_VALUE_PREDICATES, MemoryNamespace, MemoryPredicate, NEGATIVE_SIGNALS, OrgRelationship, POSITIVE_SIGNALS, type PaginatedResponse, Predicates, type Provenance, RELATIONSHIP_LABELS, REVERSE_RELATIONSHIPS, RapportPredicate, RecallNamespace, type RecallResult, type RecallSearchInput, type RecallSearchResponse, type RecordRapportInput, type RecordSignalInput, type RegisterPersonInput, type RegisterPersonResult, type Relationship, RelationshipTypes, RelationshipsNamespace, type ResolveSignalInput, type RetryConfig, type Rule, type RulePredicate, RulePredicates, type RuleQueryOptions, type RuleSeverity, type RuleType, type RuleValue, RulesNamespace, SIGNAL_DECAY_CONFIG, SYSTEM_SIGNAL_TYPES, SearchNamespace, type SearchResult, type SemanticSearchInput, type SignalEntry, type SignalQueryOptions, type SignalSnapshot, type SignalType, SignalsNamespace, type StoreMemoryInput, SubCortexAuthenticationError, SubCortexAuthorizationError, SubCortexClient, type SubCortexClientOptions, SubCortexConflictError, SubCortexError, SubCortexNetworkError, SubCortexNotFoundError, SubCortexRateLimitError, SubCortexServerError, SubCortexTimeoutError, SubCortexValidationError, SubjectPrefix, type SupersedeAssertionInput, type SystemSignalType, type TemporalBounds, TemporalNamespace, type TemporalRange, type TemporalSnapshot, type Trajectory, type TraversalNode, type TraversalResult, type TraverseInput, type UpdateAgentInput, type UpdateRuleInput, type UserIdentification, type UserMemory, UsersNamespace, WorkPredicate, confidenceToScore, formatContext, getDecayHalfLife, isValidSignalType, scoreToConfidence, subject, toContextXml };