{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package taskdetect\n\nPackage taskdetect notices when work the user just did should become a durable capability, and proposes the task that would do it.\n\nTwo independent kinds of evidence feed one proposal system:\n\n\ta STRONG single turn   this piece of work is plainly repeatable\n\tREPEATED weak signals  the same capability keeps being asked for\n\nThe second is the one that matters. Anyone can suggest cron. Recognising \"you have asked me to keep provider catalogs current four times across three sessions, shall I just keep them current\" is memcode learning a capability from working with someone, and it is a different message with a different weight.\n\nThe detector's output is a PROPOSED TASK, never a boolean. Interrupting somebody to ask \"want to automate that?\" and then making them answer a configuration questionnaire is worse than not asking: if there is enough confidence to interrupt, there is enough to propose cadence, authority, verification and runtime, and let them accept it whole.\n\n## Constants\n\n```go\nconst (\n\tActionCreate    = \"create\"\n\tActionCustomize = \"customize\"\n\tActionNotNow    = \"not_now\"\n\tActionNever     = \"never\"\n)\n```\nThe four actions. Deliberately not Yes/No: the difference between \"not right now\" and \"never this kind\" is the difference between a system that learns and one that nags.\n\n## Functions\n\n```go\nfunc DBPath() (string, error)\n```\nDBPath keeps signals alongside the rest of memcode's per-machine state.\n\n```go\nfunc Ready(c Cluster) bool\n```\nReady reports whether a cluster is worth offering, by EITHER path.\n\nBoth are checked here because a prospective offer is made in the middle of a session, where nothing may interrupt — so it waits with the historical ones, and would be silently lost if this only knew about accumulated evidence.\n\n```go\nfunc WouldOfferOnFirstContact(p Proposal) bool\n```\nWouldOfferOnFirstContact reports whether a proposal clears the first-contact bar, without touching any store. Exported so the detector evaluation measures the REAL rule rather than a paraphrase of it that can drift.\n\n## Types\n\n```go\ntype Classifier interface {\n\tClassify(ctx context.Context, in Turn) (Proposal, bool, error)\n}\n```\nClassifier turns a finished turn into a proposal. Injectable: the real one costs a model call, and the pipeline around it has to be testable without one.\n\n```go\ntype Cluster struct {\n\tFamilyKey string\n\tFamily    string\n\tProject   string\n\t// Weight is confidence summed with age decay. Sessions counts DISTINCT\n\t// sessions, which is the part that matters: three signals in one\n\t// conversation is one person repeating themselves, not a pattern.\n\tWeight   float64\n\tSessions int\n\tSignals  int\n\t// Latest is the most recent proposal, used for the offer — the newest\n\t// phrasing of the capability is the one to show back.\n\tLatest   Proposal\n\tEvidence []string\n\tLastSeen time.Time\n}\n```\nCluster is the accumulated evidence for one capability.\n\n```go\nfunc (c Cluster) Capability() Proposal\n```\nCapability returns the cluster's proposal named for the CAPABILITY rather than for whichever instance happened to be seen last.\n\nA cluster is the recognised standing job; accepting it should produce \"provider-catalog-maintenance\", not \"check-fireworks-catalog\" just because Fireworks was the most recent thing asked about. The instance name is right for a single-turn offer and wrong here.\n\n```go\ntype Decision struct {\n\tKind     Kind\n\tProposal Proposal\n\t// Sessions and Occasions describe the evidence behind a repeated offer.\n\tSessions  int\n\tOccasions int\n\t// Why explains a decision NOT to offer, for the debug surface. Silence that\n\t// cannot be explained is indistinguishable from a broken detector.\n\tWhy string\n}\n```\nDecision is the outcome of evaluating a turn.\n\n```go\nfunc ClusterDecision(c Cluster) Decision\n```\nClusterDecision renders a waiting cluster as the offer it should become.\n\nAccumulated evidence wins when it exists: \"you have asked me this three times\" is a stronger and more personal claim than \"this kind of thing recurs\", and having earned it, memcode should say it.\n\n```go\ntype Detector struct {\n\tStore      *Store\n\tClassifier Classifier\n}\n```\nDetector evaluates finished turns and decides whether to offer anything.\n\n```go\nfunc (d *Detector) Evaluate(ctx context.Context, in Turn, now time.Time) (Decision, error)\n```\nEvaluate classifies a turn, records what it learned, and reports whether to make an offer.\n\nRecording happens even when no offer follows: today's weak signal is what makes next month's recognition possible, and a detector that only remembers what it already acted on can never learn anything.\n\n```go\ntype Effect string\n```\nEffect says what a run of this work does to the repository.\n\n```go\nconst (\n\t// EffectNone reads and reports; it changes nothing.\n\tEffectNone Effect = \"none\"\n\t// EffectPossible may change code, depending on what it finds. The common\n\t// case for maintenance: usually nothing to do, sometimes a real diff.\n\tEffectPossible Effect = \"possible\"\n\t// EffectExpected changes code essentially every run.\n\tEffectExpected Effect = \"expected\"\n)\n```\n\n```go\ntype Gap struct {\n\tField    string\n\tQuestion string\n\tWhy      string\n}\n```\nGap is something that must be settled before a task can safely run unattended, with the question to ask.\n\n```go\ntype Kind string\n```\nKind is which evidence path produced an offer. They read differently to the user because they mean different things.\n\n```go\nconst (\n\t// KindNone: nothing to offer.\n\tKindNone Kind = \"\"\n\t// KindProspective: the work will be needed again for a reason that exists in\n\t// the world, said on FIRST contact. The primary path — memcode understanding\n\t// the work rather than waiting to watch someone repeat it.\n\tKindProspective Kind = \"prospective\"\n\t// KindRepeated: recurrence learned from behaviour instead of inferred. The\n\t// fallback, and the right answer when the work has no inherent cadence but\n\t// this particular person keeps wanting it.\n\tKindRepeated Kind = \"repeated\"\n\t// KindExplicit: the user asked for it to be automated. No inference needed.\n\tKindExplicit Kind = \"explicit\"\n)\n```\n\n```go\ntype Offer struct {\n\tHeadline string\n\tDetail   string\n\tOptions  []Option\n}\n```\nOffer is the message and choices shown to the user.\n\n```go\nfunc Message(d Decision) Offer\n```\nMessage renders the offer for a decision.\n\nThe two paths read differently ON PURPOSE. A single-turn offer is a suggestion about the work just done. A repeated offer is memcode saying it noticed a habit and can take it over — which is a materially bigger claim, and flattening both into one generic automation prompt throws away the only part that is interesting.\n\n```go\ntype Option struct {\n\tKey         string\n\tLabel       string\n\tDescription string\n}\n```\nOption is one action.\n\n```go\ntype Proposal struct {\n\t// Family is the SEMANTIC identity of the capability, normalized. It is what\n\t// lets three differently worded requests accumulate into one recognised\n\t// thing, so it names a capability rather than an instance:\n\t// \"provider-model-catalog-maintenance\", not \"update-anthropic-models\".\n\tFamily string `json:\"task_family\"`\n\t// Operation and Target are the parts Family is built from, kept separately\n\t// because they are what a human reads when asked to confirm the grouping.\n\tOperation string `json:\"operation\"`\n\tTarget    string `json:\"target\"`\n\t// Scope and Project bound where the capability applies.\n\tScope   string `json:\"scope\"`\n\tProject string `json:\"project,omitempty\"`\n\t// Constraints are the conditions that must hold for the work to be correct\n\t// (\"verify prices against the vendor's page\"). Part of identity: the same\n\t// operation under materially different constraints is different work.\n\tConstraints []string `json:\"constraints,omitempty\"`\n\n\tName         string   `json:\"name\"`\n\tReason       string   `json:\"reason\"`\n\tInstructions string   `json:\"instructions\"`\n\tVerify       []string `json:\"verify,omitempty\"`\n\n\t// SuggestedEvery is a Go duration (\"168h\") and SuggestedCron a 5-field\n\t// expression; at most one is set.\n\tSuggestedEvery string `json:\"suggested_every,omitempty\"`\n\tSuggestedCron  string `json:\"suggested_cron,omitempty\"`\n\n\tEffect Effect `json:\"code_changes\"`\n\t// Confidence that the work is well-shaped enough to automate at all.\n\tConfidence float64 `json:\"confidence\"`\n\t// Trigger is what starts each occurrence. Only TriggerClock work is a\n\t// schedule; anything else (including a proposal recorded before this field\n\t// existed) is not offered unless the user asked for the automation.\n\tTrigger Trigger `json:\"trigger,omitempty\"`\n\t// Recurrence is the causal claim about whether it will be needed again.\n\t// Separate from Confidence on purpose: work can be perfectly automatable and\n\t// still never need doing twice.\n\tRecurrence Recurrence `json:\"recurrence\"`\n\t// ExplicitRequest is the user actually asking for this to be automated,\n\t// which needs no inference at all.\n\tExplicitRequest bool `json:\"explicit_request,omitempty\"`\n\t// ClarifyingQuestions are decisions the model could not make for the user —\n\t// usually scope or side effects. \"Should major version bumps be included?\"\n\t// is a different task depending on the answer, and guessing it silently is\n\t// how an autonomous job does something nobody asked for.\n\tClarifyingQuestions []string `json:\"clarifying_questions,omitempty\"`\n\n\t// The four eligibility gates. Repetition alone is NOT enough: a password\n\t// reset recurs, a vague \"make this better\" recurs, an emotionally repetitive\n\t// question recurs, and none of them is a capability worth handing to an\n\t// unattended machine.\n\tBounded        bool `json:\"bounded\"`\n\tReproducible   bool `json:\"reproducible\"`\n\tUnattendedSafe bool `json:\"unattended_safe\"`\n\tEvaluable      bool `json:\"evaluable\"`\n}\n```\nProposal is a task memcode believes it could take over, with everything needed to create it.\n\n```go\nfunc (p Proposal) Eligible() bool\n```\nEligible reports whether the work qualifies at all, independent of how confident or how often it has been seen.\n\n```go\nfunc (p Proposal) FamilyKey() string\n```\nFamilyKey is the coarser identity used for SUPPRESSION and for grouping signals: family plus scope plus project, without the constraint detail.\n\nCoarser on purpose. Someone who says \"don't suggest this kind\" means the kind, not that exact phrasing with that exact constraint list — and an offer that returns next week because one condition differed is the behaviour they were trying to stop.\n\n```go\nfunc (p Proposal) Fingerprint() string\n```\nFingerprint is the durable identity signals accumulate against.\n\nBuilt from MEANING — operation, target, scope, project, constraints — and not from wording. \"Update our Anthropic models\", \"OpenAI added models, update ours\" and \"is the Fireworks catalog stale again?\" share no useful phrasing and are the same capability; a fingerprint over words would file them as three unrelated things and never notice the pattern.\n\n```go\nfunc (p Proposal) Gaps() []Gap\n```\nGaps reports what is missing before this task should be created.\n\nThe point is NOT to interrogate the user. Most of a task is inferable and should be inferred; these are the few things where guessing wrong has consequences that only show up later, at 3am, with nobody watching.\n\n```go\nfunc (p Proposal) IneligibleReason() string\n```\nIneligibleReason names the first failing gate, for a log line.\n\n```go\nfunc (p Proposal) Ready() bool\n```\nReady reports whether the proposal can be created without asking anything.\n\n```go\nfunc (p Proposal) SameCapability(q Proposal) bool\n```\nSameCapability reports whether two proposals describe one capability: the same family key, or near-identical family names within the same scope and project.\n\n```go\nfunc (p Proposal) ToTask(now time.Time) (task.Task, error)\n```\nToTask converts a proposal into a real task definition.\n\nEvery field is filled from the proposal or from a documented default, so accepting an offer writes a COMPLETE, valid task and never opens a questionnaire. Anything the proposal did not determine falls to the same defaults a hand-written file would get.\n\n```go\ntype Recurrence struct {\n\tKind RecurrenceKind `json:\"kind\"`\n\t// Cause states WHAT makes it recur, in the model's own words. Required for\n\t// a prospective offer: an offer that cannot say why is a guess, and it goes\n\t// in the message so the user can judge the reasoning rather than the verdict.\n\tCause string `json:\"cause,omitempty\"`\n\t// Confidence in the causal claim, distinct from confidence that the work is\n\t// well-shaped.\n\tConfidence float64 `json:\"confidence\"`\n\t// Value is what automating it buys — usually \"notice X without you having\n\t// to remember to look\".\n\tValue string `json:\"value,omitempty\"`\n}\n```\nRecurrence is the structured reason to expect the work again.\n\n```go\nfunc (r Recurrence) Inherent() bool\n```\nInherent reports whether the work recurs for a reason that exists in the world, independent of this user's habits. These are the offers that can be made on first contact.\n\n```go\ntype RecurrenceKind string\n```\nRecurrenceKind is WHY this work would happen again — the causal claim behind an offer, rather than an observation that it happened twice.\n\nThis is the difference between a system that notices patterns and one that understands work. \"Update our Anthropic models\" is obviously recurring the FIRST time it is asked, because upstream vendors change their models whether or not anyone here is watching. Waiting to see it three times before saying so makes memcode look less intelligent than it is.\n\n```go\nconst (\n\t// RecurrenceOneOff will not happen again: renaming the product, fixing one\n\t// specific bug. Bounded, reproducible and evaluable — and still not a\n\t// standing job, which is exactly why the four gates are not enough on their\n\t// own.\n\tRecurrenceOneOff RecurrenceKind = \"one_off\"\n\t// RecurrenceExternal recurs because the WORLD changes independently of this\n\t// repository: vendors ship models, packages release versions, advisories\n\t// appear, certificates expire. The strongest reason to offer immediately.\n\tRecurrenceExternal RecurrenceKind = \"externally_recurring\"\n\t// RecurrenceInternal recurs because of this project's own rhythm:\n\t// regenerating a report as data lands, re-running a check as code grows.\n\tRecurrenceInternal RecurrenceKind = \"internally_recurring\"\n\t// RecurrenceUserPattern is not inherent to the work — it recurs because\n\t// THIS person keeps wanting it. Not knowable on first contact; this is what\n\t// accumulated history is for.\n\tRecurrenceUserPattern RecurrenceKind = \"user_pattern\"\n\t// RecurrenceUncertain: no confident causal claim either way.\n\tRecurrenceUncertain RecurrenceKind = \"uncertain\"\n)\n```\n\n```go\ntype Signal struct {\n\tID          string\n\tSessionID   string\n\tObservedAt  time.Time\n\tProject     string\n\tFamily      string\n\tFamilyKey   string\n\tFingerprint string\n\tOperation   string\n\tTarget      string\n\tScope       string\n\tConfidence  float64\n\tEvidence    string\n\tProposal    Proposal\n}\n```\nSignal is one observation that a capability might be worth automating.\n\n```go\ntype Store struct {\n\t// contains filtered or unexported fields\n}\n```\nStore is the durable signal and suppression record.\n\n```go\nfunc Open(ctx context.Context, path string) (*Store, error)\n```\nOpen creates or opens the signal store.\n\n```go\nfunc OpenDefault(ctx context.Context) (*Store, error)\n```\nOpenDefault opens the store at its standard location.\n\n```go\nfunc (s *Store) Close() error\n```\n\n```go\nfunc (s *Store) Clusters(ctx context.Context, project string, now time.Time) ([]Cluster, error)\n```\nClusters groups signals into capabilities, newest evidence first.\n\nGrouping is by family key, then MERGED across near-identical family names via SameCapability — so a classifier that named the same thing slightly differently on two occasions still accumulates rather than splitting.\n\n```go\nfunc (s *Store) Forget(ctx context.Context, p Proposal) error\n```\nForget drops signals for a capability, used when a task is actually created so its own evidence stops re-proposing it.\n\n```go\nfunc (s *Store) Prune(ctx context.Context, before time.Time) error\n```\nPrune drops evidence too old to matter, keeping the store small.\n\n```go\nfunc (s *Store) Record(ctx context.Context, sessionID string, p Proposal, evidence string, now time.Time) (Signal, error)\n```\nRecord persists one observation.\n\n```go\nfunc (s *Store) Suppress(ctx context.Context, p Proposal, now time.Time) error\n```\nSuppress records a durable \"don't suggest this kind\", keyed to the capability rather than the wording.\n\nDeclining to automate provider-catalog updates says nothing about whether to automate a weekly dependency audit, so suppression attaches to family, scope and project — never to \"automation\" in general.\n\n```go\nfunc (s *Store) Suppressed(ctx context.Context, p Proposal) (bool, error)\n```\nSuppressed reports whether this capability has been refused durably.\n\nChecks the exact family key and, because a classifier's naming drifts, any suppressed family near enough to be the same capability. Someone who said no once should not be asked again because the wording moved.\n\n```go\nfunc (s *Store) Suppressions(ctx context.Context) ([]string, error)\n```\nSuppressions lists what has been refused, for \\`task suggestions\\`.\n\n```go\nfunc (s *Store) Unsuppress(ctx context.Context, family string) (int, error)\n```\nUnsuppress lifts a durable refusal.\n\n```go\ntype Trigger string\n```\nTrigger is what STARTS the work. Only clock-triggered work can be a schedule: a timer can notice that a vendor shipped or a certificate is near expiry, but it cannot know that the user just merged a change or cut a release. Work that follows a step in the user's own work recurs, but each occurrence is started by a decision, not by time.\n\n```go\nconst (\n\t// TriggerClock: something changes on its own time, and checking on a\n\t// schedule notices it (models ship and retire, packages release,\n\t// advisories appear, certificates near expiry, data lands).\n\tTriggerClock Trigger = \"clock\"\n\t// TriggerYourWork: it follows a step in the user's own work (after a\n\t// change merges, after a release is cut, after a deploy). Shipping and\n\t// watching what was just shipped belong here.\n\tTriggerYourWork Trigger = \"your_work\"\n)\n```\n\n```go\ntype Turn struct {\n\tSessionID string\n\tProject   string\n\t// Request is what the user asked for, Summary what was done.\n\tRequest string\n\tSummary string\n\t// Changed reports whether the turn actually altered the repository — weak\n\t// but real evidence that the work was substantive.\n\tChanged bool\n}\n```\nTurn is what the detector sees after work completes.\n\n","path":"github.com/memcode-ai/memcode/internal/taskdetect","name":"taskdetect","synopsis":"Package taskdetect notices when work the user just did should become a durable capability, and proposes the task that would do it.","isRedistributable":true}
