Skip to content

Commit 6f322d8

Browse files
committed
added includeTimestamps parameter to reflog tool (false during test); transcript tests
1 parent 6915423 commit 6f322d8

File tree

3 files changed

+117
-8
lines changed

3 files changed

+117
-8
lines changed

unison-cli/src/Unison/MCP/Tools.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,10 @@ reflogTool =
736736
openWorldHint = Just False
737737
},
738738
toolArgType = Proxy,
739-
toolHandler = \(ReflogToolArguments {projectContext, scope, limit}) -> handleToolError $ do
739+
toolHandler = \(ReflogToolArguments {projectContext, scope, limit, includeTimestamps}) -> handleToolError $ do
740740
let limitVal = fromMaybe 100 limit
741741
scopeVal = fromMaybe "branch" scope
742+
includeTs = fromMaybe True includeTimestamps
742743
Env {codebase} <- ask
743744

744745
-- Resolve project and branch from context
@@ -759,7 +760,7 @@ reflogTool =
759760
Nothing -> pure []
760761
Just branch -> Codebase.getProjectBranchReflog (limitVal + 1) branch.branchId
761762
-- Convert entries to JSON-friendly format
762-
pure $ map (reflogEntryToJSON schLength) rawEntries
763+
pure $ map (reflogEntryToJSON includeTs schLength) rawEntries
763764

764765
let hasMore = length entries > limitVal
765766
finalEntries = take limitVal entries
@@ -771,16 +772,16 @@ reflogTool =
771772
pure $ textToolResult $ Text.decodeUtf8 . BL.toStrict $ Aeson.encode response
772773
}
773774

774-
reflogEntryToJSON :: Int -> ProjectReflog.Entry Project ProjectBranch CausalHash -> Aeson.Value
775-
reflogEntryToJSON schLength entry =
776-
Aeson.object
775+
reflogEntryToJSON :: Bool -> Int -> ProjectReflog.Entry Project ProjectBranch CausalHash -> Aeson.Value
776+
reflogEntryToJSON includeTimestamps schLength entry =
777+
Aeson.object $
777778
[ "project" Aeson..= (into @Text $ entry.project.name),
778779
"branch" Aeson..= (into @Text $ entry.branch.name),
779-
"time" Aeson..= iso8601Show entry.time,
780780
"fromHash" Aeson..= fmap (("#" <>) . SCH.toText . SCH.fromHash schLength) entry.fromRootCausalHash,
781781
"toHash" Aeson..= (("#" <>) . SCH.toText . SCH.fromHash schLength $ entry.toRootCausalHash),
782782
"reason" Aeson..= entry.reason
783783
]
784+
<> ["time" Aeson..= iso8601Show entry.time | includeTimestamps]
784785

785786
historyTool :: Tool MCP
786787
historyTool =

unison-cli/src/Unison/MCP/Types.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,8 @@ instance FromJSON DeleteNamespaceToolArguments where
960960
data ReflogToolArguments = ReflogToolArguments
961961
{ projectContext :: ProjectContext,
962962
scope :: Maybe Text, -- "branch" | "project" | "global", default "branch"
963-
limit :: Maybe Int
963+
limit :: Maybe Int,
964+
includeTimestamps :: Maybe Bool -- default True
964965
}
965966
deriving (Eq, Show)
966967

@@ -981,6 +982,11 @@ instance HasInputSchema ReflogToolArguments where
981982
.= object
982983
[ "type" .= ("integer" :: Text),
983984
"description" .= ("Maximum number of entries to return. Default is 100." :: Text)
985+
],
986+
"includeTimestamps"
987+
.= object
988+
[ "type" .= ("boolean" :: Text),
989+
"description" .= ("Whether to include timestamps in the output. Default is true." :: Text)
984990
]
985991
],
986992
"required" .= ["projectContext" :: Text]
@@ -991,7 +997,8 @@ instance FromJSON ReflogToolArguments where
991997
projectContext <- o .: "projectContext"
992998
scope <- o .:? "scope"
993999
limit <- o .:? "limit"
994-
pure $ ReflogToolArguments {projectContext, scope, limit}
1000+
includeTimestamps <- o .:? "includeTimestamps"
1001+
pure $ ReflogToolArguments {projectContext, scope, limit, includeTimestamps}
9951002

