@subcortex-ai/sdk 0.2.0 → 0.3.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/dist/index.cjs +273 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +211 -1
- package/dist/index.d.ts +211 -1
- package/dist/index.js +271 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -687,6 +687,214 @@ declare class SignalsNamespace {
|
|
|
687
687
|
}>;
|
|
688
688
|
}
|
|
689
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
|
+
|
|
690
898
|
/**
|
|
691
899
|
* SubCortexClient — the main entry point for the SubCortex SDK.
|
|
692
900
|
*
|
|
@@ -1508,6 +1716,8 @@ declare class SubCortexClient {
|
|
|
1508
1716
|
readonly experiences: ExperiencesNamespace;
|
|
1509
1717
|
/** Entity schema management — create, describe, and manage data models */
|
|
1510
1718
|
readonly entities: EntitiesNamespace;
|
|
1719
|
+
/** Code guardrails — typed rules stored as assertions with file-scope matching */
|
|
1720
|
+
readonly rules: RulesNamespace;
|
|
1511
1721
|
private readonly http;
|
|
1512
1722
|
constructor(options: SubCortexClientOptions);
|
|
1513
1723
|
/** Check SubCortex server health. */
|
|
@@ -1656,4 +1866,4 @@ declare class SubCortexTimeoutError extends SubCortexNetworkError {
|
|
|
1656
1866
|
constructor(timeoutMs: number);
|
|
1657
1867
|
}
|
|
1658
1868
|
|
|
1659
|
-
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, 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, 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 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -687,6 +687,214 @@ declare class SignalsNamespace {
|
|
|
687
687
|
}>;
|
|
688
688
|
}
|
|
689
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
|
+
|
|
690
898
|
/**
|
|
691
899
|
* SubCortexClient — the main entry point for the SubCortex SDK.
|
|
692
900
|
*
|
|
@@ -1508,6 +1716,8 @@ declare class SubCortexClient {
|
|
|
1508
1716
|
readonly experiences: ExperiencesNamespace;
|
|
1509
1717
|
/** Entity schema management — create, describe, and manage data models */
|
|
1510
1718
|
readonly entities: EntitiesNamespace;
|
|
1719
|
+
/** Code guardrails — typed rules stored as assertions with file-scope matching */
|
|
1720
|
+
readonly rules: RulesNamespace;
|
|
1511
1721
|
private readonly http;
|
|
1512
1722
|
constructor(options: SubCortexClientOptions);
|
|
1513
1723
|
/** Check SubCortex server health. */
|
|
@@ -1656,4 +1866,4 @@ declare class SubCortexTimeoutError extends SubCortexNetworkError {
|
|
|
1656
1866
|
constructor(timeoutMs: number);
|
|
1657
1867
|
}
|
|
1658
1868
|
|
|
1659
|
-
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, 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, 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 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 };
|