9961003
-- | Arguments for the history tool
9971004
data HistoryToolArguments = HistoryToolArguments

unison-src/transcripts/idempotent/mcp.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,3 +824,104 @@ RESPONSE:
824824
}
825825
826826
```
827+
828+
## reflog
829+
830+
First, set up a branch with some changes to create reflog entries:
831+
832+
``` ucm
833+
scratch/reflog-test> builtins.merge lib.builtins
834+
835+
Done.
836+
```
837+
838+
``` unison :hide
839+
reflogTestTerm = 1
840+
```
841+
842+
``` ucm
843+
scratch/reflog-test> update
844+
845+
Okay, I'm searching the branch for code that needs to be
846+
updated...
847+
848+
Done.
849+
```
850+
851+
Now get the reflog:
852+
853+
``` api
854+
POST /mcp
855+
BODY:
856+
{
857+
"jsonrpc": "2.0",
858+
"id": 1,
859+
"method": "tools/call",
860+
"params": {
861+
"name": "reflog",
862+
"arguments": {
863+
"projectContext": {
864+
"projectName": "scratch",
865+
"branchName": "reflog-test"
866+
},
867+
"scope": "branch",
868+
"limit": 5,
869+
"includeTimestamps": false
870+
}
871+
}
872+
}
873+
874+
RESPONSE:
875+
{
876+
"id": 1,
877+
"jsonrpc": "2.0",
878+
"result": {
879+
"content": [
880+
{
881+
"text": "{\"entries\":[{\"branch\":\"reflog-test\",\"fromHash\":\"#btddbo4t1j\",\"project\":\"scratch\",\"reason\":\"update\",\"toHash\":\"#6bknb5j9uv\"},{\"branch\":\"reflog-test\",\"fromHash\":\"#sg60bvjo91\",\"project\":\"scratch\",\"reason\":\"builtins.merge scratch/reflog-test:lib.builtins\",\"toHash\":\"#btddbo4t1j\"},{\"branch\":\"reflog-test\",\"fromHash\":null,\"project\":\"scratch\",\"reason\":\"Branch Created\",\"toHash\":\"#sg60bvjo91\"}],\"hasMore\":false}",
882+
"type": "text"
883+
}
884+
],
885+
"isError": false
886+
}
887+
}
888+
889+
```
890+
891+
## history
892+
893+
``` api
894+
POST /mcp
895+
BODY:
896+
{
897+
"jsonrpc": "2.0",
898+
"id": 1,
899+
"method": "tools/call",
900+
"params": {
901+
"name": "history",
902+
"arguments": {
903+
"projectContext": {
904+
"projectName": "scratch",
905+
"branchName": "reflog-test"
906+
},
907+
"limit": 5
908+
}
909+
}
910+
}
911+
912+
RESPONSE:
913+
{
914+
"id": 1,
915+
"jsonrpc": "2.0",
916+
"result": {
917+
"content": [
918+
{
919+
"text": "{\"errorMessages\":[],\"outputMessages\":[\"Note: The most recent namespace hash is immediately below this message.\\n\\n⊙ 1. #6bknb5j9uv\\n\\n + Adds / updates:\\n \\n reflogTestTerm\\n\\n□ 2. #btddbo4t1j (start of history)\"],\"sourceCodeUpdates\":[],\"stderr\":\"\",\"stdout\":\"\"}",
920+
"type": "text"
921+
}
922+
],
923+
"isError": false
924+
}
925+
}
926+
927+
```

0 commit comments

Comments
 (0)